How to program the STM32

If you like it, share it

For programming the STM32 there are four different possibility that are:

  • SWD – is ARM specification, useful for developing a FW, it use only 2 pins + GND, VCC and optionally /RST pin
  • JTAG – is ARM specification, useful for developing a FW
  • DFU or DFUSE  – is STM utility that use USB interface and the STM32 must be in boot mode)
  • Flash Loader – is STM utility that use UART interface and the STM32 must be in boot mode
  • Some useful A.N.

JTAG – SWD connector

The yellow signal are indispensables for SWD.
TRACE-SWO is an optional for SWD.

Go on TOP


DFU or DFUSE (STSW-STM32080)
DFU is a SW is for programming the STM32 via the USB (UM0412)
The package contains all binaries and source code for DfuSe USB device firmware upgrade (DFU) software, including the demonstration, debugging GUIs and protocol layers.
It includes the DFU driver compatible with the latest Microsoft®OS.
DfuSe utility can be used to interact with the STM32 system memory bootloader or any In-Application Programming (IAP) firmware, running from the user Flash, thus allowing internal memories programming through USB.

See this video.

Example: How to use DFU
After the DfuSe installation, in the package, there is the utility: DFU File Manager that is used for generate a .DFU file form a .HEX or .S19 file, see below.

Now we use the .DFU file with the DfuSe Demonstration, to program the device.
Follows the steps below.

You must generate a .DFU file from an .HEX or .S19 file, for do this use the DFU File Manager.

You must put in DFU mode your eval-board (boot mode), in our case the board is the STM32F072B-DISCO and is necessary connect the BOOT pin to VDD pin, see below the red box.

Now connect your eva-board to the PC and you must see a message from USB that the eva-board is in DFU mode.
Run the DfuSe Demonstration and download .DFU file on your eval-board.
Now remove the boot jumper (in our case, remove the jumper from BOOT pin to VDD pin) and reset your eval-board.

You must see the run of the program that you are downloaded via DfuSe Demonstration.

Go on TOP


Flash Loader
The STM32 Flash loader demonstrator (FLASHER-STM32) is a free software PC utility from STMicroelectronics, which runs on PC and communicates through the RS232 with the STM32 system memory bootloader.
To get an example of how to execute the device bootloader, refer to the STM32 microcontroller system memory boot mode Application note (AN2606).
To get information about the USART protocol used in the STM32 bootloader, refer to the USART protocol used in the STM32 bootloader Application note (AN3155).

Remember to put your STM32 in boot mode before to run Flash Loader.
For example for put in boot mode the STM32L031K6 is necessary connect to VCC (VDD) the boot pin that is pin 31.

ATTENTION
Up to now, 10-November-2017, there is a problem to program the STM32L0x1/2/3 (32KFlash) using the standard Flash Loader (ver.2.8.0) present on the STM Internet  site.
If you had the necessity to program the STM32L0x1/2/3 download this release (ver.2.9.0) of the Flash Loader and use it.

Go on TOP


Some useful A.N.

  • AN2606: STM32 microcontroller system memory boot mode
  • AN3155: USART protocol used in the STM32 bootloader
  • AN3156: USB DFU protocol used in the STM32 bootloader
  • X-CUBE-IAP-USART – STM32Cube in-application programming using the USART embedded software
    • Flash erase
    • Flash programming
    • UART communication using Ymodem protocol
    • Flash write protection configuration
    • Separating application from loader
    • Read also the AN4657 – STM32 in-application programming (IAP) using the USART

Go on TOP