0

Can RP2040 PIO PULL be used in CircuitPython?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Can RP2040 PIO PULL be used in CircuitPython?

by kevinjwalters on Fri Feb 19, 2021 8:50 am

Is the PIO PULL instruction fully supported in CircuitPython for the Raspberry Pi Pico including feeding the data to it via the FIFO? I was trying to create the equivalent of this PIO PWM MicroPython code in CircuitPython but couldn't get it to work. That example uses exec's instructions to run code before the state machine starts up. The init constructor parameter looks like it can't be used as a sustitute (or to initialise things) because it is not guaranteed to run before the state machine's code? From https://github.com/adafruit/circuitpyth ... eMachine.c

:param ReadableBuffer init: a program to run once at start up. This is run after program is started so instructions may be intermingled


I also couldn't control-c the write method sometimes from serial console.

Are there any plans to add a loop option to write?

How many state machines can be created in CircuitPython? The hardware looks like it has 2*4=8?

kevinjwalters
 
Posts: 883
Joined: Sun Oct 01, 2017 3:15 pm

Re: Can RP2040 PIO PULL be used in CircuitPython?

by tannewt on Fri Feb 19, 2021 9:39 pm

kevinjwalters wrote:Is the PIO PULL instruction fully supported in CircuitPython for the Raspberry Pi Pico including feeding the data to it via the FIFO?


The latest checked in code requires you to block in your pioasm. Otherwise, `write` will never return. My working branch has this changed so you can set `wait_for_txstall` to False.

kevinjwalters wrote:I was trying to create the equivalent of this PIO PWM MicroPython code in CircuitPython but couldn't get it to work. That example uses exec's instructions to run code before the state machine starts up. The init constructor parameter looks like it can't be used as a sustitute (or to initialise things) because it is not guaranteed to run before the state machine's code? From https://github.com/adafruit/circuitpyth ... eMachine.c


I'm changing this as well in my branch. init code will run before start up. I didn't realize you could run stuff when the SM wasn't enabled.

kevinjwalters wrote:I also couldn't control-c the write method sometimes from serial console.


I'll double check the wait loops in write when I look at this code next.

kevinjwalters wrote:Are there any plans to add a loop option to write?


Not in the near future. It's not clear what the right API is since write blocks.

kevinjwalters wrote:How many state machines can be created in CircuitPython? The hardware looks like it has 2*4=8?


Ya, 8 assuming your instructions can all fit. CP will co-locate into a PIO if given the same program bytearray and a free SM is available.

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Can RP2040 PIO PULL be used in CircuitPython?

by kevinjwalters on Sat Feb 20, 2021 12:19 pm

That's good news.

Will first 16 bytes of write be non-blocking if the TX FIFO is empty?

Can state machine code that differs be run from a different section of memory, i.e. if there were three 10 instruction code blocks could they all fit/relocate into the 32 instruction memory of a single PIO? The state machines appear to have their own PC, EXECCTRL_WRAP_TOP and EXECCTRL_WRAP_BOTTOM registers.

And does CircuitPython's assembler support the wrap functionality used in https://github.com/adafruit/Adafruit_Ci ... eopixel.py ?

kevinjwalters
 
Posts: 883
Joined: Sun Oct 01, 2017 3:15 pm

Re: Can RP2040 PIO PULL be used in CircuitPython?

by tannewt on Sat Feb 20, 2021 8:18 pm

kevinjwalters wrote:Will first 16 bytes of write be non-blocking if the TX FIFO is empty?


No, CP will wait until the FIFO is empty to return. By default, it'll wait for a TXSTALL as well unless the new `wait_for_txstall=False`.

kevinjwalters wrote:Can state machine code that differs be run from a different section of memory, i.e. if there were three 10 instruction code blocks could they all fit/relocate into the 32 instruction memory of a single PIO? The state machines appear to have their own PC, EXECCTRL_WRAP_TOP and EXECCTRL_WRAP_BOTTOM registers.


Yes, CP should automatically fit three programs into a single PIO. However, it is possible that the program memory could fragment if you are creating and destroying programs. State machines are almost entirely independent. The only shared resources are program memory and interrupt state.

kevinjwalters wrote:And does CircuitPython's assembler support the wrap functionality used in https://github.com/adafruit/Adafruit_Ci ... eopixel.py ?


No it doesn't. It always sets wrap to encompass the whole `program`. I wasn't sure how to gather "metadata" out of the pioasm. Generally, you can split the pre-wrap code and have it as the `init` program instead.

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Can RP2040 PIO PULL be used in CircuitPython?

by kevinjwalters on Mon Feb 22, 2021 6:57 am

Is there going to be support for exec of intermingled code while it's running? This is used to extract data in the example on MicroPython Forum: Pi pico pioasm in Micropython documentation.

kevinjwalters
 
Posts: 883
Joined: Sun Oct 01, 2017 3:15 pm

Re: Can RP2040 PIO PULL be used in CircuitPython?

by tannewt on Mon Feb 22, 2021 5:24 pm

My current branch has a `run` function that would. However, I'm not sure it'll exactly work now because the constructor automatically sets fifo merging based on the given program's instructions.

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Can RP2040 PIO PULL be used in CircuitPython?

by kevinjwalters on Thu Mar 04, 2021 4:12 pm

I had a go with a converted PWM example using write() and PULL and it did something on adafruit-circuitpython-raspberry_pi_pico-en_US-20210227-24fdda0.uf2 but didn't work in terms of varying brightness...

kevinjwalters
 
Posts: 883
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.