Unfortunately, AVR Studio 4.08 is not installed at the lab. The
older version of AVR Studio has a bug that makes it incompatible
with the WinAVR tool set. This is not a mistake on WinAVR's
part (or any of its contributors), but on Atmel's part. WinAVR
has the necessary tools to create files conforming to Atmel's
description of the COFF format, but AVR Studio 3.5x itself
does not conform to Atmel's own standard.
Another reason why software source should be open.
Anyway, we can still debug programs without Atmel's simulator.
A GPL'd simulator, called simulavr, has been written to
provide the backend to simulate the execution of AVR code on practically
any platform. This simulator runs with gdb (GNU Debugger)
to provide debugging ability.
Let's get familiarized with the necessary components to get this to
work:
- WinAVR: this is the inclusive package that you should install
on a PC running Windows. If you use Linux, you need to
download various packages.
- avr-gcc: this is the GNU C Compiler cross targetted to the
AVR.
- avr-libc: this is a collection of libraries for use with
avr-gcc.
- avr-gdb: this is a debugger cross targetted to the AVR.
- avr-binutils: this is a collection of useful utility programs
to create executables.
- simulavr: this is the simulator. It can run as a ``server''
so that a debugger connects to it as it is a remote target
machine. The connection, however, is via a socket rather than
a serial port.
- insight: this is a GUI-based frontend of gdb. You don't
need this to debug a program. Most people find the text
interface of gdb a little too primitive and commands difficult
to learn. This is included in WinAVR.
Now, let's go through the step-by-step procedures to debug a program
using this tool chain:
- Make sure the program is compiled and linked, see
subsection 2.2.2.
- Click the Start button, then ``run...'', then type in
the following:
simulavr --gdbserver --device at90s2313
Substitute at90s2313 with whatever target MCU your
program is targetted. Selecting the correct target is
very important.
Note that once simulavr runs, it does not exit.
It gives you a message like ``Waiting on port 1212 for gdb
client to connect...'' if everything is okay.
Leave the command line interface alone (minimize it if you
don't want to clutter up your screen).
- If you install WinAVR, you should see an icon titled
``AVR Insight (WinAVR)'' on the desktop. Run the program.
If you do not see the desktop icon, go to the folder
containing the executable and launch it manually. The full
path is usually c:\WinAVR\bin\avr-insight.exe.
- In Insight, use ``File | Target Settings'', and select
``GDBServer/TCP'' as the Target, the ``Host'' should be
``localhost'', and the ``Port'' should be
set to 1212. For convenience, make sure ``Set breakpoint at
`main' '' is checked.
Click on ``More Options'', and make sure both
``Attach to Target'' and ``Download Program'' are both
checked.
You only need to do this once. Insight saves the options
autonatically.
- In Insight, use ``File | Open'' and locate
demo.elf. Click ``Open''.
- In Insight, use ``Run | Download'' to upload the executable.
This step should not have been necessary, but it is!
- Click the run icon (a running person), the program should
start, and the debugger stops on the first statement.
- If you see a line highlighted in green, you have successfully
launched the debugger!
Copyright © 2006-02-15 by Tak Auyeung