</>EmbeddedInterview

What is the difference between flash and EEPROM, and what is wear levelling?

MediumMicrocontrollers & ARM Cortex-M

Short answer: Both are non-volatile memories. Flash is erased in large blocks (sectors or pages, typically 1–128 KB on MCUs) and programming can only change bits from 1 to 0; to change a 0 back to 1 you must erase the whole block. EEPROM can usually be erased and written byte by byte. Both wear out after a limited number of erase/write cycles (typically 10,000 for MCU flash, 100,000 to 1,000,000 for EEPROM). Wear levelling spreads writes across many locations so no single block reaches its limit early.

Flash (MCU embedded) EEPROM
Erase unit sector/page (KBs) byte or word
Write unit word/double-word/row (bits 1 → 0 only) byte
Endurance ~10k cycles (some 100k) 100k–1M cycles
Retention 10–20 years 10–100 years
Speed erase ms (sector: up to seconds), program µs write ~3–5 ms per byte/page
Density / cost high / low low / higher
Reads while writing usually blocks reads of the same bank independent (external EEPROM)

Emulated EEPROM on flash (common technique)

  • Use two (or more) flash pages. Store records as (ID, value) pairs appended sequentially.
  • To update a value, append a new record; the newest record for an ID is valid.
  • When a page fills, copy the latest value of each ID to the other page, then erase the old page.
  • Each erase now covers many updates, multiplying the effective endurance.

Wear levelling in general: log-structured storage, rotating sectors, keeping erase counts per block. Filesystems like LittleFS (MCU), UBIFS and F2FS (Linux) do this; managed flash (eMMC, SD) has a controller that does it internally.

Power-loss safety: a write or erase interrupted by power failure leaves a half-programmed area. Use sequence numbers and CRCs per record, write the new copy before invalidating the old, and validate at boot.

Endurance calculation example: writing a 32-byte record every minute to a 2 KB page pair with 10k cycles: each page holds 64 records → one erase per 64 minutes per page, alternating → each page erased about every 2 hours → 10k cycles last ~2.3 years. Using 8 pages instead extends it ~4×. Interviewers like to see this kind of estimate.