Tips for choosing the type of memory and basic principles to be followed
Ora pubblicata: 2020-06-11 11:35:31
The type of memory will determine the operation and performance of the entire embedded system, so the choice of memory is a very important decision.
Regardless of whether the system is battery-powered or mains-powered, the application requirements will determine the type of memory (volatile or non-volatile) and purpose of use (storage code, data, or both). In addition, in the selection process, the size and cost of the memory are also important factors to consider. For smaller systems, the built-in memory of the microcontroller may meet system requirements, while larger systems may require the addition of external memory. When selecting a memory type for an embedded system, some design parameters need to be considered, including the choice of microcontroller, voltage range, battery life, read and write speed, memory size, memory characteristics, erase / write endurance, and system total cost.
Figure 1 lists the most commonly used memory types in embedded applications. The basic principles that should be followed when choosing a memory are discussed below.
Figure 1: Common Embedded system memory types
Basic principles to follow when choosing storage
1. Internal memory and external memory
In general, after determining the storage space required to store program code and data, the design engineer will decide whether to use internal memory or external memory. Normally, internal memory has the highest price-performance ratio but the lowest flexibility, so the design engineer must determine whether the demand for storage will grow in the future and whether there is a way to upgrade to a microcontroller with more code space. Based on cost considerations, people usually choose the microcontroller with the smallest memory capacity that can meet the application requirements, so special care must be taken when predicting the code size, because the increase in code size may require replacement of the microcontroller.
Currently there are external memory devices of various sizes on the market, and it is easy to adapt to the increase in code size by adding memory. Sometimes this means replacing existing memories with memories of the same package size but larger capacity, or adding memories to the bus. Even if the microcontroller has internal memory, it can meet the system's demand for non-volatile memory by adding external serial EEPROM or flash memory.
2. Boot memory
In larger microcontroller systems or processor-based systems, design engineers can use boot code to initialize. The application itself usually determines whether a boot code is required and whether a dedicated boot memory is required. For example, if there is no external addressing bus or serial boot interface, internal memory is usually used instead of a dedicated boot device. But in some systems without internal program memory, initialization is part of the operation code, so all code will reside in the same external program memory. Some microcontrollers have both internal memory and external addressing bus, in this case, the boot code will reside in the internal memory, and the operation code in the external memory. This is probably the safest method, because the operation code does not accidentally modify the boot code. In all cases, the boot memory must be non-volatile memory.
3. Configuration memory
For field programmable gate array (FPGA) or system on chip (SoC), people use memory to store configuration information. Such memory must be non-volatile EPROM, EEPROM or flash memory. In most cases, FPGAs use SPI interfaces, but some older devices still use FPGA serial interfaces. Serial EEPROM or flash memory devices are the most commonly used, and EPROM is used less frequently.
4. Program memory
All systems with processors use program memory, but the design engineer must decide whether this memory is located inside or outside the processor. After making this decision, the design engineer can further determine the memory capacity and type. Of course, sometimes, the microcontroller has both internal program memory and external addressing bus, at this time the design engineer can choose to use any one of them, or both. This is why choosing the best memory for an application is often complicated by the choice of microcontroller, and why changing the size of the memory will also lead to changing the choice of microcontroller.
If the microcontroller uses both internal and external memory, the internal memory is usually used to store code that does not change frequently, and the external memory is used to store code and data that are updated more frequently. Design engineers also need to consider whether the memory will be reprogrammed online or replaced with a new programmable device. For applications that require reprogramming, people usually choose microcontrollers with internal flash memory, but microcontrollers with internal OTP or ROM and external flash memory or EEPROM also meet this requirement. To reduce costs, external flash memory can be used to store code and data, but care must be taken to avoid accidental code modification when storing data.
In most embedded systems, people use flash memory to store programs to upgrade firmware online. Older application systems with stable code can still use ROM and OTP memory, but due to the versatility of flash memory, more and more application systems are turning to flash memory. Table 1 gives a comparison of the parameters of the program memory type.
Table 1: Comparison of program memory types
5. Data storage
Similar to the program memory, the data memory can be located inside the microcontroller or an external device, but there are some differences between the two cases. Sometimes the microcontroller contains both SRAM (volatile) and EEPROM (non-volatile) data memories, but sometimes it does not contain internal EEPROM. In this case, when a large amount of data needs to be stored, the design engineer can choose an external Serial EEPROM or serial flash memory device. Of course, parallel EEPROM or flash memory can also be used, but usually they are only used as program memory.
When an external high-speed data memory is required, parallel SRAM is usually selected and an external serial EEPROM device is used to meet the requirements for non-volatile memory. Some designs also use the flash memory device as a program memory, but reserve a sector as a data storage area. This method can reduce cost, space and provide non-volatile data storage.
For non-volatile memory requirements, serial EEPROM devices support I2C, SPI or microwire (Microwire) communication bus, and serial flash memory usually uses SPI bus. Because the writing speed is very fast and has I2C and SPI serial interface, FRAM is used in some systems. Table 2 compares the advantages and disadvantages of various types of data storage.
Table 2：Comparison of data memory types
6. Volatile and non-volatile memory
Memory can be divided into volatile memory or non-volatile memory, the former will lose data after power off, while the latter can still retain data after power off. Design engineers sometimes use volatile memory with battery backup to make it behave like a non-volatile device, but this may be more expensive than simply using non-volatile memory. However, for systems that require very large memory capacity, DRAM with battery backup may be a method that meets design requirements and is cost-effective.
In systems with continuous energy supply, volatile or non-volatile memory can be used, but the final decision must be made based on the possibility of power failure. If the information in the memory can be recovered from another source when power is restored, volatile memory can be used.
Another reason for choosing volatile memory for use with batteries is speed. Although nonvolatile memory devices can retain data when power is turned off, it takes longer to write data (one byte, page, or sector).
7. Serial memory and parallel memory
After defining the application system, the choice of microcontroller is a factor in deciding whether to choose serial or parallel memory. For larger application systems, the microcontroller usually does not have a large enough internal memory. In this case, an external memory must be used, because the external addressing bus is usually parallel, and the external program memory and data memory will also be parallel.
Smaller applications usually use microcontrollers with internal memory but no external address bus. If additional data storage is required, an external serial storage device is the best choice. In most cases, this additional external data storage is non-volatile.
According to different designs, the boot memory can be serial or parallel. If the microcontroller does not have internal memory, parallel non-volatile memory devices are the right choice for most applications. But for some high-speed applications, an external non-volatile serial storage device can be used to boot the microcontroller and allow the main code to be stored in internal or external high-speed SRAM.
8. EEPROM and flash memory
The maturity of memory technology has blurred the boundary between RAM and ROM. Today, there are some types of memory (such as EEPROM and flash memory) that combine the characteristics of the two. These devices read and write like RAM and retain data when power is off like ROM. They are all electrically erasable and programmable, but each has its own advantages and disadvantages.
From a software perspective, independent EEPROM and flash memory devices are similar. The main difference between the two is that EEPROM devices can be modified byte by byte, while flash memory devices only support sector erasure and words, pages, or sectors of erased cells Area. The reprogramming of flash memory also requires the use of SRAM, so it requires more devices to work for a longer period of time, thereby consuming more battery energy. The design engineer must also confirm that enough SRAM is available when modifying the data.
Memory density is another factor that determines the choice of serial EEPROM or flash memory. The capacity of independent serial EEPROM devices currently available on the market is 128KB or less, and the capacity of independent flash memory devices is 32KB or more.
If multiple devices are cascaded together, serial EEPROM can be used to achieve a capacity greater than 128KB. High erasure / write endurance requirements have prompted design engineers to choose EEPROM because a typical serial EEPROM can be erased / written one million times. Flash memory can generally be erased / written 10,000 times, and only a few devices can achieve 100,000 times.
Today, most flash memory devices have a voltage range of 2.7V to 3.6V. If byte addressability or high erasure / write endurance is not required, the use of flash memory in applications within this voltage range can make the cost relatively low.
9. EEPROM and FRAM
The design parameters of EEPROM and FRAM are similar, but the read and write times of FRAM are very high and the writing speed is relatively fast. However, under normal circumstances, users will still choose EEPROM instead of FRAM, the main reason is the cost (FRAM is more expensive), quality level and supply. Design engineers often use lower-cost serial EEPROMs unless durability or speed are mandatory system requirements.
DRAM and SRAM are both volatile memory. Although both types of memory can be used as program memory and data memory, SRAM is mainly used for data memory. The main difference between DRAM and SRAM is the lifetime of data storage. SRAM can keep its data as long as there is power, but DRAM has only a very short data life, usually about 4 milliseconds.
Compared with SRAM, DRAM seems to be useless, but the DRAM controller inside the microcontroller makes the performance of DRAM the same as SRAM. The DRAM controller periodically refreshes the stored data before the data disappears, so the contents of the memory can be maintained for as long as necessary.
Because of the low bit cost, DRAM is usually used as a program memory, so applications with huge storage requirements can benefit from DRAM. Its biggest disadvantage is its slow speed, but the computer system uses high-speed SRAM as a high-speed buffer memory to make up for the speed defect of DRAM.
Table 3 summarizes the characteristics of the various types of memory mentioned in this article. It should be noted that different types of memory are suitable for different situations, and each type has its own strengths and weaknesses, so comparing item by item does not always yield meaningful results.
Table 3: Characteristics of various types of memory
Summary of this article
Although we can use almost any type of memory to meet the requirements of embedded systems, end application and total cost requirements are usually the main factors that affect our decision-making. Sometimes, combining several types of memory can better meet the requirements of the application system. For example, some PDA designs use both volatile and non-volatile memory as program memory and data memory. Store permanent programs in non-volatile ROM, and store programs and data downloaded by users in volatile DRAM with battery support. Regardless of which memory type is chosen, the design engineer must carefully consider various design factors before deciding which memory will be used in the final application system.Etichetta: memory