Building your own avr-gcc environment with atmega328p capabilities, Linux
ArticleCategory: [Choose a category, do not translate
AuthorImage:[Here we need a little image from you]
TranslationInfo:[Author + translation history. mailto: or
original in en Guido Socher
AboutTheAuthor:[A small biography about the author]
Guido likes Linux because it is a really good system to
develop your own hardware.
Abstract:[Here you write a little summary]
Atmel announced the atmega328p chip a while ago but it is only
now that one can really order such chips. The atmega328p is the
big brother of atmega88 and atmega168. It is fully pin
compatible and provides 2Kb ram and 32Kb flash. Especially the
larger amount of ram makes it very attractive.
You can load code compiled for atmega168 into an atmega328p and
it will work but you will not be able to use the extra ram and
flash memory. To use the full capabilities of the new chip a new
compiler is needed.
ArticleIllustration:[This is the title picture for your
ArticleBody:[The article body]
Installing avr-gcc under Linux
Linux is a great system for software development. It is very easy
to add a full avr-gcc development environment.
There is a chapter for Mac and windows at the end of this article.
The installation is very straight forward. Just follow the
commands below. We will install the following versions:
I have verified that those packages are working together. The
final installation will give you a compiler that supports the
atmega328p chip. Everything will be installed under /usr/local/avr
You should add the directory /usr/local/avr/bin to
your Unix search PATH environment variable after completion of
Installation step by step
Just download the files and run the commands one by one in the
order shown below. The commands are in bash syntax.
Besides a C-compiler with gmake and basic unix commands you need also: texinfo,
bison, flex, gawk, readline and ncurses.
You should switch now to bash unless you use bash already as
your default shell. Type:
tar jxvf binutils-2.19.tar.bz2
../configure --target=avr --prefix=/usr/local/avr --disable-nls --enable-install-libbfd
tar jxvf gcc-core-4.2.3.tar.bz2
../configure --target=avr --prefix=/usr/local/avr --disable-nls --enable-languages=c --disable-libssp
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.
tar jxvf avr-libc-1.6.4.tar.bz2
./configure --build=`./config.guess` --host=avr --prefix=/usr/local/avr
now check if configure printed the line:
checking if avr-gcc has support for atmega328p... yes
just to be sure that you will get atmega328p support
tar zxvf avrdude-5.5.tar.gz
Now the installation is complete. It's a good idea to add some version information file
so you know later on what you installed. Go back one level such
that you can see the downloaded packages and their unpacked directories
and then type ls:
ls > /usr/local/avr/version-info.txt
Manual changes to avrdude.conf
The avrdude.conf file was installed during the above procedure
in /usr/local/avr/etc. It needs some manual editing.
You need to add an atmega328
section (click here) as avrdude does not yet have atmega328
support in the standard configuration file. Search for
atmega168 and add it before or after.
To use avrusb500 with avrdude go to the beginning of the
avrdude.conf file and add this:
default_serial = "/dev/ttyUSB0";
id = "avrusb500";
desc = "tuxgraphics avrusb500";
type = stk500v2;
The io.h for atmega168 contains pin definitions which have been
renamed in atmega328. Those will cause compile errors. In case
of the tuxgraphics ethernet code you will find that you will
have to change the following in the source code:
change PB1 to PORTB1
change PB3 to PORTB3
change PB5 to PORTB5
change PD7 to PORTD7
We will update the code on our website over time too but it
might take a while.
Installing avr-gcc for BSD unix, Mac and windows
- The procedure is identical to the above description
- Your best bet is to get a pre-compiled version at:
software comes with a Makefile. Most of our software consists of more than one
.c file therefore remember to use the supplied Makefile during compilation.
A problem of windows is the lack of a decent shell environment and
a command interface.
In Winavr you can use a batch file to setup the environment while
calling the make-utility. An example of such a script is shown below.
Put the batch file in the same directory where the code is and call it
something.bat . To compile just double click on it form the file manager.
It is also possible to call that script from avr-studio
when using avr-studio. Note that avr-studio is as such is a avr assembler
programming environment. To program in C you need the
Here is a batch file to compile C-code under windows. Please adapt the
path inside the script according to your avr-gcc installation.
REM *** you need to edit this file and adapt it to your WinAVR
REM *** installation. E.g replace c:\avrgcc by c:\WinAVR-20090313
@echo -------- batch file for windows to call make --------
make -f Makefile
@echo -------- end --------