中国高校课件下载中心 》 教学资源 》 大学文库

《嵌入式应用开发》课程教学资源(文献资料)AN2594 Application note EEPROM emulation in STM32F101xx and STM32F103xx microcontrollers

文档信息
资源类别:文库
文档格式:PDF
文档页数:16
文件大小:146.84KB
团购合买:点击进入团购
内容简介
《嵌入式应用开发》课程教学资源(文献资料)AN2594 Application note EEPROM emulation in STM32F101xx and STM32F103xx microcontrollers
刷新页面文档预览

AN2594STApplicationnoteEEPROMemulationinSTM32F101xxandSTM32F103xxmicrocontrollersIntroductionManyapplications require EEPROM (electrically erasableprogrammableread-onlymemory)for non-volatiledata storage.Forlow-costpurposes,the STM32F101xxandSTM32F103xxdevicesdonotuseEEPROM.Instead,they implementEEPROMemulationusing the embedded Flash memory.Thisapplicationnoteexplains thedifferencesbetweenexternalEEPROMand embeddedFlash memory, and it describes a software method for emulating EEPROM using the on-chipFlashmemoryoftheSTM32F101xxandSTM32F103xxdevices.Thisdocumentalsofocusesonsomeembeddedaspects inemulatedEEPROMdatastorage, that the reader is assumed to know.GlossaryMedium-densitydevicesareSTM32F101xxandSTM32F103xxmicrocontrollerswheretheFlashmemorydensityrangesbetween32and128Kbytes.High-density devices are STM32F101xx and STM32F103xx microcontrollers where theFlashmemorydensity rangesbetween256and512Kbytes.Rev 2June20081/16www.st.com

June 2008 Rev 2 1/16 AN2594 Application note EEPROM emulation in STM32F101xx and STM32F103xx microcontrollers Introduction Many applications require EEPROM (electrically erasable programmable read-only memory) for non-volatile data storage. For low-cost purposes, the STM32F101xx and STM32F103xx devices do not use EEPROM. Instead, they implement EEPROM emulation using the embedded Flash memory. This application note explains the differences between external EEPROM and embedded Flash memory, and it describes a software method for emulating EEPROM using the on￾chip Flash memory of the STM32F101xx and STM32F103xx devices. This document also focuses on some embedded aspects in emulated EEPROM data storage, that the reader is assumed to know. Glossary Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 32 and 128 Kbytes. High-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes. www.st.com

ContentsAN2594Contents1EmbeddedFlashmemoryversusEEPROM:maindifferences51.1Differenceinwriteaccesstime51.26Differenceinwritingmethod1.36Differenceinerasetime2ImplementingEEPROMemulation12.1Principle-2.1.18Applicationexample2.1.2EEPROMsoftwaredescription..8311Embeddedapplication aspects3.111Datagranularitymanagement.113.1.1Programming on a word-by-word basis...113.1.2Programming on a byte-by-byte basis3.211Wearleveling:Flashmemoryendurance improvement.113.2.1Wear-leveling implementation example3.312Page header recovery in case of power loss3.413Cycling capability4Revision history15S2/16

Contents AN2594 2/16 Contents 1 Embedded Flash memory versus EEPROM: main differences . . . . . . . 5 1.1 Difference in write access time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 Difference in writing method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.3 Difference in erase time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Implementing EEPROM emulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1.1 Application example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.1.2 EEPROM software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3 Embedded application aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1 Data granularity management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1.1 Programming on a word-by-word basis . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1.2 Programming on a byte-by-byte basis . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2 Wear leveling: Flash memory endurance improvement . . . . . . . . . . . . . . 11 3.2.1 Wear-leveling implementation example . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.3 Page header recovery in case of power loss . . . . . . . . . . . . . . . . . . . . . . 12 3.4 Cycling capability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

AN2594ListoftablesList of tablesTable 1.DifferencesbetweenembeddedFlashmemoryandEEPROM......5Table 2..·..13Status combinations andactionstobetaken....Table 3.Maximum number of variables stored in emulated EEPROM (with 10 000 cycles) ......14Table 4........15Document revision historyST3/16

AN2594 List of tables 3/16 List of tables Table 1. Differences between embedded Flash memory and EEPROM . . . . . . . . . . . . . . . . . . . . . . 5 Table 2. Status combinations and actions to be taken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Table 3. Maximum number of variables stored in emulated EEPROM (with 10 000 cycles) . . . . . . 14 Table 4. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

ListoffiguresAN2594ListoffiguresFigure 1...7Headerstatusswitchingbetweenpage0andpage1Figure 2...8EEPROMvariableformat....:8Figure 3.Dataupdateflow............10Figure 4.WriteVariableflowchart.........-...12Figure 5.Pageswapschemewithfourpages (wearleveling)SA4/16

List of figures AN2594 4/16 List of figures Figure 1. Header status switching between page0 and page1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Figure 2. EEPROM variable format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 3. Data update flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 4. WriteVariable flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 5. Page swap scheme with four pages (wear leveling). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

AN2594EmbeddedFlashmemoryversusEEPROM:maindifferences1EmbeddedFlashmemoryversusEEPROM:maindifferencesElectrically erasable andprogrammableread-only memory (EEPROM) is a key componentofmanyembedded applicationsthat requirenon-volatilestorageof dataupdated witha byteor word granularity duringrun time.Ontheotherhand,themicrocontrollers usedinthosesystems areeachtimemore oftenbasedonembeddedFlashmemory.Toeliminatecomponents,savesiliconspaceandreduce systemcost, the STM32F10xxxFlash memory may be used instead of EEPROM forsimultaneous code and data storage.UnlikeFlashmemory,however,externalEEPROMdoesnotrequireaneraseoperationtofree up space beforedata can be rewritten.Hencea special software management isrequiredtostoredata intoembeddedFlashmemory.Obviouslytheemulationsoftwareschemedependsonmanyfactors,includingtheEEPROMreliability,thearchitectureoftheFlashmemoryused,andtheproductrequirements.The main differences between embeddedFlashmemoryandexternal serial EEPROMaregenerictoanymicrocontrollerthatusethe sameFlashmemorytechnology(it isnot specifictotheSTM32F10xxxfamilyproducts).ThemajordifferencesaresummarizedinTable1.Table 1.DifferencesbetweenembeddedFlashmemoryandEEPROMEmulated EEPROM using on-chipFlashFeatureExternalEEPROMmemory-afewms-randombyte:5to10msWrite timeWord program time: 20 μs-page:a hundred μsper word (5 to10msperpage)N/AErasetimePage/MassErasetime:20msoncestarted,isCPU-dependent:aCPUoncestarted,isnotCPU-dependentWrite methodreset will stopthe writeprocess even if theonlyneedspropersupply.suppliedpowerstayswithinspecifications- serial: a hundred μs-parallel:a hundred nsReadaccess- random word: 92 μs-veryfewCPUcyclesperword.-Accesstime:35ns-page:22.5μsperbyte-from 10kilocycles to 100 kilocycles (theuseofmanyon-chipFlashmemorypagesWrite/Erasefrom 10 kilocycles to 1 000isequivalenttoincreasingthenumberofcycleskilocycleswrite cycles)seeSection3.4:Cyclingcapability1.1Difference in write access timeAsFlashmemorieshaveashorterwriteaccesstime,critical parameterscanbestoredfasterintheemulatedEEPROMthaninanexternalserialEEPROM,therebyimprovingdatastorage.ST5/16

AN2594 Embedded Flash memory versus EEPROM: main differences 5/16 1 Embedded Flash memory versus EEPROM: main differences Electrically erasable and programmable read-only memory (EEPROM) is a key component of many embedded applications that require non-volatile storage of data updated with a byte or word granularity during run time. On the other hand, the microcontrollers used in those systems are each time more often based on embedded Flash memory. To eliminate components, save silicon space and reduce system cost, the STM32F10xxx Flash memory may be used instead of EEPROM for simultaneous code and data storage. Unlike Flash memory, however, external EEPROM does not require an erase operation to free up space before data can be rewritten. Hence a special software management is required to store data into embedded Flash memory. Obviously the emulation software scheme depends on many factors, including the EEPROM reliability, the architecture of the Flash memory used, and the product requirements. The main differences between embedded Flash memory and external serial EEPROM are generic to any microcontroller that use the same Flash memory technology (it is not specific to the STM32F10xxx family products). The major differences are summarized in Table 1. 1.1 Difference in write access time As Flash memories have a shorter write access time, critical parameters can be stored faster in the emulated EEPROM than in an external serial EEPROM, thereby improving data storage. Table 1. Differences between embedded Flash memory and EEPROM Feature External EEPROM Emulated EEPROM using on-chip Flash memory Write time – a few ms – random byte: 5 to 10 ms – page: a hundred µs per word (5 to 10 ms per page) Word program time: 20 µs Erase time N/A Page/Mass Erase time: 20 ms Write method – once started, is not CPU-dependent – only needs proper supply. once started, is CPU-dependent: a CPU reset will stop the write process even if the supplied power stays within specifications. Read access – serial: a hundred µs – random word: 92 µs – page: 22.5 µs per byte – parallel: a hundred ns – very few CPU cycles per word. – Access time: 35 ns Write/Erase cycles – from 10 kilocycles to 1 000 kilocycles – from 10 kilocycles to 100 kilocycles (the use of many on-chip Flash memory pages is equivalent to increasing the number of write cycles) see Section 3.4: Cycling capability

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

ImplementingEEPROMemulationAN2594Figure 2.EEPROMvariableformatEEPROM variable element = 32-bit wordVariable data (16 bits) -Variable virtual address (16 bits)256 elements (1 Kbyte page)for Medium-density devicesor512 elements (2Kbyte page)for High-density devicespageopage1ai14608b2.1.1ApplicationexampleThe following example shows the software management of three EEPROM variables (Var1,Var2andVar3)withthefollowingvirtualaddresses:Var1:5555h,Var2:6666handVar3:7777hFigure3.Data updateflowaqeoPage12FF国EE3TFFFF12132FE132EFFF127777福E印国01FF77FFFFrNSFRCNCDEFdVarddVarVa32h1245hBCFFFFFFFFFFFFFFFFFFFFFFFFFctive PagPagelMAactivePagictivePage=Paceu646468R74TErase6BO8KK二2F5454FFFFFFFFFFEFEF17ai146092.1.2EEPROMsoftwaredescriptionThissectiondescribesthedriverimplementedforEEPROMemulationusingtheSTM32F10xxxFlashmemorydriverprovidedbySTMicroelectronics.AsampledemonstrationprogramisalsosuppliedtodemonstrateandtesttheEEPROMemulationdriverusingthethreevariablesVar1,Var2andVar3definedintheVirtAddVarTabtabledeclaredinthesoftwaremain.cfileS8/16

Implementing EEPROM emulation AN2594 8/16 Figure 2. EEPROM variable format 2.1.1 Application example The following example shows the software management of three EEPROM variables (Var1, Var2 and Var3) with the following virtual addresses: Var1: 5555h, Var2: 6666h and Var3: 7777h Figure 3. Data update flow 2.1.2 EEPROM software description This section describes the driver implemented for EEPROM emulation using the STM32F10xxx Flash memory driver provided by STMicroelectronics. A sample demonstration program is also supplied to demonstrate and test the EEPROM emulation driver using the three variables Var1, Var2 and Var3 defined in the VirtAddVarTab table declared in the software main.c file. Variable data (16 bits) ai14608b Variable virtual address (16 bits) EEPROM variable element = 32-bit word 256 elements (1 Kbyte page) for Medium-density devices or 512 elements (2 Kbyte page) for High-density devices page0 page1 12 32 77 77 12 45 77 77 BC BC 55 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 34 34 66 66 12 32 77 77 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 12 32 77 77 12 45 77 77 BC BC 55 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF Page0 Page1 Active Page = Page0 FF FF FF FF FF FF FF FF 32 32 77 77 22 45 66 66 BD BD 55 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 54 54 77 77 12 32 77 77 Add Var3 =1232h Add Var3 =1245h Add Var1 =BCBCh Add Var2 =6464h Erase Page0 Add var2 =3434h Page0 Page1 Active Page = Page0 Page0 Page1 Active Page = Page0 12 32 77 77 12 45 77 77 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF Page0 Page1 Active Page = Page0 Page0 Page1 Active Page = Page0 Page0 Page1 Active Page = Page0 Page0 Page1 Active Page = Page1 32 32 77 77 22 45 66 66 BD BD 55 55 64 64 66 66 54 54 77 77 BD BD 55 55 FF FF FF FF FF FF 54 54 77 77 12 32 77 77 Page0 Page1 Active Page = Page1 FF FF FF FF FF FF FF FF FF FF FF FF 64 64 66 66 54 54 77 77 BD BD 55 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF ai14609

AN2594ImplementingEEPROMemulationTheprojectcontainsthreesourcefiles inadditiontotheFlashmemory librarysourcefiles:eeprom.c.it contains C codeforthefollowing projectroutines:OEE_Init()EE_Format()EE_FindValidPage()EE_VerifyPageFullWriteVariable()EE_ReadVariable()EE_PageTransfer()EE_WriteVariable()eeprom.h:itcontainstheroutineprototypesandsomedeclarations...main.c:thisapplication program is an exampleusing thedescribed routines inordertowritetoandreadfromtheEEPROM.UserAPIdefinitionThesetoffunctionscontainedintheeeprom.cfile,thatareusedforEEPROMemulation,aredescribedbelow:EE_Init()OSector header corruption is possible in theevent of powerloss duringdataupdateorsectorerase/transfer.Inthiscase,theEEInit()functionwillattempttorestorethedatabasetoaknowngoodstate.Thisfunctionshouldbecalledpriortoaccessingthedatabaseaftereachpower-down.Itacceptsnoparameters.Theprocessisdescribedin Table 2.OEE_Format()ThisfunctionerasespageOandpage1andwrites aVALID_PAGEheadertopage0..EE_FindValidPage()Thisfunctionreadsbothpageheadersandreturnsthevalidpagenumber.Thepassedparameterindicates if thevalidpageis soughtforawriteorreadoperation(READ_FROM_VALID_PAGEor WRITE_IN_VALID_PAGE),EE_VerifyPageFullWriteVariable()It implementsthewriteprocessthatmusteitherupdateorcreatethefirst instanceofavariable.Itconsists in finding thefirst emptylocationontheactivepage,starting fromthe end, and filling it with the passed virtual address and data of the variable. In thecasethe activepage is full,the PAGE_FULLvalue isreturned.This routine uses theparametersbelow:Virtual address:may be any of the three declared variables'virtual addresses(Var1,Var2orVar3)Data:the value of the variableto be storedThisfunctionreturnsFLASH_COMPLETEonsuccess,PAGE_FULLif thereisnotenoughmemoryfora variableupdate,oraFlashmemory error codeto indicateoperationfailure (eraseorprogram).EE_ReadVariable()This function returns the data corresponding to the virtual address passed as aparameter.Only the last update is read.Thefunction enters in a loop in which it readsthevariableentriesuntilthelastone.Ifnooccurrenceofthevariableisfound,theReadStatus variable is returned with thevalue"1",otherwise it is resetto indicate thatST9/16

AN2594 Implementing EEPROM emulation 9/16 The project contains three source files in addition to the Flash memory library source files: ● eeprom.c: it contains C code for the following project routines: EE_Init() EE_Format() EE_FindValidPage() EE_VerifyPageFullWriteVariable() EE_ReadVariable() EE_PageTransfer() EE_WriteVariable() ● eeprom.h: it contains the routine prototypes and some declarations. ● main.c: this application program is an example using the described routines in order to write to and read from the EEPROM. User API definition The set of functions contained in the eeprom.c file, that are used for EEPROM emulation, are described below: ● EE_Init() Sector header corruption is possible in the event of power loss during data update or sector erase / transfer. In this case, the EE_Init() function will attempt to restore the database to a known good state. This function should be called prior to accessing the database after each power-down. It accepts no parameters. The process is described in Table 2. ● EE_Format() This function erases page0 and page1 and writes a VALID_PAGE header to page0. ● EE_FindValidPage() This function reads both page headers and returns the valid page number. The passed parameter indicates if the valid page is sought for a write or read operation (READ_FROM_VALID_PAGE or WRITE_IN_VALID_PAGE). ● EE_VerifyPageFullWriteVariable() It implements the write process that must either update or create the first instance of a variable. It consists in finding the first empty location on the active page, starting from the end, and filling it with the passed virtual address and data of the variable. In the case the active page is full, the PAGE_FULL value is returned. This routine uses the parameters below: – Virtual address: may be any of the three declared variables’ virtual addresses (Var1, Var2 or Var3) – Data: the value of the variable to be stored This function returns FLASH_COMPLETE on success, PAGE_FULL if there is not enough memory for a variable update, or a Flash memory error code to indicate operation failure (erase or program). ● EE_ReadVariable() This function returns the data corresponding to the virtual address passed as a parameter. Only the last update is read. The function enters in a loop in which it reads the variable entries until the last one. If no occurrence of the variable is found, the ReadStatus variable is returned with the value “1”, otherwise it is reset to indicate that

ImplementingEEPROMemulationAN2594thevariablehasbeenfoundandthevariablevalueisreturnedontheRead_datavariable..EE_PageTransfer()It transfers the most recent data (last variable updates)from a full page to an emptyone.Atthebeginning,itdeterminesthe activepage,whichis the page the dataistobetransferredfrom.Thenewpageheaderfieldisdefinedandwritten(newpagestatus isRECEIVE_DATAgiven that it is in theprocess of receiving data).When thedatatransfer is complete, the new page header is VALID_PAGE, the old page is erased anditsheaderbecomesERASEDEE_WriteVariable(..)OThis function is called by the user application to update a variable. It uses theEE_VerifyPageFullWriteVariable(),andEE_PageTransfer()routinesthathavealreadybeendescribed.Figure4shows the procedure forupdatinga variable entry in theEEPROM.Figure 4.WriteVariableflowchartFunction callAdd element requestFind Valid pageEE_VerifyPageFullWriteVariable()EE_FindValidPage()1currentYesNoactivepageCopy all current elements byAddnewelementatreadingtheactivepagethe 1st empty elementfrom thebottom, takingplace in the currentinto account the newactive pageupdated element.EE_PageTransfer()T+EB_ReadVariable()EndErase previous active pageChange the active pageEnaai14610bKeyfeatures.User-configuredemulatedEEPROMsizeIncreased Flash memory endurance: page erased only when it is full..Non-volatile data variables can be updated infrequently.Interrupt servicing during program/erase is possibleS10/16

Implementing EEPROM emulation AN2594 10/16 the variable has been found and the variable value is returned on the Read_data variable. ● EE_PageTransfer() It transfers the most recent data (last variable updates) from a full page to an empty one. At the beginning, it determines the active page, which is the page the data is to be transferred from. The new page header field is defined and written (new page status is RECEIVE_DATA given that it is in the process of receiving data). When the data transfer is complete, the new page header is VALID_PAGE, the old page is erased and its header becomes ERASED. ● EE_WriteVariable(.) This function is called by the user application to update a variable. It uses the EE_VerifyPageFullWriteVariable(), and EE_PageTransfer() routines that have already been described. Figure 4 shows the procedure for updating a variable entry in the EEPROM. Figure 4. WriteVariable flowchart Key features ● User-configured emulated EEPROM size ● Increased Flash memory endurance: page erased only when it is full ● Non-volatile data variables can be updated infrequently ● Interrupt servicing during program/erase is possible Add element request current active page full Add new element at the 1st empty element place in the current active page Erase previous active page End End Change the active page Find Valid page Yes No EE_FindValidPage() Copy all current elements by reading the active page from the bottom, taking into account the new updated element. EE_PageTransfer() EE_ReadVariable() Function call ai14610b EE_VerifyPageFullWriteVariable()

共16页,试读已结束,阅读完整版请下载
刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档