Setting up Rasberry Pi Debug Probe on Linux

This took me a while today, there were a few hoops I had to jump through. So I'd like to take some notes for my future self or anyone else who might need this.

Have a read through the official docs if you haven't done so already. There a few things here that don't work right off the bat. I'll be covering them here.

Installing openocd

The first challenge was getting openocd to work for the Rasberry Pi Pico. Which was not present in the version that apt installed. So the only option was to build from source. It was much easier than I thought it would be (I had help on the stream).

Clone the latest tag

Clone the latest tag from the openocd repository. At the time of writing this post it was v0.12.0.
NOTE: remove any other version of openocd before you do this. If you tried to install openocd using apt, run sudo apt remove openocd before proceeding.

git clone git@github.com:openocd-org/openocd.git -b v0.12.0

Once inside the repository run the following commands to install openocd:

  1. ./bootstrap (if you get erros for missing dependecies, simply install them using apt install)
  2. ./configure
  3. make
  4. sudo make install

If you want more details refer to the README. You'll find these commands in the compiling section.

Install gdb-multiarch

This command worked just fine for me, ensure that you install the latest version and that it supports the ARM architecture. You can install it by running:
sudo apt install gdb-multiarch

Setting up Serial Wire Debugging (SWD)

Verify that your build process produces an .elf file if you want to do debugging. I'm using Microzig, so I just had to add a single line to my build.zig:
mb.install_firmware(firmware, .{ .format = .elf });

Now after you run the build command, cd into the folder where you .elf file is present and run one of these two commands:

  1. To upload the updated code to pico without the whole bootsel business and having to unplug the device: sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program blink.elf verify reset exit"
  2. To debug the with SWD: sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"

The interface/cmsis-dap.cfg and target/rp2040.cfg should be present in /usr/local/share/openocd/scripts if you have built openocd from source by following the steps above. If you used apt you can find them by looking up where your openocd is installed with the command which openocd.

Modifying cmsis-dap.cfg (only if the default config does not work)

This step entirely depends on wether you were able to run either of the openocd commands above successfully. The cmsis-dap.cfg did not work for so I had to update one line in the config. In you cmsis-dap.cfg you'll notice a comment on the last line that says:
# Optionally specify the serial number of CMSIS-DAP usb device.

All it says is that you need to specify the usb serial id for the debug probe if openocd is unable to find it by default. To get the serial id of this USB port. You can follow the following steps:

  1. Run lsusb in your terminal. Look for Rasberry Pi Debug Probe. You should find something like this: Bus 001 Device 116: ID 2e8a:000c Raspberry Pi Debug Probe (CMSIS-DAP)
  2. Use BUS#:DEVICE# to get the iSerial. So in this instance it will be: lsusb -s 001:116 -v | grep -i iserial
  3. Once you have your iSerial number, you can update the last line in cmsis-dap.cfg file to: adapter serial <your-usb-serial-number>

Running gdb

Finally, you are ready to run the debugger. You can start gdb by running: gdb-multiarch. Once gdb is running you can start the gdb server by running: target remote localhost:3333 from within gdb. When I ran this command, gdb suggested that I use a different one, you can run that instead as I don't remember it and am too lazy to look it up at this point.

It does look like a lot of steps, but after all of the above I was able to get the debugger working. It would have taken me a lot longer if I had to do it myself, but luckily I had some help. Maybe this helps you out. You can find my repository here for a an example running Microzig. Hope this helps.