Just a thought

Setting up AVR development environment in Ubuntu

Posted by stringofthoughts on November 6, 2009

Setting up a development environment for AVR microcontrollers in Ubuntu is very easy. Although for a new user it can be a time consuming task. I’ve recently setup the environment for my lab and I’m gonna just document it for future reference. Apart from the command line environment I’ve installed and configured Code Blocks, a very nice IDE, for building the project and I’ve also configured avrdude ( programmer for avr microcontrollers ) in Code Blocks. So now it’s no less than any other IDE. With this configuration it’ll be easy for coders who are used to a windows environment. Click here for code blocks installation and configuration.

let’s get started.

first of all update the indexes for repository

$ sudo apt-get update

next make sure you ‘ve latest gcc compiler installed

$ sudo apt-get install gcc build-essential

now for setting up avr environment you need following packages : gcc-avr, gdb-avr, binutils-avr, avr-libc, avrdude

$ sudo apt-get install gcc-avr gdb-avr binutils-avr avr-libc avrdude

Basic command line environment is ready. I’m only gonna describe the command line method in this post. For configuring Code Blocks click here. Before we start building programs we need a make file. For new users, a make is a utility for automatically building executable programs and libraries from source-code. Download the make file for AVR microcontrollers from here. It’s a very easy to configure make file for avr. Download the file to your project directory. Now make a simple c file say test.c

#include <avr/io.h>

int main(void)
// Set Port D pins as all outputs
DDRD = 0xff;

// Set all Port D pins as HIGH

return 1;

Next step is configuring the make file for your project. so open the make file and modify it as described below. You need to modify following parameters for your project. I’m assuming that The microcontroller is ATmega32 and programmers hardware is STK200. The parameters are divided in two groups , one is target specific and other is programmer (avrdude) specific.

#####         Target Specific Details #####
#####     Customize these for your project #####

# Name of target controller
# (e.g. ‘at90s8515’, see the available avr-gcc mmcu
# options for possible values)
MCU=atmega32 /*  Add the name of the processor you are using */

# id to use with programmer
# default: PROGRAMMER_MCU=$(MCU)
# In case the programmer used, e.g avrdude, doesn’t
# accept the same MCU name as avr-gcc (for example
# for ATmega8s, avr-gcc expects ‘atmega8’ and
# avrdude requires ‘m8’)
PROGRAMMER_MCU=m32 /* This is microcontroller id. see manual pages of avrdude */

# Name of our project
# (use a single word, e.g. ‘myproject’)
PROJECTNAME=myproject  /* Project name , This could be anything you wish 😛 */

# Source files
# List C/C++/Assembly source files:
# (list all files to compile, e.g. ‘a.c b.cpp as.S’):
# Use .cc, .cpp or .C suffix for C++ files, use .S
# (NOT .s !!!) for assembly source code files.
#PRJSRC=main.c myclass.cpp lowlevelstuff.S
PRJSRC=test.c    /* Add the source files here */

#####      Programmer specific details #####
# programmer id–check the avrdude for complete list
# of available opts.  These should include stk500,
# avr910, avrisp, bsd, pony and more.  Set this to
# one of the valid “-c PROGRAMMER-ID” values
# described in the avrdude info page.
AVRDUDE_PROGRAMMERID=stk200  /* Programmer ids are listed in /etc/avrdude.conf */

# port–serial or parallel port to which your
# hardware programmer is attached
AVRDUDE_PORT=/dev/parport0 /* Make sure that driver for parallel port is loaded and working and change permissions to 777 */

Save the file and you are ready. Go to the directory containing test.c and modified Make file and execute these commands.

$ make              /* Compile your project*/

$ make hex        /* Generate hex file */

$ make install    /* Burn hex file in microcontroller ( Make sure your board is switched on and programmer is connected )*/

if everything goes right test.c will turn PORTD high. Leave me a message if you having problems.


5 Responses to “Setting up AVR development environment in Ubuntu”

  1. AVR freak said

    Great tutorial for AVR development under Linux. I am wondering many times why do I use The Windows.

  2. Peter said

    These instructions are simple and actually worked. Thanks. Other pages that I found were amazingly complicated and involved large amounts of unzipping and patching, and always failed when it got to the mathematics libraries.

  3. Bhaumik Shah said

    Dear Sir,

    your tutorial is gr8. i love the may u have made it simple i am new to linux & using ubuntu 10.4

    i have question
    1) where you write your source code & how ?
    can you help me for same.

    i have worked on windows using AVR studio & Codevision avr but procedure here is different…
    please help me adapt it

    • brainwave said

      U write the source code on your favourite text editor…..and then save the makefile (edited) in the same folder as the source code.

  4. Karim Mansour said

    Thanks a lot for this great tutorial, but for Linux Ubuntu 10.10 the make file should be modified so the flash part could work

    1. Add new field in configuration part (at the beginning) —> AVRDUDE_UPLOAD_RATE= 57600 #or whatever the rate you want
    2. The write flash part should be modified to be as the following:
    writeflash: hex
    -U flash:w:$(HEXROMTRG)

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: