0
0
Embedded Cprogramming~10 mins

Memory layout on a microcontroller (Flash, SRAM, EEPROM) in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Memory layout on a microcontroller (Flash, SRAM, EEPROM)
Program Start
Load Flash Memory
Initialize SRAM
Access EEPROM
Run Program Loop
End or Reset
This flow shows how a microcontroller uses Flash to store code, SRAM for variables during run, and EEPROM for long-term data.
Execution Sample
Embedded C
const int x = 10;  // stored in Flash
int y = 5;          // stored in SRAM
void main() {
  y = x + 2;
  // EEPROM read/write simulated
}
This code shows constants in Flash, variables in SRAM, and simulates EEPROM usage.
Execution Table
StepMemory AreaActionContentNotes
1FlashStore constant x=10x=10Flash is non-volatile, stores program code and constants
2SRAMAllocate variable y=5y=5SRAM is volatile, stores variables during execution
3SRAMExecute y = x + 2y=12Variable y updated in SRAM
4EEPROMRead stored datadata=previous valueEEPROM stores data that persists after power off
5EEPROMWrite new datadata=updated valueEEPROM write simulated
6-Program runs loop or ends-Microcontroller continues running or resets
💡 Program ends or resets; SRAM loses data, Flash and EEPROM retain contents
Variable Tracker
VariableStart (Flash/SRAM/EEPROM)After Step 2After Step 3After Step 5Final
x (Flash)1010101010
y (SRAM)undefined51212undefined (after reset)
EEPROM dataold valueold valueold valueupdated valueupdated value
Key Moments - 3 Insights
Why does variable y lose its value after reset but x does not?
Because y is stored in SRAM which is volatile and loses data on power off, while x is stored in Flash which is non-volatile and keeps data.
Can we change the value of x during program execution?
No, x is stored in Flash memory which is read-only during normal operation; only variables in SRAM or EEPROM can be changed.
Why use EEPROM if Flash is also non-volatile?
EEPROM allows data to be changed and saved during program run, unlike Flash which is mainly for code and constants.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of y after Step 3?
A5
B12
C10
Dundefined
💡 Hint
Check the 'Content' column for Step 3 in the execution table.
At which step does EEPROM data get updated?
AStep 5
BStep 3
CStep 2
DStep 6
💡 Hint
Look for 'Write new data' action in the execution table.
If the microcontroller resets, which memory area retains its data?
ASRAM only
BEEPROM only
CFlash and EEPROM
DSRAM and Flash
💡 Hint
Refer to the exit note and variable tracker for data retention after reset.
Concept Snapshot
Memory layout on microcontrollers:
- Flash: stores program code and constants, non-volatile
- SRAM: stores variables during execution, volatile
- EEPROM: stores data that must persist across resets
- Variables in SRAM lose data on power off
- Constants in Flash and data in EEPROM persist
Full Transcript
This visual execution shows how a microcontroller uses three main memory areas: Flash, SRAM, and EEPROM. Flash memory holds the program code and constants like x=10. SRAM holds variables like y=5 during program run and changes as the program executes. EEPROM stores data that must be saved even when power is off. The execution table traces storing x in Flash, allocating y in SRAM, updating y, reading and writing EEPROM data, and program running or resetting. Variables in SRAM lose their values after reset, but Flash and EEPROM keep their contents. This helps beginners understand memory roles and data persistence on microcontrollers.