Skip to main content

Posts

Showing posts from October, 2024

[Basic] C program and SRAM, flash, stack, heap ... Why microcontrollers use different types of memory like that?

Preface When you build the source code in C/C++, you might see some output messages as the blow: Flash used: 1166 of 262144 bytes (0.4%). SRAM used: 2505 of 65536 bytes (3.8%). Stack: 2048 bytes. Heap: 128 bytes. --------------- Rebuild Succeeded: 10/01/2024 17:46:40 --------------- Figure 1: The output message from PSoC Creator Figure 2: The output message from Arduino IDE Have you asked yourself what are technical jargon such as flash, stack, and heap? In short, they are kinds of memory for machines. Microcontrollers use different types of memory (Flash, SRAM, EEPROM, etc.) because each type serves a specific purpose, balancing factors like cost, speed, power consumption, and data persistence . Key Differences Between These Memory Types: The explanation for the output message in the figure 1: Flash used : 1222 of 262144 bytes (0.5%) The program's code occupies 1222 bytes of the total available 262144 bytes in Flash memory. This is a very small portion, showing efficient memory us