Showing results for 
Search instead for 
Did you mean: 

How to Write Firmware and Start It Automatically by Using STM32_Programmer_CLI ? (USB DFU)

Associate II


I'm using STM32WB55 mcu. (USB DFU)

I write a simple program which runs STM32_Programmer_CLI multiple times with these arguments and than checking return code & CLI output If every step completed successfully.

1) Clearing nBoot0 and nSWBOOT0 bytes.   

    "-c port=usb sn=serialNumber -ob nBoot0=0x00 nSWBOOT0=0x00 -ob displ"

2) If user requested FUS and BLE stack update :

    "-c port=usb sn=serialNumber -fwdelete" and than

     "-c port=usb sn=serialNumber -r32 0x20030030 1"      to read FUS version.

     "-c port=usb sn=serialNumber -fwupgrade PathToFile 0x080EC000 firstinstall=0"   to update FUS

     "-c port=usb sn=serialNumber -fwupgrade PathToFile 0x080CE000 firstinstall=0" to update BLE stack.

3) Write my firmware.

    "-c port=usb sn=serialNumber -w  fwPath 0x08000000";

4) Set nBoot0 and nSWBOOT0 bytes.  

    "-c port=usb sn=serialNumber -ob nBoot0=0x01 nSWBOOT0=0x01 -ob displ",

I want my firmware start automatically after all these steps.

If I do it this way, sometimes it works and sometimes it doesn't. I'm probably doing something wrong. What is the correct way to do this?



Associate II

And if I try to "Mass Erase" by using this command "-c port=usb sn=SerialNumber -e all" i got an error

"Mass erase command is not available for WB devices..."

How can ı erase all user space in flash?

Lead II

Hello @traxformania 

I'm not an expert of CLI programming. But I think you should add this command: 


Also, you may find help reading this UM2237 specially chapter 3 and the part 3.2.22.

Best regards.




I've also had issue with this, but not on the WB series. I've found that simply connecting and disconnecting is a reliable way to start your firmware.

User space is configurable on the WB. There's an option byte that specifies the boundary. To erase the user portion, interpret the option byte and erase the relevant sectors.

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

Hello, thanks for your response.

Because I'm clearing nBoot0 and nSWBOOT0 bytes until I set them again my firmware does not start. If I call start command without setting those bytes device leaves bootloader mode but my firmware does not start.

If I set nBoot0 and nSWBOOT0 bytes my firmware immediately starts. (But ST's CLI app tries to reconnect and it timeout.)


The problem is that this doesn't always work. For example it fails 1 out of 10 times. So, I suspect that I'm doing something wrong. Is there a more consistent way to do this?

Edit: By the way I find a way to mass erase this device : Setting 'Read Protection Option Byte' to 'BB' and than 'AA'.