Debugging nesC code with the AVR JTAG ICE

Note: we do not currently support the JTAG ICE mkII from Atmel.

The Atmel ATMEGA 128 processor offers in-circuit debugging through its JTAG interface. This document explains how to setup your environment to allow gdb to be used with mica motes.  A separate document, here, describes how to debug nesC programs with gdb (this applies to both JTAG debugging on motes and tossim-based debugging on PCs). This document also gives an example of a debugging session using the JTAG ICE.

A number of separate elements are needed for JTAG debugging on motes:

Once you have built up this bit of infrastructure, your setup might look something like this:
At that point you should be able to simply compile your nesC application (make sure you're compiling with debugging support (-g flag), the easiest is to include the word debug in your make command line). Connect the pod to your serial port, turn the pod on, turn the mote on, and from a shell window you should be able to do something like the following:
 
cd ~/trunk/tinyos-1.x/apps/CntToLeds
make clean; make mica debug
export AVARICE_ARGS='-j COM1' # a cygwin example, /dev/ttyS0 on Linux (and should work on cygwin too)
ice-gdb build/mica/main.exe
This should start the avarice (the PC-side of the JTAG setup), which understands the GDB remote debugging protocol, and gdb itself. It will load the program onto the mote, and stop the execution in the initialization. At that point you should have all the familiar GDB hooks at your disposal: breakpoints, displaying memory, registers, etc. You could also use the ice-insight command if you prefer a more graphical debugging environment. Please refer to the man pages for ice-gdb and ice-insight for more options.
Robert Szewczyk, 13 Mar 2003, David Gay, 21 August 2003