A simple solution is to support two versions of the data (on separate pages for flash memory), the current version and the previous version. Each version has a header containing a sequence number and a word that checks the sequence number - just 1 addition of a sequence number, for example:
--------- | seq | --------- | ~seq | --------- | | | data | | | ---------
Most importantly, when writing data, the words seq and ~seq written last.
At startup, you read data that has the highest permissible sequence number (for example, to account for short sequence words). When you write data, you overwrite and check the oldest block.
The solution you are already using is valid as long as the CRC is written last, but it lacks simplicity and imposes an overhead on the calculation of the CRC, which may be undesirable or desirable.
In FRAM, you're not worried about endurance, but it's a problem for flash memory and EEPROM. In this case, I use the write-back caching method, where the data is stored in RAM, and when the timer changes, it starts or restarts if it is already running - when the timer expires, the data is written - this prevents bursts from erasing memory and is useful even on FRAM. because it minimizes the software overhead of data recording.
Clifford
source share