Embedded Memory Types Explained-Embedded C Training in Hyderabad

PREV_LEC  |  NEXT_LEC

Embedded Memory Types Explained

ROM, RAM, Flash, EEPROM, and the memory hierarchy — from EmbeddedPathashala’s free embedded systems course

5 Memory Types
4 Comparison Tables
100% Free Course

Memory is where an embedded system’s identity actually lives — its firmware, its runtime state, and its calibration data all sit in different kinds of memory chosen deliberately for speed, cost, and persistence. In this lecture from EmbeddedPathashala’s free embedded systems course, we break down every memory type you will encounter on a real MCU datasheet: ROM, RAM, Flash, EEPROM, SRAM, DRAM, and the full memory hierarchy that connects them. If you are comparing options for the best embedded systems training in Hyderabad or working through an embedded systems course online at your own pace, this chapter gives you the exact depth firmware engineers use on the job — not just textbook definitions.

Key Terms Covered in This Lecture

ROM RAM Flash Memory EEPROM SRAM vs DRAM Volatile Memory Memory Hierarchy

What You Will Learn

  • The five core memory types used in embedded systems and what each one is for
  • How ROM and RAM differ in volatility, purpose, and speed
  • Why Flash memory is the standard choice for storing firmware on modern MCUs
  • When to use EEPROM instead of Flash for configuration data
  • The real electrical and cost differences between SRAM and DRAM
  • How the memory hierarchy (registers → cache → SRAM → Flash) affects performance
  • The distinction between code memory and data memory in a Harvard architecture

Prerequisites

This lecture builds on the previous chapter, “Embedded Processing Units Explained”, where we introduced the STM32F411RE and its on-chip Flash and SRAM. Reviewing that lecture first will make the memory concepts here click faster, though it is not mandatory.

5.2 Memory in Embedded Systems

Memory in an embedded system stores three distinct things: the program code itself, the runtime data the program manipulates, and configuration parameters that must survive a power cycle. Choosing the right memory type for each of these jobs is a core embedded systems design skill, and it directly affects your product’s cost, speed, and reliability.

5.2.1 Types of Memory

An embedded engineer will typically work with five memory types across a project: ROM, RAM, Flash, EEPROM, and — in more advanced systems — Cache. Each exists because no single memory technology can be simultaneously the fastest, cheapest, and most persistent.

5.2.2 ROM vs RAM

ROM (Read-Only Memory) is non-volatile — it retains its contents without power — and is traditionally used to store firmware that should rarely or never change. RAM (Random Access Memory) is volatile, losing its contents the instant power is removed, and is used to store data that only matters while the system is actively running.

ROM vs RAM — Quick Comparison

FeatureROMRAM
VolatilityNon-volatileVolatile
PurposeStore firmwareStore runtime data
SpeedSlowerFaster

5.2.3 Flash Memory

Flash memory is the dominant non-volatile memory technology in modern embedded systems. It stores your compiled program code, and — unlike classic ROM — it can be erased and rewritten many times, which is exactly how you re-flash new firmware onto a development board during debugging.

On the STM32 family (and virtually every modern MCU), the compiled program’s .text section is stored directly in on-chip Flash. Because Flash is non-volatile, your firmware survives a power loss and begins executing again automatically the next time the board is powered on.

5.2.4 EEPROM

EEPROM (Electrically Erasable Programmable Read-Only Memory) is another non-volatile memory type, but unlike Flash, it supports fine-grained byte-level access rather than requiring erase operations on large blocks or pages. This makes it the natural choice for small amounts of data that change occasionally but must persist across power cycles.

Typical EEPROM use cases include storing calibration values (such as sensor offset corrections) and device serial numbers — data you write once or update rarely, but which must never be lost when the device is powered off.

5.2.5 SRAM vs DRAM

SRAM (Static RAM) and DRAM (Dynamic RAM) are both volatile, but they differ significantly in speed, cost, and how they retain data internally. SRAM uses flip-flop circuits that hold their state as long as power is applied, requiring no refresh. DRAM stores each bit as a charge on a tiny capacitor that leaks over time and must be refreshed thousands of times per second.

SRAM vs DRAM — Quick Comparison

FeatureSRAMDRAM
SpeedVery fastSlower
CostHighLow
RefreshNoYes

Most MCUs — including the STM32F411RE with its 128 KB of on-chip SRAM — use SRAM for their internal data memory, because the amount of RAM needed on a typical embedded product is small enough that SRAM’s higher per-bit cost is not a limiting factor, and its speed and simplicity (no refresh controller needed) make it the clear winner on-chip.

5.2.6 Volatile vs Non-Volatile Memory

This distinction cuts across every memory type above and is one of the first concepts every embedded student must internalize: volatile memory (RAM, including SRAM and DRAM) loses its data the moment power is removed, while non-volatile memory (Flash, EEPROM, ROM) retains its data indefinitely without power. Firmware always lives in non-volatile memory; working data always lives in volatile memory.

5.2.7 Memory Hierarchy

No single memory technology can be the fastest, cheapest, and largest all at once — so embedded systems (like all computer systems) organize memory into a hierarchy, trading capacity for speed as you move closer to the CPU core.

Embedded Memory Hierarchy
Registers (fastest, smallest) → Cache → SRAM → Flash / External Memory (slowest, largest)

The rule of thumb is simple: the closer a memory sits to the CPU core, the faster it is — and the smaller its capacity tends to be. Registers are the fastest memory of all because they live directly inside the CPU, while Flash or external memory offers large capacity at the cost of much higher access latency.

5.2.8 Code Memory vs Data Memory

Code memory stores the compiled instructions your CPU fetches and executes, while data memory stores the variables, stack, and heap your program manipulates while running. In a Harvard architecture — used by most modern MCUs, including the ARM Cortex-M4 core in the STM32F411RE — code memory and data memory sit on physically separate buses, allowing the CPU to fetch an instruction and access data simultaneously, which significantly improves throughput compared to a single shared-bus (Von Neumann) design.

Common Mistakes Beginners Make

  • Storing frequently-changing data in Flash — Flash has a limited number of erase/write cycles (often tens of thousands), so writing to it every few seconds will wear it out; use RAM or EEPROM instead for frequently updated values.
  • Assuming EEPROM and Flash are interchangeable — EEPROM supports byte-level writes ideal for small config data, while Flash typically requires erasing an entire page/sector before rewriting, making it better suited for larger, less frequent updates like full firmware images.
  • Forgetting that RAM contents are lost on reset — any variable that must survive a power cycle or reset must be explicitly saved to non-volatile memory (Flash or EEPROM), not left in RAM.
  • Ignoring memory hierarchy effects on performance — code or data placed in slower external memory instead of on-chip SRAM/Flash can silently bottleneck a real-time application.

Best Practices for Embedded Memory Usage

  • Keep the compiled firmware image in Flash, and reserve RAM strictly for runtime variables, stack, and heap
  • Use EEPROM (or an emulated EEPROM region in Flash, common on MCUs without dedicated EEPROM) for calibration values and serial numbers that change rarely
  • Budget your SRAM usage carefully on constrained MCUs — check your linker map file to see actual stack, heap, and static data usage
  • Minimize Flash write/erase cycles in your application logic to extend the chip’s operational lifetime
  • Where performance matters, place time-critical code and data in the fastest available memory tier (on-chip SRAM) rather than external memory

Summary and Key Takeaways

Every embedded system relies on a deliberate mix of memory types: ROM and Flash for non-volatile firmware storage, RAM (typically SRAM on-chip) for fast volatile working data, and EEPROM for small persistent configuration values. The memory hierarchy — registers, cache, SRAM, and Flash/external memory — governs the speed-versus-capacity tradeoff that shapes real-time performance, while the code memory vs data memory split in a Harvard architecture lets modern MCUs fetch instructions and access data in parallel. Mastering these distinctions is essential groundwork in this free embedded systems course, whether you’re self-studying or pursuing the best embedded systems training in Hyderabad.

Frequently Asked Questions

What is the difference between ROM and RAM in embedded systems?

ROM is non-volatile and used to store firmware, retaining data without power but at slower access speeds. RAM is volatile and used for runtime data, offering much faster access but losing its contents when power is removed.

Why is Flash memory used instead of traditional ROM in modern MCUs?

Flash memory offers the same non-volatile persistence as ROM but can be erased and rewritten many times, which is essential for reprogramming firmware during development and for field updates.

When should I use EEPROM instead of Flash?

Use EEPROM for small amounts of data that change occasionally and need byte-level write access, such as calibration values or serial numbers. Use Flash for the larger, less frequently updated firmware image.

What is the difference between SRAM and DRAM?

SRAM is faster, more expensive, and needs no refresh, making it ideal for on-chip MCU memory. DRAM is slower, cheaper, and requires periodic refreshing, making it common in larger external memory used by microprocessors.

Why does memory hierarchy matter in embedded systems?

Memory hierarchy balances speed and capacity: registers and cache are fastest but smallest, while Flash and external memory are largest but slowest. Placing time-critical code and data closer to the CPU improves real-time performance.

What is the difference between code memory and data memory?

Code memory stores the compiled program instructions the CPU executes, while data memory stores variables, the stack, and the heap. In a Harvard architecture, these live on separate buses so both can be accessed simultaneously.

Does the STM32F411RE use SRAM or DRAM?

The STM32F411RE uses 128 KB of on-chip SRAM, which is standard for MCUs because SRAM’s speed and simplicity outweigh its higher per-bit cost at the small memory sizes typical embedded applications need.

Is this embedded systems course online really free?

Yes. EmbeddedPathashala’s embedded systems course, including this memory chapter, is completely free and covers processing units, memory, peripherals, embedded C, and Linux kernel/device driver development.

Continue Your Embedded Systems Journey

Explore more free lectures in this course and build real hands-on skills.

Browse the Full Course Next: Embedded Peripherals

PREV_LEC  |  NEXT_LEC

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *