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

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

1131416181954

Comments

  • Changed handling of ? operator in Spin2 to be compatible with PNut

    Thanks Eric! :smiley:

  • @ERSmith There seems to be some mischief happening with FlexBASIC's PRINT USING in 5.3.0-beta. Running the following code gives interesting results:

        dim myVar as single
        myVar = 123.4
        print using "####"; myVar   ' "1.2e"
        print using "#.##"; myVar   ' " 123"
        print using "##.#"; myVar   ' "1.2e"
        print using "###.#"; myVar  ' "1.2e+"
    
    

    The formatting character "#" seems to be misinterpreted and the "." is being ignored. Also, note the extra space in the PRINT USING "#.##" example. Odd.

    I don't know if this is a new bug or an old one as I never really tested PRINT USING much.

  • @JRoark : Yes, there was definitely something weird going on with print using on float values. I've fixed this so it's a bit better in the final 5.3.0 release (which is available now); it still needs some work though. At least now if the float overflows the given space it prints *'s (as the integer print does) to let you know.

  • I've uploaded flexprop 5.3.0 to my Patreon page and to github. There are a lot of bug fixes in this release, so it's well worth updating. In particular P2 Edge users will probably want to update to this version since it has the newest loadp2, which fixes a checksum error that is seen on some Edge boards.

  • RaymanRayman Posts: 13,800

    So that loadp2 issue is only with edge modules...

    Any idea why?

  • @Rayman said:
    So that loadp2 issue is only with edge modules...

    Any idea why?

    No, I don't know why, and I don't know for sure that it's only Edge modules (but that seems to be where it's been happening). At least there's a work-around.

  • Speaking of loadp2, has anyone written some code for using it to copy files onto the SD card yet?

  • @Wuerfel_21 ,

    Why would you want to do that? You can just plug the card into your PC and write them.

    I did use SPIFFS and wrote files from the SD card to the Flash memory though.

    Mike

  • @Wuerfel_21 said:
    Speaking of loadp2, has anyone written some code for using it to copy files onto the SD card yet?

    There's a complete command line shell that comes with FlexProp, in the samples\shell subdirectory. It mounts the SD card as /sd and the host file system as /host, so you can do things like:

    copy /host/something.txt /sd/myfile.txt
    

    (or vice-versa). It also lets you create and remove directories and do other housekeeping operations.

  • RaymanRayman Posts: 13,800

    That's neat! I thing you said earlier that one can also mount Plan9 and uSD at the same time in C....

  • @Rayman said:
    That's neat! I thing you said earlier that one can also mount Plan9 and uSD at the same time in C....

    That's exactly what the shell program does. The source code is there in the samples directory if you want to see, but there's really nothing tricky to it -- just call mount() multiple times with different file systems and different mount point names.

  • roglohrogloh Posts: 5,122
    edited 2021-03-26 03:49

    @ersmith
    Eric, does FlexProp check SEND being assigned to zero before calling it, in case some called code calls SEND but has not set it up prior? I was running into a problem with an old SEND buried in called code where the caller had not set it up prior, apparently causing the app to be relaunched for a second time. I think if SEND is unassigned / zero by default it should not get invoked, at least as type of safety measure to prevent application crashes. Same goes for RECV I guess. Maybe return 0 or perhaps $ffffffff in that case.

  • @rogloh said:
    @ersmith
    Eric, does FlexProp check SEND being assigned to zero before calling it, in case some called code calls SEND but has not set it up prior? I was running into a problem with an old SEND buried in called code where the caller had not set it up prior, apparently causing the app to be relaunched for a second time. I think if SEND is unassigned / zero by default it should not get invoked, at least as type of safety measure to prevent application crashes. Same goes for RECV I guess. Maybe return 0 or perhaps $ffffffff in that case.

    I'm not sure that silently failing is better than spectacularly failing -- either way if SEND is not set up properly then the program will not work as expected.

  • I was trying to install flexprop to my new xubuntu machine and I got the following error:

    ray@gbbrix1:~/src$ cd flexprop
    ray@gbbrix1:~/src/flexprop$ make install
    cpp -xc++ -DTCL_SRC < version.inp > src/version.tcl
    cpp: fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory
    compilation terminated.
    make: *** [Makefile:283: src/version.tcl] Error 1
    ray@gbbrix1:~/src/flexprop$

    Not sure if this is a problem with xubuntu or the flexprop install itself.

    Ray

  • Looks like the C++ compiler isn't installed in your xubuntu. Make sure you follow all of the steps in the "Building from source" section of the flexprop README.md.

  • @ersmith said:

    @Wuerfel_21 said:
    Speaking of loadp2, has anyone written some code for using it to copy files onto the SD card yet?

    There's a complete command line shell that comes with FlexProp, in the samples\shell subdirectory. It mounts the SD card as /sd and the host file system as /host, so you can do things like:

    copy /host/something.txt /sd/myfile.txt
    

    (or vice-versa). It also lets you create and remove directories and do other housekeeping operations.

    Yeah, that works. Well, kindof, the file I copied ended up split into four fragments, which doesn't work for my purposes. Any chance of improving the FAT code to avoid fragmentation?

  • The FAT code came from elsewhere, it's not mine. In any event fragmentation is a feature of the FAT file system, so it could happen no matter what OS or tools you use -- the only way to avoid it is to wipe the disk clean before trying to do the copy.

  • @ersmith said:
    The FAT code came from elsewhere, it's not mine. In any event fragmentation is a feature of the FAT file system, so it could happen no matter what OS or tools you use -- the only way to avoid it is to wipe the disk clean before trying to do the copy.

    The file system drivers on PCs actively avoid fragmentation when copying a file by looking for a run of contiguous free clusters large enough to hold the file. It never happens unless the volume is almost full (or very fragmented as is).

  • RamonRamon Posts: 484
    edited 2021-03-27 04:57

    Eric,

    Please can you point at some document that explains how to write leading zeros on serial printf and binary formating.
    I am using SPIN2, and need something like ser.printf(" Value : %02d, " , two_digits_variable) and ser.printf(" Binary : %b", bin_data).

    Not sure if the problem is that current printf doesn't have that functionality, and I should use sprintf instead. I am not able to get ser.sprintf working either.

    Thanks!

    Edit: I am using

    OBJ
    ser: "spin/SmartSerial"

  • @ersmith said:

    @rogloh said:
    @ersmith
    Eric, does FlexProp check SEND being assigned to zero before calling it, in case some called code calls SEND but has not set it up prior? I was running into a problem with an old SEND buried in called code where the caller had not set it up prior, apparently causing the app to be relaunched for a second time. I think if SEND is unassigned / zero by default it should not get invoked, at least as type of safety measure to prevent application crashes. Same goes for RECV I guess. Maybe return 0 or perhaps $ffffffff in that case.

    I'm not sure that silently failing is better than spectacularly failing -- either way if SEND is not set up properly then the program will not work as expected.

    Yes though if send is silently outputting nothing because you've not assigned it, I think that is okay. People will likely soon realize that there should be no output if send hasn't yet been assigned. However if the application simply restarts at address 0 because you've included some other object that happened to leave a send instruction buried in it expecting the top level to have already set up a pointer to some default output device, it will cause all sorts of havoc, and people may not realize why. Took me a quite a while to figure out what was going on because my program would effectively start up twice and the initial state would be different on the second run. I could see this error being quite a common mistake and based on the weirdness you observe you don't immediately suspect it has anything to do with send not being assigned, especially if the send call is nested deeper into the code.

  • @rogloh ,

    Some processors when they boot start at a high address just to avoid this problem. They put the interrupt instructions at the low addresses. That way when some program code does a call or jump to a null pointer it causes a null pointer exception.

    Well the P2 starts at address zero so now what. Put a jump instruction at that address to jump to a null pointer exception?

    Mike

  • So, I reinstalled the latest version of xubuntu, and tried doing the the flexprop thing. Still running into problems.

    After doing the initial install of tcl tk, bison, and git, the first problem:

    ray@gbbrix1:~/src$ cd flexprop
    ray@gbbrix1:~/src/flexprop$ make install
    Command 'make' not found, but can be installed with:
    sudo apt install make # version 4.3-4ubuntu1, or
    sudo apt install make-guile # version 4.3-4ubuntu1

    After doing the sudo apt install make, the second problem:

    ray@gbbrix1:~/src/flexprop$ make install
    cpp -xc++ -DTCL_SRC < version.inp > src/version.tcl
    cpp: fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory
    compilation terminated.
    make: *** [Makefile:283: src/version.tcl] Error 1

    This was as far as I got the last time, so -

    ray@gbbrix1:~/src/flexprop$ sudo apt install cpp
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    cpp is already the newest version (4:10.2.0-1ubuntu1).
    cpp set to manually installed.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    ray@gbbrix1:~/src/flexprop$

    Now, where do I go from here, it seems that xubuntu does not like flexprop.

    Ray

  • @Ramon said:
    Eric,

    Please can you point at some document that explains how to write leading zeros on serial printf and binary formating.
    I am using SPIN2, and need something like ser.printf(" Value : %02d, " , two_digits_variable) and ser.printf(" Binary : %b", bin_data).

    Not sure if the problem is that current printf doesn't have that functionality, and I should use sprintf instead. I am not able to get ser.sprintf working either.

    Thanks!

    Edit: I am using

    OBJ
    ser: "spin/SmartSerial"

    The printf function in SmartSerial is not complete, it does not support printing leading zeros. Using printf is probably not a good idea, since it relies on flexspin specific Spin2 enhancements. I would use the ers_fmt.spin2 object instead:

    OBJ
      ser: "spin/SmartSerial"
      fmt: "spin/ers_fmt"
    ...
      send := @ser.tx
      send("Value: ", fmt.decn(two_digits_variable, 2), " anything else you want printed")
      send(" Binary: ", fmt.bin(bin_data))
    
  • @Rsadeika said:
    So, I reinstalled the latest version of xubuntu, and tried doing the the flexprop thing. Still running into problems.

    After doing the initial install of tcl tk, bison, and git, the first problem:

    You missed the most important install, build-essential. Seriously, follow the steps in the README exactly. I just tried them on a fresh xubuntu 20.10 live CD and they worked -- they were originally written for an ubuntu 16.04 LTS system, so I'm pretty sure they'll work on any recent Ubuntu. Here they are again:

    cd $HOME
    mkdir -p src
    cd src
    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install bison
    sudo apt-get install git
    sudo apt-get install tk8.6
    sudo ln -s /usr/bin/wish8.6 /usr/bin/wish
    git clone --recursive https://github.com/totalspectrum/flexprop
    cd flexprop
    make install
    

    Accept the defaults for any prompts you are given from apt-get.

  • @rogloh : the current version in Github initializes RECV and SEND to a simple function that just returns 0.

  • Sounds good Eric.

  • Thank you Eric for pointing out about ers_fmt.spin2 object and providing example !!

    I have another question: I think I have found some issue (bug?) with flexprop.

    ISSUE: empty in-line PASM (org .. end) inside a repeat blocks/interferes with the streamer.

    The following code use the streamer to toggle pin 36 at around 1 Hz:

    CON
    
      _clkfreq = 4_000_000
      DOWNLOAD_BAUD = 115_200
    
      OUTPIN   = 36
    
    PUB main() | md
    
      md := %0100_0000_1<<23 + OUTPIN<<17 + 32  'streamer mode: imm 32x1, 32 bits
      org
            setxfrq ##536            'streamer freq: 1/32 sysclock
            drvl    #OUTPIN                     'pin = output, low
            xinit   md, ##%1010_1010_1010_1010_1010_1010_1010_1010
      end
      repeat
        org
           'nop
        end
    

    PNut v35k : It compiles and execute correctly (pin 36 actually toggles)
    FlexProp 5.2 : It compiles, but pin 36 is not toggling.

    Thank you !

  • @Ramon : thank you for the bug report, I'll look into it. It does seem like putting any assembly language at all into the ORG / END fixes the issue, so at least there is an easy work-around.

  • I've uploaded a new version of flexprop (5.3.1) to both Patreon and github. The major compiler changes in this version are:

    - Added aliases for _pinw, _pinl, and _pinh in Spin (to match the documentation).
    - Better error messages for some bad C function declarations.
    - Cleaned up operator precedence to match Spin2
    - Fixed typos in SmartSerial.spin that made it stop working
    - Improved accuracy of parsing floating point constants.
    - Provided default dummy functions for send() and recv()
    

    On the GUI side, I added a Special menu option for running the command shell on P2 which allows you to copy files to/from the host.

  • ersmithersmith Posts: 5,900
    edited 2021-03-28 22:37

    I forgot to mention in my previous message that the binaries in the flexprop5.3.1.zip file are signed for both Mac and Windows, and so should be easier to install on Mac OS.

Sign In or Register to comment.