Application Note 5000 16 April 2008 Debugging Applications with the JTAG In-Circuit Emulator AVR64/128 This document describes how to debug embedded wireless applications using the JTAG in-circuit emulator (ICE) for AVR microcontrollers. This method is principally useful in the early stages of development to debug device-level functionality. When application development moves into debugging the network behavior of devices, the JTAG ICE method becomes much less useful for the following reasons: It can only provide information about a single device. Not being a realtime debugger, it must halt code execution to read state, which negatively affects both the device under scrutiny and the operation of its neighbors, because the node is effectively removed from active participation in any mesh routing. The Ember developer kit provides tools that can be used to debug network behavior, such as an Ethernet backchannel and the EmberScope packet sniffer. User guides for these tools are provided in the developer kit. Note: T o use the JTAG ICE, you must be using an image from an EmberZNet network stack or an EmberNet network stack release of 3.0-b12 or greater. You should be familiar with the Atmel AVR Studio software, because JTAG debugging of AVR processors typically requires use of this interface. You should also be familiar with AVR JTAG ICE debugging procedures; for moreinformation, refer to the AVR JTAG ICE User Guide: http://www.atmel.com/dyn/resources/prod_documents/doc2475.pdf. Topics This document covers the following topics: Preliminary steps for using the JTAG ICE, page 2 Setting up and using the JTAG ICE, page 3 Restoring the RCM to normal operation, page 4
Page 2 Preliminary steps for using the JTAG ICE Before using the JTAG ICE, you must configure the microcontroller fuses and adjust the IAR build process to allow for JTAG debugging. Note: When you finish with the JTAG debugging process for your RCM, remember to follow the procedures described later, in Restoring the RCM to normal operation, so you can use your node in a standard context and bootload a new image onto it. Configuring microcontroller fuses Only three fuse settings are relevant to using the JTAG ICE: the Reset Vector (BOOTRST), EESAVE, and JTAGEN. Other fuses, lockbits, and boot options may need to be configured for your hardware to function correctly. For more information about microcontroller fuses, including suggested settings and the purpose and procedure for setting them, see Application Note 5001, Bringing Up Custom Nodes for AVR 64/128. Configuring the fuses requires an in-system programmer (ISP). The Ember developer kit does not include one, but many are available. Be sure to select a device that supports the microcontroller used in your Ember radio frequency communication module (RCM). (ISP usage is described in Application Note 5001, Bringing Up Custom Nodes for AVR 64/128.) Note: If you plan to use the Kanda programmer, you must obtain an adapter from Ember in order to connect the Kanda device to the developer kit carrier board s AVR programming header. The Ember developer kit carrier board provides a programming port (labeled J17 AVR PROGRAMMER) with 0.1-inch pin spacing rather than the 0.3- inch pin spacing found on most ISP connectors. Please contact Ember at support@ember.com to request this adapter. Warning: The Ember developer kit carrier board port with 0.3-inch pin spacings (port J16, labeled AVR JTAG) should be used for JTAG connections only. Although some ISP connectors may fit this port without the use of an adapter, it is not possible to program the microcontroller through this port. Warning: Configuring fuse settings incorrectly may result in an unusable RCM. If the RCM becomes unusable, see Application Note 5001, Bringing Up Custom Nodes for AVR 64/128, for information on restoring it to its proper state. If you are unsure about the proper settings for your RCM, please contact a support engineer at support@ember.com for assistance Connect the ISP (In System Programmer) programmer of your choice to the ISP port (J17) and set the fuses as follows: Fuse Setting BOOTRST: Reset Vector (found under Lockbits & Boot Options) UNSET (Boot Block) EESAVE: EEPROM memory is preserved after Chip Erase SET
Page 3 Fuse Setting JTAGEN: Enable JTAG SET Other fuses, lockbits, and boot options should be set according to the procedures described in Application Note 5001, Bringing Up Custom Nodes for AVR 64/128. Adjusting the build process You must adjust the IAR Workbench build process to obtain a build image that the software for your ICE can use. The following procedure pertains to IAR Workbench version 4.10B and the.eww files in the Ember developer kit for EmberZNet 2.0. However, it should translate easily to any recent build that is using a similar version of the IAR Workbench. For each RCM to be debugged, make the following changes to IAR Workbench: 1. Open the.eww file that applies to the RCM that you want to debug. 2. Select a debug configuration from the drop-down list (for example, Simple- EM2420-Debug Target). 3. Select Project > Options. The Options dialog opens. 4. Select the Assembler category, then click the Output tab. Select Generate debug information. 5. Select the Linker category, then click the Output tab. In the Output file box on this tab, deselect Override default. In the Format box select Other, and in the Output Format drop-down list, select ubrof 8 (forced). 6. Click the #Define tab and change the INTVEC_BASE symbol value from 100 to 0. 7. Click the Extra Options tab (at the far right of all the tabs) and remove the - y(code) string. 8. Click the Build Actions category, and then clear all fields in the category. 9. Click OK to close the Options dialog. 10. Rebuild the image by selecting Project > Rebuild All in the main menu. Setting up and using the JTAG ICE Using the JTAG ICE on an AVR processor requires the AVR Studio software. To set up the AVR Studio 4.11 JTAG ICE environment: 1. Connect the JTAG ICE to a serial port on a PC and to the JTAG header (J16) on the Ember developer kit carrier board. 2. Follow this power-up sequence: Power the target (the carrier board). Power the JTAG ICE.
Page 4 Launch AVR Studio. Load and run the.dbg image. Note: When AVR Studio comes up in the open dialog, be sure to select JTAG ICE, ATmega128, ATmega64, and OPEN PLATFORM OPTIONS. 3. In the JTAG ICE Properties window, click the Debug tab and select Preserve EEPROM contents when reprogramming device. Click Apply, then click OK. The Initialized Data window displays. 4. Select Cancel in the Initialized Data window. Warning: You must cancel the Initialized Data window. If you do not, you will erase the tokens on the RCM. 5. Run the image. Note that you must pause execution to read the device s state. The JTAG ICE does not support execution tracing or realtime debugging. Debugging tips Initially, you are likely to see only the radioreceiveinterrupt() and RX overflows. The cause is radio traffic, in particular, the high interrupt rate on the EM1020 radio and the false SFD detects on packets in the EM2420 radio. When single-stepping or breaking, the node cannot function on the network because these methods interrupt the normal operation of the network stack, and this will negatively affect mesh relay traffic. This means that you cannot run JTAG while having the node participate on the network. To see the application code executing, disable the RX interrupt to keep the network stack from reacting to incoming packets. Do this by opening the EXTERNAL_INTERRUPT- >EIMSK in the 128 I/O tree and deselecting INT4. It is best to set breakpoints in the user application only and avoid the manual break or pause function. Doing this keeps the program flow from being paused within the context of the network stack library, where debugging is not reasonable because the source code for these functions is not provided. During the debugging process, the code sometimes hangs or repeatedly asserts on EEPROM accesses or UART activity. If this happens, repeat the power-up sequence. Restoring the RCM to normal operation You restore the RCM to normal operation by performing two tasks: Restore fuse settings Reload the application bootloader Restore fuse settings When you have finished debugging with the JTAG ICE, reset the fuses to the settings described in Application Note 5001, Bringing Up Custom Nodes for AVR 64/128.
Page 5 Note: Heed the following warning from in the Atmel datasheet: Never ship a product with the OCDEN Fuse programmed regardless of the setting of lockbits and the JTAGEN Fuse. Reload the application bootloader Because the application bootloader was erased from the RCM during setup for JTAG debugging, you must reload it so that you can upload applications to the node. For the procedure to upload the application bootloader, see Application Note 5001, Bringing Up Custom Nodes for MSP430F1612. For more general information on the application bootloader, see Application Note 5022, Programming and Using the Application Bootloader After reading this document If you have questions or require assistance with the procedures described in this document, please contact an Ember support representative at support@ember.com.
Copyright 2002-2008 by Ember Corporation All rights reserved. The information in this document is subject to change without notice. The statements, configurations, technical data, and recommendations in this document are believed to be accurate and reliable but are presented without express or implied warranty. Users must take full responsibility for their applications of any products specified in this document. The information in this document is the property of Ember Corporation. Title, ownership, and all rights in copyrights, patents, trademarks, trade secrets and other intellectual property rights in the Ember Proprietary Products and any copy, portion, or modification thereof, shall not transfer to Purchaser or its customers and shall remain in Ember and its licensors. No source code rights are granted to Purchaser or its customers with respect to all Ember Application Software. Purchaser agrees not to copy, modify, alter, translate, decompile, disassemble, or reverse engineer the Ember Hardware (including without limitation any embedded software) or attempt to disable any security devices or codes incorporated in the Ember Hardware. Purchaser shall not alter, remove, or obscure any printed or displayed legal notices contained on or in the Ember Hardware. Ember, Ember Enabled, EmberNet, EmberZNet, InSight Desktop, and the Ember logo are trademarks of Ember Corporation. All other trademarks are the property of their respective holders.