I'd like to hook together two Raspberry pi 3b+ to use jtag/SWD with OpenOCD. I learned it can be done, but implementing it has proven challenging. I have two questions:

  1. How to connect the Rpi's. If I'm understanding this guide (pdf) correctly, I wire GND to GND, BCM 24 to BCM 24, BCM 25 to BCM 25, and it says BCM 18 may not be required. But then I look at /usr/local/share/openocd/scripts/interface/raspberrypi-native.cfg the pins are different.

  2. How to configure OpenOCD for the Rpi. When I look in /usr/local/share/openocd/scripts/target/ it's not clear what file applies, and I'm not sure if raspberrypi-native or raspberrypi2-native is the interface file I want.

As you may be able to tell, I really don't have the background I should probably have for this, but I'm interested in jtag/SWD and what I can learn, so why not start. Any pointers to resources for learning about jtag or SWD would be appreciated.


Here are the steps to get your code onto a Atmel SAMD21G18, which is often used by Adafruit, by using OpenOCD on a Raspberry Pi 2/3 Model B running an up-to-date Raspbian. You Need to build OpenOCD by yourself to enable the gpio-flags.

Install the build dependencies. Telnet is needed for communication with OpenOCD later:

apt-get install git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev telnet

Get OpenOCD from Github:

git clone https://github.com/ntfreak/openocd.git

Build it:

cd openocd
./configure --enable-sysfsgpio --enable-bcm2835gpio
./make install

Create a minimal config '~/openocd.cfg' containing:

source [find interface/raspberrypi2-native.cfg]
transport select swd
set CHIPNAME at91samd21g18
source [find target/at91samdXX.cfg]
reset halt

If you use a different microcontroller, set the config file accordingly. Have a look at the flash driver section of the OpenOCD user guide: http://openocd.org/doc/html/Flash-Commands.html

Take a look at the Raspberry config file that came with OpenOCD. It works for both RPI 2 and 3:

less /usr/local/share/openocd/scripts/interface/raspberrypi2-native.cfg

Find the header pin numbers of swclk, swdio and srst:

# swclk and sdwio
bcm2835gpio_swd_nums 11 25
# srst
bcm2835gpio_srst_num 24

Uncomment the srst line:

reset_config srst_only srst_push_pull

Now, connect your microcontroller. Have a look at the pinout of your Raspberry Pi: https://en.wikipedia.org/wiki/Raspberry_Pi#Model_B

Connect swclk, swdio, srst and Gnd accordingly. For instance, swclk is mapped to GPIO 11, which is wired to pin 23 on the Raspberry Model B.

Run OpenOCD (needs superuser access) with your config file:

openocd -f "~/openocd.cfg"

Connect a telnet client:

telnet localhost 4444

You can now play around with the flash tools of the manual: http://openocd.org/doc/html/Flash-Commands.html

The erase parameter of flash write_image seems not to work for large blocks of data. Use at91samd chip-erase before flashing, instead.

Flash your code, then:

flash write_image image.bin 0x0000 bin
flash verify_bank 0 image.bin 0x0000

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.