@pretoriandave wrote:
Many thanks @mƎALLEm , great service as ever. I think there may be an important distinction in here that we should bottom out, as I think it might warrant a tweak to AN4898 and/or the headers in eeprom_emul.c as they seem to be at odds...
I think what I'm gathering from the team's response is that, despite the function name, EE_Format is not how one should first format the EEPROM emulation space. In any case, without my tweak, you can't, since the CRC block is not clocked.
The response above is that calling EE_Init is mandatory after each reset and I presume that includes the very first time the MCU is powered after programming too. In other words, one should use the following to first format the EEPROM space..
EE_Init(EE_FORCED_ERASE)
By contrast, the header of eeprom_emul.c says:
(#) EEPROM emulation initialization functions:
(++) Format the FLASH pages used by EEPROM emulation using EE_Format().
This function is optionally used, it can be called the very first
time EEPROM emulation is used, to prepare FLASH pages for EEPROM
emulation with empty EEPROM variables. It can also be called at
any time, to flush all EEPROM variables.
(++) Initialize EEPROM emulation, and restore the FLASH pages used by
EEPROM emulation to a known good state in case of power loss
using EE_Init(). It must be performed at system start up.
The header suggests that EE_Format can be used to format the EEPROM space the first time the MCU is powered and the function name certainly supports that view. That is how I first did it and it didn't work for the reasons already stated. 'It can be called the very first time EEPROM emulation is used'. No it can't.
My use-case is that I am storing calibration parameters in the EEPROM emulation space which are determined the very first time the MCU is powered up, at end of line testing. The MCU is powered up, EE_Format called, the measurements made (actually Time of Flight device calibration), and the results stored.
The headers say that's fine but in fact it can't work. So, please, which should it be, EE_Init or EE_Format? It's really not clear and it's certainly not clear that in fact EE_Format cannot be used. If the answer is EE_Init then what use is EE_Format anyway? It seems that EE_Init(EE_FORCED_ERASE) is always the preferred choice.
Sorry to labour the point but the documentation isn't clear and I'd like to contibute to it being improved to save other developers any wasted time. Many thanks
Hello @pretoriandave ,
This is an internal feedback regarding your last one:
As you correctly mentioned :
(++) Initialize EEPROM emulation, and restore the FLASH pages used by
EEPROM emulation to a known good state in case of power loss
using EE_Init(). It must be performed at system start up.
Since it must be performed at system start up, this is the first thing that needs to be called in order to setup the EEPROM Emulation mechanism.
Regarding the "it can be called the very first time EEPROM emulation is used, to prepare FLASH pages for EEPROM emulation with empty EEPROM variables."
-> that means that you can call it anytime when you're using the EEPROM emulation, but if there is no init the EEPROM Emulation can't be used (as a lot of peripherals or software mechanism).
But I can understand how you could have been misled by the header of the Format function.
Now regarding your question about the use of the Format function, you may want to flush your data or format your data without the need of a new initialization, since the init is supposed to be called at system startup and then you don't need to.