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
Solved! Go to Solution.
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.
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.
2025-11-27 2:44 PM - edited 2025-11-27 3:03 PM
Hi TDK,
I thought it was resolved by disabling an ISR, as it worked 1 time. But now appears to fail again
I check memory in cortex-debug memory view and STLINK
if I step through the code memory appears to erase and write correctly in cortex-debug. But when I disconnect and open STLINK it reads all 0x00000000 (I'm erasing sector 0 in bank 2)
But I am starting to think it's just STLINK failing to read for some reason as when I restart and read out the memory in code it appears to be correct.