Skip to main content
Visitor II
December 15, 2021
Question

STLink CLI utility can't program option bytes

  • December 15, 2021
  • 4 replies
  • 5099 views

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

    This topic has been closed for replies.

    4 replies

    Super User
    December 15, 2021

    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

    ALins.2Author
    Visitor II
    December 15, 2021

    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.2Author
    Visitor II
    December 15, 2021

    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.

    Graduate II
    December 17, 2021

    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

    ALins.2Author
    Visitor II
    December 17, 2021

    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.

    Graduate II
    December 20, 2021

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