Shop OBEX P1 Docs P2 Docs Learn Events
Micropython for P2 - Page 13 — Parallax Forums

Micropython for P2

1789101113»

Comments

  • I'm learning Micropython, (actually Circuit Python) so forgive the elementary questions.

    Will this Micropython be able to use existing Circuit Python libraries? This opens up a lot of possibilities with an existing code base.
    My initial impression of Micropython on the P2 was it appeared to be a very expensive way to run the platform, that is until I realized that you were replacing the necessity of a programming platform like a PC. Then it makes sense!

    I'm curious about those boards I saw in the video from 3 months ago. Will these be available from Parallax or a partner?

    RJ

  • @RetroJeff said:
    I'm learning Micropython, (actually Circuit Python) so forgive the elementary questions.

    Will this Micropython be able to use existing Circuit Python libraries? This opens up a lot of possibilities with an existing code base.
    My initial impression of Micropython on the P2 was it appeared to be a very expensive way to run the platform, that is until I realized that you were replacing the necessity of a programming platform like a PC. Then it makes sense!

    I'm curious about those boards I saw in the video from 3 months ago. Will these be available from Parallax or a partner?

    RJ

    Those boards are from @Tubular and I've also wondered if they'd be completed.

    As for Circuit Python, TeamOz will answer that question. I believe the effort was to stay close to the hardware and original MicroPython code base produced by Damien.

    Ken Gracey

  • HI Retrojeff

    I suspect running CircuitPython is possible, there's more similarities than differences, we just haven't tried it yet. Do you have a particular library you wanted us to try?

    As for the P2DIP40 boards, yes these will be made available, they're about to be deployed in their first serious application and if all goes well we'll run a batch of 180

  • @Tubular said:
    HI Retrojeff

    I suspect running CircuitPython is possible, there's more similarities than differences, we just haven't tried it yet. Do you have a particular library you wanted us to try?

    Neopixel (neopixel.mpy) for those ws2811 strings as provided in the P2 holiday kits

    As for the P2DIP40 boards, yes these will be made available, they're about to be deployed in their first serious application and if all goes well we'll run a batch of 180

    I would definitely be interested when you have them for sale.

    RJ

  • Just giving this a small bump to see what the current state of Micropython for the propeller is.
    Curious if it will be able to support downloadable libraries?

    RJ

  • RaymanRayman Posts: 13,891

    @ersmith Been a while, but I'm attempting to compile this, without much luck. Not so surprising maybe...

    Are there instructions for compiling the P2 version?
    Is it just running make in the riscv-p2 folder?

    I've tried in Windows, Mac, and Ubuntu and can't get anywhere...
    One thing is that compiler complains about a lot of QSTR strings that aren't defined anywhere...

  • RaymanRayman Posts: 13,891
    edited 2024-04-16 21:14

    Or, if possible to provide a release with VGA basepin set to 8, maybe I could skip all this...
    Actually, guess I'd need to change uSD pins too...

  • RaymanRayman Posts: 13,891
    edited 2024-04-17 21:52

    Ok, think I've finally figured it out...
    Seems I had to download the code version of micropython and not the "latest release".
    Something about integer definitions is wrong in latest release.

    Then, had to copy the riscvp2 "latest release" into /opt (instead of wherever I wanted it).
    Also, seemed to be an issue with micropython make expecting version 8.2.0 of riscvp2 instead of the 8.3.0 that I downloaded. One thing is that the folder name needs to be riscv instead of riscvp2, just made a copy for that. Then, fixed error looking for libgcc.a in a 8.2.0 folder when I had a 8.3.0 folder. Just made a copy and renamed to 8.2.0 to fix that.

    Anyway, it finally compiles!
    Not sure it works yet though...

    Ok, doesn't work.. Get this: *** ERROR: illegal instruction at: 000252D6
    Maybe I need to get the 8.2.0 version of riscvp2...

  • MicksterMickster Posts: 2,610

    I'm really surprised that micropython isn't crazy-popular on the P2, considering the eight cogs. Surely it would attract many more developers.

    Craig

  • rosco_pcrosco_pc Posts: 451
    edited 2024-04-18 10:15

    There is not really an 'official' micropython implementation for the P2. There is this one from Eric based on his riscv emulator. And then one implementation from 'team Oz' based on an old hacked GCC compiler creating native code. The parallax quick bytes for micropython is based on the later implementation and Eric's one got forgotten

  • MicksterMickster Posts: 2,610

    @rosco_pc said:
    There is not really an 'official' micropython implementation for the P2. There is this one from Eric based on his riscv emulator. And then one implementation from 'team Oz' based on an old hacked GCC compiler creating native code. The parallax quick bytes for micropython is based on the later implementation and Eric's one got forgotten

    Yeah, that's the way I read it.....Criminal, I tell ya :|
    I'm not really interested in Python (rebranded Basic) because Eric has already provided everything I could wish for in Flexprop but I see others, struggling to achieve things on other MCUs, using micropython, that would be a total breeze if they had the Prop's cogs.

  • Is it possible now to write Tasks in Python for P2 for more than one cog?
    When I heard last of Micropython for P2, that was not possible and therefore it seemed to make absolutely no sense for P2.

  • MicksterMickster Posts: 2,610

    @"Christof Eb." said:
    Is it possible now to write Tasks in Python for P2 for more than one cog?
    When I heard last of Micropython for P2, that was not possible and therefore it seemed to make absolutely no sense for P2.

    I don't believe it got that far but it could have, even if it was only limited to Python cogs, it would be awesome.

  • RaymanRayman Posts: 13,891

    So, I switched back to the "release" version of micropython and got it to compile by adding #include "stdint.h" in a few places and also a clock freq definition.
    Still getting an error though...

    But, added a printf to main.c and it does get there:

    ( Entering terminal mode.  Press Ctrl-] or Ctrl-Z to exit. )                    
    started USB on cog 2                                                            
    Made it this far!   
    

    So, maybe I can figure out what is making it go off the rails...

  • RaymanRayman Posts: 13,891

    Success! (sort of)
    Commented out the uSD initialization in main() and now appears to work:

    ( Entering terminal mode.  Press Ctrl-] or Ctrl-Z to exit. )                    
    started USB on cog 2                                                            
    Made it this far!MicroPython v1.10 on 2024-04-18; P2-Eval-Board with p2-cpu     
    Type "help()" for more information.                                             
    
    
      
        
          help
        
      
    
    
    <function>                                                              
    
    
      
        
          help()
        
      
    
    
    Welcome to MicroPython!                                               
    
    For online docs please visit http://docs.micropython.org/                       
    
    Control commands:                                                               
      CTRL-A        -- on a blank line, enter raw REPL mode                         
      CTRL-B        -- on a blank line, enter normal REPL mode                      
      CTRL-C        -- interrupt a running program                                  
      CTRL-D        -- on a blank line, exit or do a soft reset                     
      CTRL-E        -- on a blank line, enter paste mode                            
    
    For further help on a specific object, type help(obj)                           
    
    
      
        
          
        
      
    
    
    
  • RaymanRayman Posts: 13,891
    edited 2024-04-18 17:29

    Looks like a problem with the riscvp2 compiler... Can write to P2 pins, but read goes off the rails...

  • RaymanRayman Posts: 13,891
    edited 2024-04-20 19:27

    Thanks @ersmith for the riscvp2 compiler fix.
    Micropython compiles now and I can do os.listdir() and see files on uSD card.
    So, pin writing and reading is obviously fixed.

    There is something a bit strange that I'm seeing now where the FlexProp terminal (running micropython) sometimes misses keystrokes.
    Not sure what is going on there... Hopefully, just a fluke...

    Now, want to see about getting VGA and USB keyboard going. I think these are compiled into micropython, but don't appear to be working.
    The USB adapter on Eval board does have a blinking blue light, so I think it might be trying to work at least...

    Wondering if the P2 clock is not set fast enough... That might explain the serial...

    Clock is good, 160 MHz, but found that the latest code in Github is better than the "latest release" version in terms of the terminal issue.
    Also seems to have a few months of improvements...

  • RaymanRayman Posts: 13,891
    edited 2024-04-20 21:08

    Ok, think I have it now...
    Needed to add this to both uart_core.c and main.c:

    #define MICROPY_USE_VGA (1) //RJA
    #define MICROPY_USE_USB (1) //RJA
    #define MICROPY_P2_USE_VGA (1) //RJA
    #define MICROPY_P2_USE_USB (1) //RJA
    

    This doesn't exactly feel like the right way, but it works, now have USB and VGA working...

    Also, found the VGA basepin setting in uart_core.c

  • roglohrogloh Posts: 5,167

    @Rayman said:
    Clock is good, 160 MHz, but found that the latest code in Github is better than the "latest release" version in terms of the terminal issue.
    Also seems to have a few months of improvements...

    Which version are you running? Is it still 1.10 or something more recent?

  • RaymanRayman Posts: 13,891
    edited 2024-04-21 10:49

    This is the riscvp2 version from @ersmith github, totalspectrum

  • RaymanRayman Posts: 13,891

    To make it easier to change pin assignments and such, made a platform.h file that starts with #include "Propeller.h" and then replace that include in certain files with #include "platform.h".
    This binary is configured for SimpleP2 board, but is easily changed back to Eval board by editing platform.h and then recompiling.

    Wish could change P2 clock in platform.h, like can with FlexProp C, but that is kind of baked into the riscvp2 compiler and looks to be a headache to change.
    But, not a big deal to just recompile the toolchain with a different P2 clock freq (I hope).

    Might attempt to update the core micropython files and see if the P2 port will still compile. But, maybe wait a bit on that.

    Also want to see about updated the vgatext to use 720p. Probably wait a bit on that too...

    One thing that looks like it would be really useful here is to implement the flash file system. Either the Parallax one or @ersmith version...

  • @Rayman : One way to change the clock is to bake it in to the binary by changing the words at offset $14 and $18. The riscvp2 runtime will use those values if they are non-zero, only defaulting to the 160 MHz if they were 0 to start with. It's probably a pain to change this in the .elf file, but if you produce a .binary it's simple to patch it.

    Alternatively, there is an emulated system call _clkset(unsigned mode, unsigned clkfreq) (declared in propeller2.h) that will change the clock frequency at run time.

  • RaymanRayman Posts: 13,891

    @ersmith Thanks. One issue here is with this old USB driver. It has the clock frequency baked in. Not sure newer ones are any better in this respect...

Sign In or Register to comment.