Building & Flashing STM32 Firmware
The companion MCU firmware is organized as an STM32CubeIDE project located under companion-STM32-firmware/.
A pre-built production binary is always kept ready at:
companion-STM32-firmware/Debug/BrainfuinoMCU.hex.
Toolchain Setup
To modify or rebuild the firmware:
- Download and install STM32CubeIDE (free from STMicroelectronics, cross-platform for Windows, Linux, and macOS).
- Launch STM32CubeIDE and select your workspace directory.
- Go to File → Import → General → Existing Projects into Workspace.
- Browse to the root of
companion-STM32-firmware/and click Finish.
Rebuilding the Project
- In the Project Explorer, right-click
BrainfuinoMCU. - Select Build Project (or press Ctrl+B / Cmd+B).
- The GCC ARM toolchain compiles the STM32 HAL drivers, USB Device library, and
main.c. - The output
.elf,.bin, and.hexfiles are generated in theDebug/folder.
Automated Command-Line Build & Flash Script
For the fastest development workflow, a cross-platform PowerShell automation script is provided at companion-STM32-firmware/build.ps1:
-
Compile Only:
Locates the embedded GCC ARM toolchain automatically, compiles startup assembly and C sources, links the ELF binary, and generatesDebug/BrainfuinoMCU.hex. -
One-Click Build & Flash (over USB DFU):
Automatically compiles, auto-detects the Brainfuino virtual COM port, sends the!DFU!trigger command to reboot the STM32 into its factory USB DFU bootloader, connects viaSTM32_Programmer_CLI, flashes the binary, and immediately resumes program execution. No jumper movement needed!
Automated Hardware Verification Test Suite
Hardware functionality and menu workflows can be verified end-to-end against a live Brainfuino board connected over USB:
-
Menu, Program Library, and TOC Test:
Runs an automated 10-stage test validating menu rendering, Left/Right arrow cycling, program addition and comment pruning, pre-run verification skipping (n), live FPGA execution, and zero-erase tombstone deletion. -
Clock Speed & Printing Strobe Test:
Cycles through all 25 FPGA clock frequencies (from 10 Hz PWM up to 12 MHz MCO) and verifies zero dropped characters during high-speed execution.
Flashing the Microcontroller
There are several convenient methods to flash firmware onto the STM32F072:
Method 1: WebUSB Browser Flasher (1-Click, Zero Install)
The fastest and easiest way to flash firmware is right inside your browser with the Web Serial Terminal:
- Connect Brainfuino to your PC with a USB-C data cable.
- Open the Web Serial Terminal and navigate to the Flasher tab.
- Under Target Component, select STM32 Coprocessor MCU.
- Select a release binary from the dropdown (or drag and drop your freshly compiled
BrainfuinoMCU.hex). - Click Flash Firmware:
- If connected via serial, the terminal automatically sends
!DFU!to soft-reboot the STM32 into factory DFU mode. - The browser prompts to authorize the STM32 BOOTLOADER (
0483:df11). - The WebUSB flasher erases flash pages, writes the new binary, verifies checksums, and reboots Brainfuino back into run mode—all in under 5 seconds!
- If connected via serial, the terminal automatically sends
Method 2: Automated Command-Line Script (build.ps1 -Flash)
For automated terminal workflows:
- Connect Brainfuino to your PC via USB-C.
- Run
pwsh companion-STM32-firmware/build.ps1 -Flash. - The script auto-detects the COM port, sends the
!DFU!token, and usesSTM32_Programmer_CLIto flash and reboot without touching hardware jumpers.
Method 3: Manual Hardware Boot Jumper DFU (STM32CubeProgrammer)
If you ever flash a corrupt binary that hangs before USB initialization, you can always enter the factory DFU bootloader using the physical hardware header:
-
Set DFU Mode:
- Place the jumper into the BOOT position (pulls
BOOT0HIGH to 3.3V).

- Place the jumper into the BOOT position (pulls
-
Connect Hardware:
- Connect the Brainfuino to your computer using a USB-C data cable.
-
Connect in STM32CubeProgrammer:
- Launch STM32CubeProgrammer.
- In the top-right connection panel, select USB from the drop-down menu, verify that Port USB1 appears (click the refresh icon if needed), and click Connect.

-
Open the Firmware Binary:
- Click the Open file tab in the top bar:

- Browse and select
BrainfuinoMCU.hex(found undercompanion-STM32-firmware/Debug/or downloaded from the GitHub release). - The BrainfuinoMCU.hex tab will load, showing the firmware mapped to starting flash address
0x08000000:

-
Download & Flash Firmware:
- Click the blue Download button:

- The programmer will erase sectors and write the firmware. Verify the console displays File download complete:

-
Return to Run Mode:
- Unplug the board, move the
BOOTjumper back so the STM32 can boot normally, and plug the USB-C cable back in. - The STM32 coprocessor is now fully programmed and ready to run!
- Unplug the board, move the
Method 4: Via ST-Link Programmer (Hardware Debugging)
If you are actively developing code and want live breakpoints, variable watches, and hardware stepping:
- Connect an ST-Link v2 or v3 programmer to the 4-pin SWD header:
- Pins:
SWDIO,SWCLK,GND,3.3V
- Pins:
- In STM32CubeIDE, click Run → Debug (or click the Bug icon).
- The IDE will connect over SWD, flash the firmware into Flash memory, and pause execution at
main().