Shop OBEX P1 Docs P2 Docs Learn Events
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 115 — Parallax Forums

flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler

1109110111112113115»

Comments

  • In Spin, "global" variables (the ones in the VAR sections) should be initialized to zero. However, if I run the attached code it prints out

    Cog0  init head = $0, tail = $5, used = $5
    Cog0  zero head = $0, tail = $0, used = $0
    

    which means that the variables tail and used are NOT initialized to zero. As none of my code is executed before Demo() I think it's not my fault. Somehow the memory for the VAR section must have been overwritten with something else. If I change the code only a slight bit (different length of the strings or removing one of the debug() statements, for example) the contents of the variables also change. BTW, after initializing the variables to zero manually, the rest of the program works as expected.

  • It gets even funnier if I call functions of DebugLog.spin2 from C code instead of compiling it stand-alone. I get error messages like

    C:/flexprop/include/libc/stdio/fprintf.c:23: error: unknown identifier putchar in class _struct___fmtfile
    C:/flexprop/include/libc/stdio/fprintf.c:23: error: putchar is not a member of _struct___fmtfile
    

    I guess that the OBJ c: "libc.spin2" trick works for Spin only programs but creates some name space conflicts if C and Spin are mixed together.

    enum {_clkfreq = 200_000_000, _xtlfreq = 25_000_000};
    
    struct __using ("DebugLog.spin2") log;
    
    void main ()
    {
        log.Print0 ("hello world");
        log.DumpBuffer ();
        while (1) {};
    }
    
  • ersmithersmith Posts: 5,894

    @ManAtWork When I run your DebugLog.spin2 program stand-alone it prints:

    ( Entering terminal mode.  Press Ctrl-] or Ctrl-Z to exit. )
    Cog0  INIT $0000_0000 $0000_0000 load
    Cog0  INIT $0000_0404 $0000_0000 load
    Cog0  init head = $0, tail = $0, used = $0
    Cog0  zero head = $0, tail = $0, used = $0
    Cog0  Alloc head = $0, tail = $0, used = $0
    Cog0  exit head = $0, tail = $0, used = $2
    Cog0  Alloc head = $2, tail = $0, used = $2
    Cog0  exit head = $2, tail = $0, used = $5
    

    which I think is expected. Are you using loadp2 to run your program, or have you put it in flash? There might be some kind of startup problem when booting from flash, perhaps the boot code in ROM does not zero memory in this case.

    As for using DebugLog.spin2 from a C program, you'll end up with two copies of the C library (the normal one plus the one loaded by libc.spin2 inside DebugLog.spin2) and that almost certainly won't work, even if you could get it to compile.

Sign In or Register to comment.