2025-12-17 7:16 PM - edited 2025-12-17 7:22 PM
I'm using STM32_Programmer_CLI software v.2.20.0 to program an ST Nucleo board (NUCLEO-C071RB).
I wish the software were better at automatically handling situations that make it fail.
For example, this command does work normally for uploading firmware to the board:
STM32_Programmer_CLI --connect port=swd --download firmware.elf --start
However, if you have enabled read-out protection (RDP) by setting RDP=0 in the option bytes, then it fails with "Error: failed to erase memory" (and for some reason, it prints that message twice). If read-out protection truly does prevent you from erasing, the software should be smart enough to detect that RDP is on and then turn it off temporarily. Instead, we have to manually ask the software to do that:
STM32_Programmer_CLI --connect port=swd -ob RDP=0xAA --download firmware.elf --start
Next, if you have enabled write protection for a relevant portion of flash, the software fails with the same "Error: failed to erase memory" error messages. It seems like it should be smart enough to temporarily disable write protection in order to make the download succeed. Instead, we have to manually ask the software to do that:
STM32_Programmer_CLI --connect port=swd -ob RDP=0xAA -ob WRP1A_STRT=0x3F -ob WRP1B_STRT=0x3F --download firmware.elf --start
Next, if your firmware disabled debugger access to the core by setting DBG_SWEN in FLASH->ACR, the software will fail with the error messages "Error: Unable to get core ID" and "Error: No STM32 target found! If your product embeds Debug Authentication, please perform a discovery using Debug Authentication". The software should just automatically use its connection to the target's RST pin to work around this, but it does not. I tried using "--hardRst" and/or "--rst" right after "port=swd", but it did not help. Instead, the workaround for this problem is that you must hold the Nucleo's RESET button down with your finger while starting the software, then release it after the software has started running and is waiting.
It kind of feels like the STM32_Programmer_CLI is a scripting language with some useful commands in them, but to achieve my end goals I need specialized knowledge of how STM32 chips are programmed, in order to figure out which commands to use and which order to put them in. I feel like the software would be more useful and enjoyable to use if it were a high-level program that allowed you to specify your goals in terms of the state of the microcontroller and its memory and then it takes care of all the details of making those goals happen, automatically handling situations that might interfere with that process.
I hope this post is useful to others working around these issues, and also that someone on the STM32CubeProgrammer team with decision-making authority sees it. Thanks!
2025-12-18 8:02 AM
Hello David,
Thank you for your input.
From a device and security perspective:
Read and write protections are essential to safeguard user data and device integrity. The additional step is intentionally designed so that the user authorizes sensitive operations, such as lowering the RDP level and to not perform these actions automatically by default to prevent unwanted operations.
For example, allowing STM32CubeProgrammer to automatically change from RDP 1 to RDP 0 erases the flash memory, which can result in unintentional data loss.
Regarding the second point, it is expected behavior for STM32CubeProgrammer to not allow debugger read access if DBG_SWEN is set to 0.
Another thing is that STM32CubeProgrammer already operates at a relatively high level. You could simply connect to an MCU and program or erase the memory.
In summary, disabling these options automatically reduces user control over the device, removes a crucial protection layer and renders protections ineffective. It is necessary to take into consideration device security, protection of intellectual property, and prevention of unwanted interference.
I hope this has cleared any misconceptions, feel free to ask any question on our community.
Best regards,
Kouthair