Compiling and uploading Firmware

paalsteek edited this page Jul 2, 2013 · 3 revisions
Clone this wiki locally

This article describes how you can compile your own Hexabus Device firmware image and upload it to the device.

Compiling a Firmware Image

The firmware image can be compiled using avr-gcc. You will also need avr-binutils and the avr-libc.

There are some issues with several avr-gcc versions and Contiki, so not all avr-gcc's will build a working firmware image (your device may reboot at indeterminate intervals).

We recommend using avr-gcc 4.3 (and the associated avr-libc). This version is installed by default in Ubuntu 11.04. Since this version is quite old, we also provide a Debian VM image which comes with all the necessary tools pre-installed.

The VirtualBox image can be found here: AvrgccVM.tar.gz (User: khaan, Password: h3xabus). Setup your shared folder under Machine -> Settings -> Shared Folders and mount it using "sudo mount -t vboxsf -o uid=1000,gid=1000 <share name> <mount point>". If you want to ssh to the VM, go to Machine->Settings->Network->Port forwarding create a new entry with Guest Port 22, Host Port 2222 and both IP fields blank. Now use "ssh -p 2222 localhost" to ssh to the VM.

You can build the Firmware images for the Hexabus-Plug and the Hexabus-USB-Stick by running make in the folders firmware/Hexabus-Socket and firmware/Hexabus-USB respectively. When make finishes without errors, you will end up with a .hex file (Hexabus-Socket.hex or Hexabus-USB.hex).

This file can be uploaded to the Hexabus Device's microcontroller. For flashing a Hexabus Plug, we recommend using a JTAG adapter. A Hexabus USB Stick can be flashed using the pre-installed bootloader.


The boards in the Hexabus Socket (and the Hexabus Development Boards) have a micromatch connector through which the JTAG interface of the microcontroller can be reached. The connections are described here.

Using this connector, a firmware image can be uploaded using avrdude with the command

avrdude -c jtag2 -P usb -p atmega1284p -U flash:w:Hexabus-Socket.hex -F

(if you are using a JTAGICEmkII. For other JTAG programmers (AVR Dragon and JTAGICEmkIII work fine, others also should work) replace the part behind the -c)

Note: The Hexabus board needs to be powered during the process. The best way to do this is to apply 12V (AC or DC) to pins 3 and 5 of the smaller micromatch connector (the one which normally connects to the HV board). It's also possible to use Pins 1 (+) and 6 (GND) for 12V DC (or 3 and 6 ... you might find more possibilities if you look at the schematic). You can make a simple power supply adaptor that looks like this:

hexabus lv board power adaptor

The adaptor in the image can power two Hexabus boards at the same time - it has all but the power wires between the two micromatch plugs cut.

The internal power supply of the Hexabus Plug should never be used for this! Plugging it in with the case open would apply mains voltage to the HV board of the Hexabus Plug, which has several exposed solder points. The Hexabus Plug should only be plugged into a power socket when the case is closed tightly!


When flashing a device without hexabus firmware, the fuses have to be set. This can be done with the following command:

sudo avrdude -c jtag2 -P usb -p atmega1284p -U lfuse:w:0xe2:m -U hfuse:w:0x10:m -U efuse:w:0xff:m -F

To read the fuses:

sudo avrdude -c jtag2 -P usb -p atmega1284p -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h -F

The Bootloader

The USB stick can be flashed using the bootloader. The necessary steps are described here.

While flashing Hexabus USB Sticks using the bootloader works fine, the current version of the bootloader has some problems when uploading firmware to a Hexabus Plug wirelessly, and does not always work as intended, especially when there are several active Hexabus devices around or there is other traffic on the Hexabus radio frequency. It can nevertheless be used to upload a firmware image to a Hexabus device.