PIO in Python with with multiple IOs

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
smoorby
Posts: 7
Joined: Thu Apr 01, 2021 9:29 am
Location: Basingstoke, UK

PIO in Python with with multiple IOs

Post by smoorby » Sun Apr 11, 2021 10:20 am

Hi, Anyone figured out the syntax for multiple outputs (I'm guessing inputs as well) with 'pioasm' when output is for Python?
It works fine in Python, multiple lines are given to the asm_pio() decorator as a tuple, e.g :-

@rp2.asm_pio(
out_init = (
rp2.PIO.OUT_LOW,
rp2.PIO.OUT_HIGH,
rp2.PIO.OUT_LOW))
PIO initialisation can by output from 'pioasm' with the 'lang_opt' directive. For one line the following works
.lang_opt python out_init = rp2.PIO.OUT_LOW
but
.lang_opt python out_init = (rp2.PIO.OUT_LOW, rp2.PIO.OUT_HIGH, rp2.PIO.OUT_LOW)
doesn't work, 'pioasm' sees this as a syntax error. I've tried a few variants like list instead of tuple and just comma separated values. All the examples seem to use just one pin.

taPIQoLEHUMA
Posts: 15
Joined: Thu Mar 04, 2021 2:59 am

Re: PIO in Python with with multiple IOs

Post by taPIQoLEHUMA » Thu Apr 22, 2021 12:16 am

It seems to work OK if you remove the spaces from the list:

Source line:

Code: Select all

.lang_opt python out_init = (rp2.PIO.OUT_LOW,rp2.PIO.OUT_HIGH,rp2.PIO.OUT_LOW)
Generated python code:

Code: Select all

@rp2.asm_pio(out_init=(rp2.PIO.OUT_LOW,rp2.PIO.OUT_HIGH,rp2.PIO.OUT_LOW))
Original error pointing to the space (sort-of):

Code: Select all

sb.pio:13.47-63: syntax error, unexpected text, expecting end of file or end of line
   13 | .lang_opt python out_init = (rp2.PIO.OUT_LOW, rp2.PIO.OUT_HIGH, rp2.PIO.OUT_LOW)
      |                                               ^~~~~~~~~~~~~~~~~

Post Reply