Image grohtml-71961.png


This page briefly describes how to install and use GNU Modula-2 to produce ATMega8 binaries.

gm2-avr is a Modula-2 cross compiler for the Atmel series of microprocessors. It is available as a package which will run on Debian x86_64 Squeeze or Ubuntu x86_64. To install it you need to add these lines to your /etc/apt/sources.list file.

#
#  GNU Modula-2 repo
#
deb http://floppsie.comp.glam.ac.uk/debian/ squeeze main non-free contrib
deb-src http://floppsie.comp.glam.ac.uk/debian/ squeeze main non-free contrib

Now from the command line you should:

$ sudo apt-get update
$ sudo apt-get install gm2-avr

This will install gm2-avr, binutils-avr and avr-libc.

A tiny example avr project can be found here gm2-avr-example-0.3.tar.gz and it would be sensible to download it, just as a reference. Now untar the example project, and build it.

$ tar zxf gm2-avr-example-0.3.tar.gz
$ cd gm2-avr-example-0.3
$ make clean
$ make

You should see the following output:

avr-gm2 -mmcu=atmega8 -g -Os -fno-exceptions -O2 flashled.mod -flibs=min -o flashled.elf

To check the size of the binary, type:

$ avr-size flashled.elf
   text      data       bss       dec       hex   filename
    266         0         4       270       10e   flashled.elf

Notice that the compiler is being invoked with -Os, -O2 and -flibs=min which optimises for space and code speed. It indicates that the compiler should use the minimum set of libraries. The overhead of the minimum libraries is 170 bytes. This could be dramatically reduced if hand generated assembler versions of SYSTEM and M2RTS were used. Currently these modules are implemented in Modula-2 and compiled for portability amongst other targets.

Inside this directory the makefile contains various rules to build a flashing LED program and download it to a ATMega8 using uisp. Additionally it contains rules to build the executable suitable for simulation with simulavr. The test program pulses a LED in the following circuit. I obtained my ATMega8 hardware from tuxgraphics and built the low cost development board as described in the same article. The circuit is nice and simple and does not require advanced soldering skills!

Image atmega8-1.eps.png

Tuxgraphics also supply usb programmers which can interface to Atmel development boards. I plan to use their usb programmer with the development boards kindly donated by Atmel.

If you have problems email the GNU Modula-2 mailing list.


This document was produced using groff-1.22.