Avr-studio

Version 16 (Anthony Rowe, 02/04/2008 02:00 pm)

1 1 Anthony Rowe
2 1 Anthony Rowe
3 16 Anthony Rowe
h1. AVR Studio
4 16 Anthony Rowe
5 16 Anthony Rowe
6 14 Anthony Rowe
This page describes how to use AVR Studio for debugging Nano-RK applications running on a single node. AVR Studio is good for debugging execution of complicated C / Assembly algorithms, or debugging memory problems.  It is not good for simulating network interactions or multiple nodes communicating.  For that you need a network wide simulation environment.
7 2 Anthony Rowe
8 1 Anthony Rowe
In order to run Nano-RK inside AVR Studio, you will need version 4.13 build 571 or newer.  This can be downloaded for free from the following link: http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725
9 1 Anthony Rowe
10 16 Anthony Rowe
*Step 1:  Install AVR Studio
11 16 Anthony Rowe
*
12 1 Anthony Rowe
13 16 Anthony Rowe
*Step 2:  Install AVR Studio Service Pack 2
14 16 Anthony Rowe
*
15 1 Anthony Rowe
16 16 Anthony Rowe
*Step 3:  Install Nano-RK and [[WinAVR]] on a Windows Machine
17 16 Anthony Rowe
*
18 16 Anthony Rowe
* This is required so that the source can be correctly linked against the binary file.  Using a binary built in linux works except that you will not be able to browse the connected C source, just the assembly (with no comments!).
19 1 Anthony Rowe
20 16 Anthony Rowe
*Step 4:  Build an elf file
21 16 Anthony Rowe
*
22 16 Anthony Rowe
* The Nano-RK build system automatically builds the elf file when you run make in a project.  To test this, go into a project like basic_tasks and type "make".  You should see the following files:
23 16 Anthony Rowe
** main.o
24 16 Anthony Rowe
** main.d
25 16 Anthony Rowe
** main.lst
26 16 Anthony Rowe
** main.eep
27 16 Anthony Rowe
** main.lss  
28 16 Anthony Rowe
*** You may need to run make twice for this one.  It is an extended list file with all assembly code for all functions
29 16 Anthony Rowe
** main.sym
30 16 Anthony Rowe
** main.map
31 16 Anthony Rowe
** main.hex
32 16 Anthony Rowe
** *main.elf*  
33 16 Anthony Rowe
*** This is the file we need for the simulator!
34 16 Anthony Rowe
*** You can copy this file to a separate debugging directory if you like...
35 1 Anthony Rowe
36 16 Anthony Rowe
*Step 5:  Start up AVR Studio
37 16 Anthony Rowe
*
38 16 Anthony Rowe
* Start-> Programs -> Atmel AVR Tools -> AVR Studio 4
39 1 Anthony Rowe
40 16 Anthony Rowe
*Step 6: Load the elf file
41 16 Anthony Rowe
*
42 16 Anthony Rowe
* Click "Open" and navigate to your .elf file
43 16 Anthony Rowe
* On the next screen, save the .aps file in the same directory. 
44 16 Anthony Rowe
** This file is used to store debugger settings etc
45 6 Anthony Rowe
46 16 Anthony Rowe
*Step 7: AVR Simulator Settings
47 16 Anthony Rowe
*
48 16 Anthony Rowe
* For the Debugging Platform select: AVR Simulator
49 16 Anthony Rowe
* For the Device select: ATmega1281
50 16 Anthony Rowe
* Press Finish
51 16 Anthony Rowe
* make sure you see something like the following in the Messages window:
52 1 Anthony Rowe
53 16 Anthony Rowe
<pre>
54 6 Anthony Rowe
Loaded plugin STK500
55 7 Anthony Rowe
Loaded partfile: E:\Program Files\Atmel\AVR Tools\PartDescriptionFiles\ATmega1281.xml
56 7 Anthony Rowe
AVR Simulator: Please wait while configuring simulator...
57 7 Anthony Rowe
AVR Simulator: ATmega1281 Configured OK
58 7 Anthony Rowe
Loaded objectfile: E:\Documents and Settings\agr\Desktop\nrk-debug\main.elf
59 16 Anthony Rowe
</pre>
60 7 Anthony Rowe
61 7 Anthony Rowe
62 8 Anthony Rowe
63 16 Anthony Rowe
*Step 8: Set processor speed 
64 16 Anthony Rowe
*
65 16 Anthony Rowe
* Go Debug Menu -> AVR Simulator Options
66 16 Anthony Rowe
* Set Frequency to 8 MHz
67 7 Anthony Rowe
68 7 Anthony Rowe
----
69 7 Anthony Rowe
70 7 Anthony Rowe
71 16 Anthony Rowe
h1. Tips
72 7 Anthony Rowe
73 11 Anthony Rowe
74 16 Anthony Rowe
*View -> Memory*
75 16 Anthony Rowe
* This lets you look at the various memories on the processor.
76 7 Anthony Rowe
77 16 Anthony Rowe
*View -> Watch*
78 16 Anthony Rowe
* This lets you monitor particular variables in your code.
79 16 Anthony Rowe
* Select the variable in your code window and then right click -> Add Watch: "xxx"
80 7 Anthony Rowe
81 16 Anthony Rowe
*Setting Breakpoints*
82 16 Anthony Rowe
* You can set break points anywhere in your code (even in sections not currently displayed in the debugger)
83 16 Anthony Rowe
* File -> Open File
84 16 Anthony Rowe
** Navigate to any source file in Nano-RK
85 16 Anthony Rowe
** Once it opens, you can right click -> Toggle Breakpoint
86 16 Anthony Rowe
** This will cause the simulator to stop once it reaches that point
87 16 Anthony Rowe
88 16 Anthony Rowe
*Dissassembler Window*
89 16 Anthony Rowe
** View -> Disassembler will show the raw assembly
90 16 Anthony Rowe
** You can switch back and forth from the C code to the assembly code etc
91 16 Anthony Rowe
92 1 Anthony Rowe
----
93 1 Anthony Rowe
94 1 Anthony Rowe
95 16 Anthony Rowe
h1. Trouble?
96 1 Anthony Rowe
97 16 Anthony Rowe
98 16 Anthony Rowe
99 1 Anthony Rowe
If you see the following in the Message Window:
100 16 Anthony Rowe
<pre>
101 1 Anthony Rowe
Coordinator: The object file does not contain source code information.
102 16 Anthony Rowe
</pre>
103 1 Anthony Rowe
You probably did not select the elf file (the hex file will load without source) or you are using an old version of AVR Studio.