cancel
Showing results for 
Search instead for 
Did you mean: 

Erasing a flash sector not in the app region resets CPU in STM32F437

0xBADC0DE
Associate

Using STM32F437 (internal flash 2MBytes).

I have a boot application located in sectors 0 - 5 (up to 256KB), and another application located in sectors 6-10 (in linker script I allow up to sector 10 which means up to 640KB, but the binary itself takes less than 256KB).

I use a function which erases sector 11 in flash.

When I run it from boot it works fine. When I run it from the application it causes a CPU reset (immediate, not a watchdog, and I couldn't catch any exception there).

The same order of unlock/lock, interrupts enable/disable, flag clearing etc. is run in both applications.

In the map file I can't see any code even close to the erased sector.

When I compile it in debug and try to debug it, I see it resets while running FLASH_WaitForLastOperation() from the HAL, but sometimes, if I wait enough time before stepping into this function, it works fine.

I tried changing the sectors (10, 11, even changed to the second bank - 12, 23) but the result is the same.

During the erase itself interrupts are disabled.

Any idea what can cause it?

Thanks

3 REPLIES 3
TDK
Guru

Does RCC->CSR say anything about the source of the reset?

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

@TDK​ 

Thanks! you've pointed me to the right place.

RCC->CSR = 0x44000000.

The matching reset flags are RCC_FLAG_PINRST and RCC_FLAG_WWDGRST.

The problem was that Window watchdog was active in this application, and since the interrupt was disabled and it did not refresh it reset the CPU.

It's disabled in the boot application so there it worked.

Ozone
Lead

Instruction fetch from Flash stall during Flash operations in the same bank (not sector).

You can execute parts of flashing your code from RAM if necessary.