cancel
Showing results for 
Search instead for 
Did you mean: 

FLASH_EraseProgram example code for STM32CubeU3 not working. fails in erasing

rajathks
Associate II

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

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 

 

View solution in original post

4 REPLIES 4
TDK
Super User

FLASH_EraseProgram should not be called directly. Use HAL_FLASHEx_Erase as is done in the example programs like this one:

https://github.com/STMicroelectronics/STM32CubeU3/blob/453c7fafaeb4774b4b0f6e4f8486e7c183fc254e/Projects/NUCLEO-U3C5ZI-Q/Examples/FLASH/FLASH_EraseProgram/Src/main.c#L146

Show your code.

If you feel a post has answered your question, please click "Accept as Solution".

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

TDK
Super User

No such issues here running it in STM32CubeIDE. Are you loading it with the Example Selector in STM32CubeMX?

If you feel a post has answered your question, please click "Accept as Solution".

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