Shop OBEX P1 Docs P2 Docs Learn Events
PNut/Spin2 Latest Version (v51 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, EXP floating-point ops) - Page 75 — Parallax Forums

PNut/Spin2 Latest Version (v51 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, EXP floating-point ops)

17071727375

Comments

  • @wummi said:
    Hi Chip,
    I found a strange behavior with REPEAT <count> WITH <variable> when count is zero.

    PUB go () | i
      repeat 0 with i
        debug(sdec(i))
    { debug output
    Cog0  i = 0
    Cog0  i = -1
    }
    

    I expected debug(sdec(i)) is never executed, but it executes twice.

    I believe this behavior is expected. The Spin document indicates that the count value is normally expected to be a number greater than 0.
    The WITH form of the REPEAT statement is a smaller/faster version than the REPEAT FROM statement.

    v40 2023-09-21 ● New smaller/faster REPEAT form added for iterating a variable from 0 to n-1, where n > 0.
       REPEAT n WITH i 'best way to iterate a variable from 0 to n - 1
       REPEAT i from 0 to n - 1 'general equivalent, though WITH needs n > 0
    
    Example:
    
    _clkfreq = 200_000_000
    
    PUB go () | i,n
    
      repeat 0 with i
        debug("with loop: ",sdec(i))
    
      n := 0  
      repeat i from 0 to n-1
        debug("from loop: ",sdec(i))
    
    Output:
    Cog0  with loop: i = 0                                                          
    Cog0  with loop: i = -1                                                         
    Cog0  from loop: i = 0                                                          
    Cog0  from loop: i = -1
    
  • wummiwummi Posts: 103

    OK, i do not now that n must be greater than 0

  • evanhevanh Posts: 16,678

    Undefined is not the same as expected.

  • cgraceycgracey Posts: 14,280
    edited 2025-04-02 21:30

    A new PNut_v51 has been posted at the top of this thread.

    v51 - 2025.04.02 - New POW, LOG2, EXP2, LOG10, EXP10, LOG, and EXP floating-point operators. SIZEOF() can now be used by PASM code to get sizes of structures. Long variables within structures can now be used as method pointers. Ignore-multiple-return-values '_ (number_of_longs)' had a stack bug rendering it useless, so it has been fixed and the syntax has been changed to use brackets, instead: '_ [number_of_longs]'.

  • Posted this to the github but I'm not sure if it goes there or here, having some syntax issues with structs vs the example.

    https://github.com/parallaxinc/P2_PNut_Public/issues/6

    Hope I didn't miss a post about it or something. lil help?

  • ersmithersmith Posts: 6,203

    Make sure your code has a {Spin2_v51} comment at the very start to declare the Spin2 version number.

    In your posted example you've got syntax like:

    STRUCT mavlink_message_header(BYTE mark = PROTOCOL_MARKER_V1, BYTE mlen, BYTE seq, BYTE srcSystem, BYTE srcComponent, BYTE msgId)
    

    I don't think initializing the structure members (mark = xxx) is legal in PNut; it certainly isn't in FlexSpin.

  • Thanks. I'd like to suggest this be made more prominent in the manual than just in a changelog note 10 versions back from current. This is extremely easy to miss if you don't know what you're looking for.

  • Also you are correct, you cannot have constant structure members or defaults in Spin2. Nice to have but really not required.

    Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?

  • RaymanRayman Posts: 15,560

    @RbtsEvrywhr_Riley said:
    Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?

    Think that is the idea behind PNut_TS ...

  • JonnyMacJonnyMac Posts: 9,437

    @RbtsEvrywhr_Riley said:
    Also you are correct, you cannot have constant structure members or defaults in Spin2. Nice to have but really not required.

    Matteo's been hoping for a Propeller Tool that supports v51 or a more portable solution, so that IDEs can be pointed to compiler executables and you can decouple IDE development from compiler development. Any possibility of these in the near future?

    Have you looked at Spin Tools IDE? It has an internal compiler (which Marco keeps up to date with PNut) and facilities to use external compilers. There are features I still like about Propeller Tool (bookmarks and code folding in the main window), so I start there, then move to Spin Tools where I can call the latest version of PNut to do the compilation if desired.

    Spin Tools thread
    -- https://forums.parallax.com/discussion/174436/spin-tools-ide#latest

  • Thanks, I'm gonna put some brain cycles into looking at that shortly!

  • RbtsEvrywhr_RileyRbtsEvrywhr_Riley Posts: 44
    edited 2025-07-08 20:49

    I've found an issue with structs in DAT blocks in the current pnut v51a

    CON
        STRUCT foo (bar, baz)
    
    DAT
    stuff foo[64]
    

    Does not compile. You cannot initialize a block of structs in a DAT block, which kinda defeats the purpose of packed DAT blocks to begin with. Is this something that may change in the future?

  • @RbtsEvrywhr_Riley said:

    DAT
    stuff foo[64]
    

    But <typename>[<expression>] has never been valid syntax for anything in a DAT block. There's no initializer syntax for structs, but you can

    DAT
    stuff foo
    long 0[64*2]
    

    or maybe

    stuff foo
    long 1,2
    long 10,20
    ' etc...
    
  • Yeah, as long as you fill it with 0s, you can define a block of, for example, 64*2 longs.

    So you do that with structs by doing the same thing, but just putting a single struct pointer at the start, and then just moving a struct pointer around. Or just use an offset table like we did on the P1. Got it.

    It's definitely a slightly different approach, as at least as far as I remember from the P1 if I define 100 longs starting from pointer foo, I can go foo[32] and just have an offset, but if foo is a struct pointer I can't? Or can I?

    Sounds like the functionality works and the manual could stand to be clearer.

  • RbtsEvrywhr_RileyRbtsEvrywhr_Riley Posts: 44
    edited 2025-07-12 03:08

    PNut is failing to load and compile this object in Obex. It's giving me "invalid character" errors and if I save from pNut it corrupts the file. Anybody know what's going on?

    https://obex.parallax.com/obex/fat32-sd-card-driver/

    Edit: the encoding of the spin2 file is UCS-2. That's probably it.

  • evanhevanh Posts: 16,678
    edited 2025-07-12 04:45

    Ya, first thing I always do is convert the source files to UTF-8. Or even strip it down to ASCII and ignore/delete the damaged comments sections.

  • ke4pjwke4pjw Posts: 1,213

    Having an issue with V51a. I am creating a binary file by using the -c option, however when I rename it _BOOT_P2.BIX and place it on the SD card, the P2 does not appear to boot. Same card works when doing this with PropTool and spin-tools. Also, I can get it to work by programming and booting from RAM.

    Am I doing it correctly with PNUT?

  • ke4pjwke4pjw Posts: 1,213

    Just bumping this again. Is -c the correct flag to create a bootable SD card image?

  • JonnyMacJonnyMac Posts: 9,437

    Pretty sure it's -ci, but I've been having troubles, too. Will get back to it tomorrow.

    From the docs:

    What I have in my external tools setup inside Spin Tools:

  • JonnyMacJonnyMac Posts: 9,437

    Whoops... I've not been sleeping well and I missed the detail about booting from an SD card; I need a file that I can write to flash without modifying.

  • RaymanRayman Posts: 15,560

    So, the flash binary is something new and special and the uSD is just the regular old binary?

    BTW: Why didn't they make it so the regular binary works from both Flash and uSD and HUB Ram? Can't remember why the flash version has to be different...

  • ke4pjwke4pjw Posts: 1,213

    A 2nd stage bootloader is needed for flash. Probably just to make it robust.

    Yeah, it's weird as I can boot from the same card if PropTool or SpinTool creates the image. I can also run from RAM with PNUT, but with the image it creates with the -c flag, that isn't bootable on SDcard.

    Tonight I will try with a simple image to make sure there isn't something else causing the issue. I am trying to get all of my programs working on the current toolsets.

  • JonnyMacJonnyMac Posts: 9,437

    Can't remember why the flash version has to be different...

    I think it has to do with the Spin2 interpreter being part of the image.

  • RaymanRayman Posts: 15,560

    @ke4pjw Maybe it works in the gui with "Generate Binary File after Compiling" option on?

  • @JonnyMac said:

    Can't remember why the flash version has to be different...

    I think it has to do with the Spin2 interpreter being part of the image.

    The interpreter always needs to be there, the flash version needs a bootloader. The current PNut bootloader also needs a checksum and file size added in.

    IIRC there point there was that there's way too many different flash chips, so the bootloader stub is loaded using the simplest commands possible and that then handles the rest of the load.

  • RaymanRayman Posts: 15,560

    @Wuerfel_21 can see that, and yet there is only one boatloader right?

    Seems would be better if rom loaded a bootloader from flash that then loaded the regular binary from some offset…
    But cake is baked.

  • @Rayman said:
    @Wuerfel_21 can see that, and yet there is only one boatloader right?

    Seems would be better if rom loaded a bootloader from flash that then loaded the regular binary from some offset…
    But cake is baked.

    It does work like that, ROM loads the bootloader and that is then able to do whatever it wants.

  • ke4pjwke4pjw Posts: 1,213

    @Rayman said:
    @ke4pjw Maybe it works in the gui with "Generate Binary File after Compiling" option on?

    It created the same size file, so I assume it is identical. This may just be me. I might be doing something wrong. Thanks for showing me how to turn that on in the GUI. It wasn't intuitive.

  • RaymanRayman Posts: 15,560

    @Wuerfel_21 That's a good point. Suppose could have just one boot file located at $0 and then cook the flasher to put the regular binary at $1000 instead of $0.
    That could work, right?

    This is suddenly reminding me of the menu system that am wanting to make...

  • RaymanRayman Posts: 15,560

    Now thinking about having a _BOOT_P2.BIX that lives in a flash file system, to be auto-started by the flash bootloader...

Sign In or Register to comment.