Skip to content

Storage & SD Card

The ESP32-P4-WIFI6-DEV-KIT provides two storage options beyond the main firmware flash: a high-speed microSD card slot and 16 MB of onboard NOR flash. This guide covers setting up both for file I/O in your applications.

StorageInterfaceCapacitySpeedUse case
microSD cardSDIO 3.0 (4-bit)Up to 128 GB+Up to ~50 MB/sLarge files, logs, media, OTA images
Onboard NOR flashQSPI16 MB~40 MB/s readConfiguration, small assets, SPIFFS/LittleFS

The SDIO 3.0 interface supports:

  • SDHC: 4 GB — 32 GB (FAT32)
  • SDXC: 64 GB — 2 TB (exFAT, with appropriate filesystem support)
  • Speed class: Class 10 or UHS-I recommended for sustained write performance
  1. Power off the board.

  2. Insert a microSD card into the TF card slot on the board. The slot uses a push-push mechanism — press to insert, press again to eject.

  3. Power the board back on.

  1. Include the SDMMC and VFS headers in your application:

    #include "esp_vfs_fat.h"
    #include "sdmmc_cmd.h"
    #include "driver/sdmmc_host.h"
  2. Mount the SD card using the SDMMC host driver:

    #define MOUNT_POINT "/sdcard"
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = false,
    .max_files = 5,
    .allocation_unit_size = 16 * 1024,
    };
    sdmmc_card_t *card;
    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    host.max_freq_khz = SDMMC_FREQ_HIGHSPEED; // 40 MHz
    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config.width = 4; // 4-bit SDIO mode
    esp_err_t ret = esp_vfs_fat_sdmmc_mount(
    MOUNT_POINT, &host, &slot_config, &mount_config, &card);
    if (ret == ESP_OK) {
    sdmmc_card_print_info(stdout, card);
    }
  3. Once mounted, use standard C file I/O:

    FILE *f = fopen("/sdcard/data.txt", "w");
    if (f) {
    fprintf(f, "Sensor reading: %d\n", sensor_value);
    fclose(f);
    }
    f = fopen("/sdcard/data.txt", "r");
    if (f) {
    char line[64];
    fgets(line, sizeof(line), f);
    printf("Read: %s", line);
    fclose(f);
    }
  4. Unmount when done (important before power-off to prevent corruption):

    esp_vfs_fat_sdcard_unmount(MOUNT_POINT, card);

The board includes 16 MB of NOR flash connected via QSPI. Part of this flash is used for firmware storage. The remaining space can be partitioned for application data.

ESP-IDF uses a partition table to divide the flash into regions. A typical layout:

PartitionTypeSizePurpose
nvsdata24 KBNon-volatile storage (WiFi credentials, settings)
phy_initdata4 KBPHY calibration data
factoryapp4 MBMain application firmware
storagedata~10 MBApplication data (SPIFFS, LittleFS, or FATFS)
ota_0 / ota_1appvariableOTA update slots (if OTA is enabled)

SPIFFS (SPI Flash File System) is a lightweight filesystem designed for NOR flash:

#include "esp_spiffs.h"
esp_vfs_spiffs_conf_t conf = {
.base_path = "/storage",
.partition_label = "storage",
.max_files = 5,
.format_if_mount_failed = true,
};
esp_err_t ret = esp_vfs_spiffs_register(&conf);
if (ret == ESP_OK) {
FILE *f = fopen("/storage/config.json", "w");
fprintf(f, "{\"brightness\": 80}");
fclose(f);
}

LittleFS handles power-loss resilience better than SPIFFS and is recommended for applications where data integrity is critical:

Terminal window
idf.py add-dependency "joltwallet/littlefs"
#include "esp_littlefs.h"
esp_vfs_littlefs_conf_t conf = {
.base_path = "/storage",
.partition_label = "storage",
.format_if_mount_failed = true,
};
esp_vfs_littlefs_register(&conf);
FactormicroSD cardOnboard NOR flash
Capacity4 GB — 128+ GB~10 MB usable
RemovableYesNo
Speed (write)~10—50 MB/s~1—3 MB/s
Wear levelingHandled by card controllerMust use wear-aware FS (LittleFS)
Power-loss safetyRisk of corruption without unmountLittleFS handles gracefully
Best forLogs, media, large datasetsConfiguration, small assets, OTA
SymptomCauseFix
SD card mount failsCard not formatted as FAT32Reformat the card (use SD Card Formatter tool)
“No card detected”Card not fully insertedReseat the card in the slot
Slow write speedsUsing 1-bit SDIO modeSet slot_config.width = 4 for 4-bit mode
Flash partition not foundPartition label mismatchVerify the label matches your partitions.csv
SPIFFS corruption after power lossSPIFFS limitationMigrate to LittleFS for better resilience