You are here

Linux AVR tools, AVRDUDE, avr-gcc etc..

Submitted by sjs205 on Tue, 03/12/2013 - 18:53

I do so little AVR development these days that when I start again, it takes me a short while to get back into the swing of things. So rather than digging out old notes, I've reproduced the main elements here.

Install

To compile AVR C programs on linux you need the avr-gcc toolchain, along with a few other utilities. On Fedora one installs all of the packages required with:

Build .hex Image

Once these are installed the easiest way to build applications is by creating a 'Makefile' in the root of the project directory and using automake. Makefiles for the avr platform can be found all over the web, but my favorite is one written by Eric B. Weddington, Jorg Wunsch, et al. This file can be downloaded here: Makefile. Update the file to include the name of the object file, and sources files as outlined below:

Running 'make' in the project directory should now build the project and provide a .hex file which can be flashed to the device. The makefile above will build an object file, main.hex, from the source files foo.c, bar.c and main.c.

Flash Image

Now we have our device image, the main.hex file, we can flash this to the device using AVRDUDE. In my case I have a simple variant of the USBasp -USB programmer for Atmel AVR controllers, and as such, flash the main.hex to the device with the following command:

$ avrdude -p m48 -c usbasp -U flash:w:main.hex

We can also program the high and low fuses straight from the command line with the following command:

sudo avrdude -p m48 -c usbasp -U lfuse:w:0xE2:m

This will program the low fuse with the immediate(m) byte 0xE2. To program the high fuse change 'lfuse' to 'hfuse'.