Shop OBEX P1 Docs P2 Docs Learn Events
FlexProp: a complete programming system for P2 (and P1) - Page 43 — Parallax Forums

FlexProp: a complete programming system for P2 (and P1)

1404143454654

Comments

  • @RS_Jim said:
    @ersmith : What is the latest version?
    Jim

    The source code checked into github is always the latest version. The version number is currently 6.0.0-beta.

  • @ersmith
    eric,
    I have tried compiling the attached program an I get a fail and a bunch of warnings. I am sure my error is in the wording of my cog init statement but cannot figure it out.
    Thanks
    Jim

  • @RS_Jim: I can't compile that file at all, it's missing outside files like boardcfg.kiss and ADC_millivolts_pasm. I was able to work around that, and see several problems:

    (1) The first warning is

    jsm_adc_demo7.spin2:119: warning: no argument given for ASM coginit/cognew; assuming 0
    

    If you look at line 119 it's a call to coginit with only two parameters. Normally there are 3 parameters (cog number, function to start, and pointer to parameters). You've written

      cog:=COGINIT(COGEXEC_NEW,ADC_pasm(_pins,_samples))   ' read adc pins as millivolts
    

    but ADC_pasm is a label, not a function. Also, there are a bunch of undefined data at the and of the assembly code (which I presume you've cut and pasted from elsewhere) in res statements, and a comment that says "Initially set by Spin2 code to select the pins", but that happens nowhere.

    (2) Most of the warnings are probably harmless, since they're about constants after altd or alts; you can get rid of them by replacing "0" with "0-0" as suggested in the warning message.

    (3) The actual error is jsm_adc_demo7.spin2:179: error: Unknown symbol D because of line 179:

            wrword  D,#samples
    

    The symbol D is not defined anywhere in your program. What is that supposed to be?

  • @RS_Jim: you'll want to try something like what I've attached to this message, probably. I don't actually have any ADC hardware equipped, but it's producing output similar to Chip's (on a serial port instead of on a VGA monitor).

  • Thanks Eric,
    I downloaded what you attached and after adjusting a few parmiters to get everything working in my environment, it works like a charm. I had to read through the code to realize that you are running this under an interupt just in a cog. that works fine and I have no shortage of cogs.
    Now to add in the other elements of my code. Thanks again for all you do.
    Jim

  • Have a strange bug here:

    I have this main program:

    #include <stdio.h>
    #include <propeller.h>
    #include "test.h"
    
    
    int main(int argc, char** argv)
    {
        int i;
    
        printf("Starting...\n");
    
        Test("Test this function");
    
        while (1)
        {
            _pinl(56);
            _pinh(57);
            _waitms(500);
            _pinh(56);
            _pinl(57);
            _waitms(500);
        }
    }
    

    I have this test header file:

    /**
     * @file test.h
     * @author your name (you@domain.com)
     * @brief 
     * @version 0.1
     * @date 2023-03-11
     * 
     * @copyright Copyright (c) 2023
     * 
     */
    
    /**
     * @brief Test Function
     * @param data
     */
    void Test(char *data) __fromfile("test.c");
    

    I have this test function:

    /**
     * @file test.c
     * @author your name (you@domain.com)
     * @brief 
     * @version 0.1
     * @date 2023-03-11
     * 
     * @copyright Copyright (c) 2023
     * 
     */
    
    char Buffer[256];
    
    
    void Test(char *data)
    {
        sprintf(Buffer, "This is First %s\n", data);
    
        printf(Buffer);
    }
    

    When I run this program I get this:

    Loading 24516 bytes.
    Program Loaded
    Entering terminal mode.  Press Ctrl-] to exit. 
    Starting...
    Test this functionThis is First
    

    The output should be "This is First Test this function".
    If I put an sprintf function in the main somewheres all is good.

    Mike

  • @iseries : yes, that was a strange one. It was basically a flaw in an optimization that tried to simplify the printf code when there were no sprintfs or fprints; it didn't know about functions pulled in via __fromfile() and so missed that Test() contained sprintf. I've disabled that optimization in the github sources, at least for now.

  • Question?
    I know you calculate the baud rate on first output. How do I reset that if I later change processor speeds.

    Mike

  • I see you have littefs now included as a file system. I was trying to get that to work some time ago but couldn't get past the MACRO defs.

    I thought espressif was moving in that direction since spiffs was no longer being developed.

    I see now that they have removed littefs from there builds and have gone back to spiffs.

    I had spiffs running some time ago but didn't really move forward with it.

    So don't know where the market is going, and I guess they both do the same thing.

    Mike

  • @iseries said:
    Question?
    I know you calculate the baud rate on first output. How do I reset that if I later change processor speeds.

    Mike

    It was supposed to be reset automatically if you use _clkset() to change the speeds, but I see that isn't working right. I'll try to fix it, but in the meantime there's a _setbaud(BAUD_RATE) call that should always work.

  • @iseries said:
    I see you have littefs now included as a file system. I was trying to get that to work some time ago but couldn't get past the MACRO defs.

    I managed to improve FlexC's c99 support to get past that.

    I thought espressif was moving in that direction since spiffs was no longer being developed.

    I see now that they have removed littefs from there builds and have gone back to spiffs.

    Hmm, interesting. Littlefs seems to have more features and better support (in particular they had some good examples of how to use it) so now that it can compile with FlexC I think I'll try to add a _vfs for it to hook it in to the C file system code. We could add spiffs too, later.

    Regards,
    Eric

  • RaymanRayman Posts: 13,710

    LittleFS is included? As alternative to FatFS? Or, as way to use extra flash space as a drive?

  • @Rayman said:
    LittleFS is included? As alternative to FatFS? Or, as way to use extra flash space as a drive?

    As a way to use extra space in the flash. It's not quite polished yet, although what's checked in to flexspin's github sources is usable (you can read and write files on the flash). The part that's giving me headaches right now is locking out the SD card while flash is in use, and vice-versa. Plus, it all needs documenting.

  • I've released FlexProp 6.0.0 (with bytecode and flash file system support) on my Patreon page. The sources and compiler binaries are on github now; I'll make an IDE binary release on github later this week.

    The big changes from the last release are (a) better P2 bytecode support (it's now getting pretty reasonable, although there are still likely bugs) and (b) support for the LittleFS flash file system used on ARM devices. LittleFS is hooked into the regular mount() system, just like the host file system and FAT file system, so all the usual C and BASIC file operations work with it. By default it uses 6 MB of the boot flash, starting at offset 2 MB; that leaves lots of space for boot code and overlays. You can change this by passing a structure to the _vfs_open_littlefs_flash routine. For example, here's a BASIC program to save a user's message in flash:

    '
    ' example of using the built-in FLASH memory on the P2 Eval board
    ' to save some data
    '
    ' Written by Eric R. Smith and placed in the public domain
    
    #ifndef __P2__
    #error "This demo requires a P2"
    #endif
    
    const AUTO_FORMAT_NO =  0   ' no automatic format of flash
    const AUTO_FORMAT_YES = 1   ' format flash if necessary
    
    ' flash configuration
    ' this is the default config used by C (6MB starting at offset 2MB),
    ' change it if you want
    
    dim shared as ulong(8) flashcfg = {
      256,          ' page size for writes
      65536,        ' block size for erases
      2*1024*1024,  ' starting address (must be a multiple of erase block size)
      6*1024*1024,  ' size of file system (must be a multiple of erase block size)
      0, 0, 0, 0    ' reserved
    }
    
    dim as integer choice  ' which choice the user selected
    
    '
    ' first, we have to mount the flash file system
    '
    mount "/flash", _vfs_open_littlefs_flash(AUTO_FORMAT_YES, flashcfg)
    
    ' for testing, we could use the host file system instead
    ' mount "/flash", _vfs_open_host() ' for development / testing
    
    
    ' now loop asking the user whether to show old message or
    ' write new message
    
    do
      print
      print "(1) see previous message"
      print "(2) save new message"
      input "Which one"; choice
      print
      if choice == 1 then
        show_message
      else if choice == 2 then
        save_message
      else
        print "invalid selection "; choice
      end if
    loop
    
    '
    ' routine to show an old message
    '
    sub show_message()
      dim as string msg$
      dim as integer err
    
      ' try to open the message file
      ' if we cannot, fail and return
      try
        open "/flash/msg.txt" for input as #3
      catch err
        print "Unable to open msg.txt, error is:", err
        return
      end try
    
      print "Message is:"
      ' read the whole file
      do
          ' get up to 1024 characters from the file
          msg$ = input$(1024, 3)
          print msg$;
      loop while msg$ <> ""
    
      close #3
      print "<END>"
    end sub
    
    '
    ' routine to write a new message into the file
    '
    sub save_message()
      dim as string a$
      dim as integer err
    
      ' try to open or create the file
      try
        open "/flash/msg.txt" for output as #3
      catch err
        print "Unable to open msg.txt, error is:", err
        return
      end try
    
      ' read lines from the user
      ' an empty line will read as "", so terminates the loop
      print "Enter your message (terminate with an empty line):"
      do
        line input a$
        if a$ <> "" then
           print #3, a$  
        endif
      loop until a$ = ""
    
      print "<END>"
      close #3
    end sub
    
  • RaymanRayman Posts: 13,710
    edited 2023-03-15 16:17

    LittleFS support is very nice!
    Seems like you'd want to use all the space over 2 MB in order to maximize the wear leveling, right?
    Or, are you thinking of there being multiple drives there?
    Does it use long file names?

    Also, what about rebooting from a P2 binary on the LittleFS drive... Sound possible?

  • @Rayman said:
    LittleFS support is very nice!
    Seems like you'd want to use all the space over 2 MB in order to maximize the wear leveling, right?

    Well, I thought some boards might only have 8MB chips. But it's all configurable, so I suppose perhaps the default should be to use 14 MB. Honestly I don't think wear leveling is too much of a factor on modern flash chips, and I think LittleFS has pretty advanced handling for this.

    Does it use long file names?

    Up to 255 characters, by default, although you can change this by defining LFS_NAME_MAX on the command line.

    Also, what about rebooting from a P2 binary on the LittleFS drive... Sound possible?

    I haven't tried it, but it should be -- it's just another file system, so the exec() and chain() functions should work from it (with the usual restriction that both the original binary and the new one have to fit in memory at the same time).

  • pik33pik33 Posts: 2,342
    edited 2023-03-16 11:23

    I tried 6.0.1 with the P2Play.

    This:

    declare a6502buf alias $64000 as ubyte($10FFF)

    causes this:

    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:62: error: Internal error expecting function call

    Edit: 5.9.26 has also this error comment... I have now to find the latest version that can compile the player.

    Edit 2

    When tried the older version, now the command line is

    "C:/Users/Piotr/Desktop/flexprop/bin/flexspin" -2 -l --tabs=8 -D_BAUD=230400 -Os    utf8 -I "C:/Users/Piotr/Downloads/flexprop-5.9.9/flexprop/include"  "D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas"
    

    which results with the error

    Unable to open file `utf8': child process exited abnormally`
    

    Edit 3

    I found and deleted the config file. Now 5.9.20 can compile the player.

    The results so far: 5.9.20 OK, 5.9.26: 'Internal error expecting function call`

    I have no versions between them to test and I am now on a Windows machine, so I cannot do git magic.

  • @pik33 : Are you able to share the code you're trying to compile? Or at least the exact line 62 from player30.bas? My simple test cases for declare alias still work, so there's some specific way that you're using it that's triggering the compiler bug.

  • pik33pik33 Posts: 2,342
    edited 2023-03-16 14:03

    That's this project: https://gitlab.com/pik33/P2-retromachine/-/tree/main/Propeller/P2P16, file "player30.bas"

    I tried the simplest code (extracted the declare lines) and it compiles OK, so there is maybe something in other files that is incompatible with new versions of Flexprop. I will try to narrow the problem

    The best I can do (later) is to switch to the Linux machine and try git bisect to find the change that broke the compatibility. 5.9.20 compiles the project while 5.9 26 doesn't.
    I found peek/poke functions redefined in the project, but removing these definitions didn't help.

    The log:

    "C:/Users/Piotr/Downloads/flexprop-6.0.1/flexprop/bin/flexspin" -2 -l --tabs=8 -D_BAUD=230400 -O1    --charset=utf8 -I "C:/Users/Piotr/Desktop/flexprop/include"  "D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2023 Total Spectrum Software Inc. and contributors
    Version 6.0.1 Compiled on: Mar 15 2023
    player30.bas
    |-ht009.spin2
    |-|-psram.spin2
    |-|-|-psram16drv.spin2
    |-retrocog.spin2
    |-trackerplayer.spin2
    |-audio093b-8-sc.spin2
    |-sidcog8.spin2
    |-psram.spin2
    |-spccog.spin2
    |-a6502-1.spin2
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/ht009.spin2:349: warning: used spaces for indentation (previous lines used tabs)
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/ht009.spin2:938: warning: used spaces for indentation (previous lines used tabs)
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:62: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:62: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:62: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:62: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:64: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:64: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:64: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:63: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:64: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:64: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:63: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:63: error: Internal error expecting function call
    D:/Programowanie/P2-retromachine-1/Propeller/P2P16/player30.bas:62: error: Internal error expecting function call
    child process exited abnormally
    Finished at Thu Mar 16 15:02:21 2023
    

    The lines:

    declare a6502buf alias $64000 as ubyte($10FFF) '64000 doesnt work, why?
    declare mainstack alias $75000 as ubyte(2559)
    declare filebuf alias $76400 as ubyte(16383)
    
  • @pik33 : I think I've found the issue, it's related to some changes to support Spin2 anonymous objects which unfortunately interacted badly with some BASIC ALIAS syntax, but this only affected functions called before they were compiled (my tests always had them the other way around). I should have a fix for this soon. Thanks for the bug report!

  • I've just uploaded FlexProp 6.0.2. This has the bug fix for the ALIAS problem that @pik33 found, as well as another fix for internal errors that another user found, so I recommend upgrading to it.

  • pik33pik33 Posts: 2,342
    edited 2023-03-17 13:40

    The player (the working file is 029, not 030) now compiles and works in standard asm mode using 6.0.2

    It compiles now in the bytecode mode too (the first time it can) and the result is much shorter binary (about 150 kB instead of 250 kB) but it doesn't work. It tries (I can see the picture for about a second but then all disappears).

    However the player is several thousand lines of buggy code, so I am not surprised that something does't work in the new compiler mode.

  • JRoarkJRoark Posts: 1,214
    edited 2023-03-18 18:50

    @ersmith I'm having issues getting littleFS to work in FlexBASIC. Any MOUNT returns the error "Invalid Argument" (error 10). This code shows it:

    OPTION EXPLICIT
    CONST HEAPSIZE = 16000
    
        dim fHandle as ulong
        dim i as ulong
        dim a$ as string
        dim o$ as string
    
        mount "/fs", _vfs_open_littlefs_flash()   '<---- fails: Invalid Argument
        'mount "/fs", _vfs_open_host()    '<---- works.
    
        print "MOUNT returned: ";strerror$(geterr()); "  Error# "; geterr()
    
        fHandle = freefile()
        print "FREEFILE returned: ";strerror$(geterr()); "  Error# "; geterr()
    
        if fHandle < 0 then
            print "Oops. No free file handles available"
            do:loop
        end if
    
        print "Writing 10 records:"
        open "/fs/file.txt" for output as #fHandle
        print "OPEN:WRITE returned: ";strerror$(geterr()); "  Error# "; geterr()
        for i = 1 to 10
            o$ = "This is a test of the number " + strint$(i)
            print #fHandle, o$
            print o$
        next i
        close #fHandle
        print "CLOSE:WRITE returned: ";strerror$(geterr()); "  Error# "; geterr()
    
        print
        print "Reading 10 records:"
        open "/fs/file.txt" for input as #fHandle
        print "OPEN:READ returned: ";strerror$(geterr()); "  Error# "; geterr()
        for i = 1 to 10
            line input #fHandle, a$
            print a$
        next i
        close #fHandle
        print "Done!"
    

    If you simply change the MOUNT from littleFS to Host, the above code works fine. Thoughts?
    Edit: I'm using Flex 6.0.2 on Win10 with optimization set to "default".

  • @JRoark : For _vfs_open_littlefs_flash in BASIC you'll have to provide 2 parameters. The first is an integer specifying whether to format the flash if it is not already formatted; 0 means do *not* format, any non-zero value means format. The second parameter is a pointer to the flash configuration, or 0 to use the default configuration. So changing your line to:

       mount "/fs", _vfs_open_littlefs_flash(1, 0)
    

    should work. There's an example "flash.bas" in the FlexProp samples directory.

  • Question? I want to use full duplex for the default serial port. How do I disable the default driver, stdout, stdin, stderr and open it with a full duplex driver.

    On the P1 we had simpleterm_close().

    Mike

  • @iseries said:
    Question? I want to use full duplex for the default serial port. How do I disable the default driver, stdout, stdin, stderr and open it with a full duplex driver.

    Unfortunately we don't have freopen yet, I need to work on that. For now you could replace the low level I/O routines putcf and getcf in the standard handles, something like

    #include <stdio.h>
    #undef printf  // very important, do not use builtin_printf
    
    int putx(int x, FILE *f) {
        // all output becomes upper case
        if (x >= 'a' && x <= 'z') {
            x = x + ('A' - 'a');
        }
        _tx(x);
    }
    
    int getx(FILE *f) {
        int x;
        x = _rx();
        // all input becomes lower case
        if (x >= 'A' && x <= 'Z') {
            x = x + ('a' - 'A' );
        }
        return x;
    }
    
    void main() {
        int ch;
        stdin->getcf = getx;
        stdout->putcf = putx;
        // leave stderr alone, for now
        for(;;) {
            printf("press a key: ");
            ch = fgetc(stdin);
            fprintf(stderr, " got '%c' = 0x%x\n", ch, ch);
        }
    }
    
  • @ersmith said:
    @JRoark : For _vfs_open_littlefs_flash in BASIC you'll have to provide 2 parameters. The first is an integer specifying whether to format the flash if it is not already formatted; 0 means do *not* format, any non-zero value means format. The second parameter is a pointer to the flash configuration, or 0 to use the default configuration. So changing your line to:

       mount "/fs", _vfs_open_littlefs_flash(1, 0)
    

    should work. There's an example "flash.bas" in the FlexProp samples directory.

    That works a treat, Eric. Thank you.

    This was one of those “I should have RTFM’d” moments. 🙈 Next time I need to hit the samples directory too!

  • bob_g4bbybob_g4bby Posts: 401
    edited 2023-03-21 10:08

    Hi @ersmith, Running Flexprop 6.0.2 on Windows 10 64 bit and compiling program:-
    Print "Hello World!"
    Compile bytecode on the P1 is successful, but compile in fast mode produces a long string of errors. Is that expected at the moment? Compile on P2 works fine in both modes.

    Here's some of the error message:-

    "C:/flexprop/bin/flexspin" --tabs=8 -D_BAUD=115200 -l -O1    --charset=utf8 -I "C:/Program Files/flexprop/include"  "C:/Users/bobed/Documents/Hi World.bas"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2023 Total Spectrum Software Inc. and contributors
    Version 6.0.2 Compiled on: Mar 17 2023
    C:/Users/bobed/Documents/Hi World.pasm:5: error: HUB PC mismatch for entry: at $18 but label value is $0
    C:/Users/bobed/Documents/Hi World.pasm:11: error: HUB PC mismatch for cogexit: at $2c but label value is $14
    C:/Users/bobed/Documents/Hi World.pasm:14: error: HUB PC mismatch for spininit: at $34 but label value is $1c
    C:/Users/bobed/Documents/Hi World.pasm:30: error: HUB PC mismatch for LMM_LOOP: at $70 but label value is $58
    C:/Users/bobed/Documents/Hi World.pasm:33: error: HUB PC mismatch for LMM_i1: at $78 but label value is $60
    C:/Users/bobed/Documents/Hi World.pasm:37: error: HUB PC mismatch for LMM_i2: at $84 but label value is $6c
    C:/Users/bobed/Documents/Hi World.pasm:41: error: HUB PC mismatch for LMM_i3: at $90 but label value is $78
    
  • @bob_g4bby : There's a bug in the listing file output for P1. I'll updated FlexProp soon to fix this, but in the meantime you can work around it by turning off the listing file. Thanks for the bug report.

  • After a joyful time playing with design of P2 hardware, now comes the much less fun part for me with the coding. I tried all available software for P2 (as I am just a starting coder with it), and Flexprop is decisively my favourite, however, there are some very basic features which are either missing or I was unable to enable.
    First, it looks to me like there is no concept of a project in terms of a unit of several source files. Am I right to assume that? Also, probably descending from the latter, there is no side panel with project tree or folder, and (the one I am missing the most) - no document tabs.
    Regardless, I still prefer Flexprop over the insane complexity of VS Code, and I never managed to get Catalina to work at all, so a bit forced choice, but still valid.
    Is there any chance at least document tabs might appear any time soon in Flexprop?

Sign In or Register to comment.