Just a thought

Archive for November, 2009

Code Blocks IDE for avr-gcc and avrdude (Ubuntu)

Posted by stringofthoughts on November 6, 2009

Code Blocks is very light weight, extensible and fully configurable C/C++ IDE. You can download code blocks from here. This post focuses on installation and configuration of code blocks on Ubuntu. Download the binary package codeblocks_8.02-0ubuntu1.deb.tar.gz. Inside the compressed file there is a folder with following packages.


Install the packages in bold letters. In case you are wondering how to install, just double click on the packages (damn it’s easy to install softwares in Ubuntu 😛 ) After the installing you can access code blocks from menu Applications -> Programming -> Code::Blocks IDE.

Click on Create a new project in home window to create your new project. Code blocks automatically adds an AVR Project option. Select that and click next. Fill the required informations like project name, path, crystal frequency etc and click finish.

In the Project Tab of management window (left side of the screen) you ‘ve your workspace. Inside the sources you ‘ve main.c. you can of-course add more files. Now your project is ready. congratulations !!! . There is still one thing left to do. Open build options from menu: Project -> Build options and in compiler flags tab check flag “Optimize generated code (for size) [-Os]”. You might wonder why? well compiler won’t compile your code and you ‘ll be stuck with warning(s) 🙂 ( I myself checked the flag after getting warnings )

# Make sure to switch to Release mode to generate hex file. Do all the debugging in debug mode and once it’s done switch to Release mode and build again to generate hex file. Project hex file is in <Project dir>/<bin>/<Release> and it’s the .elf.hex file you need.

Adding avrdude in code blocks tools. Follow the steps

Open the “User defined tools” window from menu: Tools -> configure tools.

Click on Add button to open Edit tool window.


Add the parameters for avrdude as shown in above image and you are done. After compiling in release mode just click on the avrdude option in tools menu and it will burn .elf.hex file in the microcontroller (Make sure the the target is powered on and programming cable is connected )

Have a nice time buring microcontrollers 😛


Posted in Linux | 9 Comments »

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.

Posted in Linux | 5 Comments »