Utility STM32 Cube Programmer from STMicroelectronics has become a standard tool for programming, debugging and configuration of microcontrollers of the family STM32. It supports all modern series - from budget STM32F0 to high performance STM32H7, offering flexible ways to download firmware through interfaces SWD, JTAG and even USB DFU. But despite the wide possibilities, many developers encounter difficulties: from connection errors to incorrect work with protected memory areas.

In this article we will analyze not only the basic functions of the program (installation, interface, firmware), but also unique techniques for working with read protection (RDP), restoring “bricks” via UART, as well as optimizing download speed for mass production. We will pay special attention to typical mistakes - for example, when STM32CubeProgrammer "does not see" the microcontroller or issues Error: No STM32 target found, - and ways to eliminate them without purchasing expensive debuggers.

What is STM32 Cube Programmer and why is it needed?

Unlike STM32CubeIDE (full-fledged development environment), STM32 Cube Programmer is a specialized tool for low-level interaction with a microcontroller. Its key tasks:

  • 🔹 Firmware through SWD, JTAG, USB (DFU) or UART (for recovery).
  • 🔹 Read/Write Memory: Flash, SRAM, OTP (once programmable memory).
  • 🔹 Security management: Setting levels RDP (Read Protection) and WRP (Write Protection).
  • 🔹 Debugging: reset, start/stop kernel, read registers.
  • 🔹 Mass production: support for scripts to automate the firmware of batches of devices.

The program recognizes more 1000 STM32 models, including the latest STM32U5 And STM32WBA (with Bluetooth 5.3 support). It is important that it works with both official debuggers (ST-Link, J-Link), and with cheap clones based on CH340 or FT232 - if the drivers are configured correctly.

The main advantage over alternatives (for example, OpenOCD or J-Flash) — native support for all STM32 specific functions, such as:

  • 🔧 Configuration Option Bytes (bootloader settings, protection level).
  • 🔧 Working with Dual-Bank Flash (for microcontrollers with two memory banks).
  • 🔧Recovery via UART Bootloader (if SWD is locked).
📊 Which interface do you most often use to flash STM32 firmware?
  • SWD
  • JTAG
  • USB DFU
  • UART
  • Other

Installation and first launch: step-by-step instructions

The program is available for Windows, Linux And macOS, but official support is best provided on Windows. You can download the latest version from ST official website (section Tools & Software).

To install on Windows:

  1. Download the archive en.stm32cubeprg.zip (about 100 MB).
  2. Unpack it into a folder without Cyrillic characters (for example, C:\STM32\CubeProgrammer).
  3. Run SetupSTM32CubeProgrammer-x.x.x.exe on behalf of the administrator.
  4. During installation, check the box Add to PATH - this will make it easier to launch from the command line.

For Linux/macOS:

  • 🐧 Unpack the archive and run STM32CubeProgrammer from the terminal (may be required chmod +x).
  • 🍎 On macOS, first install drivers for ST-Link through Homebrew:
brew install --cask stlink

After installation, check the operation of the program by connecting a debugger ST-Link to PC and microcontroller. In the main window in the section Connection the port must be determined (for example, ST-Link (SWD)).

Install drivers for the debugger (ST-Link/J-Link)

Connect the debugger to the PC and microcontroller

Check the board power supply (3.3V or 5V)

Run STM32CubeProgrammer as administrator

Select the correct interface (SWD/JTAG) in the settings-->

Program interface: analysis of key tabs

Interface STM32 Cube Programmer is divided into 5 main tabs, each of which is responsible for specific functions. Let's look at them in detail:

Tab Purpose Key Features
Erasing & Programming Flashing and erasing memory
  • Selecting the firmware file (.hex, .bin, .elf)
  • Setting the download address
  • Checksum verification (CRC)
Option Bytes Configuration of protected areas
  • Installation RDP (Read Protection)
  • Settings WRP (Write Protection)
  • Selecting a clock source
OB (User Configuration) Custom Settings
  • Configuration BOR (Brown-Out Reset)
  • Settings NRST_MODE

On the tab Erasing & Programming pay attention to the parameter Verify programming — it automatically checks the recorded data with the source file. This is critical for mass production, where a firmware error in even one device can lead to the failure of the entire batch.

Tab Option Bytes requires special care. For example, setting RDP Level 2 irreversibly blocks access to memory via SWD/JTAG, and it will be possible to restore the microcontroller only through UART Bootloader (unless it is disabled).

💡

Before changing Option Bytes, always make a backup of your current configuration via the button Save on the tab OB (User Configuration).

Microcontroller firmware: step-by-step process

Let's look at the firmware process using the example of a microcontroller STM32F407G (popular board STM32F4 Discovery). We assume that you already have a compiled firmware file in the format .hex.

Step 1. Connection and connection setup

  1. Connect a debugger ST-Link to the board (connector SWD: CLK, DIO, GND, 3.3V).
  2. B STM32 Cube Programmer select:
    • Port: ST-Link
    • Interface: SWD
    • Speed: Normal (for the first connection) or Fast (after a successful test).
  • Click Connect. A message should appear in the log Connected to target.
  • Step 2. Firmware download

    1. Go to the tab Erasing & Programming.
    2. In the field File Path specify the path to the file .hex.
    3. Make sure that the correct firmware start address is selected (usually 0x08000000 for Flash).
    4. Click Start Programming.

    The process will take from 5 to 30 seconds depending on the size of the firmware and the speed of the interface. After completion, it will appear in the log Verification OK.

    What to do if the firmware freezes at 99%?

    Most often this is due to incorrect settings Option Bytes or conflict of protected areas. Try:

    1. Disable the option Verify programming and repeat the firmware.

    2. Reduce interface speed to Low.

    3. Check if it is installed RDP Level 1/2 (complete erasure of the chip is required).

    Working with security: RDP and WRP

    Protection system STM32 includes two key mechanisms:

    • 🔒 RDP (Read Protection) — blocks memory reading through debugging interfaces.
    • 🔒 WRP (Write Protection) - protects individual sectors Flash from recording.

    Levels RDP:

    • Level 0 — protection is disabled (access to all memory).
    • Level 1 — reading the memory is blocked, but you can erase the chip completely and remove the protection.
    • Level 2irreversible protection: Reading and mass erasing are disabled. Recovery is only possible through UART Bootloader (unless it is disabled in Option Bytes).

    To install RDP Level 1:

    1. Connect to the microcontroller.
    2. Go to the tab Option Bytes.
    3. In the section Read Protection select Level 1.
    4. Click Apply.
    ⚠️ Attention: If you install RDP Level 2 and forget your password (or disable UART Bootloader), the microcontroller will be restored impossible without the use of specialized equipment (for example, ChipWhisperer for glitch attacks).

    To configure WRP (write protection):

    1. On the tab Option Bytes find the section Write Protection.
    2. Specify sector ranges Flashthat need to be protected (for example, Sector 0-3 for the bootloader).
    3. Apply the settings with the button Apply.
    💡

    Always test protection on a separate microcontroller before mass production. An error in the Option Bytes settings can lead to the failure of an entire batch of devices.

    Restoring a “brick”: what to do if STM32 is not detected

    The situation when STM32 Cube Programmer gives an error No STM32 target found or Could not connect to target, is familiar to many developers. The reasons may be different:

    • 🔌 Eating problems: microcontroller does not receive 3.3V or 5V.
    • 🔌 Incorrect SWD connection: mixed up CLK And DIO, or there is no common GND.
    • 🔌 Hardware protection: installed RDP Level 2 or disabled Debug Port in Option Bytes.
    • 🔌 Bootloader is damaged: for example, after incorrect firmware via USB DFU.

    Recovery algorithm:

    1. Check power: Connect the oscilloscope to the pin VCAP (if available) or measure the voltage at VDD multimeter.
    2. Check SWD connection:
      • Make sure NRST not connected to ground.
      • Try reducing the interface speed to Low.
    3. Recovery via UART (if SWD is locked):
      • Connect UART1 (TX, RX, GND) to PC.
      • Close the pin BOOT0 on 3.3V and submit a reset.
      • B STM32 Cube Programmer select interface UART and port (for example, COM3).
      • Download the firmware via UART Bootloader (default speed is 115200 baud).

    If the microcontroller is still not detected, try:

    • 🔧 Use another debugger (for example, J-Link instead of ST-Link).
    • 🔧 Connect an external power source (sometimes the PC USB port does not provide enough current).
    • 🔧 Check chains NRST And BOOT0 for a short circuit.
    ⚠️ Attention: When recovering through UART Bootloader some models STM32 (For example, STM32L4) require a command 0x7F for synchronization. B STM32 Cube Programmer this is done automatically, but when done manually through PuTTY or Tera Term This byte may need to be sent manually.

    Firmware automation for mass production

    To flash batches of devices (for example, 100+ boards), manually use STM32 Cube Programmer ineffective. Instead, you can use the built-in support scripts And command line.

    Method 1: Command Line

    The program supports launching from CMD or Bash with parameters. Example command for firmware:

    STM32_Programmer_CLI.exe -c port=SWD -w "firmware.hex" -v -rst

    Where:

    • -c port=SWD — interface selection.
    • -w "firmware.hex" - firmware file.
    • -v — check after recording.
    • -rst - reset after flashing.

    Method 2: Scripts (TCL)

    For complex scenarios (for example, firmware + configuration Option Bytes + check CRC) you can write a script in TCL. Example:

    ST-Link_SWD.connect
    

    ST-Link_SWD.write_memory 0x08000000 "firmware.bin"

    ST-Link_SWD.verify_memory 0x08000000 "firmware.bin"

    ST-Link_SWD.reset

    The script is launched via:

    STM32_Programmer_CLI.exe -script "flash.tcl"

    Method 3: Python Integration

    Using the module pystm32 (or calls subprocess) you can automate the process from a Python script. Example:

    import subprocess
    
    

    result = subprocess.run([

    "STM32_Programmer_CLI.exe",

    "-c", "port=SWD",

    "-w", "app.bin",

    "-ob", "RDP=1", # Установить RDP Level 1

    "-v"

    ], capture_output=True, text=True)

    print(result.stdout)

    To speed up firmware in mass production:

    • 🚀 Use Fast or Very Fast interface speed (if stability allows).
    • 🚀 Disable verification (-v) for already tested firmware.
    • 🚀 Connect several debuggers to one PC via a USB hub (but take into account current limitations).

    FAQ: answers to frequently asked questions

    Is it possible to flash STM32 without a debugger (via USB only)?

    Yes, if your microcontroller supports USB DFU (Device Firmware Update). To do this:

    1. Activate USB DFU in the project (via STM32CubeMX or manually).
    2. Connect the board to the PC via USB (the port should be defined as STM32 BOOTLOADER).
    3. B STM32 Cube Programmer select interface USB and download the firmware.

    Limitation: USB DFU only works if the bootloader is not damaged and is not disabled in Option Bytes.

    How to reset RDP Level 2 if UART Bootloader is disabled?

    If installed RDP Level 2 and disabled UART Bootloader, using standard methods to restore the microcontroller impossible. Solutions:

    • 🔧 Use glitch attack (for example, via ChipWhisperer or homemade circuits on FPGA).
    • 🔧 Contact the service center STMicroelectronics (for serial customers).
    • 🔧 Replace the microcontroller (if this is permissible by the design of the device).

    Avoid in the future RDP Level 2 without a backup recovery channel!

    Why doesn't STM32 Cube Programmer see ST-Link?

    Common reasons:

    • 🔌 Drivers are not installed (download STSW-LINK009 from the ST website).
    • 🔌 Conflict with other programs (for example, STM32CubeIDE or Keil occupy the debugger).
    • 🔌 Faulty cable or USB port (try a different connector).
    • 🔌 ST-Link clone based on CH340 requires manual installation of drivers.

    Solution: reinstall drivers, check Device Manager (should display ST-Link Virtual COM Port).

    How to flash STM32 via JTAG instead of SWD?

    To use JTAG:

    1. Connect 5 signals: TMS, TCK, TDI, TDO, GND.
    2. B STM32 Cube Programmer select interface JTAG.
    3. Make sure that in Option Bytes not disabled JTAG-DP (it is enabled by default).

    Please note: JTAG slower SWD, but allows you to debug multiprocessor systems.

    Is it possible to flash STM32 via Arduino (as a debugger)?

    Yes, but with restrictions. For example, fee Arduino Uno with firmware STM32duino-bootloader can emulate ST-Link through the library ArduinoSTM32. However:

    • ⚠️ The firmware speed will be low (due to restrictions ATmega328P).
    • ⚠️ Not all functions STM32 Cube Programmer will be available.

    For reliable operation it is better to use the original ST-Link or J-Link.