Skip to main content
abotha
Associate III
Oct 29, 2018 11:57 AM UTC
Question

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

This topic has been closed for replies.

3 replies

abotha
abothaAuthor
Associate III
Oct 30, 2018 2:15 PM UTC

I have figured out that the root cause of the failure is due to "HAL_Error" being returned from withing "Flash_WaitForLastOperation" which is called twice within HAL_Flash_Program.

After the HAL_Error if I call HAL_Flash_GetError I get error number 168, but I can't figure out what the number 168 means?

Flash_WaitForLastOperation 1 returned:1

Error Handler ..\Src\eeprom_emul.c at line 1480

Flash Write Status @987 Value:1 ee_status = 2

Flash Read Status @987 Value:1 ee_status = 0

Flash_WaitForLastOperation 2 returned:1 FlashError:168

Flash_WaitForLastOperation 2 returned:1 FlashError:168

The Error Handler is called from here:

 /* Program variable data + virtual address + crc */
 /* If program operation was failed, a Flash error code is returned */
 if (EE_FLASH_PROGRAM(activepageaddress+uwAddressNextWrite, EE_ELEMENT_VALUE(VirtAddress,Data,crc)) != HAL_OK)
 {
	 _Error_Handler(__FILE__, __LINE__);
	 return EE_WRITE_ERROR;
 
 }

ANaga.2
Associate III
Aug 27, 2020 8:25 AM UTC

Hi abotha,

I am facing the similar issue. EE_FLASH_PROGRAM is returning HAL error because FLASH->SR is set to 160. I am trying to write 32 bit data.

Could you please let me know if you have found the solution for this.

Bence
Associate II
Nov 26, 2020 7:50 AM UTC

Hi abotha,

Chip FLASH write operations are prone to errors. Clearing the error flags before writing can solve this problem.

E.g:

 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR |
 
 FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR |
 
 FLASH_FLAG_RDERR | FLASH_FLAG_OPTVERR);
 
 status = EE_WriteVariable32bits(addr, (uint32_t)*buf);
 
 /* Start cleanup IT mode, if cleanup is needed */
 
 if ((status & EE_STATUSMASK_CLEANUP) == EE_STATUSMASK_CLEANUP) {ErasingOnGoing = 1;status|= EE_CleanUp_IT();}
 
 if ((status & EE_STATUSMASK_ERROR) == EE_STATUSMASK_ERROR) {Error_Handler();}

​