2017-12-26 01:51 AM
Hello everyone,
I wish to store a variable in flash memory untouched which will be changed only once but I can read or write it anytime I want, how is that possible? I do not wish to use the ROM unless there is no way around.
Thank you in advance
#stm32-flash-memory #stm-32 #stm32l02017-12-26 02:53 AM
A memory which keeps data after reset or power off/on are non volatile memories.
If you want just small amount of data, use EEPROM (electrically erasable ROM).
Some STM32 have built-in EEPROM (STM32L15x), or use an I2C EEPROM. Some of these EEPROM have OTP page (you can write once to prevent accidental erase).
Otherwise, you can use FLASH sectors, sometime emulating EEPROM behaviour.
The corresponding area in FLASH shall be 'excluded' from the linker normal allocatable code space and you'll have to make sure the programmer does not affect this area when debugging or reflashing.
2017-12-26 09:02 AM
Shrink the memory described to the linker by the size of one flash sector. This sector will then be available at the end of the memory space, and you can erase, write and read that area. Typically one could use a structure, with a signature, and checksum, and you could use a pointer to access the memory, checking for valid content, and writing/using defaults in the absence of valid data.