Skip to content

Firmware Flashing

Overview

Two MCUs must be flashed independently, in order. Flashing the KB2040 first is recommended since the STM32 will report [UART] no data on the serial monitor until the KB2040 is running.

PlatformIO setup

Both firmware projects use PlatformIO (Arduino framework).

# Install PlatformIO CLI (if not using VS Code)
pip install platformio

# Or install the VS Code extension:
#   Extensions → search "PlatformIO" → install

There are two separate PlatformIO projects inside the workspace:

Project Path MCU Framework
STM32F405 firmware/stm32f405/ STM32F405 Feather Express STM32duino
KB2040 firmware/kb2040/ KB2040 (RP2040) Arduino-Pico

Step 1: Flash the KB2040

cd firmware/kb2040
pio run -t upload
  1. Connect the KB2040 to your PC via USB-C
  2. Double-tap the BOOT button — the NeoPixel turns green and a RPI-RP2 drive appears
  3. PlatformIO will copy the .uf2 file automatically
  4. After upload, the board reboots and LED_BUILTIN lights up after setup() completes

Tip

If double-tap BOOT doesn't work, hold BOOT while pressing RESET, then release RESET first.

Verify

Open serial monitor (115200 baud):

pio device monitor -b 115200

Expected output:

KB2040: I2C0 ok, I2C1 ok, seq=0
KB2040: seq=1  seq=2  ...

The KB2040 streams at 100 Hz to Serial1 (UART1 = GP4/GP5), not the USB CDC port — so the monitor only shows debug output, not the 70-byte IMU frames.


Step 2: Flash the STM32F405

cd firmware/stm32f405
pio run -t upload
  1. Connect the STM32F405 to your PC via USB-C
  2. Press the RESET button — the board enters STM32 bootloader (DFU mode)
  3. PlatformIO uploads via DFU; the board reboots after flashing

DFU not detected

Press RESET after pio run -t upload starts, when you see "Looking for DFU device". Some Linux systems require sudo or udev rules for DFU access. See PlatformIO STM32 DFU docs.

Verify

Open serial monitor (115200 baud):

pio device monitor -b 115200

Expected output:

STM32F405: init
[IMU] 0:ok 1:ok 2:ok 3:ok
[ADC] EMG 2ch, FSR 4ch
[UART] KB2040 bridge on USART6
seq=0  seq=1  seq=2  ...

If [UART] no data appears, the KB2040 is not connected or not transmitting — check the UART wiring (PC6→GP5, PC7←GP4, GND common).


Re-flashing after code changes

  • KB2040: double-tap BOOT, pio run -t upload
  • STM32F405: press RESET, pio run -t upload

Both projects support incremental builds — pio run only recompiles changed files.


Troubleshooting

Symptom Cause Fix
pio: command not found PlatformIO CLI not installed pip install platformio
can't open device (KB2040) Not in bootloader mode Double-tap BOOT
DFU timeout (STM32) Not in DFU mode Press RESET after upload starts
[IMU] N:fail BNO055 not detected on that bus Check I2C wiring, pull-ups, ADR pin
LED_BUILTIN stays off setup() crashed Check serial monitor for error messages
[UART] no data KB2040 not transmitting Check PC6→GP5, PC7←GP4 wiring