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) orUART(for recovery). - 🔹 Read/Write Memory:
Flash,SRAM,OTP(once programmable memory). - 🔹 Security management: Setting levels
RDP(Read Protection) andWRP(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).
- 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:
- Download the archive
en.stm32cubeprg.zip(about 100 MB). - Unpack it into a folder without Cyrillic characters (for example,
C:\STM32\CubeProgrammer). - Run
SetupSTM32CubeProgrammer-x.x.x.exeon behalf of the administrator. - 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
STM32CubeProgrammerfrom the terminal (may be requiredchmod +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 |
|
Option Bytes |
Configuration of protected areas |
|
OB (User Configuration) |
Custom Settings |
|
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
- Connect a debugger ST-Link to the board (connector
SWD:CLK,DIO,GND,3.3V). - B STM32 Cube Programmer select:
- Port:
ST-Link - Interface:
SWD - Speed:
Normal(for the first connection) orFast(after a successful test).
- Port:
Connect. A message should appear in the log Connected to target.Step 2. Firmware download
- Go to the tab
Erasing & Programming. - In the field
File Pathspecify the path to the file.hex. - Make sure that the correct firmware start address is selected (usually
0x08000000forFlash). - 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 sectorsFlashfrom 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 2— irreversible protection: Reading and mass erasing are disabled. Recovery is only possible throughUART Bootloader(unless it is disabled inOption Bytes).
To install RDP Level 1:
- Connect to the microcontroller.
- Go to the tab
Option Bytes. - In the section
Read ProtectionselectLevel 1. - Click
Apply.
⚠️ Attention: If you installRDP Level 2and forget your password (or disableUART Bootloader), the microcontroller will be restored impossible without the use of specialized equipment (for example, ChipWhisperer for glitch attacks).
To configure WRP (write protection):
- On the tab
Option Bytesfind the sectionWrite Protection. - Specify sector ranges
Flashthat need to be protected (for example,Sector 0-3for the bootloader). - 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.3Vor5V. - 🔌 Incorrect SWD connection: mixed up
CLKAndDIO, or there is no commonGND. - 🔌 Hardware protection: installed
RDP Level 2or disabledDebug PortinOption Bytes. - 🔌 Bootloader is damaged: for example, after incorrect firmware via
USB DFU.
Recovery algorithm:
- Check power: Connect the oscilloscope to the pin
VCAP(if available) or measure the voltage atVDDmultimeter. - Check SWD connection:
- Make sure
NRSTnot connected to ground. - Try reducing the interface speed to
Low.
- Make sure
- Recovery via UART (if SWD is locked):
- Connect
UART1(TX,RX,GND) to PC. - Close the pin
BOOT0on3.3Vand submit a reset. - B STM32 Cube Programmer select interface
UARTand port (for example,COM3). - Download the firmware via
UART Bootloader(default speed is115200 baud).
- Connect
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
NRSTAndBOOT0for a short circuit.
⚠️ Attention: When recovering throughUART Bootloadersome models STM32 (For example, STM32L4) require a command0x7Ffor synchronization. B STM32 Cube Programmer this is done automatically, but when done manually throughPuTTYorTera TermThis 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.connectST-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 subprocessresult = 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
FastorVery Fastinterface 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:
- Activate
USB DFUin the project (via STM32CubeMX or manually). - Connect the board to the PC via USB (the port should be defined as
STM32 BOOTLOADER). - B STM32 Cube Programmer select interface
USBand 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:
- Connect 5 signals:
TMS,TCK,TDI,TDO,GND. - B STM32 Cube Programmer select interface
JTAG. - Make sure that in
Option Bytesnot disabledJTAG-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.