Atmel's official toolchain for programming its AVR devices is AVR Studio. AVR Studio 5 is Windows only, but uses the gcc as its C compiler which is open-source. A viable option for Mac users is to use CrossPack, which contains precompiled versions of everything you need to develop for AVR devices, but it does not always use the latest version available.
As I'm planning to use the new ATxmega128B1 I need a newer version and so I wanted to compile everything by myself. This article gives a brief overview how to compile everything.
To compile everything you will need to have Xcode installed and I also recommend Homebrew to so you don't have to provide helper libraries for gcc compilation on your own. Follow the instruction steps on the Homebrew website and install the the libraries needed with
brew install gmp libmpc mpfr
afterwards.
binutils
The first step will be to install the avr binutils. I created 3 folders src, build and patches which will have subfolders for each program we need. We need to download binutils/binutils-2.20.1.tar.bz2 into the src folder and the corresponding patches provided by Atmel into the binutils-2.20.1 subdirectory of patches:
mkdir src build build/binutils-2.20.1 patches patches/binutils-2.20.1 wget -P src/ http://ftp.gnu.org/gnu/binutils/binutils-2.20.1.tar.bz2 wget --no-directories -l 1 -r -P patches/binutils-2.20.1 -A patch http://distribute.atmel.no/tools/opensource/avr-gcc/binutils-2.20.1
Now we can extract the source package, apply the patches and compile it. The prefix folder /usr/local/AVR/ specifies where everything will be installed.
tar -xjvf src/binutils-2.20.1.tar.bz2 -C src/ cd src/binutils-2.20.1 for I in ../../patches/binutils-2.20.1/*; do patch -p0 < $I; done cd ../../build/binutils-2.20.1 ../../src/binutils-2.20.1/configure --target=avr --prefix=/usr/local/AVR/ --disable-werror make -j5 make install cd ../..
GCC
The next step will be the gcc compiler itself. We again download the package gcc-core-4.5.1.tar.bz2 and the corresponding patches.
mkdir build/gcc-4.5.1 patches/gcc-4.5.1 wget -P src/ http://ftp.gnu.org/gnu/gcc/gcc-4.5.1/gcc-core-4.5.1.tar.bz2 wget --no-directories -l 1 -r -P patches/gcc-4.5.1 -A patch http://distribute.atmel.no/tools/opensource/avr-gcc/gcc-4.5.1
As before we extract the source package, apply the patches and compile it. Don't forget to adjust the prefix folder to the same path as chosen before!
tar -xjvf src/gcc-core-4.5.1.tar.bz2 -C src/ cd src/gcc-4.5.1 for I in ../../patches/gcc-4.5.1/*; do patch -p0 < $I; done cd ../../build/gcc-4.5.1 ../../src/gcc-4.5.1/configure --target=avr --prefix=/usr/local/AVR/ make -j5 make install cd ../..
avr-libc
The last step is the avr-libc. It can be downloaded from avr-libc-1.7.1.tar.bz2 and there are also patches from Atmel we need to download.
mkdir build/avr-libc-1.7.1 patches/avr-libc-1.7.1 wget -P src/ http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.7.1.tar.bz2 wget --no-directories -l 1 -r -P patches/avr-libc-1.7.1 -A patch http://distribute.atmel.no/tools/opensource/avr-gcc/avr-libc-1.7.1
In addition to extracting and applying the patches as before, we need to bootstrap the avr-libc to get support for the new devices. Afterwards we can compile it as seen before. Notice that we know the host and not the target parameter for configure!
tar -xjvf src/avr-libc-1.7.1.tar.bz2 -C src/ cd src/avr-libc-1.7.1 for I in ../../patches/avr-libc-1.7.1/*; do patch -p0 < $I; done ./bootstrap cd ../../build/avr-libc-1.7.1 ../../src/avr-libc-1.7.1/configure --prefix=/usr/local/AVR/ --host=avr --build= make -j5 make install cd ../..
If the bootstrap script complains about an old version of autoconf you can use Homebrew to get a recent one with
brew install autoconf
Notes
Now you should have everything you need to compile programs for your AVR device. Depending on the programmer (e.g. STK600, AVRISP mkII) you are using, you can use avrdude to transfer the files. Homebrew has a package for it and can be installed with
brew install --with-usb avrdude
The main intent for me to compile the toolchain on my own, was to use it for new devices not support in CrossPack. Sadly, this seems not work, as there seems to be missing something in the patches. I will investigate this in the near future and will post a follow-up post on that. Update: It is necessary to extract the iox128b1.h header file from the AVR Studio to get the device work. Put it into the include/avr subdirectory of the avr-libc source directory before running configure. The same applies e.g. for the iox256a3bu.h header file.
Thanks, this post finally got me a working home built toolchain (on Gentoo linux). I tried to find your private email, but couldn't, but to make this even better, I have some simple type error corrections:
Under GCC:
Don't forget to adjust the prefix folder to the same PATCH(path) as chosen before!
Under avr-libc:
Notice that we (k?)now the host and not the target parameter for configure!
Thanks again.
Martin