How do I write new firmware to Cluster Stack

Control of the ClusterCTRL Stackis done using an ATmega328P (or ATmega328PB), the IC can be reprogrammed using either a standard ISCP programmer or you can also use a Raspberry Pi.  If you're a regular programming AVR then you can skip most of this document but please remember NOT to alter the Fuses as you may end up "bricking" the IC requiring it to be removed and reprogammed with a parallel programmer.

This guide explains how to use a Raspberry Pi to write updated firmware to the ClusterCTRL Stack. 

To program the ClusterCTRL Stack following this guide you'll need a Raspberry Pi running Raspberry Pi OS with a 40 pin header, five jumper wires (female-female) and power supplies for both Pi and ClusterCTRL Stack, etc.

Connect the wires between Cluster Triple and Raspberry Pi  as shown in the table below.

ClusterCTRL Stack Raspbrrry Pi (physical/ BCM)
1 / MISO 12 / BCM18
2 / 3v3 No connect
3 / SCK 18 / BCM24
4 / MOSI 16 / BCM23
5 / RST 32 / BCM12
6 / GND 6 / GND

The physical pins on the ClusterCTRL Stack and Raspberry Pi can be see below (Pi GPIO pinout from pinout.xyz).

Cluster Stack PGM Pinout

Raspberry Pi Pinout

Once connected up you should have something like this.

Program ClusterCTRK Stack wiring

Program ClusterCTRL Stack wiring

Once you have the wiring setup between the Pi and Cluster Triple  ensure either the backplane is disconnected from the ClusterCTRL Controller, power the ClusterCTRL Stack via the barell jack, remove any cables from the "USB" port on the ClusterCTRL Controller and power on the Pi.

Log into the Pi and install the required software Git (to download the firmware) and Avrdude (programming).

sudo apt update
sudo apt -y install git avrdude

Download the ClusterCTRL firmware.

git clone https://github.com/burtyb/ClusterCTRL.git

If you haven't added the programmers used by ClusterCTRL to the avrdude.conf file previously these can be added by running.

sudo bash -c "cat ClusterCTRL/clustertriple-1.0/avrdude.conf >> /etc/avrdude.conf"

You can now either build your own firmware or install prebuild firmware.

Installing prebuilt firmware

To see the currently available firmware files.

ls ClusterCTRL/firmware/

Files are numbered with the version at the start, then the board type and harware version. You MUST pick the firmware to match the hardware you have, for example 1.2_clusterstack-1.0.hex for the ClusterCTRL Stack v1.0. Installing the wrong firmware can brick the ClusterCTRL device. If in doubt please ask on the forum first.

Double check the wiring and once you're ready program the AVR (replacing FIRMWARE with the .hex firmware file to be written "...flash:w:ClusterCTRL/firmware/1.2_clusterstack-1.0.hex" for example).

sudo avrdude -c pi_1 -p atmega328p -U flash:w:ClusterCTRL/firmware/FIRMWARE

If you see a Device Signature "avrdude: Device signature = 0x1e9516 (probably m328pb)", then your ClusterCTRL Stack has an ATmega328pb and needs to be programmed using a different command.

sudo avrdude -c pi_1 -p atmega328pb -U flash:w:ClusterCTRL/firmware/FIRMWARE

 You should then see the AVR being programmed, after a few seconds you should see "avrdude done. Thank you.". You can now unplug the PWR cable to the Cluster Triple, remove the jumper wires and then, replace the Compute Modules and connect up as normal.

Building and installing firmware

Install the software to compile firmware for the AVR

sudo apt -y install gcc-avr avr-libc

Change into the directory of the ClusterCTRL devices you have.

cd ClusterCTRL/clusterstack-1.0/

You can now modify the firmware as required, for example to increase the delay between powering on the nodes from 1 second to 5 seconds edit config.h and change the value for AUTOONDELAY from 1000 to 5000 (the delay is in milliseconds).

Build the firmware using make.

make

You should then see the firmware being built and once complete it should check the size of the firmware file - something similar to this (the numbers may be different).

...
...
avr-objcopy -j .text -j .data -O ihex firmware.bin firmware.hex
../src/checksize firmware.bin 32768 2048
ROM: 7304 bytes (data=26)
RAM: 96 bytes

If the firmware has been built correctly you can now program the IC.

sudo make program

 The IC is then detected (ATmega328p/ATmega328pb) and programmed, if you see any errors please check/post on the forum.

You can now unplug the PWR cable to the ClusterCTRL Stack, remove the jumper wires and then,connect back up as normal.

You cannot comment on this entry