Store unique device ID, write directly to flash memory (using SWD) #1391
-
Hi, I can't seem to find a solution from reading the docs and the issues section so I'll ask here... Is there an easy reliable way to write a unique uint32_t to the RP2040 flash memory, from the command line (using OpenOCD or similar), then have the RP2040 read this uint32_t to use it as a UID during operation. I'd like to have a flexible way of overwriting UIDs on devices from the command line. I imagine I could use the EEPROM library to read that section of flash during normal operation but there's no documentation that gives me a hint of how do to what I want to do. Exact memory locations etc... Thanks in advance, and thanks for a great core. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
You need to run an application on the RP2040 to actually erase and write to the flash. OpenOCD just provides a way for GDB to get into the core. Each Pico already has a unique multibyte ID, see https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#pico_unique_id |
Beta Was this translation helpful? Give feedback.
-
Apologies for not putting this question in discussions and thanks for your answer. I understand the ID is available to some flash chips but I need things to be a little more flexible. To be a little more specific: I'm using the W25Q128JV flash chip on a custom RP2040 board. So could I flash firmware, then at some point after the initial flashing write some uint32_t values to the flash at some specific location. During code execution then read that location (perhaps with EEPROM lib?) for some application specific read only variables, GUIDs etc. Really I'm just trying to store some application specific read-only data for use in the firmware. ESP32 has NVS, STM32 has access to the linker script. What would you recommend for this functionality on the RP2040 core? |
Beta Was this translation helpful? Give feedback.
Think I have it, the openocd config specifies the flash size as
set _FLASHSIZE 0x200000
but of course the flash size has to be the entire flash device memoryset _FLASHSIZE 0x1000000
. After updating this I can runopenocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program testData.bin reset exit 0x10FFF000"
and voilà ... I can now read that testData.bin data in the EEPROM library of rp2040 (EEPROM.read()).