2023-06-08 05:13 PM
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
Solved! Go to Solution.
2023-06-18 10:38 AM
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
2023-06-09 07:45 AM
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é
2023-06-09 07:56 AM
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
2023-06-09 08:09 AM
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é
2023-06-13 06:31 AM
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
2023-06-18 10:38 AM
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