Both flash memory and EEPROM provide non-volatile, electrically erasable storage. Compared to EEPROM, flash-memory cells are physically smaller, can withstand more erase/write cycles, and are cheaper to manufacture. The main disadvantage of flash memory is that unlike EEPROM, flash memory is erasable only in blocks, not by individual byte. Even so, for most storage devices, flash memory is the more practical choice, while EEPROM is useful for storing infrequently changed configuration settings.
Two flash-memory technologies in popular use are NOR and NAND.
NOR flash is suited for storing program code, where the CPU wants fast read access but rarely writes to the memory. NOR flash has fast read times but slow erase and write times. NOR flash has low density, so large amounts of storage may require multiple chips. To access NOR flash, a CPU uses the same data and address lines used to access other parallel memory chips.
Storage devices use NAND flash, which has fast erase and write times. NAND flash also has lower power consumption and is much cheaper than NOR flash. A CPU accesses NAND flash chips via data lines and command and address registers. NAND flash has high density, so large amounts of memory can fit in a small package. The advantages of NAND flash are so attractive that some devices use NAND flash for program memory along with a RAM cache to improve performance.
Three varieties of NAND flash are Old Single-level Cell (SLC), New SLC, and Multi-level Cell (MLC). MLC memory stores multiple bits in each cell and is popular because it’s cheaper to manufacture. However, compared to SLC memory, MLC memory supports fewer erase cycles, has slower write times, and consumes more power. These are the typical number of erase cycles supported by each memory type: Old SLC: 1,000,000, New SLC: 100,000, MLC: 10,000.
Wear-leveling techniques can extend the useful life of flash memory by writing to different physical locations in each erase/write cycle. A typical write operation accesses only a portion of the memory in a flash-memory card. Writing to different locations with each write operation helps to spread the erase/write operations evenly to all areas of the memory and extends the life of the memory as a whole. A card that uses chips rated for 10,000 erase cycles can thus withstand a much greater number of erase operations if each operation erases a portion of the memory. Wear leveling is especially important if the chip stores files or structures such as file allocation tables (FATs) that are rewritten frequently.
To accomplish wear leveling, firmware can map each logical address to a physical address that changes with each write operation. Higher-level firmware writes to the logical addresses, and the wear-leveling firmware translates the addresses to physical locations in the memory. For example, write operations can be mapped to the physical addresses in sequence, starting over at the beginning after reaching the end.
Error correcting code (ECC) bytes enable a controller to verify data in read operations. The controller generates and stores an ECC when writing to a block and can use the code to verify the data after reading the block. Manufacturers of flash-memory cards may implement additional protocols to help ensure data reliability. For example, under margin conditions, the controller in a Sandisk MultiMediaCard reads data back after writing to verify the write operation. If a bit is bad, the controller replaces the bit with a spare bit. The controller can also replace an entire bad block with another block. Higher-level protocols can also support error correcting via checksums sent with data.
Options for Flash Memory
Using flash-memory cards rather than raw flash chips has two advantages. The controller in the card greatly simplifies accessing the memory. And cards are easily removable and replaceable, so you can store data in multiple cards and replace cards that fail or wear out.
Things to consider when selecting a type of flash-memory card include physical size, capacities, interfacing options, data-transfer speed, power-supply voltage, and cost. Cost includes the price for the memory cards and connectors as well as any charges for specification documents, licensing, and royalties. If protecting the media’s contents from writing or copying is important, some cards have this capability built in.
Figure 1-5: Each MultiMediaCard contains memory, registers, and an intelligent controller.
For many embedded systems, a MultiMediaCard host is a good choice because the cards are small, many microcontrollers can interface to them, and MultiMediaCard hosts have no licensing fees. A MultiMediaCard host can also communicate with SD Cards if the connector accepts the slightly thicker SD cards. Other options are an SD-Card host or CompactFlash host.