embassy-rp: fix set_input_sync_bypass pin offset#5116
Conversation
this assumption isn't quite right. gpiobase is calculated when initializing the PIO according to the entire set of used pins, see here: embassy/embassy-rp/src/pio/mod.rs Line 876 in 0957e05 so pins 16..31 can either need offset 0 or offset 16 depending on what other pins are in use. You can probably read the GPIOBASE reg to know the offset to use. |
currently this function causes a crash in debug mode when used with pins greater than 32 (available on the rp235xb variant) because it overflows when doing the shift. this commit applies the GPIOBASE offset to pin value before doing the shift.
46f0516 to
eccf60a
Compare
|
ok, I have force pushed to change the commit message and turned this into a draft because right now it is not working.
I updated the code to read that register but the problem is that at the time the Line 189 in 0957e05 but the GPIOBASE register is only set later on line 210 Line 210 in 0957e05 when setting the configuration for the state machine, that happens on that line you linked in your comment above. I am fairly new to this embedded stuff so I am not sure about this but I was going through the RP2350 data sheet and the impression I get is that there are 3 PIO blocks each with its own independent GPIOBASE register and 4 state machines each. right now it seems that this GPIOBASE register is written to in the embassy/embassy-rp/src/pio/mod.rs Lines 836 to 864 in 0957e05 in the StateMachine::set_config, this function could just panic if the offset is enabled but a pin lower than 16 is used or if there is no offset and a pin greater than 31 is used. Any idea on how to fix this @Dirbaio ?
|
|
Confirming this bug affects the SparkFun IoT RedBoard RP2350 (which uses GPIOs 36/37/38 for the RM2 WiFi module's CS/CLK/DATA lines). Symptom: Root cause: Workaround: |
|
I've opened #6391 with a fix for this: it offsets the |
currently this function causes a crash in debug mode when used with pins greater than 32 (available on the rp235xb variant) because it overflows when doing the shift. this commit applies the offset to pin value before doing the shift. this assumes that when using a pin greater than 32 the GPIOBASE has already been set to 16.