Click on the above “Baijun Technology“, select “Pin Public Account”
Embedded technology insights delivered promptly
ROM(Read Only Memory) and RAM(Random Access Memory) refer to semiconductor memory, where ROM retains data even when the system is powered off, while RAM typically loses data after power loss, with the typical RAM being the computer’s memory.
There are many types of ROM, PROM is a programmable ROM, and the difference from EPROM (Erasable Programmable ROM) is that PROM is one-time programmable, meaning that once the software is written, it cannot be modified. This was used in early products and is no longer in use, while EPROM can erase the original program using ultraviolet light. Another type, EEPROM, is erased electronically, is very expensive, and has a long write time.
For example, mobile software is generally placed in EEPROM, and when we make a call, some of the last dialed numbers temporarily exist in SRAM, not immediately written into the call log (which is stored in EEPROM), because there is an important task (the call) to perform at that moment, and the long wait for writing is unbearable for users.
RAM has two main categories, one is called Static RAM (Static RAM/SRAM), which is extremely fast and currently the fastest reading and writing storage device, but it is also very expensive, so it is only used in demanding places, such as CPU’s Level 1 and Level 2 caches.
The other is called Dynamic RAM (Dynamic RAM/DRAM), which retains data for a short time and is slower than SRAM, but still faster than any ROM. However, in terms of price, DRAM is much cheaper than SRAM, and the memory in computers is DRAM.
DRAM is divided into many types, with common ones mainly including FPRAM/FastPage, EDORAM, SDRAM, DDR RAM, RDRAM, SGRAM, and WRAM, among which DDR RAM is introduced here.
DDR RAM (Data-Rate RAM), also known as DDR SDRAM, is an improved type of RAM that is fundamentally the same as SDRAM, but the difference is that it can read and write data twice in one clock cycle, which doubles the data transfer speed.
This is currently the most commonly used memory in computers, and it has a cost advantage, defeating another memory standard from Intel – Rambus DRAM. High-speed DDR RAM is also equipped on many high-end graphics cards to increase bandwidth, significantly improving the pixel rendering capability of 3D accelerator cards.
Memory is used to store data and programs that are currently in use (i.e., executing). The computer memory we usually refer to is dynamic memory (i.e., DRAM), and the so-called “dynamic” in dynamic memory means that when we write data into DRAM, after a period of time, the data will be lost, so an additional circuit is needed for memory refresh operations.
The specific working process is as follows: a DRAM storage unit stores either 0 or 1 depending on whether the capacitor has a charge; a charged capacitor represents 1, while a discharged capacitor represents 0. However, over time, the charged capacitor will discharge, and the capacitor representing 0 will absorb charge, which is the reason for data loss;
Refresh operations periodically check the capacitors, if the charge is greater than half of the full charge, it is considered to represent 1, and the capacitor is fully charged; if the charge is less than half, it is considered to represent 0, and the capacitor is discharged, thus maintaining data continuity.
The commonly used types of Flash are NOR Flash and NAND Flash. NOR Flash was invented by Intel in 1988 to replace the EPROM and EEPROM that dominated the market at that time. NAND Flash was invented by Toshiba in 1989. The main differences between the two are shown in the table below.
NOR |
NAND |
||
Capacity |
1~32MB |
16~512MB |
|
XIP |
Yes |
No |
|
Performance |
Erase |
Very Slow (5s) |
Fast (3ms) |
Write |
Slow |
Fast |
|
Read |
Fast |
Fast |
|
Reliability |
Relatively High, with bit inversion rate less than 10% of NAND Flash |
Relatively Low: bit inversion is common, requiring error checking measures such as “1-4 bit EDC/ECC“; bad block management measures must be in place |
|
Erase Cycles |
10000~100000 |
100000~1000000 |
|
Lifecycle |
Less than 10% of NAND Flash |
More than 10 times that of NOR Flash |
|
Interface |
Same as RAM interface |
I/O Interface |
|
Access Method |
Random Access |
Sequential Access |
|
Usability |
Easy |
Complex |
|
Main Usage |
Commonly used to store code and critical data |
Used for data storage |
|
Price |
High |
Low |
Differences between NOR/NAND Flash
NOR Flash supports XIP, meaning that code can be executed directly from NOR Flash without needing to copy it to memory. This is because NOR Flash’s interface is identical to that of RAM, allowing random access to any address. The efficiency of read operations on NOR Flash is very high, but the efficiency of erase and write operations is very low; additionally, NOR Flash generally has a smaller capacity.
NAND Flash has higher efficiency for erase and write operations and a larger capacity. Generally speaking, NOR Flash is used for program storage, while NAND Flash is used for data storage. Devices based on NAND Flash typically also require NOR Flash to store programs.
Flash memory devices are composed of erase units (also known as blocks), and when writing to a block, it must be ensured that the block has been erased. The block size range for NOR Flash is 64KB to 128KB; for NAND Flash, it is 8KB to 64KB, and erasing/writing a NOR Flash block takes 4s, while erasing/writing a NAND Flash block only takes 2ms.
The blocks of NOR Flash are too large, which not only increases the erase/write time but also requires more erase operations for a given write operation — especially for small files, such as a file that is only 1KB, but to save it, a NOR Flash block of size 64KB to 128KB must be erased.
NOR Flash’s interface is identical to that of RAM, allowing arbitrary access to any address. In contrast, NAND Flash’s interface contains only a few I/O pins and requires serial access. NAND Flash is generally read and written in units of 512 bytes. This makes NOR Flash suitable for running programs, while NAND Flash is more suitable for data storage.
For the same capacity, NAND Flash is smaller in size, allowing for more space savings in systems with strict space requirements. The market capacity for NOR Flash is typically 1 to 4MB (with some 32MB NOR Flash available), while NAND Flash’s capacity ranges from 8 to 512MB. The difference in capacity also means that NOR Flash is more often used for program storage, while NAND Flash is more often used for data storage.
When considering the reliability of Flash memory devices, three points need to be addressed: bit inversion, bad blocks, and erase cycles. All Flash devices encounter the issue of bit inversion: due to the inherent electrical characteristics of FLASH, during the process of reading and writing data, a bit or several bits may occasionally produce errors — this probability is very low, but the occurrence of bit inversion is much higher in NAND Flash than in NOR Flash. When bit inversion occurs on critical code or data, it may lead to system crashes.
If only reporting bit inversion, re-reading is sufficient; if bit inversion does occur, corresponding error detection/recovery measures must be in place. The probability of bit inversion occurring on NAND Flash is higher, so using EDC/ECC for error detection and recovery is recommended.
Bad blocks will be randomly distributed on NAND Flash, and they need to be scanned out before use to ensure they are not used again, or else the product will have serious faults. The erase cycles for each block of NAND Flash are typically around 100,000, which is ten times that of NOR Flash. Additionally, because the block size of NAND Flash is usually 1/8 that of NOR Flash, the lifespan of NAND Flash far exceeds that of NOR Flash.
Linux has mature software support for both NOR and NAND Flash. The jffs2 file system is commonly used on NOR Flash, while the yaffs file system is commonly used on NAND Flash. At a lower level, MTD drivers implement read, write, and erase operations for them, and they also implement EDC/ECC checks.