EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 3
MCU Memory: Flash, SRAM and EEPROM
Three kinds of memory, each with a different purpose.
Flash memory stores your program. It keeps its contents with the power off and is rewritten when you upload new firmware, but it wears out after many thousands of erase cycles.
SRAM is the working memory for variables and the call stack. It is fast but loses everything at power-off, and it is usually tiny, so large arrays can overflow it.
EEPROM (or emulated EEPROM in flash) holds small settings that must survive power loss, such as a calibration value. Write to it sparingly.
Tip: put constant data such as lookup tables in flash, not SRAM, whenever your toolchain allows.
EXAMPLE
const unsigned char sine_table[4] = {0, 90, 127, 90}; /* constant data: lives in flash */
unsigned char counter = 0; /* variable: lives in SRAM */