Internal flash failing after 60 - 70 erase/write cycles
Hi,
I am currently facing an issue on a STM32F469NI MCU where the HAL_FLASH_PROGRAM() is succeeding yet fails to write to the flash memory.
I have verified this with a basic project for the STM32F469Discovery to isolate hardware. It appears that after 60 - 70 cycles of erasing a sector and writing words the flash write does not actually commit anything. The sector can only be recovered into a writable state if a full chip erase is performed through the ST-Link Utility. When the MCU is in this fail state there are no flags set in the registers (no error and program complete) and the HAL_FLASH_PROGRAM() returns HAL_OK. If the address is read either through a memory viewer or during code execution the memory address is still in the reset (erased) state.
Here is the test code:
const uint32_t dataToProgram = 0x54329876;
const uint32_t sect23Addr = 0x81E0000;
while(1)
{
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_FLASH_Unlock();
uint32_t u32SectorErr = 0;
FLASH_EraseInitTypeDef tDef;
tDef.TypeErase = FLASH_TYPEERASE_SECTORS;
tDef.Banks = 0;
tDef.NbSectors = 1;
tDef.Sector = 23;
tDef.VoltageRange = FLASH_VOLTAGE_RANGE_4;
if (HAL_FLASHEx_Erase(&tDef, &u32SectorErr) != HAL_OK)
{
ErrorHandler();
}
HAL_FLASH_Lock();
HAL_FLASH_Unlock();
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, sect23Addr, dataToProgram) != HAL_OK)
{
ErrorHandler();
}
HAL_FLASH_Lock();
uint32_t data = (*(volatile uint32_t*)sect23Addr);
if(data != dataToProgram)
{
ErrorHandler();
}
}The test always fails on the data comparison, all HAL functions return OK with no error flags in FLASH->SR.
Thanks in advance.
Jack
