← Back to app
See also: Help · Build firmware

Firmware Update Guide

Overview

This page explains how to update your device firmware using STMicroelectronics STM32CubeProgrammer. Follow the steps carefully. Do not disconnect power or USB during flashing.

Notes

  • Close any other applications using the device’s USB port before switching to DFU.
  • Do not interrupt power or USB while programming.
  • If connection fails, try a different USB cable/port and ensure STM32 DFU drivers are installed.

Update using STM32CubeProgrammer

  1. Download and install STM32CubeProgrammer
    Get it from ST: https://www.st.com/en/development-tools/stm32cubeprog.html
  2. Download the firmware (HEX)
    Download melexis_io_fw.hex
    Save the .hex file to a known location.
  3. Enter DFU mode
    • From Terminal: send command :SYST:DFU 42
    • Using buttons: press and hold Boot, then click Reset
    In DFU mode, the device re-enumerates as an STM32 DFU device over USB.
  4. Connect STM32CubeProgrammer over USB
    • Open STM32CubeProgrammer
    • Select the USB connection type (upper right)
    • Click Refresh and choose the DFU target
    • Click Connect
  5. Upload and verify
    • Activate the Erasing & Programming tab in STM32CubeProgrammer
    • Enter the File path or click Browse to select the firmware .hex
    • Check Verify programming and Run after programming
    • Click Start Programming
    • Wait for the progress to complete and verify finishes without errors
    • With Run after programming checked, the board will reset and start the new firmware automatically

Update using STM32CubeProgrammer CLI

You can flash the firmware from the command line using STM32CubeProgrammer's CLI tool. Ensure the device is in DFU mode first (see steps above).

  1. Locate the CLI executable, typically here:
    "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe"
  2. Optional: Add the folder to your PATH so you can call the CLI from any directory:
    C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\
    Windows PowerShell (current session):
    $env:Path += ";C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin"
    Permanent (user) PATH:
    setx PATH "$env:Path;C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin"
  3. Run the command (replace paths as needed):
    "C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=USB1 -w "C:\path\to\melexis_io_fw.hex" -v -g
    -c port=USB1: connect over USB DFU · -w: write HEX · -v: verify · -g: run after programming

Update using dfu-util (Windows)

  1. Install WinUSB driver for the DFU device using Zadig:
    • Run Zadig → Options → List All Devices
    • Select STM32 Bootloader from the list
    • Choose WinUSB as the driver and click Install Driver
  2. Download dfu-util for Windows and extract it (e.g., to C:\Tools\dfu-util\).
    Add the folder to PATH or run commands from inside the extracted directory.
  3. Enter DFU mode (see steps above), then verify the device is detected:
    dfu-util --list
    You should see an entry for STM32 Bootloader with DFU interfaces.
  4. Convert the firmware HEX to BIN (dfu-util writes BIN/DFU, not Intel HEX):
    • Using ARM GCC (if installed):
      arm-none-eabi-objcopy -I ihex -O binary melexis_io_fw.hex melexis_io_fw.bin
    • Or use another converter (e.g., srec_cat) to produce .bin.
    Download the HEX from this page above or use your own build output.
  5. Flash the BIN to internal flash at address 0x08000000 and reset when done:
    dfu-util -a 0 -s 0x08000000:leave -D melexis_io_fw.bin
    Drop :leave if you do not want the board to reset automatically after programming.

Partial update: preserve Flash sectors 1–3

If you use EEPROM emulation in sectors 1–3 (0x08004000–0x0800FFFF), avoid erasing or writing those regions. Program only from 0x08010000 upward.

Case A: BIN is linked to start at 0x08010000

This is the recommended setup when you changed the linker script (FLASH origin at 0x08010000).

dfu-util -a 0 -s 0x08010000:leave -D melexis_io_fw.bin
This writes only the application region. Do not add :mass-erase. If multiple DFU devices are connected, you can select the STM32 DFU with -d 0483:df11.

Case B: BIN starts at 0x08000000 (full image)

Trim the first 64 KB (sectors 0–3) so you only program the application part at 0x08010000.

Windows PowerShell snippet to create app_only.bin from full.bin:

$in  = [System.IO.File]::OpenRead("full.bin")
$out = [System.IO.File]::Create("app_only.bin")
$in.Seek(0x10000, 'Begin') | Out-Null
$in.CopyTo($out)
$out.Close(); $in.Close()

# Flash only the app region
dfu-util -a 0 -s 0x08010000:leave -D .\app_only.bin
This preserves sectors 1–3 because they are neither erased nor written. If you must also update sector 0 (vector table), do it in a separate 16 KB write to 0x08000000 and still avoid sectors 1–3.

Update using dfu-util (Linux)

  1. No additional drivers are required on Linux.
  2. Install dfu-util from your distribution:
    Debian/Ubuntu: sudo apt install dfu-util · Fedora: sudo dnf install dfu-util · Arch: sudo pacman -S dfu-util
  3. Enter DFU mode (see above) and verify detection:
    dfu-util --list
  4. Convert HEX to BIN (same as Windows):
    arm-none-eabi-objcopy -I ihex -O binary melexis_io_fw.hex melexis_io_fw.bin
  5. Flash the BIN to internal flash and reset when done:
    dfu-util -a 0 -s 0x08000000:leave -D melexis_io_fw.bin

These steps mirror the Windows dfu-util flow; only installation differs. You may need sudo if udev permissions are not configured.

Optional: allow flashing without sudo (udev rule)

Adjust idProduct if your device reports a different PID than df11 (check with dfu-util --list).

# Create udev rule for STM32 DFU (VID 0483, PID df11)
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="df11", MODE="0666", TAG+="uaccess"' | sudo tee /etc/udev/rules.d/49-st-dfu.rules
sudo udevadm control --reload-rules
sudo udevadm trigger
# Unplug and re-plug the device (or reset to DFU) to apply
← Back to app