Menu

Setup Log in to Edit

How to build and install AVR-Ada

This tutorial explains step by step how to install AVR-Ada on a Linux system. This tutorial was tested on a 64 Bit Ubuntu 9.10 system. The steps for building AVR-Ada on a Windows system are essentially the same. The prerequisits are more demanding as you need MSYS, MinGW, Cygwin, the Atmel Toolsuite (as part of the Atmel Studio) and gprconfig and gprbuild (provided by Adacore's GNAT). See [BuildScript] for further details.

Preparations

For building the AVR-Ada cross compiler you have to download the following packages:

binutils-2.20.1.tar.bz2
gcc-4.7.1.tar.bz2
avr-libc-1.8.0.tar.bz2
avr-ada-1.2.0.tar.bz2

For building an Ada compiler you will need a working Ada compiler on your system because the Ada front-end of gcc is written in Ada. Therefore on an Ubuntu and other Debian systems you need to have the package gnat installed. On Windows you have to build a native gcc including Ada support first. MinGW currently (Summer 2012) provides gcc-4.6 which does not work.

Further check that you have the packages flex and bison installed.

On Ubuntu and Debian systems the normal gcc is built without Ada support. The gcc with Ada support is called gnatgcc. Take care you are using a gcc with Ada support for building an Ada cross compiler. You can force using the gnatgcc by setting the CC environment variable.

export CC=gnatgcc

Compiling the AVR binutils

Extract the binutils and the avr-ada packages into your working directory.

tar xvfj binutils-2.20.1.tar.bz2
tar xvfj avr-ada-1.2.0p.tar.bz2

This will create the binutils-2.20.1 and avr-ada-1.2.0 directories.

First you have to apply the AVR-Ada patches to the Binutils:

cd binutils-2.20.1
patch --verbose --strip=0 --input=../avr-ada-1.2.0/patches/binutils/2.20.1/10-binutils-2.19-sprintf-format.patch
patch --verbose --strip=0 --input=../avr-ada-1.2.0/patches/binutils/2.20.1/50-binutils-2.19-xmega-autoconf.patch

Now run the configure script:

./configure --prefix=/opt/avr --target=avr

If you don't set the prefix option the default prefix will be /usr/local. So you will find the avr-as under /usr/local/bin/. Ensure that you use the same prefix for all packages.

Than you can compile and install the whole package

make
sudo make install

This last step can be omitted if you have installed your AVR-Binutils into a standard path like /usr/local/bin. Otherwise you have to add the directory of the installation to your PATH environment variable.

export PATH=$PATH:/opt/avr/bin

To permanently add this path to your PATH variable on an Ubuntu system you have to edit the file /etc/environment.

Now your AVR-Binutils are working.

Compiling the AVR-GCC/Ada compiler

Go back to your working directory and extract the GCC Compiler package

tar xvfj gcc-4.7.1.tar.bz2

This will create the gcc-4.7.1 subdirectory.

Apply the AVR-Ada patches to the GCC package:

cd gcc-4.7.1
patch --verbose --strip=0 --input=../avr-ada-1.2.0/patches/gcc/4.7.1/22-gcc-4.7-ada-xgnatugn.patch
...

Now create a new directory build

mkdir build
cd build

Creating this build directory is very important because it is not possible to compile GCC within its root directory like most other projects. If you do so compiling will fail with strange error messages.

Now run the configure script:

../configure --prefix=/opt/avr --target=avr --enable-languages=c,c++,ada --with-dwarf2 --disable-nls --disable-libssp --disable-libada

Than you can compile and install the whole package

make
sudo make install

Compiling the AVR-Libc

Go to your working directory and extract the AVR-Libc package

tar xvfj avr-libc-1.8.0.tar.bz

For compiling the AVR-Libc you have to use the avr-gcc compiler. This is achieved by setting the CC environment variable

export CC=avr-gcc

Than you can configure, compile and install the AVR-Libc:

cd avr-libc-1.8.0
./configure --prefix=/opt/avr --build=`./config.guess` --host=avr
make
sudo make install

Compiling the AVR-Ada libraries

Note: If you installed everything into /opt/avr (for example), which is probably not already referenced in your PATH variable, now is the time to correct this. Check where your avr-gcc is being referenced now:

$ type avr-gcc
avr-gcc is /opt/avr/bin/avr-gcc

If it doesn't report your installed avr-gcc (as above) then you need to adjust your PATH. On Debian installations, you might prefer to just uninstall their C-only versions of the avr software to avoid mixing them up.

In any case, you need to put /opt/avr/bin in your PATH:

$ PATH="/opt/avr/bin:$PATH"

According to the build scripts supplied with AVR-Ada under the directory avr-ada-1.1.0/tools/build/ the installation process should work this way:

cd avr-ada-1.2.0
./configure --prefix=/opt/avr
make build_rts
sudo make install_rts
make build_libs
sudo make install_libs

Architecture Problem (attiny167)

Unfortunately compiling stopped with an error message that attiny167 is only supported in assembly language. As I do not use this processor I just removed its directory from the avr_lib directory:

rm -r avr/avr_lib/attiny167

But this is just a quick and dirty solution.

Architecture Problem (at90can)

Another error message I received when just calling make without any target. Compiling stopped when compiling a library for the at90can processor. In this case you can just call make install and than go on with make for building the missing libraries. If you do the two step build with make build_rts and make build_libs you shall not run into this error.

Architecture Problem (avr6)

A similar problem occurred for avr6 (yet attiny167 didn't):

gnat1: error: MCU 'avr6' supported for assembly only
make[1]: *** [s-bitops.o] Error 1

I found that if you just edit the top-level Makefile and comment out the offending architecture (avr6):

ARCH_LIST := avr2 avr25 avr3 avr35 avr4 avr5 # avr6

You can get it to build successfully doing:

$ make clean
$ make build_rts

The Automated Way

All the previous steps are automated in the build script '''build-avr-ada-gcc-4.3.x.sh'''. See the [BuildScript] of usage. The scripts includes an automated download of the required source packages and it also checks out the current set of patches from WinAVR. Be sure to set the paths and directories suitable for your environment in the top part of the script.

Up to date version of this script & build procedure can be found on the [Build_From_Ubuntu_Lucid_Or_Debian_Squeeze].

Adding Contributed Packages

If you find that the version of the avr-ada package you installed is missing a contributed Ada library that
you'd like to use, this section will save you some time in getting that included.

1. Get The Source Code

The first thing to do is to acquire a copy of the software package source code from the avr-ada git repository.

  1. Go to the main SF Avr-ada page (not the wiki area) and click on "Code" on the menu bar, and select "Git" (not "Git Browse").
  2. Under the heading "Git Access" you'll see how to gain access in "read-only" mode. Here I'll assume it still says "git://avr-ada.git.sourceforge.net/gitroot/avr-ada/avr-ada" when you read this.
  3. From a work area (''NOT'' where you built avr-ada), type "git clone git://avr-ada.git.sourceforge.net/gitroot/avr-ada/avr-ada". A bunch of files will be downloaded for you.
  4. cd to ./avr-ada/avr, where you should find the contributed library(ies) of interest.

2. Add to the Avr-ada Build

  1. For each library you want to include, tar up the ''pkgdir''_lib.gpr and the subdirectory ''pkgdir'' itself.
  2. cd to your avr-ada build directory, descending into it's ./avr subdirectory (example avr-ada-1.1.0/avr)
  3. Unpack your tar file to put ''pkgdir''_lib.gpr and ''pkgdir'' there.
  4. Edit the Makefile and look for the line "libraries := debug lcd sensirion onewire".
  5. Add the name ''pkgdir'' to that list. For example, if you were interested in the crc and slip contributed packages, then add "crc slip" to the list, so that it reads as follows:

    libraries := debug lcd sensirion onewire crc slip

3. Install

  1. Type "make"
  2. Become root (su)
  3. Then "make install".

Contributed Ada Packages

As of this writing, there are the following optional Ada packages that may not be in your downloaded AVR-Ada distribution:

  • [CRC] - Ada CRC package (the non C version)
  • [Fatfs] - FAT File System support for memory sticks etc. (FAT16 and FAT32)
  • [MCP4922] - SPI Support for the MCP4922 DAC chip
  • [MIDI] - MIDI message support on any byte stream
  • [Slip] - Packet SLIP support on any byte stream

Related

Wiki: BuildScript
Wiki: CRC
Wiki: Fatfs
Wiki: Home
Wiki: MCP4922
Wiki: MIDI
Wiki: Slip

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.