2013-12-11 11:54 AM
I am attempting to erase a FLASH sector, but the process hangs. Any ideas on why this might be happening?
FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); sector = GetSector(addr); if (FLASH_EraseSector(sector, VoltageRange_3) != FLASH_COMPLETE) { // error (flash,erase); FLASH_Lock(); return 1; } #stm32f4 #flash #flash-erase-watchdog2014-06-09 12:37 PM
<< Here's the thing that seems weird to me: How can the function FLASH_WaitForLastOperation do anything at all? >>
If you have a hardware watchdog running while you erase the flash then you need to run the flash erase routine from SRAM, which doesn't stall. Once the erase starts there's a polling loop along with periodic watchdog resets as needed. FLASH_WaitForLastOperation() is called from RAM to make sure a prior operation is done before the next flash command. Jack Peacock2014-06-11 04:25 AM
Thanks for the response Jack. Obviously there is something here I still don't understand ... who says that FLASH_WaitForLastOperation() is called from RAM? How the heck do I ... put that function in RAM and run it there? There must be some method of copying code from flash to RAM and then running that code in RAM but I have not seen that described.
From what I can see in the documentation any timers are still going to run while in this wait state including the watchdog timer, right? I imagine one would either halt the watchdog timer or give it an extra big kick before starting a flash erase or flash write activity, yes?Thanks.Mike2014-06-11 07:12 AM
The catch is the IWDG can't be stopped, and it will time out if you are doing a large multi-sector erase. If you use IWDG you have to erase from a RAM routine.
You can search the forum for ways to load code into RAM. They are dependent on compiler and IDE. The general principle is the same C runtime startup that initializes variables also copies code sections into RAM. Jack Peacock