Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

west flash Fails on STM32L562E-DK Only for TF-M Samples with STM32CubeProgrammer #86605

Open
JarmouniA opened this issue Mar 4, 2025 · 1 comment
Assignees
Labels
area: Flashing bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: low Low impact/importance bug

Comments

@JarmouniA
Copy link
Collaborator

JarmouniA commented Mar 4, 2025

Discussed in #85728

Originally posted by kurodash February 13, 2025
Hi,

I am following the document below to build and flash the tfm_integration/tfm_ipc sample on the STM32L562E-DK Discovery board:
[STM32L562E-DK Discovery].

However, I encountered an error when running west flash, which uses the STM32CubeProgrammer runner for flashing the code.

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

Commands Used:

west build -b stm32l562e_dk/stm32l562xx/ns samples/tfm_integration/tfm_ipc/
./build/tfm/api_ns/regression.sh
west flash

Running the following command manually works fine, but west flash fails:

STM32_Programmer_CLI --connect port=swd reset=HWrst --erase all

Environment Details:

  • OS: Ubuntu 24.04.1 LTS
  • Zephyr Version:
VERSION_MAJOR = 4
VERSION_MINOR = 0
PATCHLEVEL = 99
VERSION_TWEAK = 0
EXTRAVERSION =
  • 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.
  • west -vvv flash produces the following output:
=== Traceback (enabled by -vvv):
Traceback (most recent call last):
  File "/home/kurodash/zephyrproject/.venv/lib/python3.12/site-packages/west/app/main.py", line 561, in run_command
    self.run_extension(args.command, argv)
  File "/home/kurodash/zephyrproject/.venv/lib/python3.12/site-packages/west/app/main.py", line 716, in run_extension
    self.cmd.run(args, unknown, self.topdir, manifest=self.manifest,
  File "/home/kurodash/zephyrproject/.venv/lib/python3.12/site-packages/west/commands.py", line 194, in run
    self.do_run(args, unknown)
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/flash.py", line 33, in do_run
    do_run_common(self, my_args, runner_args, domain_file=domains_file)
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/run_common.py", line 331, in do_run_common
    prev_runner = do_run_common_image(command, user_args, user_runner_args, used_cmds,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/run_common.py", line 506, in do_run_common_image
    runner.run(command_name)
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/runners/core.py", line 720, in run
    self.do_run(command, **kwargs)
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/runners/stm32cubeprogrammer.py", line 247, in do_run
    self.flash(**kwargs)
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/runners/stm32cubeprogrammer.py", line 301, in flash
    self.check_call(cmd + flash_and_run_args)
  File "/home/kurodash/zephyrproject/zephyr/scripts/west_commands/runners/core.py", line 864, in check_call
    subprocess.check_call(cmd, **kwargs)
  File "/usr/lib/python3.12/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/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']' returned non-zero exit status 1.
  • 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 Done

Any insights on resolving this issue would be appreciated.

Additional Context
After downgrading STM32CubeProgrammer to v2.17.0, the writing process completed without errors, and the TF-M sample was able to start. It seems that STM32CubeProgrammer v2.18.0 has some issues.

(.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.17.0                  
      -------------------------------------------------------------------

ST-LINK SN  : 00380025313751XXXXXXXXXX
ST-LINK FW  : V3J15M7
Board       : STM32L562E-DK
Voltage     : 3.29V
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  : --



Memory Programming ...
Opening and parsing file: tfm_merged.hex
  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:
[==================================================] 100% 

File download complete
Time elapsed during download operation: 00:00:17.755

RUNNING Program ... 
  Address:      : 0x8000000
Application is running, Please Hold on...
Start operation achieved successfully
@erwango erwango added bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug labels Mar 4, 2025
@erwango
Copy link
Member

erwango commented Mar 4, 2025

Taking it as a bug for tracking, but there is not much that we'll able to do if this is a stm32cubeprogrammer issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Flashing bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

2 participants