Flashing STM32 boards: methods, wiring and common failures

5 min readUpdated Tutorial

How to flash an STM32 board over SWD, serial ISP or USB DFU, how to wire each one, and the errors that come up most often.

Flashing STM32 boards: methods, wiring and common failures

Note: the STM32F401 series and the STM32F411 V3.0 revision were discontinued in 2023. Anything still on sale is not made by WeAct Studio — take quality issues up with whoever sold it to you. The current STM32F411 core board is revision V3.1; check before you buy.

Supported flashing methods

text
SWD:  every STM32 series supports it
ISP mode:
    Serial:  nearly every STM32 series supports it
    USB (DFU): STM32F4, STM32H7, STM32U585, STM32G4, STM32G0B1 and others

Flashing in ISP mode

There are two ways to program the chip in ISP mode:

  1. Serial download — needs a USB-to-serial adapter.
  2. USB download — recommended, not available on STM32F103, needs only a data cable.

Entering ISP mode

  • Option 1: while powered, hold BOOT0 and reset, release reset, then release BOOT0 after 0.5 s.
  • Option 2: while unpowered, hold BOOT0, apply power, release BOOT0 after 0.5 s.

Wiring

  • USB download: connect the board's Type-C or USB port with a data cable.
  • Serial download: USB-to-serial module, TX → PA10, RX → PA9.

Recommended tools: STM32CubeProgrammer or WeAct Studio Download Tool

text
Downloads
Baidu Netdisk:  https://pan.baidu.com/s/5cdUxxlNBMhIWb_SnhLAKcw
Quark:          https://pan.quark.cn/s/c0c9ed63597e

Serial download

Wire the USB-to-serial adapter (a CH340, for example) so that TX goes to PA10 and RX goes to PA9. Do not connect the MCU's own USB port to the computer — the board must be powered externally, otherwise the download misbehaves. There are two tools: ST's own STM32CubeProgrammer, and our portable WeAct Studio Download Tool.

Serial download with STM32CubeProgrammer

Select UART mode in the software. STM32CubeProgrammer serial download 1STM32CubeProgrammer serial download 1 Once connected, drag in the firmware, click Download, wait for it to finish, disconnect and reset. STM32CubeProgrammer serial download 2STM32CubeProgrammer serial download 2

Serial download with WeAct Studio Download Tool

  1. Extract WeAct Studio Download Tool.
  2. Double-click WeAct Studio UART Download Tool.bat.
  3. Put the MCU into ISP mode.
  4. Enter the COM port number and press Enter.
  5. Drag in the firmware and press Enter.
  6. The result looks like this.

USB download in DFU mode

USB download also has two tools: ST's STM32CubeProgrammer, and our portable WeAct Studio Download Tool.

USB download with STM32CubeProgrammer

If you hit Error: failed to download Segment[0], see ISP mode FAQ.

  1. Select USB mode in STM32CubeProgrammer.
  2. Put the MCU into ISP mode and connect it to the computer with a USB data cable.
  3. Under Device Manager → Universal Serial Bus devices you should see STM32 Bootloader or DFU in FS Mode. If you see STM Device in DFU Mode instead, follow why the flasher cannot find the device.
  4. Drag in the firmware.
  5. Click Download.
  6. Disconnect and reset when it finishes.

USB download with WeAct Studio Download Tool

If you hit Error: failed to download Segment[0], see ISP mode FAQ.

  1. Extract WeAct Studio Download Tool.
  2. Double-click WeAct Studio USB Download Tool.bat.
  3. Put the MCU into ISP mode and connect it with a USB data cable.
  4. Under Device Manager → Universal Serial Bus devices you should see STM32 Bootloader or DFU in FS Mode. If you see STM Device in DFU Mode instead, follow why the flasher cannot find the device.
  5. Drag in the firmware and press Enter. Ignore Error: Start operation failed; it does not affect the integrity of the download.
  6. The result looks like this. Reset and you are done.

Common issues

Why the flasher cannot find the device

If Device Manager lists the device as STM Device in DFU Mode, the flasher will not recognise it. Right-click the device, uninstall it and tick the box to delete the driver, then install the driver from WeAct Studio Download Tool/DFU_Driver/Driver/: right-click STM32Bootloader.inf and choose Install.

Fixing the segment download error

USB download can be flaky in some weather. If you keep seeing the errors below, or the device is not recognised at all, use serial download instead and disconnect USB.

text
Error: failed to download Segment[0]
Error: failed to download the File

Why this happens: at low room temperature the HSI drifts. USB download runs off the external high-speed crystal, and the ISP program (ST's system bootloader) measures the external HSE frequency using the HSI before configuring the clock. When the HSI error is large the HSE measurement is wrong, which throws off USB timing and breaks the download. Details in /General documents/AN2606 STM32 microcontroller system memory boot mode.pdf in the shared drive. Workaround: warm the MCU above 25 °C (holding it in your hand is enough).

ST-Link / J-Link flashing

Connect the STM32's SW interface:

SW interface
GND
SCK
DIO
3.3V

Click the download button in MDK, or select ST-Link in STM32CubeProgrammer and follow the prompts.

Notes

  1. For CubeMX or standard-peripheral-library projects, enable the SW debug interface; otherwise the probe cannot see the MCU.
  2. If the clock settings or some other fault keep the probe from recognising the MCU, put the MCU into ISP mode by hand — the probe will then see it, and you can download.
  3. ISP mode is just a boot ROM that ST hard-wired into the chip. Check the BOOTx setting: in run mode it jumps to 0x08000000; in download mode it waits for a command. The SW debug interface stays open throughout, so a probe can still read and write the MCU.
  4. Debug interfaces come in SW and JTAG flavours; essentially every ARM probe supports SW.
  5. If J-Link connects but cannot download, update the J-Link driver to the latest version. V6.50a is known to work.
JTAG pinAdapterSW pin
TMSSWDIO
TCKSWCLK
VTEST, pin 1some J-Link units need 3.3 V here to see the MCU3.3V
3.3V3.3V
GNDGND

JTAG and SW interfacesJTAG and SW interfaces

Flashing through a debug probe is strongly recommended: it is faster, and you can debug afterwards. There is a lot of outdated material online; the ST website is a better reference. This page is updated whenever new STM32 flashing issues turn up.