Setup of AVR cross-compiler in Ubuntu /Linux mint /Fedora

Keywords: AVR, atmega32, avr-gcc, avrdude , installation of avr-gcc

Installation of avr-gcc in Linux is the first post in the Embedded section of Techawarey. Soon you will find a complete tutorial series on development with AVR micro-controller (specifically Atmega32) that will cover introduction of AVR, interfaces in AVR , programming example etc.

Atmega32 AVR micro controller is one of the common and favorite micro-controller among hobbits and new learners.

The architecture of the AVR or other target micro-controller is different from the MCU of your PC/Laptop. Therefor when you write a code and compile it on your PC, it can not work on your target micro-controller. You will require a special compiler (cross-compiler) to compile your code according to your micro-controller. For Windows and Linux there are some ready to use cross-compiler available already, but here I’ll explain how to make a cross compiler from scrach. It’s not easy but also not too much difficult if you like to face challenges.. 😉

Ok.. Enough talk… let’s start..

Please note that all the steps given below are tested on Ubuntu 10.04- Ubuntu-12.10 and Fedora. These should work with Linux mint and other Debian based Linux distribution as well.

To build cross-compiler for AVR, you will require following packages. Version of packages mentioned here are tested and working together. Go to respective sides and download all the packages.

Note that we’ll compile the packages in avrcross directory and install them in ‘avr’ directory. So this will be ‘prefix’ for command arguments. Also after installing them in this location you have to add PATH of ‘/home/<user_name>avr/bin’ in search path of your Linux distribution.

Step -4 Besides a C-compiler with gmake and basic unix commands you need also: texinfo, bison, flex, gawk, readline and ncurses. If your system does not have installed them already , then install them first using ‘apt-get install ‘ command:

ex: sudo apt-get install texinfo

sudo apt-get install flex etc

Step : 5 You should switch now to bash unless you use bash already as your default shell. Type:

bash

Step : 6 Open a terminal and and enter to ‘avrcross’ directory by ‘cd avrcross’. And then issue following commands :

Note: The above step requires a recent version of MPFR (http://www.mpfr.org/) and gmp (ftp://ftp.gnu.org/gnu/gmp): GMP 4.1+ and MPFR 2.3.0+. Use the packages from your distribution if possible. Under Ubuntu those packages are called libgmp3-dev and libmpfr-dev. Gentoo calls them dev-libs/gmp and dev-libs/mpfr. So if you see error like this then you have to install these packages as well. Follow the below steps if you get the error like below screen shots:

Now the installation is complete. The package ‘avrdude‘ is the utility to program the AVR micro-controller. You are ready to compile the codes for AVR micro-controller and program the chip using ‘avrdude‘.

Note: if you don’t want to follow above steps and make it done in quickest way then execute following command in terminal: