Installing the GNU tools (avr-gcc) for AVRs
February 15th, 2006I have been using PIC Microcontrollers for my robotics tinkering for a few years. I have also been primarily a Linux user for the last year or two, and have been able to rely on Linux for my work (Web Developer), my school (Computer Science), and all my personal work (robotics, programming, and other nerdy stuff of that nature). I resisted the Atmel AVR Microcontrollers for some time, despite their growing popularity within the hobby robotics community, due to the countless hours I had invested in PICs. However, after learning that the AVRs were designed with C and the GNU tools in mind--a toolset that I use regularly for schoolwork and personal programming projects--I had to give it a further look.
I read through the datasheet of the ATMega8 and the ATiny15L devices, and found that my knowledge with PICs would not be in vain and realized I would be able to learn AVRs quickly and be able to use my good ol' gcc and gdb to do so. Although I have worked with PICs in Linux, I found some things to be much more tedious than worthwhile (such as using PWM in gpsim as opposed to MPLab in Windows)-- not to mention that I never did get my programmer working in Linux. As nerdy as it is, I absolutely despise having to reboot into Windows to do anything. So, the AVRs seemed like a good choice.
This is the first of (hopefully) several articles on the topic of programming AVR microcontrollers in Linux using C. This particular article is more like "installation notes" than an article. It shows the commands to install the tools to write, compile and debug AVR programs. The next article will discuss using these tools. I am not including the tools to actually program the chip at this time, however, I will in a future article (I'll be using avrdude with the AvrUsb500 programmer).
Setup the Environment
Make a directory for the programs and add the 'bin' path for the AVR tools to your PATH environment variable:
su mkdir /usr/local/avr< mkdir /usr/local/avr/bin PATH="$PATH:/usr/local/avr/bin" export PATH exit
You may additionally want to add that path to your /etc/profile file:
PATH="$PATH:/usr/local/avr/bin" export PATH
Binary Utilities
Download the most recent release of the Binary Utilities from http://ftp.gnu.org/gnu/binutils/ (binutils-2.16.tar.gz).
Extract binutils archive:
tar -xzf binutils-2.16.tar.gz cd binutils-2.16
Configure and install binutils:
../configure --target=avr --prefix=/usr/local/avr --program-prefix="avr-" make su make install exit
GNU C Compiler
Download most recent release of the GNU C Compiler (gcc) from ftp://ftp.gnu.org/gnu/gcc/ (gcc-core-4.0.2.tar.bz2).
Extract gcc-core archive:
tar -xvf gcc-core-4.0.2.tar.bz2 cd gcc-4.0.2
Configure and install gcc:
mkdir obj cd obj ../configure --target=avr --prefix=/usr/local/avr --enable-language=c --program-prefix="avr-" make su make install exit
NOTES:
In this step, configure was run from a directory ('obj') that does not reside in the same directory as the source files. This is required. If you do not do this, you will get the following error:
configure: error: Building in the source directory is not supported in this release. See http://gcc.gnu.org/install/configure.html for more details.
If you get the following error, then you did not correctly get /usr/local/avr into you PATH variable (step 1):
make[2]: avr-ar: Command not found
AVR C Library
Download most recent release of the AVR C Library from http://download.savannah.gnu.org/releases/avr-libc/ (avr-libc-1.4.3.tar.bz2).
Extract the avr-libc archive:
tar -xvf avr-libc-1.4.3.tar.bz2 cd avr-libc-1.4.3
Configure and install avr-libc:
./configure --build=`./config.guess` --host=avr --prefix=/usr/local/avr make su make install exit
GNU Debugger
Download the most recent release of the GNU Debugger from http://www.gnu.org/software/gdb/download/ (gdb-6.4.tar.gz).
Extract the gdb archive:
tar -xzf gdb-6.4 cd gdb-6.4
Configure and install gdb:
./configure --prefix=/usr/local/avr --program-prefix="avr-" make su make install exit
Categories
Popular Posts
RSS Feeds
Archives
March 17th, 2008 at 8:07 pm
hi micah...
this is a good tutorial.
i have a problem that maybe you could help me.
i've instal; avr-gcc on my ubuntu gutsy (7.10), i installed it along with avrlib, and avr-libc,
the problem is, when i try to compile i program, it failed with an error that says : invalid bfd target..
i've post my question on another site, they said there is something wrong with the binutils-avr..
could u tell me a solution how to fix this problem?
March 25th, 2008 at 7:31 am
You may want to try uninstalling them and re-installing them, ensuring that you are using versions of each utility that are known to work with one another.
If I had to guess... and this is just a guess... I would say that you somehow missed the "--target=avr" option when building gcc.