AN2594EmbeddedFlashmemoryversusEEPROM:maindifferences1.2DifferenceinwritingmethodOneofthemajordifferencesbetweenexternalEEPROMandemulatedEEPROMforembeddedapplications isthewritingmethod.Standalone external EEPROM:once startedby theCPU,the writing of a wordcannotObe interrupted by a CPU reset. Only supply failure will interrupt the write process, soproperly sizing thedecoupling capacitors can secure the completewriting processinsideastandaloneEEPROM.EmulatedEEPROMusinganembeddedFlashmemory:oncestartedbytheCPU,theOwriteprocess canbe interrupted byapowerfailure and bya CPUreset.This differenceshouldbeanalyzedbysystemdesignerstounderstandthepossible impact(s)ontheirapplicationsand todetermine a properhandlingmethod1.3DifferenceinerasetimeThedifference inerasetime istheothermajordifferencebetweenastandalone EEPROMand emulatedEEPROMusing embeddedFlashmemory.UnlikeFlashmemories,EEPROMsdonotrequireaneraseoperationtofreeup spacebeforewritingtothem.Thismeansthatsomeformofsoftwaremanagementisrequiredtostoredata inFlashmemoryMoreover,astheeraseprocessofablock intheFlashmemorytakes afewmilliseconds,powershut-down and otherspurious eventsthatmight interrupt the eraseprocess (forexampleareset)shouldbeconsideredwhendesigningtheFlashmemorymanagementsoftware.Todesign arobust Flashmemorymanagement software it isnecessary tohaveadeepunderstandingoftheFlashmemoryeraseprocess.S6/16
Embedded Flash memory versus EEPROM: main differences AN2594 6/16 1.2 Difference in writing method One of the major differences between external EEPROM and emulated EEPROM for embedded applications is the writing method. ● Standalone external EEPROM: once started by the CPU, the writing of a word cannot be interrupted by a CPU reset. Only supply failure will interrupt the write process, so properly sizing the decoupling capacitors can secure the complete writing process inside a standalone EEPROM. ● Emulated EEPROM using an embedded Flash memory: once started by the CPU, the write process can be interrupted by a power failure and by a CPU reset. This difference should be analyzed by system designers to understand the possible impact(s) on their applications and to determine a proper handling method. 1.3 Difference in erase time The difference in erase time is the other major difference between a standalone EEPROM and emulated EEPROM using embedded Flash memory. Unlike Flash memories, EEPROMs do not require an erase operation to free up space before writing to them. This means that some form of software management is required to store data in Flash memory. Moreover, as the erase process of a block in the Flash memory takes a few milliseconds, power shut-down and other spurious events that might interrupt the erase process (for example a reset) should be considered when designing the Flash memory management software. To design a robust Flash memory management software it is necessary to have a deep understanding of the Flash memory erase process
AN2594ImplementingEEPROMemulation2ImplementingEEPROMemulation2.1PrincipleEEPROM emulation is performed in various ways by considering the Flash memorylimitationsandproductrequirements.TheapproachdetailedbelowrequiresatleasttwoFlash memory pages of identical size allocated to non-volatiledata.One that is initiallyerased,andoffersbyte-by-byteprogrammability;theotherthat isreadytotakeoverwhentheformerpageneedstobegarbage-collected.Aheaderfieldthatoccupiesthefirst16-bithalf word ofeach page indicates the page status.The header field is located at the base address of each page and gives the page statusinformation.Eachpagehasthreepossiblestates:ERASED:thepageisempty.RECEIVE_DATA: the page is receiving data from the other full page.OVALID_PAGE: the page contains valid data and this state does not change until allvaliddata are completelytransferredto the erasedpage.Figure1showshowthepagestatuseschangewithrespecttoeachotherFigure1.Header status switching between page0 and page1文WritePageOdataPageo ValidPage1 ErasedPageo FullCopy Page0 data ->Page1Pageo ValidPage1 ReceiveErasePageoWritePage1dataPageO ErasedPage1ValidPage1 FullPageO ReceiveCopy Page1 data -> Page0Page1 ValidErasePage1ai14606Generally,when usingthis method,theuserdoesnotknowinadvancethevariableupdatefrequency.The software and implementation described in this document use two Flash memorypagestoemulateEEPROMEachvariableelement isdefinedbyavirtual addressandavaluetobestored inFlashmemoryfor subsequent retrieval or update (in the implemented software both virtualaddressanddataare16bitslong).Whendataismodified,themodifieddataassociatedwith the earlier virtual address is stored into a newFlash memory location.Data retrievalreturnsthemodifieddata inthelatestFlashmemorylocation.ST7/16
AN2594 Implementing EEPROM emulation 7/16 2 Implementing EEPROM emulation 2.1 Principle EEPROM emulation is performed in various ways by considering the Flash memory limitations and product requirements. The approach detailed below requires at least two Flash memory pages of identical size allocated to non-volatile data. One that is initially erased, and offers byte-by-byte programmability; the other that is ready to take over when the former page needs to be garbage-collected. A header field that occupies the first 16-bit half word of each page indicates the page status. The header field is located at the base address of each page and gives the page status information. Each page has three possible states: ● ERASED: the page is empty. ● RECEIVE_DATA: the page is receiving data from the other full page. ● VALID_PAGE: the page contains valid data and this state does not change until all valid data are completely transferred to the erased page. Figure 1 shows how the page statuses change with respect to each other. Figure 1. Header status switching between page0 and page1 Generally, when using this method, the user does not know in advance the variable update frequency. The software and implementation described in this document use two Flash memory pages to emulate EEPROM. Each variable element is defined by a virtual address and a value to be stored in Flash memory for subsequent retrieval or update (in the implemented software both virtual address and data are 16 bits long). When data is modified, the modified data associated with the earlier virtual address is stored into a new Flash memory location. Data retrieval returns the modified data in the latest Flash memory location. Page0 Valid Page1 Erased Page0 Valid Page1 Receive Page0 Erased Page1 Valid Page0 Receive Page1 Valid Write Page0 data Copy Page0 data -> Page1 Write Page1 data Copy Page1 data -> Page0 Page0 Full Erase Page0 Page1 Full Erase Page1 ai14606