2025-02-26 12:42 AM - last edited on 2025-02-26 1:01 AM by Andrew Neil
Hi,
I am currently working with the STM32L562E-DK Discovery board and attempting to flash Trusted Firmware-M (TF-M) samples on Zephyr using the STM32_Programmer_CLI tool.
However, I have encountered an issue during the flashing process.
Error Output:
(.venv) kurodash@ubuntu:~/zephyrproject/zephyr$ west flash -- west flash: rebuilding [0/15] Performing build step for 'tfm' ninja: no work to do. [2/3] Performing install step for 'tfm' -- Install configuration: "MinSizeRel" ----- Installing platform NS ----- [3/3] Completed 'tfm' -- west flash: using runner stm32cubeprogrammer ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Under Reset Reset mode : Hardware reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- Opening and parsing file: tfm_merged.hex Memory Programming ... File : tfm_merged.hex Size : 177.99 KB Address : 0x0C000000 Erasing memory corresponding to segment 0: Erasing internal memory sectors [0 22] Erasing memory corresponding to segment 1: Erasing internal memory sector 31 Erasing memory corresponding to segment 2: Erasing internal memory sectors [50 107] Erasing memory corresponding to segment 3: Erasing internal memory sectors [169 179] Download in Progress: Error: flash loader cannot be loaded. Error: failed to download Segment[0] Error: failed to download the File FATAL ERROR: command exited with status 1: /home/kurodash/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI --connect 'port=swd reset=HWrst' --download /home/kurodash/zephyrproject/zephyr/build/zephyr/tfm_merged.hex --start
Since the target is a Zephyr sample application, west flash is used for flashing. However, internally, the following command is actually executed:
/home/kurodash/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI --connect 'port=swd reset=HWrst' --download /home/kurodash/zephyrproject/zephyr/build/zephyr/tfm_merged.hex --start
west build -b stm32l562e_dk/stm32l562xx/ns samples/tfm_integration/tfm_ipc/ ./build/tfm/api_ns/regression.sh # west flash
/home/kurodash/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI --connect 'port=swd reset=HWrst' --download /home/kurodash/zephyrproject/zephyr/build/zephyr/tfm_merged.hex --start
Running the following command manually works fine, but west flash fails:
STM32_Programmer_CLI --connect port=swd reset=HWrst --erase all
OS: Ubuntu 24.04.1 LTS
Zephyr Version: 4.0
West version: v1.3.0
STM32CubeProgrammer version: 2.18.0
STM32L562E-DK Firmware version: V3J15M7
Additional Notes:
The board is correctly connected, and STM32_Programmer_CLI detects it without issues.
The samples/hello_world sample can be successfully flashed and executed.
west build completes successfully without errors.
The regression.sh script appears to execute without errors.
(.venv) kurodash@ubuntu:~/zephyrproject/zephyr$ ./build/tfm/api_ns/regression.sh regression script started Regression to RDP 0 and tzen=1 ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Under Reset Reset mode : Hardware reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% PROGRAMMING OPTION BYTES AREA ... Warning: Option Byte: rdp, value: 0xAA, was not modified. Warning: Option Byte: tzen, value: 0x1, was not modified. Warning: Option Bytes are unchanged, Data won't be downloaded Time elapsed during option Bytes configuration: 00:00:00.003 Remove bank1 protection and erase all ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Under Reset Reset mode : Hardware reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% PROGRAMMING OPTION BYTES AREA ... Warning: Option Byte: wrp1a_pend, value: 0x0, was not modified. Warning: Option Byte: wrp1a_pstrt, value: 0x7F, was not modified. Warning: Option Byte: wrp1b_pend, value: 0x0, was not modified. Warning: Option Byte: wrp1b_pstrt, value: 0x7F, was not modified. Bank : 0x00 Address : 0x50022040 Size : 40 Bytes Reconnecting... Reconnected ! UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% OPTION BYTE PROGRAMMING VERIFICATION: Option Bytes successfully programmed Time elapsed during option Bytes configuration: 00:00:02.153 Mass erase ... Mass erase successfully achieved Remove bank2 protection and erase all ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Under Reset Reset mode : Hardware reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% PROGRAMMING OPTION BYTES AREA ... Warning: Option Byte: wrp2a_pend, value: 0x0, was not modified. Warning: Option Byte: wrp2a_pstrt, value: 0x7F, was not modified. Warning: Option Byte: wrp2b_pend, value: 0x0, was not modified. Warning: Option Byte: wrp2b_pstrt, value: 0x7F, was not modified. Bank : 0x01 Address : 0x50022060 Size : 16 Bytes Reconnecting... Reconnected ! UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% OPTION BYTE PROGRAMMING VERIFICATION: Option Bytes successfully programmed Time elapsed during option Bytes configuration: 00:00:02.154 Mass erase ... Mass erase successfully achieved Remove hdp protection ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Hot Plug Reset mode : Software reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% PROGRAMMING OPTION BYTES AREA ... Warning: Option Byte: hdp1_pend, value: 0x0, was not modified. Warning: Option Byte: hdp1en, value: 0x0, was not modified. Warning: Option Byte: hdp2_pend, value: 0x0, was not modified. Warning: Option Byte: hdp2en, value: 0x0, was not modified. Warning: Option Bytes are unchanged, Data won't be downloaded Time elapsed during option Bytes configuration: 00:00:00.003 Set default OB 1 (dual bank, swap bank, sram2 reset, secure entry point, bank 1 full secure) ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Hot Plug Reset mode : Software reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% PROGRAMMING OPTION BYTES AREA ... Warning: Option Byte: dbank, value: 0x1, was not modified. Warning: Option Byte: secbootadd0, value: 0x180030, was not modified. Warning: Option Byte: sram2_rst, value: 0x0, was not modified. Warning: Option Byte: swap_bank, value: 0x0, was not modified. Bank : 0x00 Address : 0x50022040 Size : 40 Bytes Reconnecting... Reconnected ! UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% OPTION BYTE PROGRAMMING VERIFICATION: Option Bytes successfully programmed Time elapsed during option Bytes configuration: 00:00:02.153 Set default OB 2 (bank 2 full secure) ------------------------------------------------------------------- STM32CubeProgrammer v2.18.0 ------------------------------------------------------------------- ST-LINK SN : 00380025313751XXXXXXXXXX ST-LINK FW : V3J15M7 Board : STM32L562E-DK Voltage : 3.28V SWD freq : 8000 KHz Connect mode: Hot Plug Reset mode : Software reset Device ID : 0x472 Revision ID : Rev Z Device name : STM32L5xx Flash size : 512 KBytes (default) Device type : MCU Device CPU : Cortex-M33 BL Version : -- UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% PROGRAMMING OPTION BYTES AREA ... Bank : 0x01 Address : 0x50022060 Size : 16 Bytes Reconnecting... Reconnected ! UPLOADING OPTION BYTES DATA ... Bank : 0x00 Address : 0x50022040 Size : 40 Bytes [==================================================] 100% Bank : 0x01 Address : 0x50022060 Size : 16 Bytes [==================================================] 100% OPTION BYTE PROGRAMMING VERIFICATION: Option Bytes successfully programmed Time elapsed during option Bytes configuration: 00:00:02.154 regression script DoneAny insights on resolving this issue would be appreciated.