cancel
Showing results for 
Search instead for 
Did you mean: 

First write to Flash using EEPROM Emulator fails.

SidPrice
Associate III

I am adding EEPROM emulation using the x-cube-eeprom package. On program startup I am calling EE_Init and I have traced the code through the checks for the flash to be used being erased, which it is. However, when the first element is written, the flash write fails. The error I see returned is "EE_WRITE_ERROR" in "SetPageState."

The package is being used on an STM32G070 Cube project. Perhaps I am missing some set up, I followed the instructions in AN4894 to set the user defines. Is there more setup required in CubeMx?

Sid

1 ACCEPTED SOLUTION

Accepted Solutions
SidPrice
Associate III

I have resolved my issue. Although AN4894 makes no mention of it, one needs to unlock the flash memory before using the EEPROM emulator, and then re-lock it once access is completed.

Pity this was not covered in the AppNote. I finally found it by examining one of the example projects.

Sid

View solution in original post

5 REPLIES 5
Chloe Meunier
ST Employee

Hello,

could you please share your configuration : START_PAGE_ADDRESS, CYCLES_NUMBER, GUARD_PAGES_NUMBER defined in eeprom_emul-conf.h please?

How many variables do you want to store?

Could you share also the code you developped to store your datas?

Thank you

Chloé

SidPrice
Associate III

Hello @Chloe Meunier​, thank you for responding.

/* Configuration of eeprom emulation in flash, can be custom */
#define START_PAGE_ADDRESS      0x0801e000U /*!< Start address of the 1st page in flash, for EEPROM emulation */
#define CYCLES_NUMBER           1U   /*!< Number of 10Kcycles requested, minimum 1 for 10Kcycles (default),
                                        for instance 10 to reach 100Kcycles. This factor will increase
                                        pages number */
#define GUARD_PAGES_NUMBER      2U   /*!< Number of guard pages avoiding frequent transfers (must be multiple of 2): 0,2,4.. */

I have a very small variable storage requirement, just a few variables so I set that to 100.

AT this point I have written any code to write the variables since I am testing the EE_Init operation is correct.

Sid

Chloe Meunier
ST Employee

Hello,

Ok you have a problem in step 2 of EE-Init() function if I understand well?

Your error is here :?

 /* Check if no active and no receive page have been detected */

 if (nbactivereceivepage == 0U)

 {

  /* Check if valid pages have been detected */

  if (nbvalidpage > 0U)

  {

   /* Check state of page just before first valid page.

   If it is erasing page, then page after last valid page shall be set

   to receiving state */

   if (GetPageState(PAGE_ADDRESS(PREVIOUS_PAGE(firstvalidpage))) == STATE_PAGE_ERASING)

   {

    if (SetPageState(FOLLOWING_PAGE(lastvalidpage), STATE_PAGE_RECEIVE) != EE_OK)

    {

     return EE_WRITE_ERROR;

    }

   }

  }

Chloé

Hello, it seems the forum lost my last reply :(

My error is returned from EE_Format:

    /* Format flash pages used for eeprom emulation in case no active, no receive, no valid pages are found */
    else
    {
      return EE_Format(EE_FORCED_ERASE);
    }

Sid

SidPrice
Associate III

I have resolved my issue. Although AN4894 makes no mention of it, one needs to unlock the flash memory before using the EEPROM emulator, and then re-lock it once access is completed.

Pity this was not covered in the AppNote. I finally found it by examining one of the example projects.

Sid