The ESP32's flash memory is non-volatile storage for your code (firmware), Wi-Fi credentials, and settings, persisting even when power is off, acting like a built-in SSD for the chip, using QSPI for fast access, and is crucial for storing your IoT application's permanent data and firmware, with tools like ESP-IDF and Arduino IDE managing the flashing process. Flashing involves uploading compiled code (bin files) to this memory, often using dedicated software or IDE features, and can include security features like flash encryption for protecting IP.

In this article, we will go over it.

Flash memory structure on ESP32

The ESP32 is typically equipped with 4MB to 16MB of Flash memory, of which:

Program (code you wrote): It is stored in the first part of the Flash memory. This is where the firmware you upload to the ESP32 is stored.

SPIFFS/LittleFS: The ESP32 supports the SPIFFS and LittleFS file systems, allowing for the storage of text files, images, and other data.

Partition Table: The partition table contains information about how the flash memory is divided and used.

image.png

image.png

The function of the Flash memory on the ESP32:

Program storage (Firmware): Flash memory stores the program code that the microcontroller will execute.

Storing user data: By using file systems like SPIFFS or LittleFS, you can store configuration files, images, and sensor data.

OTA Update (Over-the-Air): Allows for remote firmware updates without the need for a physical connection.

Using Flash memory on ESP32

To use the Flash memory on the ESP32, you can follow these steps:

To use the Flash memory on the ESP32, you can follow these steps:

Storing and reading data using EEPROM on the ESP32 allows you to easily write and retrieve important information such as Wi-Fi configuration and sensor parameters. The EEPROM library simplifies these operations through simple commands, ensuring that the data is stored persistently and remains available even after resets or power outages.

image.png

Write and read one character

#include <EEPROM.h>

void setup() {
Serial.begin(115200); 
EEPROM.begin(512); // Initialize EEPROM with 512 bytes

// Write data to EEPROM
EEPROM.write(0, 'A'); 
EEPROM.commit(); 

// Read data from EEPROM
char value = EEPROM.read(0); 
Serial.print("Read from EEPROM: "); 
Serial.println(value);
}

void loop() {
// Do nothing in this loop
}