SRAM or DRAM? EEPROM or flash? What types of memory will you use in your next embedded systems design?
Many types of memory devices are available for use in modern computer systems. As an embedded software engineer, you must be aware of the differences between them and understand how to use each type effectively. In our discussion, we will approach these devices from the software developer''s perspective. Keep in mind that the development of these devices took several decades and that their underlying hardware differs significantly. The names of the memory types frequently reflect the historical nature of the development process and are often more confusing than insightful. Figure 1 classifies the memory devices we''ll discuss as RAM, ROM, or a hybrid of the two.
当今的计算机系统中有多种类型的存储设备可以使用。作为嵌入式软件工程师,你必须知道这些存储设备间的区别并且懂得如何去有效使用不同类型的存储器。在这篇论述中,我们将从软件工程师的角度来了解这些设备。要知道,这些设备的发展经历了几十年,它们的硬件在根本上存在显著差别。不同类型存储器的名字通常反映了其历史发展过程,比起便于通过名称来区分,它们更容易被混淆。图一把我们将要讨论的存储设备按照RAM,ROM和两者的结合进行了分类。
Figure 1. Common memory types in embedded systems
图1. 嵌入式系统常用的存储器类型
Types of RAM
The RAM family includes two important memory devices: static RAM (SRAM) and dynamic RAM (DRAM). The primary difference between them is the lifetime of the data they store. SRAM retains its contents as long as electrical power is applied to the chip. If the power is turned off or lost temporarily, its contents will be lost forever. DRAM, on the other hand, has an extremely short data lifetime-typically about four milliseconds. This is true even when power is applied constantly.
RAM家族包含两者重要的存储设备:静态RAM(SRAM)和动态RAM(DRAM)。两者的主要区别是它们存储的数据寿命周期。SRAM在整个加电器件保存它存储的数据,如果电源关闭或临时断电,加电期间保存的数据将永久丢失;而DRAM的数据存储周期极短,大概只有4ms,哪怕是在连续加电器件也是如此。
In short, SRAM has all the properties of the memory you think of when you hear the word RAM. Compared to that, DRAM seems kind of useless. By itself, it is. However, a simple piece of hardware called a DRAM controller can be used to make DRAM behave more like SRAM. The job of the DRAM controller is to periodically refresh the data stored in the DRAM. By refreshing the data before it expires, the contents of memory can be kept alive for as long as they are needed. So DRAM is as useful as SRAM after all.
简而言之,SRAM具有你所知道的所有RAM具有的属性。相比而言,DRAM显得用途要少一些。不过,DRAM中自带的称为DRAM控制器的硬件可以使得DRAM更接近SRAM。DRAM控制器的工作就是周期刷新存储在DRAM中的数据,通过在失效前更新数据,DRAM中的信息可以在需要的时候一直保持有效。因此,实际上DRAM跟SRAM一样有用。
When deciding which type of RAM to use, a system designer must consider access time and cost. SRAM devices offer extremely fast access times (approximately four times faster than DRAM) but are much more expensive to produce. Generally, SRAM is used only where access speed is extremely important. A lower cost-per-byte makes DRAM attractive whenever large amounts of RAM are required. Many embedded systems include both types: a small block of SRAM (a few kilobytes) along a critical data path and a much larger block of DRAM (perhaps even Megabytes) for everything else.
当决定使用哪种类型的RAM时,系统设计人员必须考虑存取速度和时间成本。SRAM设备满足极短的存取时间(大约比DRAM快4倍),但是制造成本却要高很多,一般仅当对存取速度要求非常高的时候才选择使用SRAM。每字节较低的成本使得DRAM在需求大容量RAM的时候很有吸引力。很多嵌入式系统包含有两种类型的存储器:一块存储程序运行时所需关键数据的小容量SRAM(几k字节)和一块存储所有其他数据的大容量DRAM(可能甚至达若干兆字节)。
Types of ROM
Memories in the ROM family are distinguished by the methods used to write new data to them (usually called programming), and the number of times they can be rewritten. This classification reflects the evolution of ROM devices from hardwired to programmable to erasable-and-programmable. A common feature of all these devices is their ability to retain data and programs forever, even during a power failure.
ROM家族的存储器通过向它们写入新数据的方式(通常叫做编程)和能被反复写入的次数来区分。图1中ROM的分类方式反映了ROM从硬连线到可编程再到可擦除且可编程的演变。这些存储设备一个共有的特征是,即使在掉电的情况下,它们也能永久保存数据和程序。
The very first ROMs were hardwired devices that contained a preprogrammed set of data or instructions. The contents of the ROM had to be specified before chip production, so the actual data could be used to arrange the transistors inside the chip. Hardwired memories are still used, though they are now called "masked ROMs" to distinguish them from other types of ROM. The primary advantage of a masked ROM is its low production cost. Unfortunately, the cost is low only when large quantities of the same ROM are required.
最初的ROM是包括有一套预编程的数据或指令的硬连线设备,ROM中的内容必须在芯片生产前指定,这样才能根据实际数据的需要来调整芯片内部的晶体管。硬连线的存储器仍然在使用,只是它们现在被称作掩膜ROM以区别于其他类型的ROM,掩膜ROM的主要优势在于它的低制造成本。遗憾的是,只有当有大量相同的ROM需求时,ROM的成本才会低。
One step up from the masked ROM is the PROM (programmable ROM), which is purchased in an unprogrammed state. If you were to look at the contents of an unprogrammed PROM, you would see that the data is made up entirely of 1''s. The process of writing your data to the PROM involves a special piece of equipment called a device programmer. The device programmer writes data to the device one word at a time by applying an electrical charge to the input pins of the chip. Once a PROM has been programmed in this way, its contents can never be changed. If the code or data stored in the PROM must be changed, the current device must be discarded. As a result, PROMs are also known as one-time programmable (OTP) devices.
掩膜ROM朝前更进一步的是PROM(可编程ROM),它在购买的时候处于未编程的状态。如果打算查看一片未编程的PROM,你将会发现它内部数据的每一位都是1。把你的数据写入PROM的过程需要一款叫做编程器的设备,它通过对芯片的输入脚充电来每次向ROM写入一个字的数据。一旦PROM通过这种方式编程,它内部的数据将永远保持不变,如果存储在PROM中的代码或数据需要改变,那么当前的存储设备必须作丢弃处理。结果是,PROM也被称为一次可编程设备(OTP)。
An EPROM (erasable-and-programmable ROM) is programmed in exactly the same manner as a PROM. However, EPROMs can be erased and reprogrammed repeatedly. To erase an EPROM, you simply expose the device to a strong source of ultraviolet light. (A window in the top of the device allows the light to reach the silicon.) By doing this, you essentially reset the entire chip to its initial--unprogrammed--state. Though more expensive than PROMs, their ability to be reprogrammed makes EPROMs an essential part of the software development and testing process.
EPROM(可擦擦可编程ROM)的编程方式与PROM完全相同,不过,EPROM可被擦除并且能够被反复再编程。若擦除EPROM,你只需要使用强紫外线照射存储器即可(光线通过EPROM存储器顶上的窗口到达内部硅片),通过这种方式就可以将整个芯片复位到初始未编程状态。尽管相比PROM更昂贵,但可再编程的能力使EPROM成为软件开发和测试过程中不可或缺的部分。
Hybrids
As memory technology has matured in recent years, the line between RAM and ROM has blurred. Now, several types of memory combine features of both. These devices do not belong to either group and can be collectively referred to as hybrid memory devices. Hybrid memories can be read and written as desired, like RAM, but maintain their contents without electrical power, just like ROM. Two of the hybrid devices, EEPROM and flash, are descendants of ROM devices. These are typically used to store code. The third hybrid, NVRAM, is a modified version of SRAM. NVRAM usually holds persistent data.
随着近年存储器技术的成熟,RAM和ROM间的界线逐渐变得模糊。如今,多种类型的存储器都结合了两者的特征,这些设备不单独属于RAM或ROM,它们共同属于混合存储设备。混合存储器可以按照想要的方式读写,像RAM一样却又不用像RAM那样需要加电,这又如ROM一样。两种混合存储器EEPROM和flash是ROM存储器的后代,它们主要用来存储代码。第三种混合存储器NVRAM是SRAM的改进版,NVRAM通常保存需永久存储的数据。
EEPROMs are electrically-erasable-and-programmable. Internally, they are similar to EPROMs, but the erase operation is accomplished electrically, rather than by exposure to ultraviolet light. Any byte within an EEPROM may be erased and rewritten. Once written, the new data will remain in the device forever--or at least until it is electrically erased. The primary tradeoff for this improved functionality is higher cost, though write cycles are also significantly longer than writes to a RAM. So you wouldn''''''''t want to use an EEPROM for your main system memory.
EEPROM是电可擦除可编程的。它的内部类似于EPROM,但是它的擦除操作是通过电来完成的,而非紫外线的照射。EEPROM内的任意字节都可被擦除和重新写入,一旦被写入,新写入的数据将在存储器内永久保存--或至少保存到直到下一次被电擦除。这一改进的代价是更高的成本,写周期也比向RAM写入数据显著曾长。因此,你不会愿意使用EEPROM作为你的主存储器。
Flash memory combines the best features of the memory devices described thus far. Flash memory devices are high density, low cost, nonvolatile, fast (to read, but not to write), and electrically reprogrammable. These advantages are overwhelming and, as a direct result, the use of flash memory has increased dramatically in embedded systems. From a software viewpoint, flash and EEPROM technologies are very similar. The major difference is that flash devices can only be erased one sector at a time, not byte-by-byte. Typical sector sizes are in the range 256 bytes to 16KB. Despite this disadvantage, flash is much more popular than EEPROM and is rapidly displacing many of the ROM devices as well.
flash存储器结合了目前为止描述的存储器件的最好特性,它具有高密度、低成本、非易失性、快速(读取速度,而非写入速度)、电可重复编程等特点,这些压倒性的优势使flash在嵌入式系统中的应用急剧增加。从软件的视角看,flash和EEPROM技术非常相似,主要区别在于flash设备只能一扇区一扇区,而不是一字节一字节的擦除,典型的擦除扇区大小在256字节到16K字节之间。尽管有这一缺陷,flash还是比EEPROM受欢迎的多,而且还在快速取代多种ROM设备。
The third member of the hybrid memory class is NVRAM (non-volatile RAM). Nonvolatility is also a characteristic of the ROM and hybrid memories discussed previously. However, an NVRAM is physically very different from those devices. An NVRAM is usually just an SRAM with a battery backup. When the power is turned on, the NVRAM operates just like any other SRAM. When the power is turned off, the NVRAM draws just enough power from the battery to retain its data. NVRAM is fairly common in embedded systems. However, it is expensive--even more expensive than SRAM, because of the battery--so its applications are typically limited to the storage of a few hundred bytes of system-critical information that can''''''''t be stored in any better way.
混合存储器的第三种类型是NVRAM(非易失随即存取存储器),非易失性也是ROM和前面讨论的混合存储器的特点,不过,NVRAM在物理上与那些设备不同,NVRAM通常就是带有备份电池的SRAM。当电源打开时,对NVRAM的操作与其他SRAM操作一样;当电源关闭时,NVRAM利用电池提供的电源来保存其内部的数据。NVRAM在嵌入式系统中相当常见,不过它的价格成本高昂--由于增加了电池成本,它甚至比SRAM还要贵--因此,它的应用也就被限制在存储一些没有更好存储方式的几百字节系统关键信息。
Table 1 summarizes the features of each type of memory discussed here, but keep in mind that different memory types serve different purposes. Each memory type has its strengths and weaknesses. Side-by-side comparisons are not always effective.
表1总结了这里所讨论的每种类型存储器的特点,不过需要记住,不同类型的存储器用于不同目的,每种类型存储器都有它自身的优势和缺点,并行的进行比较并不一定总是有效。
Type
|
Volatile?
|
Writeable?
|
Erase Size
|
Max Erase Cycles
|
Cost (per Byte)
|
Speed
|
SRAM
|
Yes
|
Yes
|
Byte
|
Unlimited
|
Expensive
|
Fast
|
DRAM
|
Yes
|
Yes
|
Byte
|
Unlimited
|
Moderate
|
Moderate
|
Masked ROM
|
No
|
No
|
n/a
|
n/a
|
Inexpensive
|
Fast
|
PROM
|
No
|
Once, with a device programmer
|
n/a
|
n/a
|
Moderate
|
Fast
|
EPROM
|
No
|
Yes, with a device programmer
|
Entire Chip
|
Limited (consult datasheet)
|
Moderate
|
Fast
|
EEPROM
|
No
|
Yes
|
Byte
|
Limited (consult datasheet)
|
Expensive
|
Fast to read, slow to erase/write
|
Flash
|
No
|
Yes
|
Sector
|
Limited (consult datasheet)
|
Moderate
|
Fast to read, slow to erase/write
|
NVRAM
|
No
|
Yes
|
Byte
|
Unlimited
|
Expensive (SRAM + battery)
|
Fast
|
Table 1. Characteristics of the various memory types
表1. 不同类型存储器的特点
This article was published in the May 2001 issue of Embedded Systems Programming. If you wish to cite the article in your own work, you may find the following MLA-style information helpful:
Barr, Michael. "Memory Types," Embedded Systems Programming, May 2001, pp. 103-104.