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
// Set Port D pins as all outputs
DDRD = 0xff;
// Set all Port D pins as HIGH
PORTD = 0xFF;
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.