I was having the same problem. Changing “Reset mode” to “Hardware reset” on the ST-LINK configuration seems to have fixed it for me.
UM2237 on st.com, is the user guide for STM32 CubeProgrammer, which says this about the reset modes:
– Software system reset: Resets all the STM32 components except the debug via
the Cortex-M Application Interrupt and Reset Control Register (AIRCR).
– Hardware reset: Resets the STM32 device via the nRST pin. The RESET pin of the JTAG connector (pin 15) should be connected to the device reset pin.
– Core reset: Resets only the core Cortex-M via the Application Interrupt and Reset
Control Register (AIRCR).
I’m just getting started with STM32 so I can’t explain why software reset only works every other time, but hardware reset seems to work much more reliably.