Bare Metal Flashing of the Rp2040
8 hours ago
- #Flashing
- #SWD
- #RP2040
- The article discusses bare metal flashing of the RP2040 microcontroller via the SWD (Serial Wire Debug) interface.
- The standard method involves using a USB-connected Raspberry Pi Debug Probe with OpenOCD, but the author explores a simpler, low-power alternative.
- The RP2040 uses a two-pin SWD port for debugging and flashing, similar to I2C, which can be driven by any 3.3V GPIO-capable device.
- The SWD interface communicates with the ARM CoreSight Debug Access Port (DAP) inside the RP2040, independent of the Cortex-M0+ cores.
- Key features enabling flashing via SWD include reading/writing arbitrary memory locations, executing functions, and using built-in ROM flash drivers.
- The SWD protocol involves specific handshake sequences, including sending a selection alert, activation code, and line reset.
- Memory and register access via SWD involves transactions with the Debug Port (DP) and Access Port (AP) components.
- The flashing process includes erasing flash memory, writing data to RAM, and programming flash using ROM utility functions like flash_range_erase and flash_range_program.
- The article provides detailed code snippets for SWD bit operations, register access, and function calls.
- A debug trampoline function in ROM ensures deterministic control after function calls.
- The RP2040's boot ROM contains utility functions for flash operations, accessible via a lookup table with two-character codes.
- The flashing process concludes with validation checks and a reset to execute the newly flashed firmware.