You Are Here: Home » AVR ATmega Projects » Debugging AVR code in Linux with simavr

Debugging AVR code in Linux with simavr




I recently started programming AVR chips, namely the ATTiny85.  They can be programmed using C, compilers are readily available in Ubuntu, and you can do a LOT with them – just search for avr on this site!  Anyway, I was having some trouble with my project today – the LED wouldn’t flash!  I couldn’t figure out what was going on, as debugging these things is non-trivial.  That is, until I discovered simavr.

It’s a simulator for AVR in Linux that can take your ELF or HEX code and run it as if it’s actually on-chip, but gives you hooks and the possibility of dumping trace files.  I’ll go through a simple example.

simavr

Step 1: Git it

There are a few dependencies on Ubuntu (which is what I use all the time):

sudo apt-get install avr-libc libelf-dev \
   libglut3-dev gtkwave git build-essential

I had to remove some crappy Mesa symlink for OpenGL in 10.10.  Only do this if you have problems compiling related to -lGL,

sudo rm /usr/lib/libGL.so
cd /usr/lib
sudo ln -s libGL.so.1 libGL.so
cd

Finally, use git to download the source code:

git clone git://gitorious.org/simavr/simavr.git

Now, build it.

cd simavr
make

If you get any errors, leave me a comment.  I’d be happy to help.  You should have a new program called run_avr in the simavr subdirectory once that completes

Step 2: Try a test

There’s tons of tests that come with the software.  They’re located in the (surprise!) tests subdirectory in the code.  You can run one like this:

./run_avr ../tests/atmega88_example.axf

You should see something like this:

AVR_MMCU_TAG_VCD_TRACE 00c6:00 - UDR0
AVR_MMCU_TAG_VCD_TRACE 00c0:20 - UDRE0
Loaded 1760 .text
Loaded 114 .data
Loaded 4 .eeprom
Starting atmega88 - flashend 1fff ramend 04ff e2end 01ff
atmega88 init
avr_eeprom_ioctl: AVR_IOCTL_EEPROM_SET Loaded 4 at offset 0
Creating VCD trace file 'gtkwave_trace.vcd'
Read from eeprom 0xdeadbeef -- should be 0xdeadbeef..
Read from eeprom 0xcafef00d -- should be 0xcafef00d..
simavr: sleeping with interrupts off, quitting gracefully

Notice it made a VCD trace file?  Let’s see what that looks like in GTKWave!

 

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Put it together
Watch futurama on an 8×8 pixel screen using atmega168 microcontroller

here's how to convert otherwise reasonable quality video into pixelated garbage and play it on a 2 color 8x8 led...

Close
Scroll to top