Roborear

Microcontroller Memory Types Explained: A Complete Guide for Beginners

Generated image 1
Generated image 1 1 e1784639188491

The “Wait, How Many Memory Types?!” Moment

I was staring at the spec sheet for an ESP32 when I saw it.

SRAM. DRAM. IRAM. PSRAM. RTC RAM. Flash. ROM. EEPROM.

Seven different types of memory. On one tiny chip.

My brain short-circuited. My PC has ONE stick of RAM. Why does a microcontroller smaller than my fingernail need seven different types?

That question sent me down a rabbit hole. And what I found is actually pretty clever.

Let me explain why your microcontroller has so many different types of memory — and why it’s actually genius engineering.

Memory 101: The Two Families

Before we dive into specific types, let’s start with the big picture. Every memory type in a microcontroller belongs to one of two categories :

 
 
FamilyWhat It MeansExamples
VolatileForgets everything when power is offRAM types (SRAM, DRAM, PSRAM)
Non-volatileRemembers even when power is offROM types (Flash, EEPROM)

The desk analogy:

  • Volatile memory = Your desk. Everything you’re working on is there while you’re working. But when you leave, it gets cleared.

  • Non-volatile memory = Your filing cabinet. Stuff stays there even when you’re not in the room.

Every microcontroller has at least one of each. But the fun part is how different chips split up those two categories to be more efficient.

Why So Many Types? The Three Reasons

1. Speed vs Power Trade-off

The faster the memory, the more electricity it guzzles . Your PC doesn’t care about this—it’s plugged into the wall. But a microcontroller might run on a tiny coin cell battery for YEARS. It needs to sip power like a vampire.

2. Physical Space

A microcontroller is smaller than your fingernail. There’s no room for one big block of fast SRAM. Engineers have to squeeze in tiny “pockets” of different memory types where they fit .

3. Job Specialization

A PC runs an operating system that juggles 50 programs at once. It needs ONE giant flexible pool of RAM. A microcontroller does ONE job at a time — and engineers know exactly how much memory each job will take.

The Core Three: Flash, SRAM, and EEPROM

Every microcontroller has these three fundamental memory types .

Flash (The Notebook)

 
 
PropertyDetails
TypeNon-volatile
SpeedSlowest
PurposeStores your program permanently
AnalogyThe notebook that holds your code
Examples32KB on Arduino Uno, 4MB on ESP32

When you upload a sketch to your Arduino, it goes into Flash. It stays there even when you unplug the board. That’s why your program is still there the next time you power on .

Fun fact: Flash memory retains data without power by trapping charge on an isolated floating gate within each cell .

SRAM (The Desk)

 
 
PropertyDetails
TypeVolatile
SpeedFastest
PurposeVariables, stack, heap
AnalogyThe desk where active work happens
Examples2KB on Arduino Uno, 512KB on ESP32

SRAM is where your variables, the stack, and the heap live while your program runs . It’s super fast — much faster than Flash. But it’s volatile, so everything disappears when power is cut.

Why no DRAM in most MCUs? DRAM is cheap and holds a lot, but it needs constant refreshing and takes a separate controller. For a tiny MCU, that’s usually too big, too complex, and consumes too much power .

EEPROM (The Filing Cabinet)

 
 
PropertyDetails
TypeNon-volatile
SpeedSlow
PurposeSettings, configuration data
AnalogyThe filing cabinet for settings
Examples1KB on Arduino Uno

EEPROM is non-volatile like Flash, but you can change individual bytes instead of whole blocks . Perfect for saving settings like WiFi passwords or calibration values.

Note: Not every modern microcontroller has dedicated EEPROM. Some use Flash emulation instead — a software technique that uses a portion of Flash memory to simulate EEPROM behavior .

The Harvard Architecture: Why Program and Data are Separate

Here’s something that blew my mind. Many microcontrollers use something called Harvard architecture .

In the Harvard architecture:

  • Program instructions and program data live in separate memory units

  • The CPU can access both at the same time

Why this matters:

  • It’s faster (no waiting for one or the other)

  • It’s safer (your program can’t accidentally overwrite itself)

In contrast, your PC uses Von Neumann architecture where program and data share the same memory pool.

ESP32’s Specialized Memory

The ESP32 takes memory management to the next level by splitting its RAM into specialized zones for speed and power saving .

IRAM (Instruction RAM)

 
 
PropertyDetails
PurposeRunning critical code (interrupts)
SpeedFastest
LocationInternal
VolatileYes

IRAM is used for code that must run from RAM, like interrupt handlers or timing-critical functions . The default design typically places 200KB of SRAM on the instruction memory bus (IRAM), and 320KB on the data memory bus (DRAM) .

When to use IRAM: Interrupt handlers must be placed into IRAM if ESP_INTR_FLAG_IRAM is used when registering the interrupt handler .

DRAM (Data RAM)

 
 
PropertyDetails
PurposeVariables, heap, stack
SpeedFast
LocationInternal
VolatileYes

This is the normal working memory for variables, the heap, and all your runtime data .

Wait, isn’t this the same as SRAM? Yes! The ESP32 SDK calls it “DRAM” to distinguish it from IRAM, but technically, it’s just SRAM dedicated to data. Don’t confuse it with the DRAM in your PC — it’s not the same thing !

RTC SRAM (The Sticky Note)

 
 
PropertyDetails
PurposeTimekeeping in deep sleep
SpeedSlowest
LocationInternal (battery-backed)
VolatileNo (stays alive in sleep)

RTC memory can retain its contents even when the main CPUs are in deep-sleep mode, as long as the RTC domain remains powered . It’s used by the ULP co-processor and the main application to store data that needs to persist across deep-sleep cycles.

PSRAM (The Expansion Pack)

 
 
PropertyDetails
PurposeExtra memory for big projects
SpeedSlower than internal
LocationExternal (separate chip)
VolatileYes

PSRAM (Pseudo-SRAM) is external memory connected to the ESP32 that acts like extra RAM for big projects . It’s slower than internal SRAM, but it’s much bigger — perfect for audio streaming, camera buffers, complex graphics, and machine learning models.

What is PSRAM? It’s a type of memory that acts like DRAM (dynamic) but looks like SRAM (static) to the software. It provides a middle ground between speed, cost, and capacity .

STM32’s Special Memory Types

STM32 microcontrollers have their own set of specialized memory types for speed and persistence.

CCM RAM (Core Coupled Memory)

 
 
PropertyDetails
PurposePerformance-critical data/code
SpeedUltra-fast
LocationInternal (near CPU)
VolatileYes

CCM RAM is tightly coupled with the ARM Cortex core, allowing code execution at the maximum system clock frequency without any wait-state penalty . It’s typically used for real-time and computation-intensive routines like digital power conversion control loops, field-oriented 3-phase motor control, and real-time DSP tasks .

Performance benefit: A benchmark between STM32F103 and STM32F303 shows that when code runs from CCM SRAM, the total execution time drops by 20.33% compared to running from Flash .

Backup SRAM

 
 
PropertyDetails
PurposeData retention during power loss
SpeedSlow
LocationInternal (battery-backed)
VolatileNo (battery-backed)

Backup SRAM can retain data when the main system is powered down — as long as you have a backup battery connected . Perfect for storing critical system state or sensor calibration data that you don’t want to lose during a power outage.

The Stack vs Heap (Understanding SRAM)

Your SRAM is divided into two main areas: the stack and the heap .

The Stack (Organized Piles)

 
 
PropertyDetails
PurposeLocal variables, function calls
GrowthDownwards
SpeedFast
Automatic managementYes

The stack stores temporary data like local variables inside functions. It’s organized and predictable .

The Heap (Open Space)

 
 
PropertyDetails
PurposeDynamic memory allocation
GrowthUpwards
SpeedSlower
Automatic managementNo (use malloc/free)

The heap is for dynamic memory — data you create and destroy whenever you want .

The danger: If you forget to free memory on the heap, you’ll get a memory leak. And on a tiny MCU with only kilobytes of RAM, a memory leak can crash your program fast.

Pro tip: In memory-constrained MCUs (RAM < 16KB), it’s often best to avoid dynamic memory allocation entirely. Use global or static variables instead.

Comparison Table

 
 
Memory TypeSpeedVolatile?LocationPurposeBoard Examples
Flash🐢 Slower❌ NoInternalStores your programAll boards
SRAM⚡ Fastest✅ YesInternalMain workspaceAll boards
EEPROM🐢 Slower❌ NoInternalSettings storageArduino Uno
IRAM⚡ Fastest✅ YesInternalCritical code (interrupts)ESP32
DRAM⚡ Fast✅ YesInternalData workspaceESP32
RTC SRAM🐢 Slower⚠️ Yes (but stays alive in sleep)InternalTime, alarms in deep sleepESP32, STM32
PSRAM🐢 Slower✅ YesExternalExtra memory for big projectsESP32 (some models)
CCM RAM⚡ Fastest✅ YesInternal (near CPU)Performance-critical data/codeSTM32
Backup SRAM🐢 Slower⚠️ Yes (but battery-backed)InternalData retention during power lossSTM32

What This Means For You

 
 
If You’re Working With…What To Know
Arduino Uno (AVR)Simple: Flash (program), SRAM (variables), EEPROM (settings). Don’t worry about IRAM/PSRAM.
ESP32IRAM for critical code, DRAM for variables, RTC for deep sleep, PSRAM for big projects. Use IRAM_ATTR for interrupt handlers.
STM32Fast CCM RAM for performance-critical code. Backup SRAM for battery-backed data.
Any MCUWatch your stack and heap! They share SRAM and can collide.

Your Turn

So, next time you look at a microcontroller spec sheet and see a confusing list of memory types, you’ll know exactly what each one does.

  • Flash stores your program

  • SRAM runs your program

  • EEPROM saves your settings

  • IRAM speeds up critical code

  • RTC RAM remembers the time in sleep

  • PSRAM gives you extra space

  • CCM RAM delivers ultra-fast performance

  • Backup SRAM retains data through power loss

Different microcontrollers use different combinations of these memory types depending on what they’re designed for. An Arduino Uno keeps it simple with Flash, SRAM, and EEPROM. An ESP32 adds more specialized RAM for performance and power saving. And an STM32 gives you even more options for speed and data persistence.

It’s not magic. It’s engineering. And now you understand it.

Frequently Asked Questions

1. Why does my PC have one big stick of RAM, but my microcontroller has so many types?

It’s all about power, space, and job duties. Your PC is plugged into the wall—it can afford one big power-hungry pool of RAM. A microcontroller runs on a tiny battery for years, so it uses multiple specialized pockets that turn on only when needed. Plus, the MCU is smaller than your fingernail—there’s no room for a separate RAM chip! Everything has to be squeezed onto one tiny piece of silicon, so each memory type is specially built for its specific job.

 
Bad things. Very bad things. If your stack and heap collide, you’ll get unpredictable behavior—data corruption, hard faults, or your program just crashing. On a tiny MCU with only kilobytes of RAM, this is a real risk. To prevent it, avoid dynamic memory allocation (malloc/free) whenever possible. Use global or static variables instead. And always keep track of your memory usage !

Yes, but it depends on the chip. Some microcontrollers like the ESP32 support external PSRAM—a separate memory chip connected via SPI that gives you extra workspace. Other chips like STM32 support external SDRAM or QSPI/OSPI flash for bigger projects. But remember: external memory is slower than internal memory, so use it for big files (like audio buffers) rather than performance-critical code.

DRAM (Dynamic RAM) needs constant refreshing to retain data, is cheap, and holds a lot of data . It’s used in PCs and phones. PSRAM (Pseudo-SRAM) acts like DRAM internally but looks like SRAM to the software. It provides a middle ground between speed, cost, and capacity, and is often used in low-power mobile devices and embedded systems .

Running code from Flash requires going through the MMU cache, which can introduce delays from cache misses. IRAM (Instruction RAM) is directly accessible to the CPU with zero wait states, making it significantly faster. That’s why interrupt handlers and timing-critical code should be placed in IRAM .

Leave a Comment

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

Scroll to Top
Roborear Logo
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.