STM32 microcontrollers have bootloader in system memory which is write-protected. This can be booted with right sequence, that I don't cover here.

ST provide more tools to upgrade firmware from bootloader that have DFU support. With DfuSeDemo.exe is possible to upgrade microcontroller even with enabled read protection. In shis case program ask if you want to remove read protection and than it downloads firmware to device.

I'm interested in automation of firmware updating, so I winder how to pass this requirement to command line.

DfuSeCommand.exe -c --al 0 -d --v --fn $dfuFlashFile

1 Answer 1


I use STM32CubeProgrammer instead of DfuSe because it has also CLI to remove read-out protection and upload new firmware using script.

STM32 microcontroller (μC) reads boot pin at start-up to start bootloader. If you have USB it will start DFU. Remember that with removing read-out protection the microcontroller will restart - it will again test boot pin to come back to bootloader.

Figure 41 on page 47/93 of User manual UM2237 STM32CubeProgrammer software description shows CLI commands.

01. Removing read protection

Note: Removing read-out protection clear (all) flash and reset μC.

To remove read-out protection use (section 3.2.15 in UM2237) following command:

STM32_Programmer_CLI -c port=usb1 -rdu

here keep boot pin on vcc to come back into bootloader (get back DFU). μC is now unprotected and erased!

-rdu option Remove memory's Read Protection by shifting the RDP level from level 1 to level 0.

02. Writing/downloading new firmware and verification

STM32_Programmer_CLI -c port=usb1 -w "firmware.elf" –verify

or .hex or whatever you have, STM32_Programmer will figure it out.

03. Setting read protection

You can also back protect μC by setting RDU in optionByte (section 3.2.17 in UM2237)

to test option bytes ability, run:

STM32_Programmer_CLI -c port=usb1 -ob displ

than use option byte name for setting protection level as you need

STM32_Programmer_CLI -c port=usb1 -ob rdp=0xBB

Carefull!! Level 2 read protection will lock your stm32 μC! Check documentation for your μC, usually 0xCC is level 2 protection, 0xBB is level 1 protection and 0xAA and others is level 0 protection (unprotected).

  • \$\begingroup\$ Use ./STM32_Programmer.sh on linux or /STM32_Programmer_CLI.exe on windows \$\endgroup\$
    – mitjajez
    Commented Jan 2, 2021 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.