Home / Learn Chip Programming / Memory: Registers, SRAM, DRAM, Flash and EEPROM

Memory: Registers, SRAM, DRAM, Flash and EEPROM

A chip has many kinds of memory. Each one trades speed, size, cost and whether it keeps data without power.

In shortRegisters are fastest and tiny. SRAM is fast and used for RAM on microcontrollers. DRAM is dense. Flash and EEPROM keep data without power.

Theory in plain words

Memory hierarchy (fast and small on top)CPU registers: under 1 ns, a few dozen bytesCache (SRAM): 1 to 10 ns, KB to MBMain RAM (SRAM or DRAM): about 50 to 100 nsFlash / SSD / EEPROM: slower, keeps data without power
Memory hierarchy (fast and small on top)

What it is

Memory stores bits. Volatile memory loses its contents when power is removed (RAM). Non-volatile memory keeps it (Flash, EEPROM, ROM).

Why we use it

No single memory is fast, large, cheap and permanent. Chips combine several kinds in a hierarchy so programs run fast and data survives power off.

How it works

The CPU asks for a value at an address. The memory returns the byte stored there. Address lines choose the location, data lines carry the value, control lines say read or write.

Where it is used

  • Microcontroller: Flash holds your program, SRAM holds variables, EEPROM holds settings
  • PC and phone: registers, cache, DRAM, SSD
  • FPGA: block RAM and LUT RAM

Comparison

TypeVolatile?SpeedCellTypical use
Registeryesfastestflip-flopsCPU working values
SRAMyesvery fast6 transistorsmicrocontroller RAM, cache
DRAMyes (needs refresh)fast1 transistor + 1 capacitorPC and phone main memory
ROM / Mask ROMnofast readfixed at the factoryboot code
Flash (NOR)nofast read, slow writefloating gateprogram memory
Flash (NAND)nodense, block erasefloating gateSSD, SD cards, USB sticks
EEPROMnoslow writefloating gate, byte erasesmall settings and calibration

Memory map: everything has an address

On a microcontroller the CPU sees one address space. Flash, SRAM and peripheral registers each live in a different address range. Reading address 0x20000000 on an STM32 reads SRAM. Writing 0x40020014 changes a GPIO register.

Address range (STM32F1 example)What is there
0x0800 0000Flash memory (your code)
0x2000 0000SRAM (variables and stack)
0x4000 0000Peripheral registers (GPIO, UART, timers)
0xE000 0000Core peripherals (SysTick, interrupt controller)

Read and write a byte memory

A tiny 16 byte RAMTry it Yourself

Write 72, 105 at addresses 0 and 1: you stored the ASCII letters "H" and "i". Memory is just numbers; the meaning comes from how the program uses them.

Careful:Flash has a limited number of erase cycles (often 10,000 to 100,000). Never write to the same Flash or EEPROM cell in a fast loop. Use SRAM for working data and write to Flash only when a setting really changes.

Quick quiz

1. Which memory keeps data without power?

2. Where does your program normally live on a microcontroller?

Common questions

Which memory keeps data without power?

Flash. Flash is non-volatile.

Where does your program normally live on a microcontroller?

Flash. Code is stored in Flash; variables use SRAM.