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

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

17172747677116

Comments

  • RaymanRayman Posts: 13,797
    edited 2021-01-03 21:43
    I get this warning (warning: parameter passing discards const attribute from pointer) on things like this:
    playVideo("fun-1500.avi");
    
    where playVideo declared like this:
    void playVideo(char* filename)
    {//Play a .avi video using media fifo we will set up and top of RAM_G
    
    Is this warning warrented?
    I'm able to get rid of it like this:
    playVideo((char *) "fun-1500.avi");
    

    I don't really understand the reason for the "const" attribute. Guess I should look that up one day...
  • evanhevanh Posts: 15,126
    Rayman wrote: »
    Are you saying using any long filenames will break the boot from sd process?
    Or, that people are trying to boot from files with long filenames and it doesn't work?
    Neither. If I remember correctly, not that I tested the combinations, the problem only comes about with deleted long names.

  • Rayman wrote: »
    @ersmith Have you thought about adding the long filenames option to FatFs?

    Or, is it already there?
    It's there, but not enabled. I had intended to allow it to be defined on the command line with -DFF_USE_LFN=1, but I forgot to wrap the definition in filesys/fatfs/ffconf.h with a #ifndef. That's fixed in github now.
    Also, is there a way to change which pins are assigned to the uSD card?

    Not yet. Having just one uSD card and changing the pins for it would be straightforward, but I suspect most uses for different pins would want there to be an option for multiple uSD cards, and that would require some work.
  • Wuerfel_21Wuerfel_21 Posts: 4,371
    edited 2021-01-03 22:04
    Rayman wrote: »
    I get this warning (warning: parameter passing discards const attribute from pointer) on things like this:
    playVideo("fun-1500.avi");
    
    where playVideo declared like this:
    void playVideo(char* filename)
    {//Play a .avi video using media fifo we will set up and top of RAM_G
    
    Is this warning warrented?
    I'm able to get rid of it like this:
    playVideo((char *) "fun-1500.avi");
    

    I don't really understand the reason for the "const" attribute. Guess I should look that up one day...

    const before the star means that the data that is pointed to is read-only. A function that takes a string and only reads it and doesn't write to it must be declared to take a "const char *".
  • Rayman wrote: »
    I get this warning (warning: parameter passing discards const attribute from pointer) on things like this:
    playVideo("fun-1500.avi");
    
    where playVideo declared like this:
    void playVideo(char* filename)
    {//Play a .avi video using media fifo we will set up and top of RAM_G
    
    Is this warning warrented?
    I think it is warranted, because with that declaration the playVideo function is allowed to modify the file name in place (e.g. by doing something like filename[0] = 'x' to change the first letter).

    If you declare playVideo as:
    void playVideo(const char* filename)
    
    it'll get rid of the warning; this assumes, of course, that playVideo doesn't need to change the file name (which is likely true).

    In FlexC literal strings are constant (should not be modified by the application), and that's what the "const" attribute means. Technically I'm not quite sure what the C standard says about this, but practically speaking it's a very bad idea to try to write over a literal string. For example, many compilers will put them in ROM, or share multiple instances of a single string.
  • evanhevanh Posts: 15,126
    Rayman wrote: »
    I don't really understand the reason for the "const" attribute.
    The inline quoted string is default treated as a const char. The compiler then sees it being assigned to a char type without the const attribute so informs to that effect. And your workaround is to cast to the same (non-const) so thereby avoiding the warning.

    I presume that less strict compliers wouldn't produce such a warning.

  • RaymanRayman Posts: 13,797
    evanh wrote: »
    Neither. If I remember correctly, not that I tested the combinations, the problem only comes about with deleted long names.

    This sounds like a pretty serious issue! Hope it's mentioned in the docs...

    Thank you all for the "const" info. I think I get it now...
  • evanhevanh Posts: 15,126
    ersmith wrote: »
    If you declare playVideo as:
    void playVideo(const char* filename)
    
    it'll get rid of the warning; this assumes, of course, that playVideo doesn't need to change the file name (which is likely true).
    Seems best answer to me.

  • ersmith wrote: »
    Having just one uSD card and changing the pins for it would be straightforward, but I suspect most uses for different pins would want there to be an option for multiple uSD cards, and that would require some work.
    I would like the capability for a single uSD card at different pins than the default ones. I have a P2 Edge, which doesn't have a uSD connector, and I would like to connect a uSD to it using different pins.

  • RaymanRayman Posts: 13,797
    Does the trick for using Spin2 files in FlexSpin C work with c files too?

    I was just trying this:
    struct __using("Antares.c") Ant; //RJA:  Visual Studio will show an error here, but it's OK
    
    void setup()
    {
      Ant.begin();
    }
    

    Looks like it's trying to work, but gives me some errors...
  • evanhevanh Posts: 15,126
    Rayman wrote: »
    evanh wrote: »
    Neither. If I remember correctly, not that I tested the combinations, the problem only comes about with deleted long names.
    This sounds like a pretty serious issue! Hope it's mentioned in the docs...
    Not yet, Cluso coded that part so Chip has left it out of his docs. In the short term, it could be added here - http://forums.parallax.com/discussion/170637/p2-sd-boot-code-rev-2-silicon/p1

  • Cluso99Cluso99 Posts: 18,066
    Booting from SD does not use long filename, and the two boot files must be uppercase _BOOT_P2.BIX and _BOOT_P2.BIY IIRC, and the SD card must be formatted as FAT32.
    There is an alternative method where the bootfile is stored in the MBR/VOL sector(s) - for more info, see the P2 Boot ROM writeup thread.
  • evanhevanh Posts: 15,126
    hmm, scanning old comments I get this reference to an older case - https://forums.parallax.com/discussion/comment/1500150/#Comment_1500150

    ...

  • The long filenames used by Windows use more then one directory entry for the name and shortening the first one to attach some ~ and number to distinguish.

    I have a (not just by me) modified Version of KYE's driver supporting long filenames (might work in P2 too with the existing port the changes are just in Spin).

    But if you have multiple copies of _BOOT_P2.BIX with too similar names then windows will start to even make a long filename out of a perfectly valid 8.3 name.

    And there the trouble might arise. Because the boot process needs the 8.3 name.

    So long filenames are possible, one just need to take care of having the boot file as 8.3, not sure how to force that when writing to SD in case of trouble...

    Mike

  • Cluso99Cluso99 Posts: 18,066
    You cannot have multiple copies of _BOOT_P2.BIX
    And you cannot have files beginning with _BOOT_P2 as long file names. Not sure what parts the extension plays.
  • Dave Hein wrote: »
    ersmith wrote: »
    Having just one uSD card and changing the pins for it would be straightforward, but I suspect most uses for different pins would want there to be an option for multiple uSD cards, and that would require some work.
    I would like the capability for a single uSD card at different pins than the default ones. I have a P2 Edge, which doesn't have a uSD connector, and I would like to connect a uSD to it using different pins.

    I've modified the current github so you can add defines for PIN_CLK, PIN_SS, PIN_MOSI, PIN_MISO on the command line to change the default pins. Documentation for that is in "general.md" under the "File I/O" section.

    As I mentioned I'd like eventually to have some parameters to the _vfs_mount_sdcard() function to allow for multiple cards, but that will have to wait a bit.
  • Rayman wrote: »
    Does the trick for using Spin2 files in FlexSpin C work with c files too?

    I was just trying this:
    struct __using("Antares.c") Ant; //RJA:  Visual Studio will show an error here, but it's OK
    
    void setup()
    {
      Ant.begin();
    }
    

    Looks like it's trying to work, but gives me some errors...

    Generally speaking it should work, although it does depend somewhat on what exactly is in "Antares.c". What errors are you getting?
  • RaymanRayman Posts: 13,797
    Ok, good to know. Wasn't sure if should use the .h or the .c or maybe it doesn't matter?
    This would help separate the namespace and make it look more like a class.

    Here are the errors I get now:
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:17: error: Variable FifoWriteLocation is initialized twice
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:1186: error: syntax error, unexpected type name `LPCOLORREF', expecting identifier or '('
    

    Guess I look to see if they are really errors.
  • RaymanRayman Posts: 13,797
    Ok, I got past those errors by moving those global things from the ".c" to the ".h" file.
    But then, I get a ton of errors and warnings like this:
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:944: error: redefining function Wait4CoProFIFOEmpty
    1>Antares.c:944: note: the previous definition is here
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:960: warning: duplicate definition for StartCoProTransfer
    1>Antares.c:960: note: the previous definition is here
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:1004: error: redefining function CoProWrCmdBuf
    1>Antares.c:1004: note: the previous definition is here
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:1024: error: redefining function WriteBlockRAM
    1>Antares.c:1024: note: the previous definition is here
    1>D:/Propeller2/FastSpin/Demos_P2/Antares/Antares.c:1041: warning: duplicate definition for LoadFile
    1>Antares.c:1041: note: the previous definition is here
    

    I image it is due to the convoluted way I'm building the file...
    To avoid adding Antares.c to the build command line, I've added it inside the Antares.h file like this:
    #include "Antares.c"
    

    I imaging that's the source of the problem...
  • RaymanRayman Posts: 13,797
    Tried removing that include and put on command line, but still get a bunch of errors.
    Doesn't look like it's going to work. But, it's fine like it is anyway. I'll just leave it alone.

    Only issue I really have is a couple of global variables like "w" and "h" that could easily be redefined by accident... Maybe I'll just rename them to something more complex.

    BTW: The compiler output often says "1 succeeded" when it actually failed.
    But, I've learned to look for the "Program size" message to tell if it really worked.
  • Rayman,
    I believe you are running into the "no linker" issue. If you want to be able to call C functions in another c file, then in the header file for that other c file you need to add special __fromfile() tags to your declarations like this:
    unsigned get_states(int endPin, int startPin) __fromfile("libsimpletools/getStates.c");
    
    This will cause the compiler to build the code referenced in the __fromfile() for your code to then be able to call.

    If/When we get a linker, then it can be done the normal way.
  • I can't really diagnose the errors without seeing the code, but my guess is you put too much into the .h file, either directly or indirectly (via the #include "antares.c"). In general .h files should just have declarations, not anything executable, because they're designed to be included multiple times by other files.

    It sounds like the correct solution really is to put the .c file on the command line, if that's the way it's designed to be used. The FlexProp GUI doesn't directly support multiple files, but the command line tools do.
  • RaymanRayman Posts: 13,797
    Is there an example of how to launch an assembly cog from within a FlexSpin C program?

    I see the Mandelbrot, but that looks to launch hubexec code...

    Or, is better to do this with a Spin2 file and call it with the typdef struct way?
  • Rayman wrote: »
    Is there an example of how to launch an assembly cog from within a FlexSpin C program?

    led_server_asm.c and led_server_pasm.c (both in the samples/ directory).
  • RaymanRayman Posts: 13,797
    Very minor thing...

    Sometimes the errors & warnings appear at the top of the output and sometimes at the bottom (at least for me in my Visual Studio setup).

    Would be better to all be at the bottom. But again, small thing...
  • Rayman wrote: »
    Very minor thing...

    Sometimes the errors & warnings appear at the top of the output and sometimes at the bottom (at least for me in my Visual Studio setup).

    Would be better to all be at the bottom. But again, small thing...

    That sounds more like a Visual Studio problem than anything I can fix in the compiler. flexspin and flexcc always output errors and warnings to stderr, and other messages to stdout.
  • RaymanRayman Posts: 13,797
    edited 2021-01-10 18:34
    Is there a non-blocking version of getchar()?

    If not, is there a way to use something like fullduplexserial() with FlexSpin C?
    (or, a smartpin version of fullduplexserial())
  • Rayman wrote: »
    Is there a non-blocking version of getchar()?

    If not, is there a way to use something like fullduplexserial() with FlexSpin C?
    (or, a smartpin version of fullduplexserial())

    The C standard doesn't have anything like that. If you're willing to be FlexC specific and just want serial input, the function _rxraw(n) returns a character from the serial port with an n millisecond timeout (if the timeout hits before the character arrives it returns -1). n=0 means no timeout, it blocks forever.

    Using a Spin fullduplexserial object (or smartserial on P2) is done the same way as using any Spin object from C, via struct __using. The docs has this example:
    struct __using("FullDuplexSerial.spin") fds;
    
    void main()
    {
        fds.start(31, 30, 0, 115200);
        fds.str("hello, world!\r\n");
    }
    
  • RaymanRayman Posts: 13,797
    Thanks! That first way is just what I needed.
    I had resorted to using USB keyboard input, but this is simpler.

    I used it to get this Tetris game working (attached).
    It displays screen as ascii characters in terminal window.
    Got it from here: https://github.com/Gregwar/ASCII-Tetris
  • JRoarkJRoark Posts: 1,214
    edited 2021-01-11 04:17
    @ersmith Re: FlexProp V5.0.6. I was chasing what I thought was a memory corruption bug in my string handling code. However, I think the corruption is being caused by the driver that talks up the USB channel to the GUI. This code demonstrates it:
    var z = 0
    var x$ = ""
    x$ = "================================================================================================="
    do
    	'pauseMS(100)   '<-- uncomment this to "fix" it
    	print x$
    	print x$
    	print x$
    	print x$
    	print x$
    	z += 1
    	print "Loop Count: ";z
    	print
    loop
    
    My idea here is just to push lots of data up the comm channel to the PC. If you run the code without the delay, eventually (5-10 seconds) you'll start seeing erroneous data. But if you give it a short breather occasionally, then it works fine. Note that increasing things like HEAPSIZE or adding _gc_collect() does not affect this much at all.
Sign In or Register to comment.