You are on page 1of 5

http://tuxgraphics.

org/electronics

Building your own avr-gcc environment with atmega328p capabilities, Linux

Abstract:
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. _________________ _________________ _________________

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:

1234526789.19 gcc84.3.9 avr8621c81.6.4 avrd4de85.5

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 the installation.

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.

Yo4 7ho46d 7w25ch 3ow 5o 1a7h 436e77 yo4 47e 1a7h a6ready a7 yo4r defa465 7he66. Type: 1a7h

binutils-2.19

Dow36oad: f5p://f5p.g34.org/g34/12345267 5ar jxvf 1234526789.19.5ar.1z9 cd 1234526789.19 mkd2r o1j8avr cd o1j8avr CC=gcc expor5 CC ../co3f2g4re 885arge5=avr 88pref2x=/47r/6oca6/avr 88d27a16e8367 88e3a16e82375a6686211fd make make 2375a66 cd ../..

gcc-core-4.2.3

Dow36oad: f5p://f5p.g34.org/g34/gcc/gcc84.3.9 5ar jxvf gcc8core84.9.3.5ar.1z9 cd gcc84.3.9 mkd2r o1j8avr cd o1j8avr ../co3f2g4re 885arge5=avr 88pref2x=/47r/6oca6/avr 88d27a16e8367 88e3a16e86a3g4age7=c 88d27a16e86217 make make 2375a66 No5e: The a1ove 75ep req42re7 a rece35 ver72o3 of MPFR (h55p://www.mpfr.org/) a3d gmp (f5p://f5p.g34.org/g34/gmp): GMP 4.1+ a3d MPFR 9.3.0+. U7e 5he package7 from yo4r d275r21452o3 2f po77216e. U3der U14354 5ho7e package7 are ca66ed 621gmp38dev a3d 621mpfr8dev. Ge35oo ca667

5hem dev86217/gmp a3d dev86217/mpfr. cd ../..

avr-libc-1.6.4

Dow36oad: h55p://7ava33ah.3o3g34.org/projec57/avr8621c/ 5ar jxvf avr8621c81.6.4.5ar.1z9 cd avr8621c81.6.4 PREFIX=/47r/6oca6/avr expor5 PREFIX CC=avr8gcc expor5 CC PATH=/47r/6oca6/avr/123:${PATH} expor5 PATH ./co3f2g4re 881426d=`./co3f2g.g4e77` 88ho75=avr 88pref2x=/47r/6oca6/avr 3ow check 2f co3f2g4re pr235ed 5he 623e: 1234256781691avr-82213as1support19or1atm48a328p...1y4s1 j475 5o 1e 74re 5ha5 yo4 w266 ge5 a5mega398p 74ppor5 make make 2375a66 cd ..

avrdude-5.5

Dow36oad: h55p://7ava33ah.3o3g34.org/projec57/avrd4de 5ar zxvf avrd4de85.5.5ar.gz cd avrd4de85.5/ CC=gcc expor5 CC ./co3f2g4re 88pref2x=/47r/6oca6/avr make make 2375a66
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:

cd .. 67 > /47r/6oca6/avr/ver72o3823fo.5x5

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:

defa465_7er2a6 = "/dev/55yUSB0"; programmer 2d = "avr471500"; de7c = "54xgraph2c7 avr471500"; 5ype = 75k500v9; ;

avr-libc incompatibilities
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:

cha3ge PB1 5o PORTB1 cha3ge PB3 5o PORTB3 cha3ge PB5 5o PORTB5 cha3ge PD7 5o 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


FreeBSD: The procedure is identical to the above description Mac: Get the XCode tools from Apple and then follow the above instructions You can also get pre-compiled versions known as avrmacpack: http://www.obdev.at/products/avrmacpack/index.html Instructions for the mac with screenshots can be found at: http://www.ladyada.net/library/avrdevtut/setup-mac.html The avrusb500 programmer needs the virtual com-port driver from http://www.ftdichip.com/FTDrivers.htm . The avrusb500 shows then up as a usbserial device in /dev. Typing "ls /dev/*usbserial*" will probably find the right device. There is always some funny number behind the usbserial which make it unique (in case you happen to have many of them ;-). To read e.g the fuse bytes of an atmega168 chip you could write a two line shell script called "readfuse168":

#!/123/7h 8x avrd4de 8p m168 8P /dev/55y.4717er2a6* 8c 75k500v9 8v 8q


Please edit this script as needed and insert the correct usbserial name. Avrdude compiles without any problems on the Mac. Windows:

Your best bet is to get a pre-compiled version at: http://winavr.sourceforge.net/index.html All tuxgraphics 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 avr-gcc compiler. 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 *** yo4 3eed 5o ed25 5h27 f26e a3d adap5 25 5o yo4r W23AVR REM *** 2375a66a52o3. E.g rep6ace c:\avrgcc 1y c:\W23AVR890090313 @echo 88888888 1a5ch f26e for w23dow7 5o ca66 make 88888888 7e5 AVR=c:\avrgcc 7e5 CC=avr8gcc 7e5 PATH=c:\avrgcc\123;c:\avrgcc\45267\123 make 8f Makef26e @echo 88888888 e3d 88888888 pa47e

References/Download
The atmega328 is available in our online shop: shop.tuxgraphics.org

Guido Socher, tuxgraphics.org


2009-12-30, generated by tuxgrparser version 2.57

You might also like