JTAG (and OpenOCD)

JTAG is often pointed out as a standard that isn't. Any older things sold having anything to do with JTAG were, and are still, horrifyingly expensive. Of course they were rare and specialized, so the price is perfectly justified. It didn't encourage wide adoption or compatibility, though. Most of the software is specialized and most of the hardware is only designed to run with single manufacturer's software and parts. Big enough clients might bother with using JTAG as it was supposedly intended.

Today, USB-JTAG bridges and dongles are starting to be fairly commonplace. ARM and MIPS cores and SoCs often have JTAG ports and FPGA and CPLD chips are usually developed and in some cases programmed (flashed) using JTAG. FTDI bridges, microcontrollers, and even CPLD chips are reasonably priced and capable. OSHW debug boards are made and commercial offerings may come with docs or get reverse engineered.

The electronic interface, bus, and protocol actually are standardized.

So, luckily(?) the compatibility and availability is mostly a software problem and some people have been working on solutions for a long while now. The OpenOCD project in particular has grown to support a fair variety of things.

Obviously, my main interest is using OpenOCD and any suitable debugging and/or programming interfaces for interfacing with electronics (MCU and programmable logic). It should be relevant to my interests and a professional asset.

Boundary scan and automated testing

JTAG Boundary Scan Primer on the OpenOCD site makes it sound like this is a fairly unexplored area.

Some archived talk.

The suspicious looking site of "The Boundary SCAN ORG Team" sound optimistic, though.

Interface hardware

Some part manufacturers integrate various debuggers on their development and demonstration boards. Mostly these are either some kind of more specialized/simplified versions of JTAG or completely proprietary.

Some well known alternatives are UART based loaders, DFU and TFTP and other self-programming protocols, AVR ISP based on SPI, and PIC ICSP. Some of these are common interfaces, others are simple, and some are very specialized.

J-Link-ARM JTAG adapter

I had long planned to buy a Bus Blaster clone. They are cheap, simple, and seem to be relatively well supported. Along with debugging and exploring various (abandoned) embedded devices like router and NAS boxes, I had been planning to get some ARM board. Having a "real" JTAG beside development board integrated debuggers could come in handy there as well.

Later I came across an affordable J-Link adapter that many people seem to use with OpenOCD and ARM. I only later remembered that this might be handy with MSP430 and PIC32 chips and CPLD's I might come across.

Here's the first test runs:

usb 1-2: new full-speed USB device number 11 using uhci_hcd
usb 1-2: New USB device found, idVendor=1366, idProduct=0101
usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-2: Product: J-Link
usb 1-2: Manufacturer: SEGGER
usb 1-2: SerialNumber: 000099999994

(S/N doesn't seem to match the sticker.)

Let's try something.

% openocd -f interface/jlink.cfg -c 'gdb_memory_map enable' -c 'gdb_flash_program enable' -f board/stm3210c_ev
Open On-Chip Debugger 0.7.0 (2013-08-04-09:35)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
cortex_m3 reset_config sysresetreq
Info : J-Link initialization started / target CPU reset initiated
Info : J-Link ARM V8 compiled Jun 19 2012 11:29:30
Info : J-Link caps 0xb9ff7bbf
Info : J-Link hw version 80000
Info : J-Link hw type J-Link
Info : J-Link max mem block 9320
Info : J-Link configuration
Info : USB-Address: 0x0
Info : Kickstart power on JTAG-pin 19: 0xffffffff
Info : Vref = 3.306 TCK = 1 TDI = 0 TDO = 1 TMS = 0 SRST = 0 TRST = 0
Info : J-Link JTAG Interface ready
Info : clock speed 1000 kHz
Info : JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
Info : JTAG tap: stm32f1x.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection from 3333
Info : device id = 0x20036410
Info : flash size = 128kbytes
Warn : acknowledgment received, but no packet pending
undefined debug reason 6 - target needs reset
Info : JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
Info : JTAG tap: stm32f1x.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000100 msp: 0x20001750
requesting target halt and executing a soft reset
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000100 msp: 0x20001750

% arm-none-eabi-gdb 
GNU gdb (7.6.1-1+1) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb) monitor reset init
JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
JTAG tap: stm32f1x.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000100 msp: 0x20001750
(gdb) monitor soft_reset_halt
requesting target halt and executing a soft reset
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000100 msp: 0x20001750
(gdb)

Sweet. I'll need to check board and chip config and get some firmware in there.

Other sessions

Some other things related to OpenOCD, JTAG, or other debuggers.

Links