cancel
Showing results for 
Search instead for 
Did you mean: 

Eeprom emulation cannot find ERASED_PAGE when all pages are full

twoaten
Associate II

Hi,

I'm porting "eeprom emulation" into STM32L476RG. It is based on "en.x-cube-eeprom".

I set GUARD_PAGES_NUMBER 4

When all eeprom pages are full, then it can't go forward.

EE_WriteVariable32bits() -> WriteVariable() -> EE_PAGE_FULL -> PagesTransfer() -> FindPage() -> EE_NO_PAGE_FOUND -> EE_ERROR_NOERASE_PAGE

So I dump and check all eeprom page's header, and there are below

ff ff ff ff ff ff ff ff aa aa aa aa aa aa aa aa

aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa

ff ff ff ff ff ff ff ff aa aa aa aa aa aa aa aa

aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa

ff ff ff ff ff ff ff ff aa aa aa aa aa aa aa aa

ff ff ff ff ff ff ff ff aa aa aa aa aa aa aa aa

aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa

aa aa aa aa aa aa aa aa ff ff ff ff ff ff ff ff

ff ff ff ff ff ff ff ff aa aa aa aa aa aa aa aa

aa aa aa aa aa aa aa aa ff ff ff ff ff ff ff ff

ff ff ff ff ff ff ff ff aa aa aa aa aa aa aa aa

ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff

Why it can not find erase page when all eeprom page full?

Why there is no erased page?

Thank you.

Best Regards.

3 REPLIES 3
arnold_w
Senior II

The following works for me:

        EE_Status ee_status = EE_OK;
        for (uint8_t j = 0; j < 10; j++) {
            if ((ee_status = EE_WriteVariable32bits( ...  )) == EE_OK) {
                break;
            } else {
                (void) EE_CleanUp();
            }
        }

StjepanS
Associate II

@arnold_w​  I would like to comment on your topic.

It will probably work, most of the time, but what if there was an error with writing into FLASH ?

You should use EE_CleanUp, only when function returns EE_CLEANUP_REQUIRED.

For other status, you should handle it with some error/ warning handler? maybe check flash flags if there is an error? maybe try to write again ?

So, I am proposing this code :

EE_Status ee_status = EE_OK;
for (uint8_t j = 0; j < 10; j++) 
{
   ee_status = EE_WriteVariable32bits( ...  ))
      if ((ee_status  == EE_OK) 
            {
         break;
            }
      else if(ee_status == EE_CLEANUP_REQUIRED)
      {
         ee_status  =  EE_CleanUp();
      }
      else
      {
         EEprom_Error_Handler(ee_status);
      }
}

If I remember correctly, I wrote a test case where I wrote enough data to fill all the allocated pages and then some more data, to enforce that copying into an already used page would occur. It consistently failed, meaning it wasn't some temporary flash write error. The returned error code was not EE_CLEANUP_REQUIRED, but through trial and error I found that calling EE_CleanUp() made it work reliably.