Showing results for 
Search instead for 
Did you mean: 

Flash_EraseProgram example for Nucleo-G070RB hangs


Hello, I need to save data to the internal flash memory of my device. Naturally, I have opened the example that comes with the stm32cube for stm32g0 series. More specifically, I have compiled it for Nucelo-g070rb under System Workbench for stm32.

The example gets stuck on different places, depending on the optimization level. For no optimization, it jumps from HAL_FLASHEx_Erase to some invalid address and then halts.

For other optimization levels, it seemingly gets stuck on "BSP_LED_On(LED4);" (line 210), which should turn on when no error was detected during the process...

The debugger also runs into problems when this happens, stating the device was disconnected.

I have tried reducing the size of the erased memory to just a few pages and have also checked some of the addresses the example attempts to write to against the datasheet. It seems alright...

The code is the "FLASH_EraseProgram" example. I cannot append it due to size restrictions of this post. Here is the pastebin link. Thank you very much for your help!


Are you erasing flash pages in use by your program?

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

Aha! That was it! I have only tried to reduce the erased space, but it actually seems like the example is trying to erase the memory where the program is stored!

#define FLASH_USER_START_ADDR  (FLASH_BASE + (20 * FLASH_PAGE_SIZE))  /* Start @ of user Flash area */

#define FLASH_USER_END_ADDR    FLASH_BASE+(25*FLASH_PAGE_SIZE)-1//(FLASH_BASE + FLASH_SIZE - 1)  /* End @ of user Flash area */

^-- this works! There is an error in the example... Thanks for your help!