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

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

15354565859122

Comments

  • It's me again... My losing streak has no end.
      printf ("x=%04x\n", x);
    
    works as expected but
      printf ("x=%04X\n", x);
    
    results in a very strange error message: "Changing lastorg value for symbol startPid". The symbol startPid is defined in a global _asm{} block in a completely different file.

    BTW, what is the printf "%" symbol for "please always use 4 digits even if the number is negative", i.e. print "FFFF" instead of "FFFFFFFF"?

    And another one: (no bug, just an inconvenience)
    After #inlude-ing <stdio.h> I got an error saying that the symbol "time" is redefined. Before the #include the file compiled without errors. I found out that <stdio.h> includes <sys/types.h> which somewhere defines a time. Well, in the end I had to simply rename my variable, no problem. But it would be very helpful if the "symbol redefined" message would also tell where the symbol had been declared FIRST.
  • RaymanRayman Posts: 14,646
    4.2.0 seems to break my inline assembly for eMMC driver. This is not using FCACHE. Doesn't work with FCACHE either.
  • ManAtWork wrote: »
    It's me again... My losing streak has no end.
      printf ("x=%04x\n", x);
    
    works as expected but
      printf ("x=%04X\n", x);
    
    results in a very strange error message: "Changing lastorg value for symbol startPid". The symbol startPid is defined in a global _asm{} block in a completely different file.
    Would you be able to send me this example? I can understand why the two printfs are different (the first one can use the builtin printf, the second one calls the library because 'X' is not one of the letters handled by the built in one) but I cannot make either one cause an error in the examples I've tried.
    BTW, what is the printf "%" symbol for "please always use 4 digits even if the number is negative", i.e. print "FFFF" instead of "FFFFFFFF"?
    C doesn't have this feature. You have to use a mask, e.g.:
      printf("x=%04X\n", x & 0xFFFF);
    
    After #inlude-ing <stdio.h> I got an error saying that the symbol "time" is redefined. Before the #include the file compiled without errors. I found out that <stdio.h> includes <sys/types.h> which somewhere defines a time. Well, in the end I had to simply rename my variable, no problem. But it would be very helpful if the "symbol redefined" message would also tell where the symbol had been declared FIRST.

    I'll see what I can do to improve the errors in these cases.
  • ersmith wrote: »
    C doesn't have this feature. You have to use a mask, e.g.:
      printf("x=%04X\n", x & 0xFFFF);
    
    Could you also do this?
      printf("x=%04.4X\n", x);
    

  • David Betz wrote: »
    ersmith wrote: »
    C doesn't have this feature. You have to use a mask, e.g.:
      printf("x=%04X\n", x & 0xFFFF);
    
    Could you also do this?
      printf("x=%04.4X\n", x);
    
    I guess not. At least it doesn't work with the Xcode C compiler.

  • evanhevanh Posts: 15,916
    Rayman wrote: »
    4.2.0 seems to break my inline assembly for eMMC driver. This is not using FCACHE. Doesn't work with FCACHE either.
    Ah, right, that makes sense. Don't use --fcache for old timing sensitive code. Fastspin originally only used hubexec for inline assembly code. You can ignore the new warning, it should work.

  • sdspi_bashed.spin2 works for me both with and without fcache.
  • evanhevanh Posts: 15,916
    Huh, you're right Eric. I had to reduce the later edition 297 MHz sysclock back down to 250 MHz but I think that was always true. I've been using my own low-level replacement code so haven't been keeping up with Rayman's low-level routines.

  • Cluso99Cluso99 Posts: 18,069
    edited 2020-05-31 00:43
    Eric,
    Postedit: Found it was missing CON section header. But it did not fail on the first, nor on the many, just 3 lines

    Not sure about which options to use. I'm just doing this
    f420 %1.spin2 -2 -l
    l420 %1.binary -b115200 -t -SINGLE
    

    I have a compiler problem with these errors using fastspin v4.2.0. I also tried v4.1.9 with same issues.
    C:\P2\Propeller_II_Latest\ClusoZ80>f420 test-002.spin2 -2 -l
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2020 Total Spectrum Software Inc.
    Version 4.2.0 Compiled on: May 29 2020
    test-002.spin2
    SD_LUT.spin2:72: error: syntax error, unexpected '='
    SD_LUT.spin2:87: error: syntax error, unexpected '='
    SD_LUT.spin2:93: error: syntax error, unexpected '='
    
    The relevant lines are these
      _hub              = $fc500        ' base of sd driver hub code
      sdx_cs            = 60            ' pin SD Card select
      sdx_sector        = _regs +$001   ' sector number to read/write (shared with sdx_ctr1)
    
    They are in an include file. If I put those lines into the main file and remove the included file it compiles fine. I tried renaming them but that didn't fix the problem. I looked at the source with embedded characters shown and there is nothing that I can see around those lines that might cause this error.

    Thanks Eric :)
  • evanhevanh Posts: 15,916
    Cluso,
    I think you've missed out a CON directive.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-05-31 00:41
    yes. Just about to post that I found the problem :(

    Interestingly it didn't fail on the first equate line, nor on the all the others, just 3 of the many of equates.
  • avsa242avsa242 Posts: 452
    edited 2020-05-31 12:25
    Hi Eric,

    Would it be practical to modify the preprocessor so that #defines in a parent are visible to child objects? I'm trying to write a driver for a device that can interface via I2C or SPI and would like the user to be able to select which via #define at the application level without having to touch the driver.
    Right now, it works by setting the define in the child (or manually on the command line with -D), but not in the parent. I thought I'd done this before successfully but I guess I must be mistaken :blush:

    EDIT: Yes, I was - I was thinking of OpenSpin on the P1

    Thanks!
  • @Cluso99 : It failed on the second CON line because it was trying to figure out the meaning of the first line, and it wasn't until the second line that it completely gave up. At that point it went into an error recovery mode and skipped ahead, apparently until after the next block of comments (the next time the indentation reset). Then the same thing happened again, and then a 3rd time. There were three times the indentation was reset by comments at the left margin, and I think that's why there were 3 error messages.

    The parser is kind of a black box to me (it's built with yacc) so there's only so much I can do to change this behavior.
  • avsa242 wrote: »
    Would it be practical to modify the preprocessor so that #defines in a parent are visible to child objects? I'm trying to write a driver for a device that can interface via I2C or SPI and would like the user to be able to select which via #define at the application level without having to touch the driver.
    Right now, it works by setting the define in the child (or manually on the command line with -D), but not in the parent. I thought I'd done this before successfully but I guess I must be mistaken :blush:
    That would be quite difficult, unfortunately: the preprocessor is structured to deal with source files rather than objects.

    However, I think you could achieve a similar effect by putting all the common code into a file "device_common.spin", and then creating two versions of the driver ("device_i2c" and "device_spi") which just #define the appropriate define and then #include "device_common.spin".

    For example, device_i2c.spin would look like:
    #define SPI 1
    #include "device_common.spin"
    
    The application would then use either "device_i2c" or "device_spi" as the object, but you'd only really have to maintain "device_common".
  • RaymanRayman Posts: 14,646
    edited 2020-05-31 15:42
    @ersmith What is the expected behavior in Spin2 if you main routine ends without a loop?

    I just tried this:
    pub Test()
        PINL(56)
    
    pub Main() | r
    

    (BTW: Obviously, the first method is the main method, no matter what it is called.)

    I see my P56 LED on eval board light for about one second and then goes out.
    Is there some know state that the P2 is now in? Or, is it quasi-random?

    Also, do you know if it is the same with the Parallax compiler?
  • ersmith wrote: »

    However, I think you could achieve a similar effect by putting all the common code into a file "device_common.spin", and then creating two versions of the driver ("device_i2c" and "device_spi") which just #define the appropriate define and then #include "device_common.spin".

    For example, device_i2c.spin would look like:
    #define SPI 1
    #include "device_common.spin"
    
    
    The application would then use either "device_i2c" or "device_spi" as the object, but you'd only really have to maintain "device_common".

    Excellent suggestion; didn't think of that - that works!

    Cheers
  • RaymanRayman Posts: 14,646
    I wish Chip would add #include to the Parallax compiler. But, I think he decided against that...
  • That's really unfortunate if so...a preprocessor makes it so much easier to maintain different codebases. Without it, if you want to truly make a project, say, both PNut and FastSpin compatible (if the two are ever divergent in such a way that your app can't work with the same code on both), you need to maintain separate two sources - which means constantly keeping both synced.
  • Rayman wrote: »
    @ersmith What is the expected behavior in Spin2 if you main routine ends without a loop?
    In fastspin it's the same as calling "cogstop(cogid())"; that is, the main COG stops.

    I don't know what Chip's runtime system does.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-06-01 01:39
    ersmith wrote: »
    @Cluso99 : It failed on the second CON line because it was trying to figure out the meaning of the first line, and it wasn't until the second line that it completely gave up. At that point it went into an error recovery mode and skipped ahead, apparently until after the next block of comments (the next time the indentation reset). Then the same thing happened again, and then a 3rd time. There were three times the indentation was reset by comments at the left margin, and I think that's why there were 3 error messages.

    The parser is kind of a black box to me (it's built with yacc) so there's only so much I can do to change this behavior.

    Thanks Eric.
    Yes when the code being compiled has a bug, sometimes they cause compiler to go crazy and is to be expected.
    When I was able to copy the lines into the main object and it compiled without the error I knew something was causing it. As I debugged it it became apparent that it wasn't actually the lines being reported and that ultimately led me to the missing CON. Evan must have found it around the same time as I did and he just pipped me to the post.

    I guess that's what I get when cutting and pasting a block of code without properly checking I copied everything I need.

    BTW Fastspin is working nicely. Great job! I'm loading LUT and can easily jump/call between COG/LUT/HUB. :sunglasses:
  • evanhevanh Posts: 15,916
    I'm hitting issues with -O2 optimising in newest Fastspin. I'm trying to setup a streamer function and things have been crazy for me so as yet don't have details. When I've got something working I'll get back ...
  • This is a funny one...
    #include <propeller2.h>
    #include <stdio.h>
    
    #define const1 (1.0 / 32768.0)
    #define const2 0.00003051757 // same as above
    
    float test (float f)
    {
      return f * 1.0; // shouldn't change anything
    }
    
    void main ()
    {
      printf ("c1=%f c2=%f\n", const1, const2); // as expected
      float a = test (const1);
      float b = test (const2);
      printf ("a=%f b=%f\n", a, b); // surprise!
    }
    
  • ersmith wrote: »
      printf ("x=%04X\n", x);
    
    > ... error message: "Changing lastorg value for symbol startPid".

    Would you be able to send me this example?

    It seems to show up only in larger programs. I'll send you an example tomorrow. I'm out of office today.
  • roglohrogloh Posts: 5,787
    edited 2020-06-02 01:56
    Rayman wrote: »
    I wish Chip would add #include to the Parallax compiler. But, I think he decided against that...
    avsa242 wrote: »
    That's really unfortunate if so...a preprocessor makes it so much easier to maintain different codebases. Without it, if you want to truly make a project, say, both PNut and FastSpin compatible (if the two are ever divergent in such a way that your app can't work with the same code on both), you need to maintain separate two sources - which means constantly keeping both synced.

    Totally agree. Some people are against #include and #defines etc, and they can be easy to abuse, but it really helps maintain a single codeabase. Having to develop/maintain two versions of drivers, one for PNut and another one for Fastspin, is going to be a problem if there are differences that can't otherwise be avoided.

    I can see that doing #defines/#includes in a self-hosted compiler running on the P2 could make things tricky however. Easier on a PC, and you could even use the existing C pre-processor if you have one installed.
  • RaymanRayman Posts: 14,646
    I think I'm seeing something strange here...
    If I don't do the explicit return, I get zero back... Doesn't seem like it should need the explicit return...
    pub crc8x_pasm3(p_src, n) : crc | b
    
    '' Returns CRC8 of n bytes at p_src
    
      org
    .loop                   rdbyte  b, p_src
                            add     p_src, #1
                            rev     b
                            setq    b
                            crcnib  crc, #$8C
                            crcnib  crc, #$8C
                            djnz    n, #.loop
      end
    
        'return crc
    
  • RaymanRayman Posts: 14,646
    Also, I think I'm seeing that the indentation of ORG (and maybe END?) matters. Is that true?
    Wasn't sure it would...
  • @Rayman: Yes, it looks like the compiler isn't looking inside of inline assembly to see if the return variable ("crc" in your case) is ever set. That's a bug, I'll try to fix it. For now put an explicit "crc := 0" before the inline assembly; this will make sure the compiler sees that the return variable is used and set, and will also help the reader to see how the crc starts out.

    The indentation of "ORG" definitely matters, it's how the compiler knows what the level of the inline assembly is (e.g. whether it goes inside or outside of a preceding IF or REPEAT block). It's like any other Spin statement. Only between the ORG and END is the indentation ignored.

  • Cluso99Cluso99 Posts: 18,069
    Eric,
    I had this error and fastspin reported an erroneous error in another module. Just thought you would like to know.
    Missing $ in #$5A
                wrlong  #5A,        lmm_p
    
    C:\P2\Propeller_II_Latest\ClusoZ80>f420 z.spin2 -2 -l
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2020 Total Spectrum Software Inc.
    Version 4.2.0 Compiled on: May 29 2020
    z.spin2
    MON_CONST.spin2:130: error: syntax error, unexpected identifier `A', expecting instruction modifier or end of line or ','
    
  • @Cluso99: could you post a complete example? The error message you posted makes sense (the 'A' shows up after the '5' as a separate item). I gather the problem is that the file / line number are wrong?
  • Cluso99Cluso99 Posts: 18,069
    Yes, both the file it was referring to was an included file and the line number was totally wrong - it pointed to a non existent line in the main file.
    Think I shot past the problem so not sure I can go back. Should have zipped it at the time :(
Sign In or Register to comment.