STM32CubeProgrammer

Revision as of 18:57, 2 October 2019 by Patrick Delaunay (talk | contribs) (update broken link)



This article gives a short introduction to the official STM32CubeProgrammer tool: What are the flashing principles? Where to download the software? How to install it? How to use it?

STM32CubeProgrammer.png

1 STM32CubeProgrammer overview

STM32CubeProgrammer is the official STMicroelectronics tool for creating partitions into any Flash device available on STM32 platforms.
Once created, STM32CubeProgrammer allows populating and updating the partitions with the prebuilt binaries.

The connection between the host PC and the board can be done through UART or USB serial links.

Any Flash device supported on STM32MPU boards can be flashed using STM32CubeProgrammer. For example, for the STM32MP157 Evaluation board:

  1. microSDTM card
  2. eMMC
  3. NAND Flash memory
  4. NOR Flash memory
Info.png During development, it is recommended to use a microSD card; you can then switch to eMMC or NAND Flash memory.

More details on supported Flash memory technologies and mapping can be found in Flash mapping articles, e.g. STM32MP15 Flash mapping.

2 STM32CubeProgrammer installation

2.1 Installing the STM32CubeProgrammer tool

STM32CubeProgrammer for Linux® host PC STM32CubeProgrammer for Windows® host PC
Download

Version 2.2.0

Warning.png On this st.com page, the default version v2.2.1 is not compatible with STM32MP1 series. Before downloading the SetupSTM32CubeProgrammer, the right version (v2.2.0) must be explicitly selected by clicking on "Select version".
  • Download the archive file on your host PC in a temporary directory
  • Uncompress the archive file to get the STM32CubeProgrammer installers:


PC $>unzip en.stm32cubeprog.zip

Installation
  • Execute the Linux installer, which guides you through the installation process.
./SetupSTM32CubeProgrammer-2.2.0.linux
  • The path to the STM32CubeProgrammer binary must be added to the PATH environment variable
    • either in each Terminal program in which the STM32CubeProgrammer binary needs to be used, using the following command:
export PATH=<my STM32CubeProgrammer install directory>/bin:$PATH
  • or once for all by creating a link to the STM32CubeProgrammer binary in a directory already present in PATH. For example, if "/home/bin" is in the PATH environment variable, run the following command:
ln -s <my STM32CubeProgrammer install directory>/bin/STM32_Programmer_CLI /home/bin/STM32_Programmer_CLI
  • Execute the Windows installer, which guides you through the installation process.
User manual
Detailed release note
  • Details about the content of this tool version are available from ST web site at Release Note .


2.2 Preparing the USB serial link for flashing

It is recommended to use the USB (in DFU mode) for flashing rather than the UART, which is too slow.

Below indications on how to install the USB in DFU mode under Linux and Windows OS, respectively.

  • For Linux host PC or Windows host PC with VMWare:

The libusb1.0 package (including USB DFU mode) must be installed to be able to connect to the board via the USB port. This is achieved by typing the following command from the host PC terminal:

PC $> sudo apt-get install libusb-1.0-0


To allow STM32CubeProgrammer to access the USB port through low-level commands, proceed as follows:

PC $> cd <your STM32CubeProgrammer install directory>/Drivers/rules 
PC $> sudo cp *.* /etc/udev/rules.d/
  • For Windows host PC:

Run the “STM32 Bootloader.bat” file to install the STM32CubeProgrammer DFU driver and activate the STM32 microprocessor device in USB DFU mode. This driver (installed by STM32 Bootloader.bat) is provided within the STM32CubeProgrammer release package. It is located in the DFU driver folder, \Drivers\DFU_Driver.

In case of issue, refer to How to proceed when the DFU driver installation fails on Windows host PC.

To validate the installation, the DFU driver functionality can be verified by following the FAQ instructions provided in how to check if the DFU driver is functional.

STM32CubeProgrammer is now ready to use: to know more about this tool, please continue reading; otherwise, jump to the Starter or Distribution Package article corresponding to your board: Category:Starter Package or Category:Distribution Package.

3 Flash programming principles

Flash programming consists in transferring the binaries stored on the host computer into the platform Flash memory(ies), via a serial interface.
This operation requires a communication interface between the STM32CubeProgrammer and an embedded programming service.

The selection of the binaries to download and the Flash memory destination is done through the flashlayout.tsv file.
The STM32Cubeprogrammer tool uses the Flashlayout.tsv file as an input.
The Flashlayout includes a formal description of the partitions (ID, naming, type, offset) as well as the identification of the Flash memory to be populated.

Some default "tsv" files aligned with the STM32 Flash memory mapping (e.g.STM32MP15_Flash_mapping) are provided in the STM32Cubeprogrammer tool. They can be used as a starting point and can be further adapted to specific application needs.

More examples as well as information on the description format are available in STM32CubeProgrammer flashlayout.

4 How to flash with STM32CubeProgrammer

Once the STM32CubeProgrammer has been installed, complete flashing procedures for STM32 boards are available in Starter Package and Distribution Package articles. Select the article corresponding to your STMicroelectronics platform.


The generic syntax of the STM32CubeProgrammer command is explained below.

  • With Linux host PC, the main command is:
PC $> ./bin/STM32_Programmer_CLI  + options given below
  • With Windows host PC, the main command is:
PC $> ./bin/STM32_Programmer_CLI.exe + options given below

The Linux related information provided below can be extrapolated for other host PC operating systems:

  • Complete flashing command (for Linux host PC):
PC $>  STM32_Programmer_CLI -c port=<DEVICE_PORT_LOCATION> -w [<file.tsv>]
where 
 tm:
    Set timeout value in ms
 w:
     Write
 <file.tsv>:PathToFlashlayout/flashlayout.tsv file (see above) 
         if Flashlayout and binaries are not in the same directory, then the path to the Flashlayout files must be precised.
 <DEVICE_PORT_LOCATION>:
         e.g. usb1 (case sensitive): for other options, please refer to How to find the DEVICE_PORT_LOCATION parameter value for the USB link.

Populating all partitions can take a few minutes (depending mainly on the rootfs size).

5 FAQs

5.1 Where to find the STM32CubeProgrammer user manual

The user manual is available in ST deliveries under <STM32CubeProgrammer installation directory>/doc/UM2336.pdf (see Installing the STM32CubeProgrammer tool).

5.2 How to check if the DFU driver is functional

Prerequisites: STM32CubeProgrammer installation completed and STM32 board connected to the host PC.


Execute the following command and check the result:

 PC $> STM32_Programmer_CLI -l usb
  • If the DFU is functional, the result is similar to the following
     -------------------------------------------------------------------
                       STM32CubeProgrammer <tool version>                  
     -------------------------------------------------------------------

Total number of available STM32 device in DFU mode: 1

 Device Index           : USB1
 USB Bus Number         : 002
 USB Address Number     : 008
 Product ID             : USB download gadget@Device ID /0x500, @Revision ID /0x0000
 Serial number          : 0000000000
 Firmware version       : 0x0110
 Device ID              : 0x0500
  • Otherwise, the DFU is not functional and the result is the following:
 ------------------------------------------------------------------
                      STM32CubeProgrammer <tool version>
 ------------------------------------------------------------------
 

  Warning: No STM32 device in DFU mode connected

5.3 How to proceed when the DFU driver installation fails on Windows host PC

Prerequisites: STM32CubeProgrammer installation completed.


The STM32 Bootloader.bat allows to install the DFU driver on a Windows PC (see Preparing the USB serial link for flashing). In case of failure, here is a typical error log:

c:\demo\MPU\stm32_programmer_package_v1.0.3_MPU\Drivers\DFU_Driver>"STM32 Bootloader.bat"
c:\demo\MPU\stm32_programmer_package_v1.0.3_MPU\Drivers\DFU_Driver>echo off Microsoft PnP Utility
Processing inf :            DFU_in_HS_Mode.inf
Failed to install the driver on any of the devices on the system : No more data is available.
Total attempted:              1
Number successfully imported: 0

This error occurs either because the STM32CubeProgrammer DFU driver is already installed or because the DFUSE driver is installed.


To verify if the STM32CubeProgrammer DFU driver is correctly installed on your Windows host PC, please proceed as follow:

  1. Connect the board to the Windows host PC.
  2. Launch the Device Manager utility and execute the below action depending on your use case:
  • The STM32CubeProgrammer DFU driver is not installed:
Execute the STM32 Bootloader.bat script to install it (see Preparing the USB serial link for flashing).
DfuSe
Figure 1: STM32CubeProgrammer’s DFU driver is not installed


  • The DfuSe driver is installed and you must uninstall it.
Right click STM Device in DFU Mode and select Uninstall.
DfuSe
Figure 1: STM32 DFU Device with DfuSe Driver


  • The STM32CubeProgrammer DFU driver is installed and ready to be used.
DFUDevice
Figure 2: STM32 DFU Device with STM32_Programmer Driver

5.4 How to find the DEVICE_PORT_LOCATION parameter value for the USB link

Prerequisites: STM32CubeProgrammer installation completed and STM32 board connected to the host PC.


To find the value of the DEVICE_PORT_LOCATION corresponding to the USB link, use the following command:

PC $> STM32_Programmer_CLI -l usb
     -------------------------------------------------------------------
                       STM32CubeProgrammer <tool version>                  
     -------------------------------------------------------------------

Total number of available STM32 device in DFU mode: 1

 Device Index           : USB1
 USB Bus Number         : 002
 USB Address Number     : 008
 Product ID             : USB download gadget@Device ID /0x500, @Revision ID /0x0000
 Serial number          : 0000000000
 Firmware version       : 0x0110
 Device ID              : 0x0500

You can then report the value returned by the command line as explained in the How to flash with STM32CubeProgrammer chapter. Pay attention that the value must be written in lower case.

5.5 How to explore all the partitions of a populated microSD card

A populated microSD card can contain more than eight partitions, exceeding the number of partitions allowed by default in a Linux system.
At insertion step, you may get an 'Error mounting /dev/mmcblk0p9' or 'mount: cannot mount /dev/mmcblk0p9 read-only' error message.
Screenshot ubuntu 16.04 mmc block 8.png

By adding some options to modprobe, it is possible to allow more than eight partitions on a storage device:

PC $> echo 'options mmc_block perdev_minors=16' > /tmp/mmc_block.conf
PC $> sudo mv /tmp/mmc_block.conf /etc/modprobe.d/mmc_block.conf

5.6 How to update partitions

For partial Flash memory update, the flashlayout.tsv must be edited to select only the partition that needs to be updated (first column =1).
See STM32CubeProgrammer_flashlayout#Updating partitions for details and example, the rest of the procedure is the same.

On ST boards, if FSBL or SSBL partitions need to be updated, the Bin2boot fields must be configured with ST binaries, as described in STM32CubeProgrammer_flashlayout#Updating partitions using official ST bootloaders.

5.7 How to populate a microSD card inserted in a Linux host PC

STMicroelectronics distribution is delivered with the create_sdcard_from_flashlayout.sh script that allows to prepare and flash a microSD card image.

Attachments

Discussions