Table of Contents
INTRODUCTION
This is a post explaining the basic memory concepts in embedded systems.
Let’s Dive in…
The fact you’re reading this tells me two things about you
- You’re a complete beginner to Embedded Systems
- You’re an enthusiast or a hobbyist.
Whichever category you place yourself under, one thing I assume you already know is, embedded systems is a combination of hardware and software (at the very basic at least).
Let’s begin by pondering over a few questions…
Have you ever wondered where your code is stored? Or have you wondered how the processor correctly fetches the void main() in your Arduino sketch or at the least from where? To go further, what if you have a bigger project in the make and each file has its own init function or a main function? Then which one is executed and in what order exactly? Is there a conflict of interest or simply just a gap in understanding? Try the last question out on your IDE and drop a comment 🙂
This is going to be from the absolute basics; feel free to use the index to jump to sections you’re most interested in…
TYPES OF MEMORY
Although it may seem like a trivial, rhetorical heading; it is important to cover this heading to set a clear context to the text coming thereafter.
Memory is mainly categorized into two types
- Primary Memory
- Secondary Memory
Keeping this discussion glued to embedded systems, let’s understand them better in context of an embedded system.
Primary Memory
The primary memory as the name suggests is the primary memory storage unit for the processor in the sense data is first searched for in this space(of course there are cache memories and registers before this, but in the comparative sense).
The characteristics entail
- Low capacity (In Most Cases due to the cost): Relatively more expensive and hence capacity is kept to the requirement.
- Low Latency: The name and positioning of the memory within the architecture demands low latency.
- High Reliability: It is required to be robust, without the device’s stability. The system will crash.
- Low Power: In context of Embedded Systems and the associated devices, it is desirable to consume less power in order to keep the overall power rating of the device to the minimal.
As a convention and practice, the primary memory is used to store the program (referring to the code flashed into the controller) data. This is useful and critical in achieving the desired processing speed .
NOTE: These are the ideal characteristics of any memory device, but are considered with more stringency for an embedded system due to limited size, power and cost.
Types of Main Memory
Two types of primary memories used in embedded Systems are
- SRAM
- DRAM
Static Random Access Memory (SRAM)
The name random suggests that the write operation can happen anywhere in the SRAM cell irrespective of the last filled cell.
In addition, let us go through the salient features of SRAM.
- SRAMs are much faster when compared to DRAMs (about 4 times faster access time).
- Volatile in nature: They hold data as long as stable voltage is supplied to the hardware.
- They are made of flip-flops with a transistors base.
- More transistors are required to store one bit of binary data, there are different configurations such as 6T, 8T and so on.
- Called as static as the cells are self-refreshed by the flip-flops, does not need external power to refresh the cells.
- Primarily used as Caches in most electronic devices and used as a primary memory unit in time critical applications such as automotive embedded ECUs.
- Great performance comes at a steep price. Thus, SRAMs are chosen wisely only as per need basis.
The detailed functioning of SRAMs is beyond the scope of this post!
Dynamic Random Access Memory (DRAM)
The term dynamic is coined because the capacitors need to be refreshed constantly for it to continue storing the same bit of information.
In addition, let us go through the salient features of the DRAM.
- Relatively slower in terms of the access time when compared to that of SRAM, but still faster than mass storage devices.
- Uses Capacitors to store the bit of information. Each bit is stored in a different capacitor.
- Volatile in Nature.
- More power consumed in the constant refresh process.
- More data can be stored in the same area compared to SRAM.
Note: There are special cases of RAM (such as NVRAM) that work slightly differently than the ones discussed above. For the sake of focus, we are restricting our discussion to only SRAM and DRAM.
Secondary Memory
Secondary Memory, as the name suggests is used as a secondary storage device (which means it does not withhold time critical information, it may be read or written on need basis at run time) in general and in embedded systems as well.
The main advantage of a secondary memory device is its capacity to retain information with or without power, thus, making it a storage unit for embedded code along with other things written for the device.
There are different types of Secondary memories commonly used.
Secondary memory is broadly categorized into three types
- ROMs
- Flash
- Hybrid: NVRAM
Let’s understand each of them in detail to better gauge their real use in embedded systems.
Read-Only Memory (ROM)
Contrary to the name given, advancements in technology has enabled these storage devices to both read and write; and based on the easiness and feasibility to do this, they are categorized into different types.
PROM: Programmable Read-Only Memory
As the name suggests, this kind of storage device once programmed cannot be reprogrammed and is only meant to read data out. These standalone memory units are considered only in cases where there are no further changes to be made or no remote upgrades to be given by the manufacturing company.
The device is used as a storage unit in relatively smaller embedded devices such as TVs, Ovens and so on. Once the device is written, the fuses are blown at the time of fabrication to avoid further changes to the memory.
EPROM: Erasable Programmable Read-Only Memory
The next advancement in the ROM line is the EPROM; it is capable of being erased and rewritten, thus re-programmable.
Few Characteristics worth mentioning are
- Programmable multiple times with the help of a device programmer.
- Less robust when compared to PROM.
- It is moderately expensive and hence a preferred choice of memory in Embedded Systems.
- Non-Volatile in nature and hence it retains the information stored with or without power.
- Typically used to store firmware and constants in the code. Boot Loaders are also sometimes stored in this memory region.
EEPROM: Electrically Erasable Programmable Read-Only Memory
This is the widely used storage unit in modern day real time embedded systems and advancement to EPROM in the sense it is electrically erasable Vis-à-vis UV race erasing in EPROM.
Few characteristics worth mentioning are
- Used to store firmware and code constants.
- They are usually external to the controller itself and data is read and written by a protocol such as I2C, SPI etc. It could also be embedded on the SOC itself, i.e. comes with controller, but it usually isn’t the case. Usually flash storage is what comes along with the controller.
- The main advantage over flash is the fact it allows for single byte write operation. This is a very critical characteristic trait as erasing the whole page to accommodate a single bit change becomes an overhead.
- Fast; minimizing access time.
FLASH Memory
The flash memory is commonly used in embedded systems to store the code and constants. They are relatively cost effective when compared to EEPROM, thus Flashes are used to store larger data units. Other than for the way data is written onto the memory, FLASH and EEPROM are not very different.
Few Characteristics worth mentioning are
- Can be erased block at a time. This typically changes from vendor to vendor.
- Has two main types NAND Flash and NOR Flash. NOR being the less dense and preferred one coming at a heftier cost.
- Access time is irrespective of the location similar to that of RAM.
- Data cannot be appended. The block needs to be erased in order to accommodate even a byte change.
- Read and Write operations typically are in page units whereas erase is in block units.
- The numbers of write cycles that can be performed are in orders of magnitude lesser than the EEPROM. Data reliability and retention is the same across FLASH and EEPROM.
HYBRID MEMORY
Non-Volatile Random Access Memory (NVRAM)
This is a hybrid memory device having the speed of a conventional RAM device and storage capability of a Flash or ROM, thus making it a very expensive data storage device. It is used to store extremely time sensitive data.
Other commonly used Memories in Embedded Systems
- Layer 1 Cache
- Layer 2 cache
- Registers
Layer 1 and 2 Caches
Layer 1 and Layer 2 caches are a notch faster than the primary DRAMs. These are used to store the most critical information a processor needs next. Having said that, they come at a steep price and making a technical decision on as to its actual need is imperative.
Few characteristics worth mentioning
- Extremely Fast. The processor first searches for the required data from L1 Cache and failing to find it goes to the L2 Cache.
- L1 and L2 have mutually exclusive data. Same Data is not loaded to both L1 and L2 although as per some design principles this may also done.
- SRAMs are sometimes used as L1 Caches.
- It is of course a volatile storage space.
- Larger cache sizes starts to become counter-productive as more searching needs to done.
- There are algorithms to map primary memory to Caches; in the sense how data from Primary memory is loaded onto cache and what goes where.
Please feel free to go through the below write up on L1 and L2 cache. It is very informative!!
Registers
The most desirable data storage units of the processor are the registers for obvious reasons that they reside inside of the processor/controller. These hardware registers store run time data, used for loading operands and data.
There are 2 types of registers
- General Purpose Registers – used for normal computations and manipulations.
- Special Function Registers – used for critical data storage such as stack pointers, flag handlers, IO flags etc.
Summary
The following text can be summarized pictorially as shown below
With this, we come to a conclusion on the types of memories used in an embedded system. With this context being set, let us try to understand, how the code we write is physically mapped to the memory. This will be continued in the next post!
Thanks for Reading!
As always, feel free to drop your comments.
NOTE: THE COVER PAGE DOES NOT BELONG TO ME. CREDIT GOES TO THE CREATOR ALONE.
All the best bro for your future endeavours!!!
Very informative, great effort to consolidate all related information, waiting for more.
Thanks kathir!
Liked the pictorial representation. Easier to read and understand. Looking forward to more chapters.
Thanks for your feedback Allwin!
Well-structured quality content!
Thanks for your feedback Deepthi!
Very informative! ?
Thanks Sneha!
Amazing explanation of the fundamentals.
Thanks Ayush!