AVR-GCC is a free open-source C/C++ compiler for the Atmel AVR series processors. AVR-GCC is actually not a unique product but rather a subset of the complete GNU Compiler Collection (GCC) specially customized to work with AVR processors. For more information about the complete GCC, see the Free Software Foundation's (FSF) GCC Home Page.
TODO: Notes about command line interface, makefiles, hosts, targets, etc
AVR-GCC is available from a huge number of sites and locations because it is a free open-source program. You can download AVR-GCC in source-code form, or a precompiled binary (program) already made to work on a certain kind of host (OS/machine). Since many users of AVR processors are not familiar with how to compile and set up GCC directly from the source code, more experienced users have made installable packages to greatly simplify the process.
Installation packages are available for the following hosts (operating systems) supported by RSL:
- Windows (98,NT,ME,2000,XP)
- WinAVR is the best prepackaged windows AVR-GCC installation currently available.
Download it from:
- RSL AVR Software page (recommended)
- WinAVR home page (http://sourceforge.net/projects/winavr)
- Linux
- Linux installations are readily available but are not yet supported by RSL
- MAC OSX
- AVR-GCC has been successfully compiled and run on OSX because of OSX's Unix base, however, no pre-made installations are currently known.
Installing WinAVR
Before beginning the install process, you need to choose/create a location/directory where the compiler and associated files can be installed. This directory should be different from the one in which you intend to keep the code you write. The directory you choose should not contain spaces in its name or path. Some examples are:
c:\WinAVR (GOOD) c:\programming\WinAVR (GOOD) c:\Code\AVR\WinAVR (GOOD) c:\Program Files\WinAVR (NOT RECOMMENDED - HAS SPACES IN PATH) c:\My code\AVR\WinAVR (NOT RECOMMENDED - HAS SPACES IN PATH)From the download step you should have a self-installing .exe file named Winavr-20030115-bin-install.exe. It is unimportant where this file is located. You can delete it if you wish after the installation completes but you may want to keep it for later re-installs.
- Double-click the .exe file to begin installation.
- Click through license agreement
- Choose your installation folder
- Watch installation progress (should take 1-2 minutes depending on computer speed)
- Readme.txt is opened automatically (installation is complete)
If you have some time, browse through the readme.txt. It contains a wealth of information about GCC, WinAVR, important terminology, and links to AVR projects and additional information.
Following the Install step, AVR-GCC should be functional. However, like most compilers, we need to add some environment variables to help make AVR-GCC easier to access from the command-line.
- Configuring WinAVR under Windows 2000 and Windows XP
If you are running Windows 2000 or Windows XP, you will need to set the following environment variables to enable you to use avr-gcc from any command-line prompt. (These examples assume you installed WinAVR into the directory C:\WinAVR. If you installed somewhere else, alter the statements accordingly)
set AVR to C:\WinAVR
to PATH add ;C:\WinAVR\bin;C:\WinAVR\utils\bin
To add these changes in Windows 2000/XP:- Go to the Start menu and open the Control Panel.
- From the Control Panel, double-click System (XP users may need to "Switch to Classic View")
- Select the Advanced tab and and click on the Environment Variables button.
- You will need to do the following three things in this window:
- Under the System variables section, find the PATH variable and click on Edit to open an Edit System Variable box. You will need to add the following to the end of the Variable Value field: ;C:\WinAVR\bin;C:\WinAVR\utils\bin. Make sure that no extra spaces are added before the semicolon, and that the semicolons correctly separate the entires before/after your edits. When you are done, click on OK for the Edit System Variable box.
- Next, click on the New button to add a new environment variable. In the Variable Name field, enter the name AVR, then in the Variable Value field enter the value C:\WinAVR.
- That's it. Click the OK button to close the Environment Variables window.
- Click the OK button to close the System Properties window and apply the changes.
- Configuring WinAVR under Windows 98 and Windows ME
If you are running Windows 98, the WinAVR installer should have taken care of the environment variables for you. You may need to reboot for the changes to take effect. If you still have problems (such as make not being recognized as a valid command or io.h not being found) you may need to make some additional changes. You will need to add the following environment settings to your autoexec.bat file. (Remember to replace C:\WinAVR with the actual path where you installed WinAVR.)
set AVR=C:\WinAVR
set PATH=C:\WinAVR\bin;C:\WinAVR\utils\bin;%path%
You can cut and paste these to the end of your autoexec.bat file, but you may need to make one small change first. Depending on your system, you may have spaces in your path string (example: …;c:\Program Files\…) and these spaces may cause this string to get parsed as two strings instead of one. This problem should be fixable by placing quotes around %path% before copying it into autoexec.bat:
set PATH=C:\WinAVR\bin;C:\WinAVR\utils\bin;”%path%”
Once this is done and autoexec.bat has been run, any command prompt should be able to correctly call make.
There are a few simple steps you can take to verify that your WinAVR installation is ready to be used:
- Open a Command Prompt (find it in your Start Menu or select Run, and run cmd.exe)
- Type make at the prompt
- If windows reports 'make' is not recognized as an internal or external command... then you have not set the PATH variable correctly in the configuration step
- If windows reports make: *** No targets specified and no makefile found. Stop. then the compiler is working and simply didn't find any code to compile
- Change directories to C:\WinAVR\doc\examples\demo (type cd c:\WinAVR\doc\examples\demo)
- Type make clean at the prompt
- Type make
- If your output looked like this then you just compiled your first AVR program:
C:\Programa\winavr\doc\examples\demo>make avr-gcc -g -Wall -O2 -mmcu=at90s2313 -c -o demo.o demo.c avr-gcc -g -Wall -O2 -mmcu=at90s2313 -Wl,-Map,demo.map -o demo.elf demo.o avr-objdump -h -S demo.elf > demo.lst avr-objcopy -j .text -j .data -O ihex demo.elf demo.hex avr-objcopy -j .text -j .data -O binary demo.elf demo.bin avr-objcopy -j .text -j .data -O srec demo.elf demo.srec avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex demo.elf demo_eeprom.hex avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O binary demo.elf demo_eeprom.bin avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O srec demo.elf demo_eeprom.srec C:\Programa\winavr\doc\examples\demo>