How to Flash A STM32 Flight Controller

The most raw way to flash your flight controller when everything else doesn't work.

Prerequisites:

Your flight controller must at least boot into DFU mode and enumerate on your PC. Open Device Manager (Windows) and ensure that you can see the device.

Install "STM32CubeProgrammer" from here https://www.st.com/en/development-tools/stm32cubeprog.html

1) Plug in your Flight Controller holding the DFU/boot button.

The Flight controller should enumerate as "STM32 BOOTLOADER" or "STM32 in DFU mode". These drivers are typically installed alongside Mission Planner and/or STM32CubeProgrammer. If your board shows as a COM port it is likely that it hasn't booted into DFU correctly and you will need to try again.

2) Clear Current Firmware

2a) Run STM32CubeProgrammer and on the right hand side set the blue drop down to "USB" and click the refresh symbol next to "Port". Your Flight controller should appear (USB1 in this screenshot).

2b) Click the Green "Connect" button and wait 5~10 seconds for the Log to populate. You should see the raw bytes of the currently flashed firmware. In this example it's a brand new STM32F405RGT6 with no firmware (all FF Bytes).

2c) It is best to clear the current firmware before flashing so you start essentially from scratch. Go to the "Erasing and programming" tab on the left. (The menu can be opened by pressing the 3 lines). This is the main screen you will interface with.

2d) In the box at the top middle click full chip erase and then confirm.

2e) The Log will show "MASS ERASE" and may take ~2 minutes to fully erase. Do not interrupt the process.

2f) Go back to the main screen "Memory and File Editing" and click "Read" (Middle Right) and check that it now shows all FF.

3) Flashing Firmware

3a) In the "Memory & File editing" page select open and choose your firmware file. Ensure it includes a bootloader. Ardupilot users should flash the firmware with the filename that ends with *_with_bl.hex . This should then show the Bytes of the firmware you are about to flash in the main window. Click Download and wait for it to complete.

4) All Done!

This is the most reliable way to flash a STM32 based IC, given it is the official STM32 tool for doing so.

The STM ICs found on nearly all flight controllers should boot into DFU mode through USB and allow you to flash using the above method, IE it doesn't matter if you have a bad firmware. If your STM32 USB doesn't enumerate correctly you could try using an "STLink" and connecting to the SWDIO and SWCLK pins for a dedicated flashing lane while bypassing the integrated USB drivers. Unfortunately most manufacturers don't make it obvious where these pads are, on our CBUnmanned products we like to make it clear and accessible to save you time!

Last updated