pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

docs: pio_gpio_init claims it's not *needed* to enable input to a PIO

Open Gadgetoid opened this issue 8 months ago • 3 comments

The comment (and by extension docs?) for pio_gpio_init states:

Note that this is not necessary for a state machine to be able to read the input value from a GPIO, but only for it to set the output value or output enable.

I think this is wrong on RP2350, which needs pio_gpio_init to call gpio_set_function which enables input and - crucially? - disables pad isolation?

https://github.com/raspberrypi/pico-sdk/blob/ee68c78d0afae2b69c03ae1a72bf5cc267a2d94c/src/rp2_common/hardware_pio/include/hardware/pio.h#L870-L886

Gadgetoid avatar Mar 31 '25 14:03 Gadgetoid

I believe that the intention behind the "this is not necessary for a state machine to be able to read the input value from a GPIO" comment is that you can use PIO input to "sniff" the values being read/written to the GPIO pin from another function-mode (e.g. you could use PIO input to sniff the UART TX). But if you haven't configured any other function-mode onto the GPIO pin, then I guess it would indeed make sense to use gpio_set_function to set PIO input? (This is just me guessing, until Graham is able to provide a definitive answer 😉 )

lurch avatar Mar 31 '25 16:03 lurch

Thank you. I suspect the answer might well be "you should explicitly set up your pin as an input", but either way the documentation could probably be clearer about that!

( I stumbled into this looking into a MicroPython issue with the PIO's jmp_pin, where it worked fine on RP2040 but not RP2350... this is because the pin is never explicitly set-up. I need to figure out if I should call pio_gpio_init in both cases for this pin, or change the MicroPython docs to mention user must configure the pin 😆 )

( Nobody would ever want a jump pin as an output right.... right!? )

Gadgetoid avatar Mar 31 '25 17:03 Gadgetoid

Be aware that if you change the docs to say "must configure the pin" then you might run into problems like #1601

lurch avatar Mar 31 '25 17:03 lurch

The pio_gpio_init() description is pedantically correct but not very helpful. I'll expand it a bit to make it clear that there are multiple reasons why PIO may not be able to read a pin, and IO muxing is just one of them.

Wren6991 avatar Jul 18 '25 14:07 Wren6991