2018-09-03 11:43 AM
Hello guys.
I have two int variables in my application and need to save them. Somebody told me that you can do this by software that is called EEPROM emulation. I searched what it is and I'm confused.
Can anyone help me do it step by step? (If you can tell me how to do it with HAL drivers I would appreciate that.)
2018-09-15 02:49 PM
As a good example see the Silicon Labs "Persistent Store" API, it uses a similar approach.
https://www.silabs.com/documents/login/reference-manuals/Bluetooth_Smart_Software-BLE-1.6-API-RM.pdf from page 165.
It shouldn't be too hard to copy it. Key points - it allows to store limited number of pieces of limited size (up to 64 bytes) and automatically manages updating of the pieces and garbage collection.
-- pa
2018-09-22 01:05 PM
I read the example provided for STM32F4-Discovery board.
There are some parts that I don't understand.
In this example there are three variables:
uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};
uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};
uint16_t VarValue,VarDataTmp = 0;
The first one is the virtual address of 3 variables. When each word (32bit) of the flash memory has a specific address why do we have to define virtual address? I don't even know what is a virtual address?
The other variables I don't know is the VarDataTab and VarDataTmp ?What are Tab and Tmp stands for?
2018-09-22 03:01 PM
If you could use FLASH you wouldn't use EEPROM Emulation.
The emulation implements a journalling scheme, ie keeps writing in a circle, erasing one of the ping-pong buffers only as necessary.
It doesn't use physically addressing, but looks to a matching tag, the tag in this case is the Virtual Address that you're pretending to write a value too. When you do a read request it goes and grabs the most current tag from the journalled space.
2018-09-23 09:22 AM
OK thanks.
So if the virtual address is something symbolic ,it won't be important what virtual address we assign to each variable,will it?I mean the virtual address could be 0x0000 or 0x1256 or ... .The example has assigned 0x5555 and 0x6666 just for the ease of use ?
2018-09-23 09:49 AM
Correct
The example is purely illustrative, the patterns work well if you inspect the memory space.
My preference is to create a structure of values, with a CRC, and journal that across a FLASH sector.
I'd be wary of writing to the "EEPROM" in a continuous fashion, as the FLASH does have a finite life and gets slower over time.
For things with continuous requirements use on-board NVRAM/BKPRAM, or place an external EEPROM device, or external RTC with storage.
2018-09-30 02:12 PM
I downloaded the code sample for stm32f4 EEPROM emulation and used it with my stm32f217 MCU and it worked properly and I was so happy.But I added the same files to the stm32f0 project and there was a lot of errors :sad_but_relieved_face: .
I searched and I found EEPROM .c in st.com for stm32f0 and I was happy again, so I added the c file and oops lots of errors again.I found the the file is not generated for HAL drivers. So I tried just adding some variables and functions from flash.c to HAHAL_FLASH.c errors are gone, but the function write is not working. Just read function is working.
Can someone help me? I do not have time to start learning CMSIS. I can work with the CMSIS functions, but I don't know how to initialize the clock and other basic configurations that CUBE did it for me.
2018-09-30 02:28 PM
eepromstexample is the st using CMSIS and the eepromemulation2 is my cube created project and the changes are in the stm32f0xx_HAL_Flash.c and stm32f0xx_HAL_Flash.h.
I coppied the FLASH_PageErase from stm32f0xx_Flash.c to stm32f0xx_HAL_Flash.c.And copied
typedef enum
{
FLASH_BUSY = 1,
FLASH_ERROR_WRP,
FLASH_ERROR_PROGRAM,
FLASH_COMPLETE,
FLASH_TIMEOUT
}FLASH_Status;
from stm32f0xx_Flash.h to stm32f0xx_HAL_Flash.h.
2018-09-30 02:29 PM