SPIFFS

0.3.7
SPIFFS is a lightweight, heap-less file system designed for SPI NOR flash devices on resource-constrained embedded targets. It provides a POSIX-like API for flat file structures while implementing static wear leveling and garbage collection to maximize flash longevity and performance.

Features

  • Designed for low RAM usage on small embedded targets without dynamic memory allocation (heap).

  • Uses statically sized RAM buffers that remain independent of the number of files present.

  • Provides a POSIX-like API including open, close, read, write, seek, and stat functions.

  • Compatible with any NOR flash, including SPI flash and internal microprocessor flash.

  • Supports multiple SPIFFS configurations running concurrently on the same target or flash device.

  • Implements static wear leveling to prolong the life of flash memory by distributing erase cycles.

  • Includes built-in file system consistency checks to ensure data integrity after power loss.

  • Highly configurable through compile-time defines to adjust page/block sizes and features.

  • Supports optional file metadata for storing additional information alongside files.

  • Features index memory mapping to improve file reading performance and determinism.

  • Includes a temporal cache system to speed up file opening operations by caching file descriptors.

  • Offers a read-only build configuration to minimize the library’s binary footprint.

  • Provides both quick (non-intrusive) and full-scale (intrusive) garbage collection mechanisms.

  • Supports a flat file structure without directory support to minimize metadata overhead.

  • Includes API functions for file system formatting and retrieving usage information.

  • Allows for file renaming and explicit error code clearing via SPIFFS_clearerr.

  • Supports singleton mode to optimize performance and RAM when only one instance is used.

  • Configurable garbage collection heuristics to tune wear-leveling behavior.

  • Provides a HAL layer requiring only three basic functions: read, write, and erase.

Architecture

SPIFFS operates on a logical abstraction layer over physical NOR flash memory. It divides the flash into logical blocks, which are further subdivided into logical pages. A logical page is the smallest unit of data storage and metadata tracking. The system is designed to be entirely heap-less, relying on user-provided static buffers for work areas, file descriptors, and optional caches. This design ensures deterministic memory usage, which is critical for small embedded systems.

The file system utilizes a flat structure where filenames can include slashes to simulate paths, but no actual directory hierarchy exists. This minimizes the metadata overhead required for navigation. The architecture includes a Hardware Abstraction Layer (HAL) that requires only three primitive operations from the user: read, write, and erase. Internally, SPIFFS manages an object index to track file locations and a garbage collector that reclaims space from deleted or modified files while maintaining wear leveling across the flash blocks.

Core Components

  • HAL Interface: The bridge between SPIFFS and physical flash hardware, handling address-based read, write, and erase calls.
  • Object Indexer: Manages file metadata, including names, sizes, and the mapping of logical pages to physical locations.
  • Garbage Collector: Implements heuristics to select blocks for erasure, balancing free space reclamation with wear leveling.
  • Cache Subsystem: Provides optional read/write caching and a temporal file descriptor cache to improve performance on frequently accessed files.
  • Consistency Checker: A built-in tool to verify the integrity of the file system structure and repair common issues caused by unexpected power loss.

Use Cases

This library is ideal for:

  • IoT Sensors: Storing periodic sensor readings on small SPI flash chips where RAM is extremely limited.
  • Configuration Management: Saving and updating device settings, calibration data, and network credentials in non-volatile memory.
  • Bootloaders: Utilizing the read-only mode to load firmware images from flash while maintaining a minimal binary footprint.
  • Data Logging: Efficiently appending logs to files with wear leveling to prevent premature failure of specific flash sectors.
  • Embedded Web Servers: Storing static assets like HTML, CSS, and JavaScript files for local device management dashboards.
  • Resource Storage: Storing UI assets, fonts, or lookup tables for microcontrollers driving small displays.

Getting Started

To integrate SPIFFS into an embedded project, begin by copying the source files from the src/ directory and the spiffs_config.h template into your build system. You must define basic integer types (e.g., u32_t, s32_t) in the configuration header to match your architecture. The integration requires implementing three HAL functions for your specific flash hardware: read, write, and erase.

Once the HAL is ready, initialize a spiffs_config struct with the physical parameters of your flash (start address, total size, and block sizes) and provide the necessary static RAM buffers for the work area and file descriptors. Call SPIFFS_mount to initialize the system. If the flash is unformatted or contains invalid data, SPIFFS_format must be called before a successful mount can occur. For detailed configuration options and performance tuning, refer to the SPIFFS Wiki.

Related Projects (178)

View All 178 Projects →
OttoClaw

OttoClaw

OttoClaw is an AI-powered desktop humanoid robot system built on the ESP32-S3 and FreeRTOS. It features a local lightweight agent that handles conversation, memory, and autonomous physical movements through six servos without relying on cloud servers, utilizing LVGL for its graphical interface and SPIFFS for local data persistence.

freertos lvglspiffslwip
Plume — M5Cardputer ADV Edition

Plume — M5Cardputer ADV Edition

A passive RF scanner for the M5Cardputer ADV that detects Flock Safety ALPR cameras and Raven surveillance devices. It utilizes WiFi promiscuous mode and BLE scanning on the ESP32-S3, running entirely locally without cloud connectivity. Detections are logged to an SD card with GPS coordinates and signal strength visualizations.

freertos littlefsspiffsnimbleh2zero-esp-nimble-cpp
ehRadio

ehRadio

ehRadio is a feature-rich internet radio firmware for the ESP32 platform, specializing in the ESP32-S3 for high-performance audio streaming. It features a mobile-first WebUI, supports multiple audio decoders like I2S and VS1053, and integrates seamlessly with Home Assistant via MQTT.

freertos spiffs
Pomodoro Timer Dial for M5Stack Dial

Pomodoro Timer Dial for M5Stack Dial

An efficient and modular Pomodoro timer implementation specifically designed for the M5Stack Dial v1.1. It leverages the ESP32-S3 to provide a smooth rotary-based user interface, smart break calculations, and a high-performance display engine with SPIFFS-based asset management.

spiffs
Quntis LED Controller

Quntis LED Controller

A DIY remote controller for the Quntis Monitor Light Bar PRO+ that enables smart home integration using an ESP32 and NRF24L01 module. It features a dedicated sniffer to capture proprietary remote addresses and supports both standalone MQTT and native ESPHome configurations.

freertos spiffs
TankSync

TankSync

TankSync is a solar-powered, local-first smart water monitoring system built on ESP32 and ESP32-C3 hardware using the ESP-IDF framework. It utilizes long-range LoRa communication to bridge rooftop sensors with an indoor hub, offering Home Assistant integration and offline reliability via FreeRTOS-based firmware.

freertos spiffslwip

CircuitPal

CircuitPal is a multi-function ESP32 gadget featuring an SH1106 OLED display and a three-button navigation system. It integrates an NTP-synced clock, live weather updates via OpenWeatherMap, and a custom GIF player using a page-based state machine architecture. The device simplifies connectivity with a captive-portal WiFi setup and utilizes NVS flash for persistent credential storage.

spiffs
FlightRadar24-TTGO

FlightRadar24-TTGO

FlightRadar24-TTGO is an ESP32-based firmware that provides a real-time aircraft tracking display on TTGO and LilyGo-T-Display-S3 modules. It leverages the FlightRadar24 API for live updates and uses the LVGL library to render detailed flight information and carrier logos. The project includes a web-based configuration portal for setting location parameters, units, and traffic filters.

freertos lvgltft-espispiffs