cancel
Showing results for 
Search instead for 
Did you mean: 

STLink CLI utility can't program option bytes

ALins.2
Associate II

Hi,

I'm trying to use the STLink CLI to reprogram option bytes on an STM32L4 MCU. The command is accepted, but doesn't reprogram the designed option:

'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe' -c port=swd mode=hotplug -ob BFB2=0
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.9.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 55FF64066684564930141187
ST-LINK FW  : V2J39S7
Board       : --
Voltage     : 3.35V
SWD freq    : 4000 KHz
Connect mode: Hot Plug
Reset mode  : Software reset
Device ID   : 0x470
Revision ID : Rev W
Device name : STM32L4Rxxx/STM32L4Sxxx
Flash size  : 2 MBytes
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : --
Debug in Low Power mode enabled
...
PROGRAMMING OPTION BYTES AREA ...
 
  Bank          : 0x00
  Address       : 0x40022020
  Size          : 20 Bytes
 
██████████████████████████████████████████████████ 100%
 
Reconnecting...
Reconnected !
 
 
UPLOADING OPTION BYTES DATA ...
 
  Bank          : 0x00
  Address       : 0x40022020
  Size          : 20 Bytes
 
██████████████████████████████████████████████████ 100%
 
  Bank          : 0x01
  Address       : 0x40022044
  Size          : 16 Bytes
 
██████████████████████████████████████████████████ 100%
 
OPTION BYTE PROGRAMMING VERIFICATION:
 
Error: Expected value for Option Byte "bfb2": 0x0, found: 0x1
Error: Option Byte Programming failed

Has anyone seen this, or know how to use the CLI utility to reprogram option bytes?

Thanks!

-Adam

6 REPLIES 6
TDK
Guru

Are other bits able to be written correctly in the CLI?

Does it work correctly in the GUI version of STM32CubeProgrammer?

If you power cycle the board, does it take the new value?

https://community.st.com/s/question/0D50X0000BUiruJSQR/option-bytes-programming-not-working

If you feel a post has answered your question, please click "Accept as Solution".
ALins.2
Associate II

Suddenly worse behavior. Attempting to connect with the CLI tool can't find the target. GUI also can't find the target to connect after using the CLI to try to connect.

& 'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe' -c port=swd -rst
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.9.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 55FF64066684564930141187
ST-LINK FW  : V2J39S7
Board       : --
Voltage     : 3.32V
Error: No STM32 target found!

But at this point, I can connect with JLink, which shows that the CPU is halted. After resetting the MCU with JLink, STM32CubProgrammer can connect to the target. (CLI can't connect, and using it prevents the GUI from finding the target.)

The MCU board has a reset button, wired into the MCU nRST pin. After using the STLink-V2 to try to connect, the reset button doesn't reset the MCU. After clearing reset with JLink, it does.

The STLink-V2 LED glows red the whole time. I suspected drivers, but as far as I can tell there is only one set of STLink drivers installed on this Windows 10 laptop. I have an STLink-V3 to try, and I can try from a mac later today.

I did try to reprogram the option bytes (IWDG_STOP) using the GUI after connecting. It was unable to change the value.

ALins.2
Associate II

This was unexpected: holding down the external reset button while the CLI command is executing let the CLI tool connect to the CPU. This doesn't always work. I added the dlpm option to the connect command. I have valid code loaded in bank #1 and bank #2, but I can't change the option byte to switch between them. Either the tool won't connect or if it does, the option byte is not reprogrammed.

PS> 'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe' -c port=swd mode=hotplug dlpm
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.9.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 55FF64066684564930141187
ST-LINK FW  : V2J39S7
Board       : --
Voltage     : 3.23V
SWD freq    : 4000 KHz
Connect mode: Hot Plug
Reset mode  : Software reset
Device ID   : 0x470
Revision ID : Rev W
Device name : STM32L4Rxxx/STM32L4Sxxx
Flash size  : 63 KBytes (default)
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : --
Debug in Low Power mode is not supported for this device.

Piranha
Chief II

When you cannot connect to the target, set the connection mode to "Connect Under Reset". Also it's safer to add LPM, which is also the default and therefore can be skipped.

mode=UR

The CLI says 'Debug in Low Power mode is not supported for this device.' I'm not sure if device means the STLink-V2 or the MCU.

The firmware puts the MCU into STOP2 mode often. In STOP2 mode, the CLI can't connect:

PS > & 'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe' -c port=swd mode=hotplug -score
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.9.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 55FF64066684564930141187
ST-LINK FW  : V2J39S7
Board       : --
Voltage     : 3.47V
Error: No STM32 target found!

If I force the MCU out of STOP2 mode by asserting nRST externally, then the CLI can connect:

PS > & 'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe' -c port=swd mode=hotplug -score
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.9.0
      -------------------------------------------------------------------
 
ST-LINK SN  : 55FF64066684564930141187
ST-LINK FW  : V2J39S7
Board       : --
Voltage     : 3.47V
SWD freq    : 4000 KHz
Connect mode: Hot Plug
Reset mode  : Software reset
Device ID   : 0x470
Revision ID : Rev W
Device name : STM32L4Rxxx/STM32L4Sxxx
Flash size  : 63 KBytes (default)
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : --
 
Core is kept under reset

When the STLink-V2 is physically connected to the target, the MCU can be held stopped after reset and STLink still can't connect to the MCU. JLink doesn't have a problem connecting.

> The CLI says 'Debug in Low Power mode is not supported for this device.' I'm not sure if device means the STLink-V2 or the MCU.

That feature just sets some bits in DBGMCU_CR register. The software probably shows that message just because it cannot connect and set those bits. As I said, you must try "Connect Under Reset", which pulls down NRST (is it connected to the ST-LINK?) automatically. J-Link does both of those things by default...