EE 281 Lab 1: Using AVR GCC
These instructions are for installing the AVR GCC compiler and libraries on
a Windows 2000/NT system. More information about this can be obtained at
the following link: http://www.avrfreaks.net/AVRGCC/.
For information about installing AVR GCC for Linux, follow this link: http://combio.de/avr/
- Setting up the compiler:
- Downloading the
files You can get the compiler and library files here: avrgcc20011121a.exe.
You also need to download the GCCTEST files gcctest.zip.
This contains not only good sample code, but also contains a predefined
setup of makefiles which make compilation much easier.
- Installing the
compiler: Simply double-click on the executable to install the
files. By default, all components should be selected for install
and the destination directory will be C:\avrgcc
(I would strongly recommend leaving things this way). When the
executable runs, all the files will be copied over to the destination
directory and also all of the library files will be compiled for
you.
- Setting up
environment variables for Windows 2000: If you are
running Windows 2000 you will
need to set some environment variable settings to enable you to use
avrgcc from any dos prompt. (Remember to remove these settings if you are
reinstalling/upgrading. Or else the recompiling of the library files may
fail.) The environment settings can be found in the file: C:
\avrgcc\run.bat a
nd
probably look like this: (Replace C:\avrgcc
with the path where
you installed avrgcc.)
set AVR=C:\avrgcc
set CC=avr-gcc
set PATH=C:\avrgcc\bin;%path%
To add these changes in Windows
2000, right-click on My Computer
select Properties. Select the Advanced tab and and click on the Environment Variables button. You will need to do the following
three things in this window: 1) Under the User
variables for (username) section, find the path variable and click on Edit
to bring up an Edit User Variable
box. You will need to add the following to the end of the Variable Value field:
;C:\avrgcc\bin
Make sure that no spaces are added before the semicolon, otherwise
this will not work. When you are done, click on OK for the Edit
User Variable box. 2)
Next, click on the New button
to add a new environment variable. In the Variable Name field, add the name AVR, then in the Variable Value field add the value C:\avrgcc . 3) Similarly, create one more
environment variable named CC and set
its value to avr-gcc . Once you have
done this, click the OK button in the Environment Variables
window.
- Setting up
environment variables for Windows 98: If you are running Windows 98 you should be able to simply
double-click the icon that was added to your desktop or Start Menu during
the install process. If you
still have problems with this (such as make
not being recognized as a valid command or io.h
not being found) you may need to make some additional changes.
(Remember to remove these settings if you are reinstalling/upgrading. Or
else the recompiling of the library files may fail.) The
environment settings can be found in the file: C:
\avrgcc\run.bat and
they
probably look like this: (Replace C:\avrgcc
with the path where you installed avrgcc.)
set AVR=C:\avrgcc
set CC=avr-gcc
set PATH=C:\avrgcc\bin;%path%
You can cut and paste these into 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:\avrgcc\bin;”%path%”
You should probably add these quotes in both the
autoexec.bat and the run.bat files.
Once this is done and autoexec.bat has been run, any command
prompt should be able to correctly call make
(c:\avrgcc\bin\make.exe).
- Installing GCCTEST:
Extract the gcctest.zip
file to your C:\avrgcc directory.
You will need to copy the make1 and
make2 files from the C:\avrgcc\gcctest\include directory
into the C:\avrgcc\include
directory. These files are needed in order to use the makefiles in each of the
gcctest1-gcctest9 directories.
- Compiling GCCTEST
projects:
The GCCTEST files give 9 very good examples of C code written
for the AVR. Each of these can be compiled and downloaded to your STK500.
We strongly encourage you to look through these examples to get a feel for how
to use C with the AVR. Here is a description of how to compile
these projects.
- Bring up a Command
Prompt: Change directory to one of the gcctestx directories
(example: c:\avrgcc\gcctest1\).
- Compiling: Once
in the proper directory, all you need to do is type 'make' to run the compiler. The make command will run the compiler using the
makefile that is in the current
directory. If the compilation is successful, "Errors:
none" should be the last line of the 'make
output. The gcctest examples already have makefiles made. Below is
information on how to set these up for your own projects:
- Setting up makefile:
The best way to create a new makefile
for your project is to mimic one of the makefiles
in the gcctest examples. (If you need an example that uses multiple
source files, use gcctest7). If you copy a makefile from one of these gcctest
examples, then you will be able to leave most of the lines of the makefile unchanged. The only lines
that you will probably need to change are the MCU (to match the processor
you are using), TRG (to change the name of the target file, which usually
matches your .c file), SRC (if you have multiple C sources), ASRC (if you
have assembly files you want to link with your C code). You will
also need to change the dependencies if you have multiple source
files. The rest is handled by the makefile
itself and the two files that you copied from the c:\avrgcc\gcctest\include
directory (make1 and make2).
- Downloading to the
STK500: This will be exactly the same procedure as for the other labs
except that the file extension used by compiler is .rom instead of .hex. You can load this .rom file from within AVR Studio using
the STK500 programming tool.
- Other hints/suggestions:
- Use an editor with
syntax highlighting: It will make it easier to read your code if
you have an editor that performs syntax highlighting of C. The
simplest option for doing this would be to use AVR Studio, since you
already have it. Other choices such as Visual Studio or emacs would
also be useful.
Last modified: Mon Oct 22 12:19:03 PDT
2001