PIO confusion

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
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

PIO confusion

Post by pythoncoder » Mon Mar 01, 2021 6:46 pm

A couple of things still puzzling me. When instantiating a state machine input pins start at in_base, sideset pins start at sideset_base and jmp_pin denotes pins used for jump. But what is the difference between set_base and out_base?

Another thing that puzzles me is the distinction between the pin and pins symbols. The test scripts have

Code: Select all

set pins 0
wait 1 pin 0
Ref here and here. I don't understand why there are two different symbols.

Other queries: the meaning of relative vs absolute IRQ numbers. Under what circumstances does the IRQ number matter? Also the distinction between PIO.IN_LOW and PIO.IN_HIGH? I know I raised this before, but maybe someone has figured it out in the meanwhile.
Peter Hinch
Index to my micropython libraries.

rafl
Posts: 10
Joined: Tue Mar 23, 2021 7:15 am

Re: PIO confusion

Post by rafl » Wed Mar 24, 2021 6:40 pm

Set mappings are much more limited than out mappings. You can only address 5 pins, but also writing to those pins has to be done from immediate values, i.e. encoded directly into the instruction. That makes working with set pins a lot trickier if the desired output depends on run-time data, such as whatever you might've received through the FIFO.

Out mappings can't just address more pins, but they're also tied into the output shift register, making it easier to express certain things. For example, consider

Code: Select all

@asm_pio(out_init=(PIO.OUT_LOW,)*4, out_shiftdir=PIO.SHIFT_RIGHT)
def prog():
    pull()
    out(pins, 4)
Implementing that same functionality of controlling 4 output pins using 4 bits sent to the state machine with sm.put(0b0101) using a set mapping would be a lot more work and not very practical.


The pioasm syntax, as documented at https://datasheets.raspberrypi.org/rp20 ... asheet.pdf, uses PIN for the WAIT and JMP instructions when referring to an individual pin, but PINS for the MOV, SET, IN, and OUT instructions when referencing a set of consecutive pins. I presume pin and pins exist to keep PIO programs generated with python looking pretty much the same as their PIO assembler equivalents, just like the __getitem__ implementation that allows for delays to be expressed using nop() [x].


IN_HIGH and IN_LOW are still mysterious to me. They do actually set the pull-down enable and pull-up enable bits, but I'm not sure what the behaviour of those is when the input-enable bit is set. The datasheet doesn't really cover that, or what setting both the pull-up and the pull-down bits means, though the C SDK does mention a "bus keep" function that weakly pulls towards whatever the current pin state is.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: PIO confusion

Post by pythoncoder » Thu Mar 25, 2021 7:54 am

Thank you. Very informative.
Peter Hinch
Index to my micropython libraries.

Post Reply