2026-03-19 3:35 AM
I am running the FLASH_EraseProgram example code provided by STM32CubeU3. the code fails in erasing the flash and enters ErrorHandler.
I have verified the FLASH_USER_START_ADDR & FLASH_USER_END_ADDR. it is set as follows.
#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_128 /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR (ADDR_FLASH_PAGE_255 + FLASH_PAGE_SIZE - 1) /* End @ of user Flash area */
I have tested in both debug and run mode, it is not working as expected. Is anything to be modified to run the code.
regards,
Rajath
Solved! Go to Solution.
2026-03-19 6:23 AM
Hi TDK,
I resolved the issue. I reset the option bytes to default factory settings. I think the wrong bank was selected in option byte.
Also observed setting breakpoint in code is affecting the flash erase operation.
Thanks for the help!!
regards,
Rajath
2026-03-19 5:48 AM
FLASH_EraseProgram should not be called directly. Use HAL_FLASHEx_Erase as is done in the example programs like this one:
Show your code.
2026-03-19 5:58 AM - edited 2026-03-19 5:58 AM
Hi TDK,
I am using the following example code in STM32CubeU3 without any changes.
Projects/NUCLEO-U385RG-Q/Examples/FLASH/FLASH_EraseProgram
The program does not work properly, Flash page erase fails with PGSERR .
regards.
Rajath
2026-03-19 6:10 AM
No such issues here running it in STM32CubeIDE. Are you loading it with the Example Selector in STM32CubeMX?
2026-03-19 6:23 AM
Hi TDK,
I resolved the issue. I reset the option bytes to default factory settings. I think the wrong bank was selected in option byte.
Also observed setting breakpoint in code is affecting the flash erase operation.
Thanks for the help!!
regards,
Rajath
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.