STM32FLASH(1) | User command | STM32FLASH(1) |
stm32flash - flashing utility for STM32 through UART or I2C
stm32flash [-cfhjkouvCR] [-a bus_address] [-b baud_rate] [-m serial_mode] [-r filename] [-w filename] [-e num] [-n count] [-g address] [-s start_page] [-S address[:length]] [-F RX_length[:TX_length]] [-i GPIO_string] [tty_device | i2c_device]
stm32flash reads or writes the flash memory of STM32.
It requires the STM32 to embed a bootloader compliant with ST application note AN3155 or AN4221. stm32flash uses the serial port tty_device or the i2c port i2c_device to interact with the bootloader of STM32.
This feature is currently available on Linux host only.
As explained in ST application note AN2606, after reset the STM32 will execute either the application program in user flash or the bootloader, depending on the level applied at specific pins of STM32 during reset.
STM32 bootloader is automatically activated by configuring the pins BOOT0="high" and BOOT1="low" and then by applying a reset. Application program in user flash is activated by configuring the pin BOOT0="low" (the level on BOOT1 is ignored) and then by applying a reset.
When GPIO from host computer are connected to either configuration and reset pins of STM32, stm32flash can control the host GPIO to reset STM32 and to force execution of bootloader or execution of application program.
The sequence of GPIO values to entry to and exit from bootloader mode is provided with command line option -i GPIO_string.
The format of GPIO_string is:
sequence = [[-]signal]&|,[sequence]
In the above sequences, negative numbers correspond to GPIO at "low" level; numbers without sign correspond to GPIO at "high" level. The value "n" can either be the GPIO number on the host system or the string "rts", "dtr" or "brk". The strings "rts" and "dtr" drive the corresponding UART's modem lines RTS and DTR as GPIO. The string "brk" forces the UART to send a BREAK sequence on TX line; after BREAK the UART is returned in normal "non-break" mode. Note: the string "-brk" has no effect and is ignored.
The ',' delimiter adds 100 ms of delay between signal toggles, whereas the '&' delimiter adds no delay. An empty signal, thus repeated ',' delimiters, can be used to insert larger delays in multiples of 100 ms. E.g. "rts,,,,-dtr" will set RTS, then wait 400 ms, then reset DTR. "rts&-dtr" will set RTS and reset DTR without delay. You can use ',' delimiters alone to simply add a delay between opening port and starting to flash.
Note that since version 0.6, an exit sequence will always be executed if specified, regardless of the -R option, to ensure the signals are reset. If -R is specified, but no exit sequence, a software-triggered reset will be performed.
As an example, let's suppose the following connection between host and STM32:
In this case, the sequence to enter in bootloader mode is: first put GPIO_4="high" and GPIO_5="low"; then send reset pulse by GPIO_3="low" followed by GPIO_3="high". The corresponding string for GPIO_string is "4,-5,-3,3".
To exit from bootloader and run the application program, the sequence is: put GPIO_4="low"; then send reset pulse. The corresponding string for GPIO_string is "-4,-3,3".
The complete command line flag is "-i 4,-5,-3,3:-4,-3,3".
STM32W uses pad PA5 to select boot mode; if during reset PA5 is "low" then STM32W will enter in bootloader mode; if PA5 is "high" it will execute the program in flash.
As an example, suppose GPIO_3 is connected to PA5 and GPIO_2 to STM32W's reset. The command:
Another example, introducing a delay after port opening. The command:
Get device information:
stm32flash /dev/ttyS0
Write with verify and then start execution:
stm32flash -w filename -v -g 0x0 /dev/ttyS0
Read flash to file:
stm32flash -r filename /dev/ttyS0
Start execution:
stm32flash -g 0x0 /dev/ttyS0
Specify:
Flash images provided by ST or created with ST tools are often in file format Motorola S-Record. Conversion between raw binary, intel hex and Motorola S-Record can be done through software package SRecord.
The original software package stm32flash is written by Geoffrey McRae and is since 2012 maintained by Tormod Volden. See AUTHORS file in source code for more contributors.
Man page and extension to STM32W and I2C are written by Antonio Borneo.
Please report any bugs at the project homepage http://stm32flash.sourceforge.net .
srec_cat(1), srec_intel(5), srec_motorola(5).
The communication protocol used by ST bootloader is documented in following ST application notes, depending on communication port. The current version of stm32flash only supports UART and I2C ports.
Boot mode selection for STM32 is documented in ST application note AN2606, available from the ST website:
http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
stm32flash is distributed under GNU GENERAL PUBLIC LICENSE Version 2. Copy of the license is available within the source code in the file gpl-2.0.txt.
March 2022 | stm32flash |