2023-05-04 12:27 AM - last edited on 2023-09-01 09:21 AM by Amel NASRI
Hi ST community,
First question for me here.... It is about an emulated eeprom issue
I try to save dta to an emulated eeprom.
Parameter are : starting dress : 0x800D00
page size 0x800
number of variable to be saved 37
guard page number =2
cycle life =1
I do manage to save and read from eeprom however, after a while (let's say between 500 and 1000 saving operations, the eeprom comes into the loop below and don't mnage to get out...
Would somebody knows why ? I assume my parameters are wrong but I can't figure it out ...
Thanks ,
Tjhe loop that blocks ...
pageadress takes the value 28 27 26 and then back to 28.
while ((pagestate == STATE_PAGE_ACTIVE) || (pagestate == STATE_PAGE_VALID) || (pagestate == STATE_PAGE_ERASING))
{
/* Set counter index to last element position in the page */
counter = PAGE_SIZE - EE_ELEMENT_SIZE;
/* Check each page address starting from end */
while (counter >= PAGE_HEADER_SIZE)
{
/* Get the current location content to be compared with virtual address */
addressvalue = (*(__IO EE_ELEMENT_TYPE*)(pageaddress + counter));
if (addressvalue != EE_PAGESTAT_ERASED)
{
/* Compare the read address with the virtual address */
if (EE_VIRTUALADDRESS_VALUE(addressvalue) == VirtAddress)
{
/* Calculate crc of variable data and virtual address */
crc = CalculateCrc(EE_DATA_VALUE(addressvalue), EE_VIRTUALADDRESS_VALUE(addressvalue));
/* if crc verification pass, data is correct and is returned.
if crc verification fails, data is corrupted and has to be skip */
if (crc == EE_CRC_VALUE(addressvalue))
{
/* Get content of variable value */
*pData = EE_DATA_VALUE(addressvalue);
return EE_OK;
}
}
}
/* Next address location */
counter -= EE_ELEMENT_SIZE;
}
/* Decrement page index circularly, among pages allocated to eeprom emulation */
page = PREVIOUS_PAGE(page);
pageaddress = PAGE_ADDRESS(page);
pagestate = GetPageState(pageaddress);
}
Solved! Go to Solution.
2023-05-10 12:32 AM
Hello,
If you have 37 variables to store and 2 guard pages you need in total 4 pages to manage your EEPROM variables.
Starting at address 0x0800D000 it corresponds to pages 25 to 28 to store your datas.
When the endless while loop occurs can you see the values of the headers of each page (25 26 27 &28)?
For the trial at address 0x08010000 I don't understand why there is this error message. If you are using a STM32G071 device you must have 30 free pages from 0X08010000 to the end of the flash, so there is no lack of space.
BR
Chloé
2023-05-10 12:43 AM
You also have to check if a cleanup is required . XCUBE-EEPROM firmware provide a code example to store 1000 times 3 variables :
/* Store 1000 values of Variable1,2,3 in EEPROM */
for (VarValue = 1; VarValue <= 1000; VarValue++)
{
while (ErasingOnGoing == 1) { }
ee_status = EE_WriteVariable32bits(1, VarValue);
ee_status|= EE_ReadVariable32bits(1, &a_VarDataTab[0]);
if (VarValue != a_VarDataTab[0]) {Error_Handler();}
ee_status|= EE_WriteVariable32bits(2, ~VarValue);
ee_status|= EE_ReadVariable32bits(2, &a_VarDataTab[1]);
if (~VarValue != a_VarDataTab[1]) {Error_Handler();}
ee_status|= EE_WriteVariable32bits(3, VarValue << 1);
ee_status|= EE_ReadVariable32bits(3, &a_VarDataTab[2]);
if ((VarValue << 1) != a_VarDataTab[2]) {Error_Handler();}
/* Start cleanup polling mode, if cleanup is needed */
if ((ee_status & EE_STATUSMASK_CLEANUP) == EE_STATUSMASK_CLEANUP) {ErasingOnGoing = 0;ee_status|= EE_CleanUp();}
if ((ee_status & EE_STATUSMASK_ERROR) == EE_STATUSMASK_ERROR) {Error_Handler();}
}
BR
Chloé
2023-05-17 02:22 AM
cleanup seems to solve the problem once I update
ee_status=
to
ee_status|=
thanks