Shop Learn
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 71 — Parallax Forums

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

1686971737482

Comments

  • Rayman wrote: »
    I'm not seeing simple_cat and simple_ls examples in the new release.
    When I try to compile the versions I have I get this kind of warning message:
    C:/FlexSpin/include/filesys/fatfs/ff.cc:6959: warning: Bad number of parameters in call to f_opendir: expected 2 found 3
    
    Did something change with FatFs support?

    No, I just added a warning and it is correctly pointing out that there's an extraneous ",0" on line 6959 of ff.cc (which has probably always been there). You can ignore the warning, or if you'd prefer you can remove that extra 0 parameter from the ff.cc source code.

  • ersmith wrote: »
    Roy Eltham wrote: »
    FlexProp is what he renamed FlexGui to. Then there is FlexC, FlexSpin, FlexBASIC that are all compiled with spin2cpp variants (flexspin and flexcc). I think flexspin.exe and flexcc.exe are the same compiler, but flexcc has different message outputs (and maybe command line options?) to better work with IDEs/etc. that can talk to gcc/etc.
    Yes, the command line options for flexcc and flexspin are different -- flexcc takes gcc like arguments, and flexspin takes openspin like arguments. Otherwise they're the same compiler.
    Can I add in a "#pragma spin" line in my C code and start typing in Spin? :smile:

  • David Betz wrote: »
    ersmith wrote: »
    Roy Eltham wrote: »
    FlexProp is what he renamed FlexGui to. Then there is FlexC, FlexSpin, FlexBASIC that are all compiled with spin2cpp variants (flexspin and flexcc). I think flexspin.exe and flexcc.exe are the same compiler, but flexcc has different message outputs (and maybe command line options?) to better work with IDEs/etc. that can talk to gcc/etc.
    Yes, the command line options for flexcc and flexspin are different -- flexcc takes gcc like arguments, and flexspin takes openspin like arguments. Otherwise they're the same compiler.
    Can I add in a "#pragma spin" line in my C code and start typing in Spin? :smile:

    No, no mixing of languages within the same file -- except for PASM, that you can put inside anything else. But you can compile a .spin file with flexcc, or a .c file with flexspin, no problem. The language is determined by the file extension. Someday I should probably implement the "-x language" switch for flexcc, but it seems like a low priority.

  • ersmith wrote: »
    David Betz wrote: »
    ersmith wrote: »
    Roy Eltham wrote: »
    FlexProp is what he renamed FlexGui to. Then there is FlexC, FlexSpin, FlexBASIC that are all compiled with spin2cpp variants (flexspin and flexcc). I think flexspin.exe and flexcc.exe are the same compiler, but flexcc has different message outputs (and maybe command line options?) to better work with IDEs/etc. that can talk to gcc/etc.
    Yes, the command line options for flexcc and flexspin are different -- flexcc takes gcc like arguments, and flexspin takes openspin like arguments. Otherwise they're the same compiler.
    Can I add in a "#pragma spin" line in my C code and start typing in Spin? :smile:

    No, no mixing of languages within the same file -- except for PASM, that you can put inside anything else. But you can compile a .spin file with flexcc, or a .c file with flexspin, no problem. The language is determined by the file extension. Someday I should probably implement the "-x language" switch for flexcc, but it seems like a low priority.
    Yeah, I knew that. I was just giving you a hard time. That certainly wasn't justified though given all of your great work on these tools. My only defense is that I ended my post with a smiley face. :smile:

  • RaymanRayman Posts: 11,932
    edited 2020-11-30 21:56
    I think I'm seeing an issue with a function that returns a structure... Is returning a structure like this supposed to work?
    Position px=insertstr(p, buf);
    

    The symptom is that this line somehow calls the insertstr function twice (If I'm seeing it right).

    I copied enough of this into simple_ls.c to reproduce this in the attached.
  • pmrobertpmrobert Posts: 634
    edited 2020-11-30 23:38
    Similar to Rayman's question I have a warning involving "bad number of parameters". What am I doing incorrectly? The program runs correctly and I also was getting the warning when using the ff.c referenced above, I edited line 6959 if ff.c and that does get rid of the warning. Is my syntax wrong somehow?
    Warning
    C:/flexprop/DEV/ign2020/ign2020.c:97: warning: Bad number of parameters in call to decode_cog: expected 0 found 1
    
    Here's Line 97
    printf("decode_cog running on cog %d\n",cogstart(decode_cog, NULL, decode_stack, sizeof(decode_stack)));
    
    EDIT:
    I edited the code to use the builtin version of cogstart and now no warnings.
    printf("decode_cog running on cog %d\n",__builtin_cogstart(decode_cog, &decode_stack[0]));
    
    I'm sure I just didn't understand the syntax for the macro version, cogstart.
    EDIT #2: After grepping for the pertinent macros I found I was using propeller.h and not propeller2.h. Please disregard.

  • @Rayman,

    As far as I know C does not return structures. Only pointers to a structure.

    Mike
  • @iseries , C is able to return structures. However, I hardly ever use that feature. I normally used structure pointers for calling and returning values.

    @Rayman , I'm not familiar with using the construct "typedef struct Line Line", but I compiled your code in GCC, and it compiled OK, but with a few warnings.

    Instead of
    typedef struct Line Line;
    struct Line {
        char* s;  /* string content */
        size_t l; /* length excluding \0 */
        size_t v; /* visual length */
        size_t m; /* multiples of LINSIZ? */
        Line* p;  /* previous line */
        Line* n;  /* next line */
    };
    
    I would write it as
    typedef struct LineS {
        char* s;  /* string content */
        size_t l; /* length excluding \0 */
        size_t v; /* visual length */
        size_t m; /* multiples of LINSIZ? */
        struct LineS* p;  /* previous line */
        struct LineS* n;  /* next line */
    } LineT;
    
    FlexProp may be having trouble with the way you coded it even though it appears to be valid C.

  • Rayman wrote: »
    I think I'm seeing an issue with a function that returns a structure... Is returning a structure like this supposed to work?
    Position px=insertstr(p, buf);
    

    Yes, that is supposed to work. Obviously there's a bug somewhere :(.

    A more common idiom in C is to pass a pointer to a structure and manipulate the structure using the pointer, rather than passing the whole struct and then returning it. But struct passing and return is supposed to work, so I'll try to track this down. Thanks for the bug report!
  • RaymanRayman Posts: 11,932
    Thanks! Just FYI, this isn’t really my code... it’s borrowed from MVI text editor on GitHub
  • I know that it's not your code, but, now that the WX Module adapter is available for the P2 Edge, mini-Edge, and ES boards, could you add the WiFi port features of proploader to loadp2? Specificially, this would include options -i -n -W as well as supporting Telnet for terminal connections.
  • evanhevanh Posts: 10,849
    Huh, didn't even know that existed. Google search got me this - https://github.com/parallaxinc/PropLoader

    I see David Betz wrote it. I think Dave Hein started from pieces of David's code when writing loadp2.

  • On the WX module there is firmware that helps load the bootstrap code onto the P1. From there it uses telnet to load the code on to it.

    For the P2 no firmware code is needed as the load process is much simpler. Only a telnet connection is need to load the bootstrap program and then the code. The problem is then that a reset is needed to get the P2 into bootstrap mode.

    I guess there could be firmware code added to the WX module that would load a default P2 bootstrap program. Then the load program could take over after that with a telnet connection.

    Mike
  • evanh wrote: »
    Huh, didn't even know that existed. Google search got me this - https://github.com/parallaxinc/PropLoader

    I see David Betz wrote it. I think Dave Hein started from pieces of David's code when writing loadp2.
    The wifi loader will have to be rewritten to work with the P2 since its ROM loader is totally different. Probably wouldn't be that hard to do though.

  • iseries wrote: »
    On the WX module there is firmware that helps load the bootstrap code onto the P1. From there it uses telnet to load the code on to it.

    For the P2 no firmware code is needed as the load process is much simpler. Only a telnet connection is need to load the bootstrap program and then the code. The problem is then that a reset is needed to get the P2 into bootstrap mode.

    I guess there could be firmware code added to the WX module that would load a default P2 bootstrap program. Then the load program could take over after that with a telnet connection.

    Mike
    Yes, that would be a good way to handle it.

  • Mike Green wrote: »
    I know that it's not your code, but, now that the WX Module adapter is available for the P2 Edge, mini-Edge, and ES boards, could you add the WiFi port features of proploader to loadp2? Specificially, this would include options -i -n -W as well as supporting Telnet for terminal connections.

    I don't have the hardware yet, although I may order a WX adapter. It sounds like some work is required to adapt the firmware for use with the P2. I hope someone with more experience with the WX might be able to help with this...
  • JRoarkJRoark Posts: 703
    edited 2020-12-01 23:49
    @ersmith The "5.0.1" release on github (found here: https://github.com/totalspectrum/flexprop/releases/tag/v5.0.1) reports in both the TCL editor Help->About menu, and in the compiler output, as "5.0.1-Beta". The docs however show 5.0.1 (no "beta").

    Complier output:
    "d:/Flex2Gui/flexgui/bin/flexspin" -2 -l -D_BAUD=230400 -O2 -Wall   -I "d:/Flex2Gui/flexgui/include"  "d:/Flex2Gui/flexgui/P2 Libs/datetest.bas"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2020 Total Spectrum Software Inc.
    Version 5.0.1-beta-v5.0.0-11-g15693cbc Compiled on: Nov 25 2020
    
    I'm putting this out here because it's possible you unwittingly recycled the beta version of the compiler instead of producing the new version. Either that, or I'm being really obtuse again... :)

    Regardless, it's working fine for me so far!

  • RaymanRayman Posts: 11,932
    edited 2020-12-02 16:38
    Is there a way to change the default baudrate for stdio? Also, is it possible to get the serial output to work with putty or teraterm? You'd think that'd be easy, but I can't make it work for some reason...

    Ok, I found how to change the baud... Is this in the docs? Found it in mandelbrot example...
    _setbaud(_BAUD);
    

    Update: Figured out that putty and teraterm reset the P2 on connection. Had to flash the program to get it to work with these...
  • RaymanRayman Posts: 11,932
    I looks like getchar() causes an echo of anything typed to the terminal, is this right? Can that be turned off?
  • Cluso99Cluso99 Posts: 17,681
    Rayman wrote: »
    I looks like getchar() causes an echo of anything typed to the terminal, is this right? Can that be turned off?
    You could look for a command like echo off
  • RaymanRayman Posts: 11,932
    edited 2020-12-02 17:34
    I don't think it's the terminal program doing the echoing... I think the Prop is echoing back what getchar() receives. But, I might be wrong...

    Update: I check again and I think I am seeing this right... Was able to sorta fix it by putting "putchar('\b');" after the getchar(). But, I'm not 100% sure that's a good way.
    I switched to "jm_serial.spin2" for serial and that seems to do what I need.
  • Cluso99Cluso99 Posts: 17,681
    Rayman wrote: »
    I looks like getchar() causes an echo of anything typed to the terminal, is this right? Can that be turned off?
    You could look for a command like echo off
  • RaymanRayman Posts: 11,932
    edited 2020-12-02 17:07
    This Arduino code for reading memory doesn't seem to work, always comes back zero.
    But, shouldn't it work? Seems like maybe it should...
    uint8_t peekMemory(uint16_t address)
    {
        uint8_t* p, c;
        return p[address];
    }
    

    I fixed it with this:
    uint8_t peekMemory(uint16_t address)
    {
      uint8_t *p, c;
      //return p[address];
      __asm {
          rdbyte c,address
      }
      return c;
    }
    
  • Dave HeinDave Hein Posts: 6,289
    edited 2020-12-02 18:33
    Try adding the line "_setrxtxflags(_getrxtxflags() & ~TTY_FLAG_ECHO);". This will clear the echo flag. You will also need to include sys/ioctl.h.

    EDIT: There is also a flag TTY_FLAG_CRNL defined in ioctl.h. After startup, _getrxtxflags() returns a value of 3, which indicates that both the echo and the CRNL flag bits are set. I believe the CRNL flag causes both a CR and NL to be sent when calling putchar('\r'). If you want raw output you would need to turn off this flag also.
  • Rayman wrote: »
    This Arduino code for reading memory doesn't seem to work, always comes back zero.
    But, shouldn't it work? Seems like maybe it should...
    uint8_t peekMemory(uint16_t address)
    {
        uint8_t* p, c;
        return p[address];
    }
    

    IDK how that ever would work like that. It indexes into an uninitialized pointer. Would work if p was initialized to zero. Also, the parameter needs to be 32 bit on P2, doesn't it. Infact, why is it passing addresses in integers, aaaaaaaaaaaa?
  • RaymanRayman Posts: 11,932
    edited 2020-12-02 19:58
    I had tried setting p to zero, but that didn't make it work... actually it does work when initialized..
  • @Rayman, did you see my post about using _setrxtxflags()?
  • RaymanRayman Posts: 11,932
    @"Dave Hein" Yes, just tried it. Thanks, that does make it work better. It stops the echo.
    But, the program still doesn't work exactly right...

    See the screenshot. There's a funny character in the top left corner that messes up the alignment of the first row.
    Also, when I move downward past the end with arrows, all the line numbers should increment, but they don't only the last row is correct.
    715 x 435 - 16K
  • Rayman wrote: »
    I looks like getchar() causes an echo of anything typed to the terminal, is this right? Can that be turned off?

    All special processing may be disabled by _setrxtxflags(0). _setrxtxflags(m) enables various special handling based on the value of m. If bit 0 of m is set, then echo is enabled. If bit 1 is set, then carriage return is converted to line feed on input, and a carriage return is output whenever line feed is seen.

    The current state of the flags may be fetched via _getrxtxflags().
  • Rayman wrote: »
    This Arduino code for reading memory doesn't seem to work, always comes back zero.
    But, shouldn't it work? Seems like maybe it should...
    uint8_t peekMemory(uint16_t address)
    {
        uint8_t* p, c;
        return p[address];
    }
    

    p is uninitialized, so the behavior is undefined; it's fetching data from some random address. If it works on Arduino it does so by accident. If you set p=0 before the return p[address] then it should work.
Sign In or Register to comment.