The Raspberry Pi Pico supports on-chip-debugging using another Pico, making it possibly the cheapest embedded development kit with native GDB support.

Things you'll need

  • 1x Raspberry Pi Pico - as the Device Under Test (DUT)
    • This will need, at minimum, the debug pins and 5V (VSYS, #39) pins with headers, A full set is recommended
  • 1x Raspberry Pi Pico - as the debugger
    • For this one, you will need 5V (VSYS, #39), one GND and GP2 (#4) through to GP5 (#7) connectable
  • Miscellaneous breadboard cables to connect the two
  • 1x Micro-USB cable to connect the debugger to your PC
  • A PC running Linux (Windows should work, but may need adjustment)

Steps

  1. Rather than wholesale repeat the instructions here, follow the steps in Appendix A of the "Getting started with Raspberry Pi Pico" document: https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf
    • This will step you through connecting the two Picos, flashing it and setting up OpenOCD and drivers (if applicable)
  2. The guide does go through how to use GDB in Chapter 6, but below follows my general "rapid prototyping" flow
  3. Install gdb-multiarch (Debian) or your distro's version of it.
  4. Add PICO_SDK_PATH=/path-to/pico-sdk to your environment variabls
  5. Setup / generate your project using the pico-project-generator
  6. Add a line in CMakeLists.txt that will leave debug symbols in the binary: set(CMAKE_BUILD_TYPE Debug)
  7. Create a file called gdb_cmds (or similar) to auto-configure GDB, OpenOCD and load the program. Use the following:
    • target remote | openocd -f interface/picoprobe.cfg -f target/rp2040.cfg -s tcl -c "gdb_port pipe; log_output openocd.log"
    • monitor reset halt
    • load
  8. Make a build directory in your project tree, and cd to it
  9. Run the following command: cmake .. && make && gdb-multiarch -q -x ../gdb_cmds ProjectName.elf
Reading symbols from PicoTesting.elf...
Open On-Chip Debugger 0.11.0-g228ede43d-dirty (2022-10-17-21:36)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 5000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread
0x000000ee in ?? ()
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
Loading section .boot2, size 0x100 lma 0x10000000
Loading section .text, size 0x50c0 lma 0x10000100
Loading section .rodata, size 0x10b4 lma 0x100051c0
Loading section .binary_info, size 0x30 lma 0x10006274
Loading section .data, size 0xa0c lma 0x100062a4
Start address 0x100001e8, load size 27824
Transfer rate: 18 KB/sec, 4637 bytes/write.
(gdb)
  • When GDB is ready, you can use "normal" GDB commands to interact: