Flashing Firmware: STM32 and AVR

← Back to the Patchbay

Digital modules have a small computer inside: a microcontroller. When you build one from a kit, that chip is often empty, and you have to put the software (the firmware) on it yourself. That's called flashing. It sounds scary, but with the right programmer it takes a few minutes. This page explains which programmer you need and how to use it.

Still building the hardware? Start with Your First DIY Module Build. For the chips themselves, see Electronic Components Explained.

Which programmer do you need?

It depends on the type of microcontroller on your module. The build guide or the BOM tells you which chip it uses.

Chip family Programmer Typical modules Free software
STM32 (e.g. STM32F405) ST-Link V2 + pin header for STM32 Mutable Instruments designs and their DIY versions (Plaits, Rings, Clouds, Braids and more), Westlicht Performer STM32CubeProgrammer, OpenOCD, st-flash
AVR / ATmega (Arduino chips) USBasp Many Arduino-based modules, older Mutable Instruments designs avrdude, AVRDUDESS (a window around avrdude)
Teensy None: a USB cable Ornament & Crime, Temps Utile and other Teensy-based modules Teensy Loader
RP2040 (Raspberry Pi Pico) None: a USB cable Many newer DIY modules Drag and drop a .uf2 file

Updating, not first flashing? Many finished modules can update themselves once the first firmware is on: Mutable Instruments modules, for example, have a bootloader that takes a firmware update as an audio (WAV) file played into an input. The programmer is mostly needed for the very first flash of a fresh chip.

ST-Link V2 mini programmer
ST-Link V2 mini from our shop

STM32 with an ST-Link

STM32 chips are programmed through SWD (Serial Wire Debug), which needs only a few wires: SWDIO (data), SWCLK (clock), GND and often RESET. On most Eurorack modules these come out on a small 10-pin header with a 1.27 mm pitch, the standard ARM Cortex debug connector.

You'll need:

  • An ST-Link V2 and the jumper wires that come with it
  • A pin header for STM32, if your module has an empty programming footprint (see below)
  • The module, powered from your case with a power cable
  • The firmware file (.hex or .bin) from the project's website or GitHub
  • STM32CubeProgrammer (free from ST) or OpenOCD
Pin header for STM32

No programming header on your module? Many DIY PCBs, including Mutable Instruments designs, only have the empty footprint for the programming connector: ten small holes in two rows, marked SWD, JTAG or PROG. Before you can connect the ST-Link, solder our pin header for STM32 into it: a 2 × 5 pin, 1.27 mm pitch through-hole header that fits the standard 10-pin Cortex debug footprint.

The pins are very close together, so use a fine tip and little solder, and check for bridges afterwards. Note which side pin 1 is (the square pad): the header itself has no marking. You can leave it on the module after flashing, so it's ready for future updates.

ST-Link to the 10-pin Cortex debug header (SWD)ST-Link pin → header pinSWDIO → pin 2SWCLK → pin 4GND → pin 3, 5 or 9RST → pin 10 (optional)Leave the ST-Link 3.3V pin unconnected1 VTref3 GND5 GND7 key9 GND2 SWDIO4 SWCLK6 SWO8 NC10 RESETHeader on the module (1.27 mm), pin 1 = square
The standard 10-pin Cortex debug header with the pins you need highlighted. The labels on ST-Link clones vary: always read the print on your own programmer. Diagram: Melodio.

Step by step

  1. Install the software. STM32CubeProgrammer is the easiest: it has a window with buttons. It also installs the ST-Link driver on Windows.
  2. Solder the pin header into the programming footprint, if your module doesn't have one yet.
  3. Connect the module to your case and switch the case on. The module powers the chip; the ST-Link only talks to it.
  4. Connect the wires as in the diagram above. Find pin 1 on the module: it's marked with a square pad, a dot or a small triangle.
  5. Connect the ST-Link to your computer and press Connect in STM32CubeProgrammer (mode: SWD). It should show the chip type and its memory.
  6. Open the firmware file and press Download (that's ST's word for writing to the chip). A .hex file knows where it belongs; for a .bin file use start address 0x08000000 unless the build guide says otherwise.
  7. Verify, disconnect and restart the module. It should come to life.

Some projects ship one .hex file with the bootloader and the firmware combined, others ask you to flash the bootloader first and then load the firmware through the bootloader (by audio, USB or SD card). Always follow the build guide of your module.

Prefer the command line? With OpenOCD the same job is one line, for example:

openocd -f interface/stlink.cfg -f target/stm32f4x.cfg -c "program firmware.hex verify reset exit"

Use the target file that matches your chip (stm32f1x.cfg for an STM32F1, such as the STM32F103 development board).

Don't connect the 3.3V pin of the ST-Link to a module that is powered from your case. On the cheap mini programmers it's an output, and two power sources fighting each other can damage the chip or the programmer. Only use it to power a bare board, such as a development board, with nothing else connected.

USBasp AVR programmer
USBasp AVR programmer from our shop, with 10-to-6-pin adapter

AVR with a USBasp

ATmega chips (the chips on most Arduinos) are programmed through ISP: a 6-pin or 10-pin header with MISO, MOSI, SCK, RESET, VCC and GND. The USBasp has a 10-pin plug and comes with an adapter to the more common 6-pin header.

6-pin ISP header (top view)
1 MISO 2 VCC
3 SCK 4 MOSI
5 RESET 6 GND

Step by step

  1. Install avrdude, or AVRDUDESS if you prefer a window with buttons. On Windows, install the USBasp driver with the free tool Zadig (choose libusbK or WinUSB).
  2. Power the module from your case and make sure the jumper on the USBasp that supplies 5V is open, so it doesn't feed power into the module.
  3. Plug the 6-pin cable onto the ISP header. Pin 1 (MISO) is usually marked with a triangle on the cable and a square pad on the PCB.
  4. Write the firmware. For an ATmega328P, for example:
    avrdude -c usbasp -p m328p -U flash:w:firmware.hex:i
    Change m328p to your chip (m644p, m88, and so on).
  5. Fuses: some modules also need the chip's fuses set (clock source and similar). Only use the exact values from the build guide.

Careful with fuses. A wrong fuse setting can lock you out of the chip, for example by selecting an external crystal that isn't there. Copy the values from the build guide, check them twice, and never guess.

Fresh chip doesn't answer? A brand-new ATmega runs on a slow internal clock. Slow the USBasp down with the -B 32 option in avrdude (or the slow-clock jumper on some USBasps) for the first flash.

Teensy and RP2040: no programmer needed

  • Teensy (used in Ornament & Crime and Temps Utile): connect a USB cable, open the firmware in the Teensy Loader app and press the button on the Teensy. Disconnect the module from Eurorack power first, unless the build guide says the Teensy's USB power has been cut.
  • RP2040: hold the BOOTSEL button while plugging in the USB cable. The chip appears as a USB stick; drag the .uf2 firmware file onto it and it restarts by itself.

Troubleshooting

Problem Likely cause Fix
ST-Link: "No target" or "Can not connect" Wire swapped, module not powered, pin 1 the wrong way, or a solder bridge on the pin header Check the wiring against the print on your ST-Link and the module's pin 1, and look for bridges between the header pins. Try "Connect under reset" with the RESET wire connected.
ST-Link: "Read out protection" The chip was locked by earlier firmware Do a full chip erase or remove the read protection in the Option Bytes menu. This erases the chip.
USBasp: "cannot set sck period" Older USBasp firmware Usually just a warning and the flash still works. Check that it says "verified" at the end.
USBasp: "target doesn't answer" Chip running on a slow clock, wrong pin 1, or no power Use -B 32, check the cable orientation and that the module is powered.
Module still dead after a successful flash Wrong firmware file, or bootloader and app don't match Check you used the file for your exact hardware version. Then look at the Repair Guides.

FAQ

Can I break my module by flashing it?

Flashing the wrong file almost never damages the hardware: you just flash the right one. The real risks are wiring power wrong (the 3.3V pin) and wrong AVR fuses.

Where do I find the firmware?

On the project's website or GitHub page. Mutable Instruments published all their firmware as open source; see our BOM page and Modular Synth Companies. DIY kit makers usually link the right file in their build guide.

Can I try this before building a module?

Yes: an STM32F103 development board and an ST-Link make a cheap test setup. Flash a blinking-LED program to learn the process, then move on to your module.