August 11, 2022

Raspberry Pi Pico - GDB, OpenOCD and the Pico Probe

My fedora 38 linux system has "arm-none-eabi-gdb". It is an old version, circa Fedora 24 or so. For some reason, Fedora no longer supplies the cross GDB for arm as part of the Gnu/ARM stuff.

This is Gdb 7.6.2, circa 2013 -- but it works!
Gdb for x86 on my desktop is 13.2.3, circa 2023.

There is also something called "gdbtui" (or gdb-tui) that was once distributed as part of gdb. I no longer see this on my system.

Some resources

Here is an article about using GDB and openocd to debug rust programs for the Pi Pico.

The "rust" page launches GDB via this command line:
arm-none-eabi-gdb -q -ex "target extended-remote :3333" target/thumbv6m-none-eabi/debug/rp2040-project-template
The -q switch suppresses the version and copyright messages.
The -ex switch says to run the following string as a gdb command
The rest of the command is the path to the executable they want to debug

Some of my old notes suggest that you can use the following command to load an image (via openocd) into flash (this is for the blue pill).

flash write_image erase blink.bin 0x08000000

Try some things

A person can only read examples so long without trying some things. First launch openocd:
openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -s tcl
So, what is the "-s tcl" about. This adds the "tcl" directory to the openocd search path. I am not sure why this is useful, and it is probably something I can omit.

I leave this running in one text window and go to another and launch gdb:

arm-none-eabi-gdb blink.elf
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x20041f2c in ?? ()
Aha! That seems like a nice start. A message in the openocd window says:
Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"

Now I follow along with the openocd Howto above:

load
Loading section .text, size 0x4c lma 0xdeadbef0
Start address 0xdeadbef0, load size 76
Transfer rate: 608 bits in <1 sec, 76 bytes/write.
(gdb) monitor reset init
[rp2040.core0] halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
continue
And my demo begins blinking the LED. This is my assembly language LED blink demo which is only 76 bytes in size and which only has a text segment. Note that since I didn't set a breakpoint, I no longer have a gdb prompt.


Have any comments? Questions? Drop me a line!

Tom's electronics pages / [email protected]