Turn a Raspberry PI 2 into a JTAG dongle

Post Reply
User avatar
Rick Kimball
Posts: 941
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Turn a Raspberry PI 2 into a JTAG dongle

Post by Rick Kimball » Thu Feb 25, 2016 10:25 pm

I snagged a Raspberry PI 2 on sale at Christmas for $30. I bought it to run Octoprint and act as a webbased 3d print spooler . However, lately I've been looking at other things you can do with them.

One of the more interesting things I've done was to turn it into a JTAG dongle using openocd. Openocd can be configured to use the GPIO ports on RPI2 as JTAG debug pins. You can then connect those pins to your stm32 boards to implement a JTAG debugger. The file below shows you how I configured the RPI2 to act as a SWD debugger for my red pill stm32f103.

File: rpi2_redpill.cfg

Code: Select all

# RPI2 as a SWD JTAG device and stm32f103 red pill as target
#
# Connections:
# RPI2   -   STM32F103
# GPIO18 ---> DCLK
# GPIO23 ---> DIO
# GND    ---> GND

interface bcm2835gpio

bcm2835gpio_peripheral_base 0x3F000000

# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
# These depend on system clock, calibrated for stock 900MHz
# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET
bcm2835gpio_speed_coeffs 146203 36

# Each of the SWD lines need a gpio number set: swclk swdio
# Header pin numbers: GPIO18 GPIO23 (pins 12 and 16 on J8 connector)
bcm2835gpio_swd_nums 18 23

transport select swd

set WORKAREASIZE 0x2000
source [find target/stm32f1x.cfg]
reset_config none
Just connect jumper wires as described in the file above and then launch openocd and connect to it using arm-none-eabi-gdb.

Code: Select all

root@raspberrypi:/home/pi/openocd_cfg#openocd -f ./rpi2_redpill.cfg
 
Open On-Chip Debugger 0.10.0-dev-00220-gdfc6658-dirty (2016-02-19-16:19)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO nums: swclk = 18, swdio = 23
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
none separate
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : SWD only mode enabled (specify tck, tms, tdi and tdo gpios to add JTAG mode)
Info : clock speed 1001 kHz
Info : SWD IDCODE 0x1ba01477
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
After running the command above, openocd is exposing a gdb server on port 3333. You could connect to it from arm-none-eabi-gdb running on your RPI2 or more interesting would be remotely from a windows or linux development machine using the ethernet address of your RPI2. (something like : $ arm-none-eabi-gdb -ex 'target extended-remote 192.168.0.100:3333') The big advantage to using the raspberry pi 2 as the JTAG dongle, you don't need to install any drivers on your windows, mac or linux development machine. The commands are sent over a TCP/IP socket but take place on the RPI2.

So yeah, yet another interesting way to twiddle with the bits on your stm32 boards.

-rick
Last edited by Rick Kimball on Fri Feb 26, 2016 2:03 pm, edited 2 times in total.
-rick

User avatar
martinayotte
Posts: 1192
Joined: Mon Apr 27, 2015 1:45 pm

Re: Yet another way to swallow a Blue Pill

Post by martinayotte » Fri Feb 26, 2016 1:52 am

Interesting ! ;)

User avatar
Rick Kimball
Posts: 941
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by Rick Kimball » Fri Feb 26, 2016 2:17 pm

Raspberry PI 2 acting as a JTAG dongle with a STM32F103 Red Pill Board:
redpill.jpg
redpill.jpg (158.03 KiB) Viewed 3918 times
-rick

zmemw16
Posts: 1292
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by zmemw16 » Fri Feb 26, 2016 6:39 pm

before i go delving, anything major missing from the info in your first post?

for some reason i now have 3 orange pi ones, i suspect i looked at the price and thought they were pi 2

i imagine they'd work as well?

stephen, one step bigger bits and the other slower cpu :)

User avatar
Rick Kimball
Posts: 941
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by Rick Kimball » Fri Feb 26, 2016 7:43 pm

I have no experience with the orange pis, however you will probably have to use the "SysfsGPIO" interface instead of the BCM2835.
-rick

xehap
Posts: 1
Joined: Fri Mar 18, 2016 4:32 pm

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by xehap » Fri Mar 18, 2016 4:37 pm

Hello!

On the photo, the orange wire DIO seems goes to Pi's pin number 16, not 23, like in config file. Right?

zmemw16
Posts: 1292
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by zmemw16 » Fri Mar 18, 2016 11:02 pm

this link has a pretty picture. https://www.raspberrypi.org/documentati ... nd-raspi2/
probably best described as GPIO 23 is mapped to physical pin 16.

stephen

User avatar
Rick Kimball
Posts: 941
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by Rick Kimball » Sat Mar 19, 2016 1:15 am

xehap wrote:Hello!

On the photo, the orange wire DIO seems goes to Pi's pin number 16, not 23, like in config file. Right?
in the cfg file i mentioned both the gpio# and referenced which J8 physical pins
-rick

smurf
Posts: 1
Joined: Thu May 04, 2017 7:59 pm

Re: Turn a Raspberry PI 2 into a JTAG dongle

Post by smurf » Thu May 04, 2017 8:55 pm

Unhappily, as of version 0.10 the bcm interface does not support SWD mode.
The solution is to use sysfs, which is a whole lot slower but at least works.

This works for me:

Code: Select all

interface sysfsgpio
sysfsgpio_swd_nums 18 23
transport select swd


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest