Memory is a critical component in embedded systems, as it stores both the programs that drive the system’s behavior and the data that the system processes. In embedded systems, memory can be classified into two primary types: volatile memory and non-volatile memory. Each plays a distinct role, and both are essential for the proper functioning of any embedded system.
In this article, I will dive deeply into volatile and non-volatile memory, discussing their roles, types, applications, and practical usage in embedded systems.
Volatile memory refers to memory that loses its stored information once power is removed. The most common type of volatile memory in embedded systems is Random Access Memory (RAM). RAM is used for temporary data storage during program execution, acting as a workspace for the CPU to store variables, stacks, and intermediate computations.
In an embedded system like an STM32 microcontroller, RAM is used to store temporary data such as sensor readings or variable calculations during program execution. For instance:
int temperature_buffer[100]; // Allocates space in RAM for 100 temperature readings
This memory is wiped when the system loses power, making it suitable for short-term data storage but not for permanent data retention.
Non-volatile memory retains its data even when power is removed, making it ideal for storing programs, configuration settings, and any data that must survive power cycles.
In an STM32 microcontroller, flash memory stores the firmware code that is executed when the microcontroller is powered on. For example, the program that reads data from sensors and displays it on a screen would be stored in the flash memory. Whenever the system is turned on, the code is retrieved from flash and executed.
EEPROM is commonly used to store user settings, such as the preferred temperature in a thermostat. Even after a power cycle, the setting is retained as it is stored in non-volatile EEPROM:
EEPROM.write(0x00, preferred_temperature); // Store preferred temperature in EEPROM
Type | Function | Advantages | Disadvantages |
---|---|---|---|
SRAM | Stores temporary data, very fast | Fast access, no refreshing required | More expensive, less storage density |
DRAM | Main memory storage for larger systems | High density, cheaper | Slower, requires refreshing |
Flash Memory | Stores firmware, bootloaders, large blocks of data | Non-volatile, high capacity | Slower write speeds, needs block erasure |
EEPROM | Stores user settings, small configurations | Non-volatile, byte-level access | Limited write cycles, slower than RAM |
Both volatile and non-volatile memory play essential roles in embedded systems, with practical applications including: