Skip to content

Flashing the OpenDeck firmware

paradajz edited this page Jul 14, 2019 · 39 revisions

This document explains how to flash OpenDeck firmware on supported boards. In order to program the supported boards, Arduino board is used with ArduinoISP sketch loaded on it.

Supported operating systems for flashing are:

  • Windows 10 with WSL (Ubuntu 18.04+)
  • Ubuntu 18.04+
  • macOS

Arduino as an programmer

Arduino loaded with ArduinoISP sketch serves as an programmer used to flash AVR microcontrollers. Any version of Arduino Uno works, although Arduino Leonardo is recommended option since it doesn't require extra 10uF capacitor between Reset pin and GND (it is also much faster due to native USB capability).

Arduino IDE

If Arduino IDE isn't installed, it can be downloaded from www.arduino.cc. Once Arduino IDE is opened, under "Tools>Board" select "Arduino/Genuino Uno or Arduino Leonardo". Make sure to select the right port under "Tools>Port". Next, under "File>Examples" select "11.ArduinoISP>ArduinoISP". Upload the sketch to Arduino.

Wiring

Before flashing, Arduino as an programmer must be connected to the target board. A total of 6 pins are required to flash the target board:

  • MOSI
  • MISO
  • SCK
  • GND
  • 5V
  • Reset

The tables below list correct way of connecting the pins between the programmer and target board.

Programmer board pinout

Signal Uno Leonardo Pro Micro Mega
MOSI 11 10 16 51
MISO 12 11 14 50
SCK 13 9 15 52
GND GND GND GND GND
5V 5V 5V 5V 5V
Reset 10 10 10 10

Note: Pins 10, 11 and 9 on Arduino Leonardo are located on ICSP header.

Each Arduino board contains ICSP header on which all the listed are located (except for the reset pin - for this use case use pin 10):

If Arduino Uno is being used as programmer, 10uF capacitor connected between "Reset pin" and "GND" is needed.

Important: If you're using electrolytic capacitor like the one in the picture, make sure to connect positive (longer) pin to to "Reset" and negative (shorter) to GND.

Target board pinout

Table below shows pinout for various boards.

Signal Uno/ATmega328P Leonardo/ATmega32u4 Pro Micro/ATmega32u4 Mega2560/ATmega2560 Uno and Mega2560/ATmega16u2 Teensy++ 2.0
MOSI 11 16 16 51 MOSI PB2
MISO 12 14 14 50 MISO PB3
SCK 13 15 15 52 SCK PB1
GND GND GND GND GND GND GND
5V 5V 5V 5V 5V 5V 5V
Reset Reset Reset Reset Reset Reset Reset

Easiest way to connect Uno, Leonardo and Mega target boards to ArduinoISP is to use 6-pin IDC cable from programming header on Arduino used as ISP to appropriate header on target board, with reset wire on cable from ArduinoISP (second wire from the left on the cable) being cut and connected to pin 10 on ArduinoISP, as shown on the picture below.

Arduino Mega and Uno

Arduino Mega and Arduino Uno have two microcontrollers. Each microcontroller has its own programming header. First header is for ATmega16u2, or ATmega8u2 on older Arduino revisions. This MCU is responsible for USB communication between PC and main MCU. Second header is for ATmega2560 for Mega and ATmega328P for Uno (main MCUs). Both MCUs need to be flashed in order for OpenDeck firmware to work.

Flashing

There are two ways using which supported boards can be flashed. Requirement for each is that avrdude package is installed. Guide for installing required packages can be found here. Flashing using the flashing script is recommended way since the script uses already pre-built binaries found in bin directory. Those binaries also contain bootloader merged with OpenDeck firmware. Use the makefile only if you know what are you doing!

IMPORTANT: After the flashing, board will initialize the internal EEPROM memory which can take some time. On Arduino Mega the process takes about 10 seconds. It is very important not to turn the board off during this process as the EEPROM memory can get corrupted in this case. After this process is done, LED indicators on the board blink alternatively few times.

Misleading errors

During the flashing, avrdude can display error like this:

Writing |                                                    | 0% 0.00s ***failed;  
Writing | ################################################## | 100% 0.07s

This error is misleading and can be safely ignored.

flash.sh

flash.sh script in scripts directory is designed to guide the user through flashing process. Note that the script must be marked as "executable". On Linux/WSL, the script should also be run either with sudo or the current user should be added to the dialout group in order for read/write access to serial ports to work. To run the script, enter this command in terminal (make sure you're positioned in directory where script is located):

chmod +x flash.sh && ./flash.sh

Running the same command with sudo:

chmod +x flash.sh && sudo ./flash.sh

This script uses binaries located in bin/compiled directory.

Flashing of ATmega2560 MCU on Arduino Mega board is shown below.

paradajz-MacBook-Pro:scripts igor$ ./flash.sh 
Please type in correct tty port on which ArduinoISP is connected (ie. ttyUSB0):
cu.usbmodem411
Please select MCU you want to flash and then press enter:
1 - ATmega8u2 on Arduino Uno or Arduino Mega
2 - ATmega16u2 on Arduino Uno
3 - ATmega16u2 on Arduino Mega
4 - ATmega328P on Uno
5 - ATmega2560 on Mega
6 - ATmega32u4 on Leonardo
7 - ATmega32u4 on Pro Micro
8 - AT90USB1286 on Teensy++ 2.0
5
Connect programmer to ATmega2560 programming header on the Arduino Mega2560 board and then press enter.


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: erasing chip
avrdude: reading input file "0xff"
avrdude: writing lock (1 bytes):

Writing |                                                    | 0% 0.00s ***failed;  
Writing | ################################################## | 100% 0.07s

avrdude: 1 bytes of lock written
avrdude: reading input file "0xfc"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of efuse written
avrdude: reading input file "0xd2"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written

avrdude: safemode: Fuses OK (E:FC, H:D2, L:FF)

avrdude done.  Thank you.


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
        To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "../bin/compiled/arduino+teensy/fw+boot/fw_boot_mega.hex"
avrdude: input file ../bin/compiled/arduino+teensy/fw+boot/fw_boot_mega.hex auto detected as Intel Hex
avrdude: writing flash (260278 bytes):

Writing | ################################################## | 100% 14.74s

avrdude: 260278 bytes of flash written
avrdude: verifying flash memory against ../bin/compiled/arduino+teensy/fw+boot/fw_boot_mega.hex:
avrdude: load data flash data from input file ../bin/compiled/arduino+teensy/fw+boot/fw_boot_mega.hex:
avrdude: input file ../bin/compiled/arduino+teensy/fw+boot/fw_boot_mega.hex auto detected as Intel Hex
avrdude: input file ../bin/compiled/arduino+teensy/fw+boot/fw_boot_mega.hex contains 260278 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 10.82s

avrdude: verifying ...
avrdude: 260278 bytes of flash verified

avrdude: safemode: Fuses OK (E:FC, H:D2, L:FF)

avrdude done.  Thank you.


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "0xef"
avrdude: writing lock (1 bytes):

Writing |                                                    | 0% 0.00s ***failed;  
Writing | ################################################## | 100% 0.07s

avrdude: 1 bytes of lock written

avrdude: safemode: Fuses OK (E:FC, H:D2, L:FF)

avrdude done.  Thank you.

Makefile

Requirement for this process is that the compiled binary for wanted board exists in src/build directory (either placed there manually or generated by build process). Guide for compiling the code can be found here. Makefile in src directory implements upload command to flash the specific board. Command requires setting of PORT variable which specifies where the ArduinoISP is connected to PC (usually /dev/ttyACM0 on Linux). Only the last part of path is required. Below are examples of commands for every supported OS:

  • Linux: make upload PORT=ttyACM0
  • WSL: make upload PORT=ttyS5 (if ArduinoISP is connected to COM5)
  • macOS: make upload PORT=cu.usbmodem641

Note that in order for upload to work on WSL, Windows 10 April 2018 update or later is required. Also, on Linux/WSL, the command should also be run either with sudo or the current user should be added to the dialout group in order for read/write access to serial ports to work.

If you get errors that target isn't responding, double check the wiring between the target board and programmer (ArduinoISP).

You can’t perform that action at this time.