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

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

1109110112114115123

Comments

  • @ersmith In FlexBasic version 6.5.0, any attempt to reference the date/time functions produces this error at compile time:

    Unable to open file `libsys/datetime.c': child process exited abnormally
    

    Examples: SETDATE$, DATE$, TIME$

  • pik33pik33 Posts: 2,388
    edited 2023-10-01 21:24

    Yes, I have this error too. There is no 'datetime.c' anywhere in the flexprop directory. Also

    print time$

    gives

    Unable to print expression of this type
    

    Version 6.5.1-beta-v6.5.0-16-g8d96e41b Compiled on: Sep 26 2023


    Edit: I see there is a commit that includes that file... I have to update the compiler.

  • Sorry, I forgot to check in the datetime.c file. I've attached it here, just copy this file to flexprop/include/libsys/datetime.c. I'll be uploading a new release to my Patreon soon, just need to test it on Windows and Mac.

  • That fixed it nicely, Eric. Thank you.
    I really love the new features you've been adding.
    Please keep up the good work!

  • Could it be that the sprintf() is not working? I thought it had something to do with floating point support as it was with sscanf() so I changed %f to %d.

    #include <stdio.h>
    
    void UpdateDisplay ()
    {
      char str[24];
      sprintf (str, "VFD voltage: %dV", 300); //GetDcBusVoltage ());
      printf (str);
    }
    

    But I still get a mysterious error message

    E:\Projekte\Beast\QBeast\Source\QB_main.p2asm:9841: error: Changing hub value for symbol __struct___anon_9b5668f900000005_sputc
    E:\Projekte\Beast\QBeast\Source\QB_main.p2asm:9853: error: Changing hub value for symbol __struct___anon_9b5668f900000005_sputc_ret
    

    Most of the time I mess something up with C but I can't tell what it is...

  • sprintf() works in a normal C program. The problem you're seeing is most likely due to sprintf being used in different Spin objects or in some other "unusual" way: my testing with C has mostly been with the C code being at the top level, rather than as an object included in a Spin program.

    Unfortunately, while I suspect there could be a problem here, I'm not able to construct a reproducer that triggers the error. All of my attempts to use sprintf() within Spin objects compile and run correctly. Are you able to share that code?

  • Eric, thanks a lot, the exe you sent me via PM did actually fix the problem.

  • RaymanRayman Posts: 14,755

    Is Z a constant in C?
    This line is giving me an error:
    long Z;

    1>Icm20948DataConverter.c:803: error: syntax error, unexpected constant

  • @Rayman said:
    Is Z a constant in C?
    This line is giving me an error:
    long Z;

    1>Icm20948DataConverter.c:803: error: syntax error, unexpected constant

    No, Z is not a constant in C. It must be defined somewhere else in the code, possibly in an enum or in a header file.

  • RaymanRayman Posts: 14,755
    edited 2023-10-06 21:08

    Ok, found it... Guess this is the downside to not having object files, right? All the defines have global scope

    #define X                           0
    #define Y                           1
    #define Z                           2
    
  • @Rayman said:
    Ok, found it... Guess this is the downside to not having object files, right? All the defines have global scope

    #define X                           0
    #define Y                           1
    #define Z                           2
    

    Should not be the case. Only in files where defined (included).

  • @Rayman said:
    Ok, found it... Guess this is the downside to not having object files, right? All the defines have global scope

    No, defines in C have file scope. Are you putting all the files together using #include? If so, yes, you can run into conflicts like that. It's probably better to compile the C files separately.

    If you're using the command line, you can just list the files on the command line:

    flexspin -2 -o program.binary file1.c file2.c file3.c
    

    If you're using the FlexProp GUI, you can put the files into a project, e.g. by using the File > Create Project From Files... menu option. This creates a .fpide file, which is just a simple list of files to be compiled by the compiler (one per line), with blank lines and lines starting with # being ignored. Flexspin can compile those directly, e.g.:

    flexspin -2 -o program.binary program.fpide
    

    where "program.fpide" looks like:

    file1.c
    file2.c
    file3.c
    
  • RaymanRayman Posts: 14,755

    @ersmith Ok, I didn't know having all the files on the command line would fix that. Good to know, thanks.

    Right now, I'm doing it like this:

    /*************************************************************************
      Includes
    *************************************************************************/
    
    #include "Teensy-ICM-20948.h"
    
    
    
    // InvenSense drivers and utils
    #include "Icm20948.h"
    #include "SensorTypes.h"
    #include "Icm20948MPUFifoControl.h"
    
    #include "Icm20948SelfTest.c"
    #include "Icm20948Augmented.c"
    #include "Icm20948LoadFirmware.c"
    #include "Icm20948AuxCompassAkm.c"
    #include "Icm20948AuxTransport.c"
    #include "Icm20948DataBaseDriver.c"
    #include "Icm20948DataConverter.c"
    #include "Icm20948Dmp3Driver.c"
    #include "Icm20948DataBaseControl.c"
    #include "Icm20948Transport.c"
    #include "Icm20948Setup.c"
    #include "Icm20948MPUFifoControl.c"
    

    Was easy to rename Z to ZZ in that problem function...

  • Yeah, it'd be much safer to do it all on the command line (if you use the command line and/or Makefiles) or else to use a .fpide project file. Also note that the flexcc front end has a -c option that produces a kind of pseudo-object .o file that's a preprocessed version of the original .c. This is to make porting code from other platforms a little bit easier.

  • ManAtWorkManAtWork Posts: 2,178
    edited 2023-10-07 17:17
    #include <stdbool.h>
    struct __using("QB_inout.spin2") io;
    ...
      bool hit= (io.inputs >> io.bitButton) & 1;
      if (hit)
      ...
    

    io.inputs is a bit mask updated by the I/O driver. io.bitButton is equal to 16. The example above works as intended. However,

    bool hit= io.inputs & (1<<io.bitButton);
    

    doesn't. hit is always false even if bit 16 in io.inputs is set. I guess the result of the AND operation is stored in the bool variable (only one byte) without expanding any non-zero value to TRUE ($FF), first.

    Is this normal behaviour, e.g. bool is only an alias for byte? Or can I expect it to be a "real boolean" where non-zero is always treated as true no matter of the size of the assignment source?

  • @ManAtWork : It looks like there is a bug in flexspin. I thought that C _Bool type was just an alias for byte and that assigning anything other than 0 or 1 resulted in undefined behavior. This is wrong, unfortunately. I will try to fix it, but it's a fairly major change (creating a whole new type and code for promoting/demoting it). For now, try to avoid assigning anything other than 0 or 1 to a boolean.

  • FYI,

    I just installed flexprop 6.5.2 into my older HP laptop that I have running LinuxLite.

    Linux LinuxLiteLaptop 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

    I was able to use the generic Linux install instructions (substituting 'apt' for 'get-apt').

    In trying to compile/install flexprop I got the following error:

    In file included from /usr/include/string.h:630:0,
                     from frontends/lexer.c:8:
    ./util/util.h:50:14: error: expected identifier or ‘(’ before ‘__extension__’
     extern char *strdup(const char *);
                  ^
    Makefile:241: recipe for target 'build/lexer.o' failed
    make[1]: *** [build/lexer.o] Error 1
    

    I did some googling and found that others have had similar errors in various other programs, the suggested solution was to comment out the offending line.

    So I commented out line 50 in spin2cpp/util/util.h

    extern char *strdup(const char *);

    After commenting out the above line I was able compile flexprop and it appears to be working fine so far on LinuxLite. I just thought I would post this to help others that may have a similar problem when installing flexprop on other Linux versions.

  • RaymanRayman Posts: 14,755

    @ersmith Looks like new flexspin 6.4 and 6.5 don't like my old Spin2 tiled VGA driver...
    Giving me this:

    1>Version 6.5.0 Compiled on: Sep 23 2023
    1>EXEC : error : Internal error, relocation requires function index
    1>EXEC : error : Internal error, relocation requires function index

    Any tips on what that might mean?

  • @Rayman said:
    @ersmith Looks like new flexspin 6.4 and 6.5 don't like my old Spin2 tiled VGA driver...
    Giving me this:

    1>Version 6.5.0 Compiled on: Sep 23 2023
    1>EXEC : error : Internal error, relocation requires function index
    1>EXEC : error : Internal error, relocation requires function index

    Any tips on what that might mean?

    Could you give me a link to the source code? I can't seem to find it in the forums (forum search is not very helpful...).

  • RaymanRayman Posts: 14,755

    Ok, I've commented out things in the VGA driver's Start function to try to isolate the problem, but no luck yet...

    Also, a lot commented out in main program to isolate...

    BTW: Also had to change "field" to "fieldx" in driver, but I already knew about that...

  • RaymanRayman Posts: 14,755

    Tried to open that spin2 vga driver in FlexProp GUI and it is "Not Responding".

  • RaymanRayman Posts: 14,755
    edited 2023-10-08 17:37

    I think maybe it doesn't like longmove() in swap()...
    No, guess that's not it...

    BTW: Also giving me an error on things like this:
    print((value <-= 1) & 1 + "0")

    says: 1>C:/Propeller2/Demos_P2/GridEye/1080p_TileDriver_8b.spin2:488: error: assignment to constant value

  • @Rayman : Thanks. It looks like there was a typo in some of the new function pointer code; I'm amazed nobody ran into it before. Here's a version of flexspin which should have that fixed.

    As for the print((value <-= 1) & 1 + "0"), did you mean to write print((value ROL 1) & 1 "0")? That's what the version of the code you sent me (9b) has in it.

  • RaymanRayman Posts: 14,755

    Thanks @ersmith . I'm getting 1080p output now, so that's an improvement.
    Code is broke somewhere though, probably me trying to find the problem...

    This 1080p code is so old, it's amazing it works at all...

  • RaymanRayman Posts: 14,755
    edited 2023-10-08 19:36

    Grideye code is broke bad (probably something I just did today), but mixed signal scope works again, whew!

    Update: Grideye code all better, was something I did today...
    But, do see -O2 that I added also messes up display in a strange way... Fine with -O1

    640 x 480 - 159K
  • warning: Unhandled debug format pc_mouse
    

    Are there any plans to implement this?I find it quite useful for providing test stimulus. For example, I can provide a nominal position for a servo without having to connect an encoder or potentiometer to the device under test.

    At the moment, it's not absolutely necessary. All my low level drivers are written in Spin so I can compile a special stripped test software with PropTool or PNut instead of VSC/FlexSpin. But having it all at one place would be more convenient.

  • RaymanRayman Posts: 14,755

    @ersmith Was just testing what I think is the latest Parallax flash file system from here:
    https://github.com/ironsheep/P2-FLASH-FS

    After running that demo and then FlexProp "Command Shell for P2" and do a dir on it, I get this:

    cmd> cd /pfs
    cmd> dir
          86 TAçfile1                                                              
          87 Zºfile2                                                                
          88 gH,åfile3                                                              
    cmd>   
    

    Is this because the version I'm using has a different filename structure than the original from Chip?

  • @ManAtWork said:

    warning: Unhandled debug format pc_mouse
    

    Are there any plans to implement this?I find it quite useful for providing test stimulus. For example, I can provide a nominal position for a servo without having to connect an encoder or potentiometer to the device under test.

    It depends on what you mean by "implement this". Making -gbrk emit the appropriate codes for pc_mouse and pc_key looks very simple, and I will do that. However, loadp2 and the FlexProp GUI won't actually respond to these requests, only the Parallax debugger will. Making the FlexProp GUI support more of the debug protocol is something I'd like to do but probably will never find the time for :(.

  • @Rayman said:
    @ersmith Was just testing what I think is the latest Parallax flash file system from here:
    https://github.com/ironsheep/P2-FLASH-FS

    After running that demo and then FlexProp "Command Shell for P2" and do a dir on it, I get this:

    cmd> cd /pfs
    cmd> dir
          86 TAçfile1                                                              
          87 Zºfile2                                                                
          88 gH,åfile3                                                              
    cmd>   
    

    Is this because the version I'm using has a different filename structure than the original from Chip?

    Sorry, the pre-compiled shell.binary that shipped in the flexprop.zip file was built with an older version of Chip's code. Fixing it is really easy, though: if you recompile samples/shell/shell.c you'll get the newer version and the file names should come out correctly.

  • @ersmith said:
    It depends on what you mean by "implement this". Making -gbrk emit the appropriate codes for pc_mouse and pc_key looks very simple, and I will do that. However, loadp2 and the FlexProp GUI won't actually respond to these requests, only the Parallax debugger will. Making the FlexProp GUI support more of the debug protocol is something I'd like to do but probably will never find the time for :(.

    Adding the whole debug GUI stuff is not necessary. I'm using VSC (see post in VSC thread) which invokes FlexSpin as compiler and PNut as debugger. So loadP2 is only used as loader and not as terminal to display the debug output. This has the disadvantage that I need to insert a delay at startup because PNut is not ready to receive serial data immediately. But it works quite nice.

    So yes, adding mouse and keyboard support to -gbrk debugging would do the job.

Sign In or Register to comment.