Mizar32/Compiling eLua

= Use the Web Builder =

The Mizar32 Web Builder at http://builder.simplemachines.it lets you customise the firmware in several ways and will build you a new firmware image without you having to do any of this horrible stuff.

If that doesn't do enough for you, or if you just enjoy this kind of thing, then take a deep breath and...

= Install an AVR32 cross-compiler =

Atmel AVR 32-bit Toolchain 3.4.2
The cross-compiler for Linux is the Atmel AVR Toolchain for Linux.

At the time of writing, April 2013, the latest version is Atmel AVR Toolchain 3.4.2, based on the GNU C Compiler version 4.4.7.

To skip the Atmel registration form, you can use these quick download links: You will also need and, if you are interested in building the toolchain yourself, the source code is here:
 * Atmel AVR 32-bit Toolchain 3.4.2 - Linux 32-bit
 * Atmel AVR 32-bit Toolchain 3.4.2 - Linux 64-bit
 * Atmel AVR Toolchain 3.4.2 - Header Files
 * Atmel AVR 32-bit Toolchain 3.4.2 - Source code

Fetching and unpacking the toolchain
Here we show the steps to install the 32-bit version:

cd wget http://www.atmel.com/Images/avr32-gnu-toolchain-3.4.2.435-linux.any.x86.tar.gz tar xfz avr32-gnu-toolchain-3.4.2.435-linux.any.x86.tar.gz wget http://www.atmel.com/Images/atmel-headers-6.1.3.1475.zip unzip atmel-headers-6.1.3.1475.zip mv atmel-headers-6.1.3.1475/avr32 avr32-gnu-toolchain-linux_x86/avr32/include/ rm -r atmel-headers* rm avr32-gnu-toolchain-*.gz
 * 1) Fetch, unpack and install the header files
 * 1) Clean up

then, to use it, once per session:

PATH=$HOME/avr32-gnu-toolchain-linux_x86/bin:$PATH export PATH

you can, set the include path (C_INCLUDE_PATH), to use atmel-headers-6.1.3.1475 with avr32.

For the 64-bit version, replace every " " in the above with " "

Installing it as a Debian/Ubuntu package
To make a Debian/Ubuntu package out of this, do the above, then go:

sudo apt-get install alien fakeroot cd avr32-gnu-toolchain-linux_x86 mkdir usr mv [a-s]* usr/ tar cfz avr32-gnu-toolchain-3.4.2.tgz usr/avr32 usr/bin/avr32-* \ usr/lib/gcc/avr32 usr/libexec usr/share/man/man1 fakeroot alien --keep-version avr32-gnu-toolchain-3.4.2.tgz mv avr32-gnu-toolchain_3.4.2-1_all.deb avr32-gnu-toolchain_3.4.2-1_i386.deb rm avr32-gnu-toolchain-3.4.2.tgz rm -r usr
 * 1) It includes a lot of files that it shouldn't, so select the toolchain ones.

or, for the 64-bit version, do the same thing in  and rename the   file to

If you had installed their old 2.4.2 Ubuntu packages, you will need to remove those first:

sudo apt-get purge avr32-binutils avr32-buildroot-essentials avr32-gcc-newlib \ avr32-gdb avr32gdbproxy avr32headers avr32parts avr32program avr32trace \ avrfwupgrade libavr32ocd libavr32sim libavrtools libelfdwarfparser

then you can install the new toolchain with

sudo dpkg -i avr32-gnu-toolchain_3.4.2-1_*.deb

(to remove it again, )

Build a toolchain from source code
ct-ng, a fork of crosstool-ng, builds better AVR32 cross compilers for you:

sudo apt-get install git autoconf bash gawk g++ libncurses-dev git clone http://anonymous@spaces.atmel.com/git/ct-ng cd ct-ng ./bootstrap ./configure --enable-local make ./ct-ng build

By default, it installs the cross-toolchain under your home directory, so before building eLua you need to say:

PATH=$HOME/x-tools/avr32-unknown-none/bin:$PATH export PATH

On Windows
Atmel also provide the Atmel AVR Toolchain for Windows as a, for which the quick download link is:
 * Atmel AVR Toolchain 3.4.2 for Windows

= Install the build system = The Alcor6L build system (same as the official elua0.9) uses " " and " ". The eLua/Alcor6L sources are under, so install those.

On Debian or Ubuntu:

sudo apt-get install scons gcc git

= Download the sources =

Stable release
The latest stable source release is elua0.9, which fully supports the Mizar32 boards.

wget http://download.berlios.de/elua/elua0.9.tgz tar xfz elua0.9.tgz cd elua0.9

An alternative is:

The current development version
=The eLua project=

git clone https://github.com/elua/elua cd elua

Please note: The (bleeding edge) eLua build system has changed, so the instructions using  will need changing. Alcor6L on the other hand doesn't have this problem. It uses

=The Alcor6L project=

git clone https://github.com/simplemachines-italy/Alcor6L.git cd Alcor6L

= Compile eLua/Alcor6L =

For Mizar32 A and B
The 256KB and 512KB flash/64MB internal RAM versions of Mizar32 use the same eLua/Alcor6L firmware. Use this command:

scons board=mizar32 cpu=AT32UC3A0256

If you're compiling the eLua sources, the build will create a file. On the other hand if you're compiling the Alcor6L sources, it will create a file. The  indicates the date of the build.

Alcor6L will by default compile eLua (version 0.9). To use another language (for example, Lisp) on the Mizar32, use the following:

scons cpu=AT32UC3A0256 board=mizar32 lang=picolisp prog

The above will generate. The generated file can be programmed into the Mizar32 boards in various ways: see the chapter Flashing firmware.

To build a version of the eLua interpreter where all numeric variables are integers instead of floating point values, which is smaller and slightly faster, use:

scons board=mizar32 cpu=AT32UC3A0256 target=lualong

For Mizar32 C
In 128KB of flash memory you can fit the 8KB DFU bootloader and a 120K integer version of eLua. Standard eLua for the Mizar C, compiled with scons board=mizar32 cpu=at32uc3a0128 target=lualong optram=0 produces a firmware with most of the eLua modules omitted, leaving just the PIO, Timer and UART modules.

The branch of eLua has a series of modification to reduce the code size so as to be able to include all the eLua modules except for the Ethernet module. The features that it removes from eLua are:
 * the eLua shell (it runs the Lua interpreter directly);
 * Lua interrupts (an option available with the GPIO, Timer and UART modules);
 * the Lua  module, which is of little use in an embedded system;
 * , used to write compiled code or Lua data into files;
 * , used to read the same back in, or to load precompiled Lua bytecode from  files;
 * and, used to monitor and fine-tune eLua's use of RAM;
 * the Emergency Garbage Collector, used to improve the performance of systems with very little RAM.

To use this branch, fetch a copy of it: git clone http://github.com/elua/elua cd elua git checkout Mizar32 and compile it thus: scons board=mizar32 cpu=at32uc3a0128 target=lualong optram=0

= Program the firmware to the board = When the compilation is finished, it should have created a file called something like  which can be programmed into the Mizar32 board in various ways: see the chapter on Flashing firmware.

If you will be using  to do this, you will first need to convert your   file to a   file. For example:

elua=elua_lualong_at32uc3a0256 avr32-objcopy -O ihex $elua.elf $elua.hex