Raspberry Pi Raspberry Pi Pico
GND (Pin 20) SWD GND
GPIO24 (Pin 18) SWDIO
GPIO25 (Pin 22) SWCLK
as seen in
Figure 7.
TIP
If you are using another debug probe, like Picoprobe (Appendix A), you need to connect the GND, SWCLK and SWDIO
pins on your probe to the matching pins on your Raspberry Pi Pico, or other RP2040-based board.
If possible you should wire the SWD port directly to the Raspberry Pi as signal integrity is important; wiring the SWD port
via a breadboard or other indirect methods may reduce the signal integrity sufficiently so that loading code over the
connection is erratic or fails completely. It is important to also wire the ground wire ( 0v ) between the two directly and
not rely on another ground path.
Note the Raspberry Pi Pico must also be powered (e.g. via USB) in order to debug it! You must build our OpenOCD
branch to get working multidrop SWD support.
5.3. Loading a Program
OpenOCD expects program binaries to be in the form of
.elf (executable linkable format) files, not the .uf2 files used by
BOOTSEL mode. The SDK builds both types of file by default, but it’s important not to mix them up.
Assuming you have already built the
blink example, using the instructions in Chapter 3, you can run the following
command to program the resulting
.elf file over SWD, and run it:
$ openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "program blink/blink.elf
verify reset exit"
There are quite a few arguments to this command, so it’s worth breaking them down:
-f interface/raspberrypi-swd.cfg
Tell OpenOCD to use Raspberry Pi’s GPIO pins to access the SWD port. If we
were using an external USB→SWD probe, like Picoprobe in
Appendix A, we
would specify a different
interface here.
-f target/rp2040.cfg Tell OpenOCD we are connecting to a RP2040-based board. This .cfg file
contains information for OpenOCD like the type of processor (Cortex-M0+)
and how it should access the flash memory.
-c
This argument is used to pass a series of commands to OpenOCD directly
from the command line. OpenOCD also has an interactive terminal interface
which we could type the commands into instead. The commands we use
are:
program blink/blink.elf Tell OpenOCD to write our .elf file into flash, erasing the target region of
flash first if necessary. The
.elf file contains all the information telling
OpenOCD where different parts of it must be loaded, and how big those parts
are.
verify
Tell OpenOCD to read back from the flash after programming, to check that
the programming was successful.
Getting started with Raspberry Pi Pico
5.3. Loading a Program 20