AN2077 STMICROELECTRONICS | Alldatasheet

Document overview

  • Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
  • PDF pages: 19

Technical content

Rev. 2.0 AN2077 APPLICATION NOTE EEPROM Emulation with STR71x INTRODUCTION External EEPROMs are often used in applications to store data that may be later updated or adjusted. On the other hand, the microcontrollers used in these systems are based more and more on embedded Flash. The trend to continuously reduce the number of components is forcing designers to look to use Flash memory to emulate EEPROM. This application note explains the differences between external EEPROMs and embedded- Flash and gives advice on how to substitute external EEPR OM to emulated-EEPROM using the on-chip Flash of STR71xF devices. Although the concept is easy to explain and implement “as is”, there are some embedded as- pects that have to be taken into account. Substituting external EEPROM with emulated EEPROM from the embedded-Flash of the mi- crocontroller is a complex development. This application note assumes that readers are al - ready familiar with the techniques used to secure the content of evolutive information in ex - ternal EEPROM of embedded applications. This application note is organized in 4 parts: – Description of the differences between external EEPROMs and embedded-Flash, – General description of EEPROM emulation concept, – Introduction to embedded application aspects, – Software example. Although this application note is mainly refers to STR710FZ1, STR710FZ2, STR711FR1, STR711FR2, STR712FR2 and STR712FR2, most of its content is not dependent on the mi - crocontroller.

1 EMBEDDED FLASH AND EEPROM

variants). They are summarized in the table below. Table 1. Differences between Embedded Flash and EEPROM

1.1 DIFFERENCE IN WRITE ACCESS TIME

system if the same safety concept is kept.

1.2 DIFFERENCE IN WRITING METHOD

bedded applications is the writing method. be interrupted by a power failure and by a CPU reset. on their applications and to define the proper handling method. supply stays within specification. a small number of CPU cycles per word.

EEPROM Emulation with STR71x

1.3 DIFFERENCE IN ERASE TIME

The difference in erase time is the other important difference between stand-alone EEPROMs and emulated EEPROM with embedded-Flash. Unlike Flas h, EEPROM does not require a block erase operation to free-up space before write. This means that some form of software management is required to store data in Flash. Moreover, as the erase process of a block in the Flash takes few seconds, power shut-down and other spurious events that may interrupt the erase process (ex: reset) should be c onsidered when designing the Flash management software. This means that to design a robust Flash management software it is necessary to have a deep understanding of the Flash erase process. The Flash erase process is split in 3 phases: – phase1: write all bits to 0, starting from the initial content. An interrupt during this phase will result in some memory cells being at “0” logic level and the rest of the memory cells will still contain their initial content. – phase2: write all bits to 1, starting from the all “0” configuration. The longer the time before this phase is interrupted, the higher the number of cells will return a “1” logic level. The rest of the memory cells will contain their initial content, their content can be considered as totally random. – phase3: equalization. This phase is necessary to recover over-erased cells. The Flash man- agement software for EEPROM emulation should guarantee that this phase was successful- ly completed before programming in this bank. The consequence of an interrupt during phase2 is that a single bit approach should be avoided to flag the completion of the erasing process (find more details in section 2.5 on page 6). The consequence of an interrupt during phase1 and/or phase2 is that it is recommended to have fixed data inside the emulated EEPROM so that a checksum can be run to tell which Flash bank keeps the valid data. The most important point is to ensure that the Flash has been completely erased (phase3 was not interrupted) before programming data inside a bank. Note The design of Flash software management is easier if programming in a new bank is always made just after erasing of this bank (when erasing of one bank is necessary).

1.4 ADDITIONAL INFORMATION ON FLASH

Incremental programming: the Flash controller will accept to program a word that is already programmed if the new word is adding more “0” bits. Programming completion: programming completion is important to guarantee data retention time; the programming is complete when the Fl ash controller status indicates the end of pro - gramming without showing any error flag. If prog ramming is interrupted (ex: supply fail, CPU reset), the cells of the word being programmed will be partially programmed. This can result in unstable “0”s when reading this word.

2 EEPROM EMULATION CONCEPT

2.1 PRINCIPLE

linked data-list structures should be considered. The method described in this document is based on fixed-length Data-sets and 2 Flash banks. Figure 1. Bank partitioning for emulated EEPOM

EEPROM Emulation with STR71x

2.2 PROGRAM/ERASE CYCLE

The requirement number of program/erase cycles is computed by dividing the needed number of erase cycles by the total number of Data -sets in the Flash banks (for example in Figure 1: n+m). When this number is still higher than the Flash write/erase endurance characteristics, a closer analysis is needed to understand when the Data-sets are updated: – When Data-sets need to be updated during operation, it is proposed to use a buffer in RAM and to save the data before shutting-down the microcontroller. – When Data-sets are updated only before a power-down sequence, it is proposed to increase the size of the Flash bank or to use a 3rd bank (see additional information in Section 3).

2.3 READ-WHILE-WRITE

Most currently available Flash technologies must complete a program or erase operation be - fore code or data can be read from another memory block. There is a common misconception that EEPROM emulation can only be done when Read-While-Write functionality is imple - mented. Read-While-Write, when present, allows other memory blocks to be accessed during erasing and programming; this means that the CPU program does not need to be copied into RAM during programming/erasing. Read-While-Write does not prevent having a RAM buffer if access into the emulated-EEPROM is needed during programming. When Read-While-Write is not supported, program or erase suspend command can be used to temporarily read code. All STR71xF variants support program and erase suspend com - mands.

2.4 FLASH ORGANIZATION

The concept described above shows the Flash bank split into 2 parts: – Data-set storage: which keeps all variable information, – Status bit storage: which keeps status of the Flash bank and of the Data-sets. Other organizations are possible (ex: to include the Data-set status bits inside each Data-set) for which users may see advantages for their application.

2.5 DATA-SET STATUS BITS

Two status bits are proposed for each Data-set with the combinations shown in the following table.

Table 2. Status bit for Data-set configuration should be used by user’s software to detect which Flash bank holds valid data. which Data-set has the valid information.

2.6 ACTIVE FLASH BANK SELECTION

shows an example of status bits that can be used for this purpose. Table 3. Status bit for Flash banks checksum it is possible to detect if a given Flash bank has valid or invalid data. (for example, a power-fail).

11 Data-set without data (virgin)

01 Data-set with valid data (programmed)

00 Data-set with old or invalid data (dirty)

10 Reserved (invalid)

01111111 Current bank is active

00111111 Erase of the other bank is started

00011111 Completion of the erase of the other bank

00001111 New data programming in the other bank is started

00000111 New data programming in the other bank is completed

00000011 The other bank is active

EEPROM Emulation with STR71x

3 EMBEDDED APPLICATION ASPECTS

This chapter gives useful information for embedded applications where the STR71x em - bedded-Flash memory is the only non volatile memory available.

3.1 READING THE FLASH WHILE ERASING OR PROGRAMMING

Depending on which STR71xF variant is used, the entire Flash may not be visible to the CPU when a Flash bank is erased or programmed. When a given microcontroller does not support Read-While-Write, the EEPROM emulation software should: – disable all interrupts: as during erasing and programming, it is not possible to have access to STR71x interrupt vector table; – copy a few routines into the RAM: before erasing and programming, a few software rou- tines shall be copied from the Flash into the on-chip RAM; this should include at least the routines to generate erasing and programming and the routines which wait for the end of erasing or programming; – temporarily disable code protection: if code protection is activated, it should be temporar- ily disabled before executing the code copied into the on-chip RAM. To cope with application constraints, users may be obliged to support communication during the programming/erasing. This requires that: – more software is copied into the on-chip RAM, – the software loop, polling the Flash status register, is modified to handle the communication process, – the minimum communication handler (used during polling) is not using interrupts, – program/erase suspend command is used.

3.1.1 Suspend and resume commands

As stand-alone Flash memories, STR71xF embedded-Flash controller supports suspend and resume commands; this allows the erasing or the programming process to be suspended at any time and resumed later on. Once suspend command is completed, STR71xF can access the software routines that may be needed (ex: communication driver) and that were not relocated to the on-chip RAM. Note The total time for which the Flash is not available is unchanged but this gives the possibility to sus- pend the process to run specific routines during Flash erasing or programming (ex: communication protocol).

EEPROM Emulation with STR71x

3.1.2 Minimum software to be copied into the on-chip RAM

The minimum software to be copied into the on-chip RAM is: – Functions issuing the erasing and or programming commands to the STR71x embedded- Flash controller, – Functions polling the Flash status register for detecting the completion of the command and for error detection (see detailed specification), – Watchdog refresh (if activated).

3.2 DATA PROGRAMMING / ERASING WITH STR71XF

Flash programming/erasing in the field, requires the ability to deal safely with all the possible events that may occur in the application. This analysis is application-dependent and has to be carefully conducted by the user. This section assumes that users have experience with all the generic aspects of field reprogram - ming; this section will focus only on STR71xF specific events.

3.2.1 Flash field reprogramming

This subsection gives useful information for the field reprogramming of data. This advice is not specific to STR71x but is generic to any embedded application that reprograms itself a Data- set. The main points to control during Flash programming/erasing are: – completion of the self-programming/erasing process, – events that may interrupt the reprogramming process.

3.2.1.1 Completion of the programming process

The programming process is completed when the last word to be programmed has been pro- grammed correctly (i.e.: the status returned by the Flash is OK). Usually, the last word pro - grammed is an update of the status word (or status bits) of the new Data-set. If, for any reason, the programming process is interrupted, at the next restart, the value read may be either erroneous or good but with a limited retention time. This should influence how users code the st atus bits and how supply failures are detected (early warning) or prevented (CPU controlled vo ltage regulator). It is difficult to be specific here as choices will depend on application requirements and constraints.

3.2.1.2 Completion of the erasing process

As explained in Section 1.3, the completion of the erasing process before programming in a bank is very important. Single bit information to record a successful erase process should be avoided. Whenever possible:

EEPROM Emulation with STR71x – the erase (if necessary because one Flash bank is full) should be done just before Flash pro- gramming – the Flash programming should start only after the successful completion of the erasing proc- ess. As the erase process can take few seconds, this may require the use of software-controlled voltage regulators to allow the Flash to be erased after the main system is stopped (e.g. when the ignition key is removed).

3.2.1.3 Safety aspects

Depending on safety constraints, the usage of a 3rd bank may be considered: instead of using 2 banks alternatively, 3 banks are used alternatively; in the event of a failure (hardware or non- recoverable software error) inside a bank, there are still 2 banks available. Such a technique is already used in some applications for EEPROM emulation using stand-alone Flash memo ries.

3.3 FIELD REPROGRAMMING WITH STR71XF

Flash programming/reprogramming in the field, requires the ability to deal safely with all the possible events that may occur in the application. This analysis is application-dependent and has to be carefully conducted by the user. This section assumes that users have experience with all the generic aspects of field reprogram - ming and will focus only on STR71xF specific events.

3.3.1 Field events and Flash reliability

User’s applications must meet ST’s recommendations for Flash programming and erasing. Failure to do so could result in lower data retention and/or altered Flash reliability. The condi- tions leading to an altered data retention or to an altered reliability depend on the command is- sued to the Flash and the event that occurred during this command (supply out of range, reset). From FMEA’s (Failure Modes and Effects Analysis) perspective, customers should consider that when ST’s recommendations are not implemented, Flash reliability can be altered. When ST’s advice is followed and provided all field specific events are within ST recommendations (see hereafter), the Flash will meet ST published specification.

3.3.2 List of Events and Suggested Handling Methods

3.3.2.1 Reset

Reset is one of the events possible during field reprogramming, whatever the possible causes of reset (spurious reset, external hardware reset, reset due to power-shut down).

EEPROM Emulation with STR71x Detection Method: Reset can occur at any time and there is no possibility to prevent this. Suggested Handling Method: Restart the Flash command that was interrupted (i.e.: erasing or programming); use status bits and Flash information to recognize this event.

3.3.2.2 Supply variations

STR71x supply must be kept within the limits published in the Data Sheet during any erase or programming command. Detection method: A specific hardware should be added to monitor the supply and reset the STR71xF device when the supply is going out of the functional specification. Suggested Handling Method: Restart the whole Flash command (i.e.: erasing or programming). Note As for any other parameter, the STR71x supply should stay within the maximum absolute ratings defined in the published Data Sheet.

3.3.2.3 Temperature out of specification

Temperature during erasing, programming and read/fetch operations is influencing the relia - bility of the embedded-Flash. The embedded-Flash must be programmed and erased only while the junction temperature is within the limits published in the STR71x Flash Reference Manual (see relevant product doc- umentation). Failure to do so, could result in degraded reliability (lower number of erase cycles, lower data retention).

3.3.2.4 STR71x PLL Unlock

As the Flash program/erase timings are not defined by the STR71x CPU core, PLL unlock has no effect on the Flash erasing and programming. Usually, PLL unlock will stop communication because of change in bit/baud rate. Detection Method: Not necessary from STR71x point of view (to be checked with application specific constraints). Suggested Handling Method: Application-dependent.

EEPROM Emulation with STR71x

4 SOFTWARE EXAMPLE

This software example is intended to illustrate how to implement some aspects of the EEPROM emulation concept. This software implements the following features: – Data-set storage – Status bit for Data-set – Status bit for active Flash sector – Read While Write using the sectors of the second bank It also provides three output functions: – EEPROM_Init – EEPROM_DataRead – EEPROM_DataWrite

4.1 SOFTWARE EXAMPLE CONCEPT

The software example is based on fixed-length Data-sets and 2 Flash sectors This software example allows you to write from 1 to 1984 Data-Sets per sector. The configu - ration of the number of Data-Set can be set in the E3PROM.h file. For example, to configure the max Data-Set to 100 for the two sectors, configure Max_Count_1 and Max_Count_2 in the E3PROM.h file as follows: /* Max status bits for data set */ #define Max_Count_1 35 /* The number of Data-Sets in the first sector */ #define Max_Count_2 35 /* the number of Data-Sets in the second sector */ Note: You can configure the max. Data-Set for each sector independently.

Figure 2. Software example concept – 0xFFFF (Default value after an erase operation) indicates an invalid sector. to the Data-set area, the software will reset the corresponding bit in the status bits area. Figure 2. shows an example of a mechanism for setting the status bits in the status bit area. default value after an erase operation.

4.2 SOFTWARE OUTPUT FUNCTIONS

There are three output functions in the software as described below.

EEPROM Emulation with STR71x

4.2.1 EEPROM_Init

This function must be called only once at the beginning of the user code or when a full erase is required. This function initializes the Flash, erases the two correspondent sectors and marks the first as valid by writing 0x600D in the last word of this sector. The EEPROM_Init function is called as follows: /* Initialize the EEPROM */ EEPROM_Init();

4.2.2 EEPROM_DataRead

This function allows the user to read the valid Data (the last Data-Set). This function returns the following status messages: – EEPROM_FULL_ERASE_REQUIRED: To indicate if a full erase is required, – EEPROM_NO_VALID_DATA: To indicate if there is no valid data to be read, – EEPROM_SUCCESSFUL_DATA_READ: To indicate if the data is read successfully. It uses two internal functions: – EEPROM_GetValidSector: This function returns the valid sector, – EEPROM_ValidDataSet: This function returns the offset of the valid Data-set (if it exists). For this function, use the following as an example: /* Declaration */ u32 Read_Status; /* The status of the read operation */ u32 Data_Read; /* The valid Data-set */ /* Read the valid data from valid sector */ Read_Status = EEPROM_DataRead(&Data_Read);

4.2.3 EEPROM_DataWrite

This function allows the user to write a new Data-set to the valid sector without overwriting the old Data-set and then updates the corresponding status bit. When the valid sector is full, the function performs the following operations: 1) copies the last Data-set to the second sector, 2) writes the new Data-set, 3) updates the Status bits, 4) marks the second sector as valid, 5) and finally erases the first sector.

EEPROM Emulation with STR71x With this order of execution we ensure that, even if a reset event or a power cut event occurs, the last valid Data-Set cannot be lost. This function returns the following status messages: – EEPROM_FULL_ERASE_REQUIRED: To indicate if a full erase is required, – EEPROM_SUCCESSFUL_DATA_WRITE: To indicate if the new Data-set is written suc- cessfully. The function EEPROM_DataWrite uses three internal functions: – EEPROM_GetValidSector: This function returns the valid sector, – EEPROM_ValidDataSet: This function returns the offset of the valid Data-set (if it exists), – EEPROM_UpdateDataSet: This function is used to update the corresponding status bit. As an example of how to use this function: /* Declaration */ u32 Write_Status; /* The status of the write operation */ u32 Data_Set; /* The new Data-set */ /* Initialize the new Data-set */ Data_Set = 0x12345678 /* Write the new Data-set to the valid sector */ Write_Status = EEPROM_DataWrite(&Data_Set);

4.3 EEPROM OUTPUT FUNCTIONS USE EXAMPLE

In this subsection an example of how to use the three output functions of the EEPROM Emu- lation is presented. The following example allows to write and read three Data-set.

Figure 3. Example of output functions use

EEPROM Emulation with STR71x

5 SUMMARY

This application note has shown that by careful identification of events that can happen in the field, and by definition of the Flash organization and its associated control bits, it is possible to define a method to substitute external EEPROM with the embedded-Flash of a microcon - troller. Embedded aspects, handling of the different events that can happen in the field and the needed safety level are the key factors that should influence the emulation concept described in this application note.

EEPROM Emulation with STR71x

6 REVISION HISTORY

Date Revision Description of changes 13-Jan-2005 1.0 First Release 22-Jul-2005 2.0 Added the Software example section

EEPROM Emulation with STR71x “THE PRESENT NOTE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH A NOTE AND/OR THE USE MADE BY CUSTOMERS OF THE INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.” Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publicati on are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners © 2005 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia – Belgium - Brazil - Canada - China – Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America