# How to Flash A STM32 Flight Controller

**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.&#x20;

<div align="left"><figure><img src="/files/KM6mEUa3N8bT5ELlSAaG" alt=""><figcaption></figcaption></figure></div>

**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).

<figure><img src="/files/bK5deTPMRwb9SsSkdQJ4" alt=""><figcaption></figcaption></figure>

***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).&#x20;

<figure><img src="/files/CJ9opUDuWT1KgsWAou5Q" alt=""><figcaption></figcaption></figure>

***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.&#x20;

<figure><img src="/files/HuMPnVVY2K5sS8kTdtC8" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/lFNPdAaeD3K9oj6MDL7k" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/5JvxBtlcmssJSK5SdNgZ" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/9bib3GwG7AkLTd6fdWo4" alt=""><figcaption></figcaption></figure>

**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.&#x20;

<figure><img src="/files/kAJYKZaZHrDeG7kpkk7Q" alt=""><figcaption></figcaption></figure>

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.&#x20;

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!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.cbunmanned.com/wiki/guides/how-to-flash-a-stm32-flight-controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
