cancel
Showing results for 
Search instead for 
Did you mean: 

flash_erase error: can not erase certain flash pages without error, however it is possible while debugging and stepping into every function

she-peek
Associate II

Hello,

I am currently writing a program that will delete the bootloader, which is stored in 24 flash pages (Bootloader begins at 0x08000000, the program itself begins at 0x800C000).

Pages 1-11 & 13-23 can be easily erased. Now the problem is, the page 0 and 12 cannot be erased without error.

Code goes like this (same for page 12):

flash_erase(0,1);

from flash_erase() into -->

HAL_FLASH_Unlock();

HAL_FLASHEx_Erase(&erase_param, &err) //erase_param contains the right page and bank

from HAL_FLASHEx_Erase(&erase_param, &err) into -->

    FLASH_PageErase(page_index, pEraseInit->Banks);

    /* Wait for last operation to be completed */

    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); //

That's where the program gets stuck. The page erase still worked, I can see it in the device memory. But there's this error that I can't track down any further.

This is the debug call stack:

Thread #1 [main] 1 [core: 0] (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)

0xfffffffe

<signal handler called>() at 0xfffffff1

0xfffffffe

<signal handler called>() at 0xfffffff9

HAL_FLASHEx_Erase() at stm32l4xx_hal_flash_ex.c:197 0x800fc4a

flash_erase() at flash.c:201 0x8015cb8

app_process() at sulpom_app.c:227 0x8015738

main() at main.c:121 0x800ce84

While debugging, I noticed that if I step into the function

FLASH_PageErase(page_index, pEraseInit->Banks)

the program does not get stuck and the flash pages are erased properly.

Can somebody help me find the cause of this error and help find a solution? Thank you all.

Best regards

EDIT: STM32L452

10 REPLIES 10
aliosmeen
Associate

I have used all of the suggestions but not worked. After that i tried to shorten the data cable like 10cm between ST-LINK V2 and STM32. Now it is working...