STM32L4xx EEPROM Emulation Library No Active Page
Good Day
I am having some issues with the software EEPROM Emulation Library for the STM32L433.
Every couple of minutes I save a few system parameters to the virtual EEPROM.
Many times this operations fails, and EE_ERROR_NOACTIVE_PAGE is returned.
I do check for "Cleanup Required" which should switches pages as I undestand.
How do I force the library to do a cleanup or find an appropriate page?
The function below is what I call to save 32bit variables.
void save32BitToFlash(uint16_t Address, uint32_t Value)
{
uint32_t VarValue = 0;
ee_status = EE_OK;
ee_status = EE_ReadVariable32bits(VirtAddVarTab[Address], &VarValue);
char temp[100];
if (VarValue != Value) // Flash Update Required
{
HAL_FLASH_Unlock();
/* Wait any cleanup is completed before accessing flash again */
if (ErasingOnGoing == 1)
{
debugString(DUSB,"Flash ErasingOnGoing...\r\n");
while (ErasingOnGoing == 1) {}
}
ee_status = EE_WriteVariable32bits(VirtAddVarTab[Address], Value);
ee_status|= EE_ReadVariable32bits(VirtAddVarTab[Address], &VarValue);
if (VarValue != Value)
{
sprintf(temp, "Flash Write 32bit Error @ Address:%d Value:%lu - ee_status = %d - Retrying\r\n",Address,Value , ee_status);
debug(temp);
ee_status = EE_WriteVariable32bits(VirtAddVarTab[Address], Value);
ee_status|= EE_ReadVariable32bits(VirtAddVarTab[Address], &VarValue);
if (VarValue != Value)
{
sprintf(temp, "Flash Write 32bit Retry Error too - ee_status = %d\r\n", ee_status);
debug(temp);
}
}
/* Start cleanup IT mode, if cleanup is needed */
if ((ee_status & EE_STATUSMASK_CLEANUP) == EE_STATUSMASK_CLEANUP)
{
debug("Flash Cleanup Required\r\n");
ErasingOnGoing = 1;
ee_status|= EE_CleanUp_IT();
}
if ((ee_status & EE_STATUSMASK_ERROR) == EE_STATUSMASK_ERROR)
{
debug("Flash EE_STATUSMASK_ERROR\r\n");
Error_Handler();
}
//HAL_FLASH_Lock();
}
}This is the console output - Indicating frequent errors, sometimes on the second try it succeeds, sometimes it doesn't.
Flash Write 32bit Error @ Address:87 Value:42 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:3 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:11 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Float Write Error - Retrying
Flash Float Write Error - Retrying
Flash Write 32bit Error @ Address:26 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:31 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:32 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:33 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:35 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Error @ Address:36 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Error @ Address:40 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:41 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:42 Value:1 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3
Flash Write 32bit Error @ Address:87 Value:42 - ee_status = 3 - Retrying
Flash Write 32bit Retry Error too - ee_status = 3