Question
Can't erase flash on STM32407VG Discovery
I'm a bit lost by this one. I can write to the flash but cannot erase a sector. I can erase sectors with the ST-Link Utility. The result codes at every step indicate success, but the flash is not actually erased. I am using the Standard Peripheral Library as follows (the status checks with while (true) are just part of the debugging effort):
void FlashDriver::erase_sector(uint8_t sector_index)
{
DisableInterrupts di;
// Unlock the Flash Program Erase controller
if (FLASH_GetStatus() != FLASH_COMPLETE)
while (true);
FLASH_Unlock();
// Clear pending flags (if any)
FLASH_ClearFlag(
FLASH_FLAG_EOP |
FLASH_FLAG_OPERR |
FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR |
FLASH_FLAG_PGPERR |
FLASH_FLAG_PGSERR
);
// Erase the given logical sector.
if (FLASH_GetStatus() != FLASH_COMPLETE)
while (true);
if (FLASH_EraseSector(sector_index, VoltageRange_3) != FLASH_COMPLETE)
{
...
}
if (FLASH_GetStatus() != FLASH_COMPLETE)
while (true);
FLASH_Lock();
}I'd be grateful for any insights on this one.
Al