2019-11-26 07:27 AM
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
2019-11-26 06:09 PM
Does RCC->CSR say anything about the source of the reset?
2019-11-27 05:16 AM
@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.
2019-11-27 05:53 AM
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.