I recently wanted an ethernet JTAG adapter for a project I was working on. Unfortunately ethernet JTAG adapters can cost upwards of $300, and even then they can be specific to particular chipset and toolchains.
However, were already using [OpenOCD](http://openocd.sourceforge.net/) with ST-LINK/V2 programmers to communicate with out hardware, and it turns out that it’s very easy to set up OpenOCD on the Raspberry Pi. You can then plug the programmer into the Pi, connect a debugger (gdb in our case) to the OpenOCD instance, and debug your firmware remotely!
The Raspberry Pi is also a very convenient platform for adding additional interfaces to your hardware. For our project, we have FTDI serial cables and some ADC’s connected to ours as well. This lets us flash and debug our hardware, communicate with it over serial (forwarded over a socket), and continuously monitor power consumption of key components on our board. And we can do it from anywhere with an internet connection. It’s basically magic.
## 1. Acquire a Pi
First you’ll need a Rapsberry Pi and an SD card with the Raspbian installed on it. You can get a Raspberry Model B Starter Kit from [Newark](http://www.newark.com/raspberry-pi-accessories). This comes with a power adapter and an SD card with Noobs (which can automatically install Raspbian for you) pre-installed and is probably the easiest way to get started.
## 2. Install a Recent Version of OpenOCD
There is a version of OpenOCD already in the package database for Raspbian, but it’s version 0.6.1, which was too old for our platform. Fortunately it’s quite easy to install the latest OpenOCD from scratch. There are pretty good instructions on how to do this [at SourceForge](http://sourceforge.net/p/openocd/code/ci/master/tree/). But specifically for the Pi you can just do the following:
From your Pi:
sudo apt-get update sudo apt-get install libtool libusb-dev libusb-1.0 autoconf automake texinfo
git clone git://git.code.sf.net/p/openocd/code openocd-code cd openocd-code/ ./bootstrap ./configure
This should spit out a bunch of stuff and then if everything worked you should see this at the end:
OpenOCD configuration summary
MPSSE mode of FTDI based devices yes (auto)
ST-Link JTAG Programmer yes (auto)
TI ICDI JTAG Programmer yes (auto)
Keil ULINK JTAG Programmer yes (auto)
Altera USB-Blaster II Compatible yes (auto)
Segger J-Link JTAG Programmer yes (auto)
OSBDM (JTAG only) Programmer yes (auto)
eStick/opendous JTAG Programmer yes (auto)
Andes JTAG Programmer yes (auto)
Versaloon-Link JTAG Programmer yes (auto)
USBProg JTAG Programmer yes (auto)
Raisonance RLink JTAG Programmer yes (auto)
Olimex ARM-JTAG-EW Programmer yes (auto)
CMSIS-DAP Compliant Debugger no
Make sure support for the programmer you are using is enabled, and then type
make. Once that finishes, type
sudo make install.
Now OpenOCD should be installed and ready to go!
## 3. Run OpenOCD
Now you can run OpenOCD. For example, if you were using an F4 discovery board, you could so something like this:
sudo openocd -f board/stm32f4discovery.cfg
If it worked, you should see something like:
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Which means your programmer is ready to go!
You can then use `telnet ip_of_pi 4444` to connect to your OpenOCD session and run OpenOCD commands. You can also connect to it with gdb. The most convenient way is to create a .gdbinit file with something like:
target remote my_pi_ipaddress:3333 file my_firmware.elf monitor reset halt load
And then you can type `gdb` (or in my case `arm-none-eabi-gdb`), and my_firmware.elf is flashed onto the hardware and is ready for debugging!