2025-11-26 3:58 PM - edited 2025-11-26 4:24 PM
Hello,
I am trying to erase flash bank 2 and then re-write with an incoming application. This appears to work that when I read back some of this sector it's changed to 0xFFFFFFFF, however when I restart or connect with STLINK it reads out as 0x00000000.
I only get errors if I try to write too fast after erasing flash and on POR the flash is read back as 0x00000000
I have tried unlocking flash and relocking after with
HAL_FLASHEx_Unlock_Bank2();
// erase
HAL_FLASHEx_Lock_Bank2();
// and or
HAL_FLASH_Unlock();
// erase here
HAL_FLASH_Lock();
voltage range is correct.
FLASH_EraseInitTypeDef erase_init;
erase_init.TypeErase = FLASH_TYPEERASE_SECTORS;
erase_init.Sector = 0;
erase_init.NbSectors = 1;
erase_init.Banks = FLASH_BANK_2;
erase_init.VoltageRange = FLASH_VOLTAGE_RANGE_3;
HAL_FLASHEx_Erase(&erase_init, §or_error);
any suggestions or help would be appreciated
2025-11-26 4:41 PM
> when I restart or connect with STLINK it reads out as 0x00000000
Can you show a screenshot of where/how you're reading this out? 0 may indicate an error during reading rather than the actual value being read. Perhaps an ECC error.
HAL_FLASHEx_Erase returns HAL_OK?
No bank swapping enabled? SWAP_BANK=0?
The code presented looks fine.