SL:AVRDragon
AVR Dragon
The AVR Dragon can be used to do JTAG debugging with IRIS motes connected to MIB520 boards. It should also somehow work for other AVR/ATmega based platforms. (to be investigated)
Connecting AVR Dragon and MIB520
The AVR Dragon has a 10-pin connector field. We use jumper wires to connect these with the MIB520. (Note: Since a door fell on the AVR Dragon, the pins are slightly crooked and one of the jumper cables is slightly damaged, but everything should be still in working order.)
The pin layout on the AVR-Dragon looks as follows:
..... ..... 1 JTAG 9
Giving each pin a name, this becomes:
BDFHJ ACEGI 1 JTAG 9
Pin G (or 7) is not required as can be seen in this table: http://www.atmel.com/webdoc/atmelice/atmelice.connecting_jtag.html
Correspondingly, on the MIB520 programming board, the pins look as follows:
J3 ..... ● .....
The ● pin corresponds to pin 1 on the AVR Dragon, so the renumbered scheme looks as follows:
J3 BDFHJ ● ACEGI
Pins with the same position/number/name have to be connected:
BDFHJ J3 BDFHJ ACE*I ⇒ ● ACE*I 1 JTAG 9
Don't connect the AVR Dragon to the PC yet.
Preparing an IRIS node
First, you have to program a node. It's recommended to build with debug information to make things easier later:
make iris debug make iris reinstall.0 mib520,/dev/ttyUSB0
Once the node is programmed, you have to change the fuses to enable JTAG debugging. Be careful. Setting the wrong fuses might (in some cases recoverably, but don't bet on it) brick your node!
avrdude -cmib510 -P/dev/ttyUSB0 -U hfuse:w:0x19:m -pm1281
Now the node is ready. Take it off, put in some batteries and use it however you like.
Connecting Node, MIB520 and AVR Dragon
Make sure your pins are connected correctly.
Detach the MIB520 you connected to the AVR Dragon from the PC. Attach the AVR Dragon to the PC.
You have two options for attaching the node to the MIB520.
Node is running and state should be preserved
Ensure that the MIB520 is connected to the AVR Dragon and NOT connected to the PC.
This can be used e.g. for forensics to extract the contents of the node's RAM or to debug a running application. However, attaching a running node without resetting it is a bit trickier. The node should be turned on, running on batteries. If there is a sensor board that does not fit on the MIB520, take it off now.
Carefully bring together the connectors of the MIB520 at the bottom end of the MIB520 (i.e. not where the USB connector is) and the the bottom end of the IRIS node (i.e. where the power switch is). Keep the two connectors angled slightly and push them together at the bottom. Once fully connected there, start pushing in the upper parts of the connector slowly and carefully. If the node is showing some status information on its LEDs, this information/the node shouldn't be reset during this process. If the node appears to reset during it, you have to try again more carefully.
Node is not running
Ensure that the MIB520 is connected to the AVR Dragon and NOT connected to the PC.
Attach the node to the MIB520. Ensure that the node contains batteries. After attaching it to the MIB520, turn on the node.
Using the AVR Dragon
Your AVR Dragon should be connected to the PC. The 10-pin JTAG connector should be wired to the corresponding connector on the MIB520. The MIB520 should not be connected to the PC. A switched on node with batteries should be attached to the MIB520. The whole setup should look as follows:
Currently, a green and red LED should be glowing on the AVR Dragon.
First, in one terminal, start avarice:
avarice -g -j usb localhost:4242
If you get an error about the USB device not being found, your user may not be in the dialout group on Linux. Make sure to have it added etc.
The following two errors indicate that the node/MIB520 are not correctly attached or the fuses are not set correctly:
No configuration available for device ID: ffff
set paramater command failed
In the case of success, you should get output similar to the following:
AVaRICE version 2.11, Dec 22 2013 18:22:47 Defaulting JTAG bitrate to 250 kHz. JTAG config starting. Found a device: AVRDRAGON Serial number: 00:a2:00:06:61:03 Reported JTAG device ID: 0x9704 Configured for device ID: 0x9704 atmega1281 JTAG config complete. Preparing the target device for On Chip Debugging. Disabling lock bits: LockBits -> 0xff Enabling on-chip debugging: Extended Fuse byte -> 0xff High Fuse byte -> 0x19 Low Fuse byte -> 0xff Waiting for connection on port 4242.
Now that avarice is running, only the green LED on the AVR Dragon should be on. Open a second terminal. In the directory of your TinyOS application (or other, but adjust the path accordingly), you can now start gdb.
avr-gdb build/iris/main.exe
Once started, connect gdb to avarice with the following command:
target remote localhost:4242
Now you should be able to debug your application as running on the node. When you perform a command that is executed on the node, a second green LED should shortly blink on the AVR Dragon. avarice should show the following:
Connection opened by host 127.0.0.1, port 57176.
Some useful gdb commands:
- info functions List functions. Output may include things like: static uint32_t Atm1281AlarmAsyncP__0__Counter__get(void);
- info variables List variables. Output may include things like: volatile uint8_t BlinkC__test[5];
- printf Use printf commands, similar to C. For example, you could do: printf "%08x", *(uint32_t*)BlinkC__test This can also be used to read out arbitrary data in various formats from RAM.
- print Outputs data. Example: print BlinkC__test
Another thing that may be useful to know is that the 8KB of RAM from on IRIS nodes are mapped to the address 0x00800000, so all memory can be found in the range of 0x00800000 - 0x00801fff.
To quit gdb you can press Ctrl-D or use the command quit. If avarice is still running, you can forcibly terminate it with Ctrl-C. The AVR Dragon should go back to having a green and red LED. The IRIS node should have reset and be the program on it should currently be running.
Now you can restart avarice or do whatever else you like.