Using the flash and GPIO at the same time on a RPi Pico?

⚓ Rust    📅 2026-01-24    👤 surdeus    👁️ 1      

surdeus

I've been struggling with code stability in my program for .. as long as I can remember.

I've been working with the assumption that it's a hardware issue from day one. I'm moving an actuator between distinct positions, and I've been working with the assumption that it sends back a feedback, or it triggers some spike - everything is powered, in the end, by the same power (although the Pico via a 5V DC-DC buck converter, the actuator directly from the main power supply).

However, writing some testing programs, that only act on the actuator, I did manage to get that code stable as a rock.

But as soon as I try that in my "main" program (dubbed "The Big Kahuna" :slight_smile:) where I also read buttons, turn on/off LEDs, manage a Neopixel etc etc, the instability remains.

It just resets (not crashes!) quite semi-randomly. Semi-randomly, because it's in roughly three different places, but no of those should cause this, so it's probably one of the tasks being delayed and not as quick every time.

But some pointers here and there, I'm now working on the assumption that it's something to do with the flash - I need to store some state values between runs.

Disabling all that, "The Big Kahuna" works just fine!

So.. Reading up on the flash and how to use it (this was among the first code I wrote, when I was extremely green in Rust and microcontrollers, so I didn't pay attention on how to use it, just found code "out there" that worked), I'm now seeing that you can't use the flash and some of the GPIO pins at the same time... ??!

Because "I" wrote the flash part first, which worked perfectly, then wrote the actuator part, then the trouble began, so "obviously" I thought it was the actuator or the code that was at fault :smiley:.

But the information "out there" is .. not just inconclusive, but also contradictory.. Some say that it's GPIO20-25, GPIO23-29 and some GPIO23-25. Not sure which it is, but either way, I'm using some of those (GPIO 20, 21, 22, and 28 (as ADC)).

Now, only GPIO28 is actively used, the others are only allocated, but not actually read/written to. GPIO28 (as an ADC) I use to read the actuator brush (to know "where" it is).

I'm trying to read the RP2040 datasheet, but this is extremely low-level for me, so I'd appreciate some "interpretation" on this.

What ARE the pins for the QSPI (where the flash sits), and which pins can I not use at the same time?

The datasheet say:

The six QSPI Bank GPIO pins are typically used by the XIP peripheral to communicate with an external flash device. However, there are two scenarios where the pins can be used as software-controlled GPIOs:
• If a SPI or Dual-SPI flash device is used for execute-in-place, then the SD2 and SD3 pins are not used for flash access, and can be used for other GPIO functions on the circuit board.
• If RP2040 is used in a flashless configuration (USB boot only), then all six pins can be used for software-controlled GPIO functions

The flash in the Pico, is that considered an external flash (from the point of the RP2040, which is the subject of the datasheet :slight_smile:), and what is "flashless configuration"?

I'm using openocd to write my program(s) to the Pico, but I haven't seen anything about this in its documentation.

The RP2040 datasheet is 642 pages (!!) long, with extremely low-level info, that I understand only a part of, so if it's in there, feel free to point me to the section/page and I'll try to understand that better.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed