Linked to my previous post, here I'd like to discuss another topic related to persistent variables.
Some years ago I used microcontrollers with internal EEPROM memory or I used external serial I2C EEPROM to save persistent variables. It seems to me the scenario has recently changed.
With new Cortex-M microcontrollers, internal EEPROM is typically absent, but the manufacturer explains in every details (with source code too) how to use internal Flash for data storage (EEPROM emulation). This saves some cost and PCB area (and I think it saves some cost to the manufacturer too... maybe the process to integrate a real EEPROM is high).
Atmel SAM D20 Cortex-M0+ has an internal Flash memory that can be splitted in two sections: one for application and one for EEPROM emulation. Application Note AT03265 explains how to use it .
I think there's an obscure issue when using internal Flash memory for data storage. It is the page (Atmel names it row) erase time that could be some milliseconds (6ms for SAM D20). If the application needs 4 rows (4*256 byte=1kB) to save all persistent data, the sabing process will take about 24ms.
I don't know what do you think about it, but I try to split the actions in pieces that doesn't block, so the firmware can be more responsive to asyncronous events (pushing of buttons, commands from UARTs, ...) Blocking the firmware for 24ms seems to me a very *long* period.
I don't think there is a solution. You can't decompose the saving process in a state-machine, because you can't continue executing the application from Flash memory during erasing process of some rows in the*same* Flash memory. Right? You are forced to wait for the erase (and write) process end.
Now I'm studying the datasheet of new Atmel SAM C21 Cortex-M0+ microcontroller. It works with a 5V power supply and this is not common for this type of micros. Moreover I noticed the presence of an additional section of internal Flash memory that is named RWWEE (Read-While-Write EEPROM).
"It is not possible to read the RWWEE area while the NVM main array is being written or erased, whereas the RWWEE area can be written or erased while the main array is being read."
In this case, is it possible to continue executing of "normal" application that resides in the main memory during the saving process (erasing and writing of rows in the RWEE memory)? If it is possible, I could decompose the saving process in a state-machine in such a way there isn't any blocking point. I can stay in the "ERASING" state until the erasing operation finished. Of course, the state-machine stay in "ERASING" state, but the main execution process isn't blocked.
Is this exactly the goal to have a RWWEE additional Flash memory on this microcontrollers?