Benefits of Flash EEPROM: Re-programming the End Application Becomes Easy
When compared to one time programmable (OTP) or read only memory (ROM) microcontrollers (MCUs), a flash memory-based MCU is distinguished by its ability to be reprogrammed. Many applications today need memory not only for storing the application program but also for storing data, which may need to be updated from time to time and must be retained in the application system, even after power off. For example, with a remote control, the user does not want to lose the preferred settings every time the battery is changed. External serial EEPROM can serve this purpose well, but adding another component to the system means higher system cost, a larger board footprint and degraded system reliability. An MCU with reprogrammable flash memory is a good choice for such an application, particularly if the application program needs a periodic upgrade to a newer version with enhanced features.
To best utilize flash memory for electrically erasable programmable read only memory (EEPROM) emulation or firmware upgrades, the MCU must be designed with a good flash controller module. This allows the embedded designer to in-system program or erase the flash memory in a comparatively convenient and user-friendly way. A special flash control module can also be used so that developers do not need to manipulate the bits of the flash control registers. Instead, firmware developers just need to issue erase or programming commands from the application program. When programming or erasing the flash memory, an internal charge pump eliminates the need for external high voltage.
In this article, we describe the flash EEPROM features of a flash-based MCU and how end applications can benefit from specially designed dual flash arrays.
Emulating EEPROM Using a Single Flash Array
Emulating EEPROM using flash memory requires in-system erasing and programming. For devices with a single flash array, the program algorithm used to conduct the programming or erasing operations cannot be located in the same flash array that is going to be programmed or erased. Instead, the algorithm is typically executed from RAM. The user application needs to copy the program algorithm from flash memory to RAM and then jump to this RAM program to execute the algorithm.
An alternative strategy, to avoid having to copy the program algorithm from RAM, is to hard code the program in the MCU’s ROM during wafer processing, allowing the application program to be executed directly from ROM. Figure 1 shows the execution flow of in-system flash programming.
Emulating EEPROM Using Dual Flash Arrays
Freescale’s MC9S08LC family of MCUs will be used as an example. Each member has a dual flash array, each with its own flash control logic. The program and erase operations can be performed on one array while executing code from the other. There is no need to execute the program algorithm in RAM or ROM during the in-system programming process. Dual flash arrays greatly simplify the process of using flash to emulate EEPROM. For example, the programming algorithm and the application code can be stored in Flash A while Flash B is treated as flash EEPROM. The user can simply execute the code in Flash A to erase or program data in Flash B.
Benefits to the End Application Using an MCU with Dual Flash Array
Simplicity of the system design. Dual flash array in-system programming and EEPROM emulation frees up more RAM for the application and eliminates the need for external EEPROM. It simplifies the application program, which is especially helpful to software engineers who face tight memory resources. In addition, the I/O pins that would have been used for external EEPROM can be used for other functions in the end application.
System cost saving. Total system cost can be reduced by using a smaller pin count MCU with less I/O while still eliminating the need for an external EEPROM component. No system features are sacrificed, yet the PCB is smaller and the testing time on the production line is lowered because the overall system is simpler.
Better system reliability. The most frustrating issue when using a single array flash MCU to perform in-system programming occurs when the power suddenly goes off during the process. By using an MCU with dual flash array, the process is much safer because the programming algorithm in either of the flash arrays will not be lost during power off. This greatly contributes to overall system reliability when undergoing in-system programming activity.
Further advantages can be realized through dual flash array in-system programming. Again using the MC9S08LC family as an example, programming and erasing of each flash array can be conducted through the same command interface, simplifying the end application program. For better system reliability, the flash array is designed so that it is not possible to page-erase or program both arrays at the same time. Since the mass-erase command will erase both arrays, its use is not recommended when coding the end application program. Developers are advised to use page erase command to erase the flash array during in-system programming.
Initially, flash memory was primarily intended for program storage. However, because it can be reprogrammed, it can also be used to emulate EEPROM. MCUs with dual flash arrays provide simpler and more reliable in-system programming to implement EEPROM emulation. Furthermore, sudden power off will no longer disrupt the process in systems employing dual flash array MCUs. Therefore, in-system programming and field upgrades are both easier and safer.
Roger Fan is a System and Application Engineer at Freescale Semiconductor, Inc. For more information, contact Freescale Semiconductor, 6501 William Cannon Drive West, Austin, TX 78735; 800-521-6274; www.freescale.com