2026-03-31 3:45 AM - edited 2026-03-31 3:58 AM
Hi,
When I downloaded a .hex file to my STM32H563VGT6 (1MB Flash) using STM32CubeProgrammer v2.20.0, I encountered an issue where it would erase the wrong sector. For example, as shown in the image below, it was supposed to erase sectors (76..91) and sector 115, but I found that the contents of sector 27 is erased.
I also try to "Erase selected sectors" (76..116) manually, but sector 27 still be erased.
However, I did not have this problem when downloading the same .hex file using an STM32H563ZIT6 (2MB Flash).
Solved! Go to Solution.
2026-04-08 2:08 AM
Hi @Snaku,
The fix in STM32CubeProgrammer is planned, when that's done, you'll be able to resolve this by connecting in under reset mode (That way OEMiROT_boot won't be executed and won't interfere with STM32CubeProgrammer detecting the correct flash size => The correct sector indexes).
If I reproduce with OEMiROT_boot on my side and find a change to make that will resolve the issue, I'll let you know. With that being said, on the tool side, the correct behavior is what's happening in hotplug mode (We're connecting to the target that's running an application and that's by definition the hotplug mode, I don't think the tool will open additional memory regions if the running application hides them).
In any case, don't hesitate to comment if you find anything to improve on CubeH5 front as well, I'll be happy to transfer the request.
Kind regards,
Aziz
2026-03-31 7:00 AM
Hi @Snaku,
Thanks for highlighting this.
The issue exists in STM32CubeProgrammer for H5 1M devices when TZEN is enabled and in modes other than Hotplug (We're aware of this and actively investigating. Internal tracking number: 0036604).
Could you try using hotplug mode?
Aziz
2026-03-31 7:10 PM
Hi Aziz,
Thank you for your response.
As you mentioned, my TZEN setting is enabled.
However, even when I switch to Hot Plug mode to download .hex files, the problem persists.
Does this problem only exist in the STM32CubeProgramer GUI program? Does the STM32CubeProgramer CLI also have this issue? Are there any suggested workarounds?
Thank you.
Also, below are my option byte settings for your reference.
2026-04-01 2:20 AM
Hi @Snaku,
I tried erasing sectors 76 through 91 and sector 115 to try to reproduce what you're seing, but as expected, sector 27 ended up being erased only in modes other than hotplug. I suppose since you're seing a different behavior it means that either some action you're doing when navigating inside STM32CubeProgrammer is halting the CPU, or the running firmware (Since in hotplug mode the CPU is running) is interfering with this operation.
Could you first try the CLI and check if other sectors are being erased? If you encounter the same behavior, could you please share your hex file, or an example with dummy data containing the same segments as your hex file?
Aziz
2026-04-01 4:02 AM
Hi Aziz,
I can share the hex file, but I don’t think it’s necessary because I can reproduce the problem simply by erasing sectors [76 91] via STM32_Programmer_CLI.
> STM32_Programmer_CLI.exe -c port=SWD freq=4000 -e [76 91]
It is hard to say all sectors' status, but I see sectors 20 ~ 27 were erased.
Regards,
Snaku
2026-04-01 7:47 AM
Hi Snaku,
Could you try this and see if it's the same?
> STM32_Programmer_CLI.exe -c port=SWD mode=hotplug freq=4000 -e [76 91]
Aziz
2026-04-01 6:47 PM
Hi Aziz,
1. I find CLI using hot plug mode with software reset can't read the flash size
> STM32_Programmer_CLI.exe -c port=SWD mode=hotplug freq=4000 -e [76 91]
2. I change the reset mode to hardware reset, then the CLI can perform the erase command
> STM32_Programmer_CLI.exe -c port=SWD mode=hotplug reset=HWrst freq=4000 -e [76 91]
But the result is the same, sectors 20 ~ 27 erased by STM32_Programmer_CLI.
Regards,
Snaku
2026-04-02 1:37 AM
Hi @Snaku
It doesn't make sense to add the reset mode in hotplug since there's no reset. The second command you run is equivalent to connecting in normal mode with HW reset => It's normal to see the same behavior.
I didn't encounter the "Fail to read flash size" on my end, could you try again with the latest v2.22.0?
Thanks,
Aziz
2026-04-02 2:57 AM
Hi Aziz,
I switched to v2.22.0 CLI hotplug mode but couldn't execute erase.
Regards,
Snaku
2026-04-02 4:08 AM
Hi Snaku,
Thank you for the quick follow up and tests.
I can't reproduce this for now so let me investigate further and I'll get back to you if anything comes up.
Aziz