Posted by: freesystem | February 23, 2008

How-To: AVR Development under Linux

Here is a quick little how to for getting any STK500 Clone to work under most Linux systems. I am not going to be specific to any distro, as this has worked in Ubuntu, Gentoo, Debian, and Arch. I have no reason to believe that it would not work in anything else. So, all this guide assumes is that you know how to obtain and install packages for your specific distro. Also, if your STK500 Clone has a built in USB to Serial chip you need to figure out how to get that working, however the most popular ones are supported under the kernel. For instance, the CP2102 on my STK500 clone worked out of the box. I have also heard good things about FTDI’s FT232.

  1. Install, Compile, or in any other way obtain the following packages:
  • gcc-avr: A port of the GNU C Compiler to the AVR Architecture
  • avr-libc: AVR Library for stuff like accessing and manipulating registers
  • binutils-avr: Converts the object code into AVR-readable hex files
  • avrdude: The software that actually drives the programmer

I know these are in the Debian and Ubuntu repositories, so you can just use apt to get them. I don’t know about any other distros, as I needed the latest version of GCC-AVR, so I compiled it from source.

2. I use the following makefile for my development, so I do not need to type in a log cryptic code. You will need to modify it to suite your needs, such as changing the target AVR and main.c name. To get it working simply make a new file called makefile and paste the below makefile into it. Then modify it to your needs. I distribute the makefile under the terms of the GPL License Agreement.

3. To compile and download your code to the AVR all you need to do is have the makefile pointing to the source code, then cd into the directory and type “make”.

4.[OPTIONAL] I have found the SCitE IDE to work very well for AVR development. You just have the makefile correctly configured in the source directly. To compile and download code simply hit F7.

I hope this helps other people get there AVR’s working with Linux, as that was certainly one of the reasons I would have gone back to Windoze. I hope to in the future write a How-To for getting AVR JTAG to work in Linux.

Makefile:

##Location of the compiler. You generally should not have to change this unless you installed to a non-standard directory.
CC=/usr/bin/avr-gcc
##Your specific AVR
MEGA=32
##Arguments to pass on the command line. Do not modify this unless you know what you are doing.
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega$(MEGA)
##Path to avr-binutils, specifically avr-objcopy. You should not have to change this unless you installed to a non-standard directory.
OBJ2HEX=/usr/bin/avr-objcopy
##Path to AVRdude. You should not have to change this
PROG=/usr/bin/avrdude

##Target Source file, you will probably have to change this for every project you do. Do not include .C or anything.
TARGET=main

program : $(TARGET).hex
$(PROG) -c avrispv2 -p m$(MEGA) -P /dev/ttyUSB0 -e
$(PROG) -c avrispv2 -p m$(MEGA) -P /dev/ttyUSB0 -U flash:w:$(TARGET).hex

setfuse:
avrdude $(AVRDUDE_FLAGS) -u -U lfuse:w:0xA4:m
avrdude $(AVRDUDE_FLAGS) -u -U hfuse:w:0xD1:m

%.obj : %.o
$(CC) $(CFLAGS) $< -o $@

%.hex : %.obj
$(OBJ2HEX) -R .eeprom -O ihex $< $@

clean :
rm -f *.hex *.obj *.o

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: