From cf9ffc29b0ad8e5acd875f05b81e7098eb13110b Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Mon, 28 Sep 2026 15:47:57 +0200 Subject: [PATCH] feat(wio-tracker-l2): internal flash as LittleFS instead of SPIFFS helpers/esp32/InternalFS.h picks the filesystem: -D ESP32_LITTLEFS mounts LittleFS on the same "spiffs" partition, otherwise SPIFFS as before. Only the L2 LVGL envs set it; every other ESP32 board is unchanged. A settings save drops from ~0.5 s to ~80 ms and the files survive power loss mid-write. No migration: the first boot formats the partition (fresh identity). Co-Authored-By: Claude Opus 5.5 --- examples/companion_radio/DataStore.cpp | 8 ++++---- examples/companion_radio/MyMesh.h | 2 +- examples/companion_radio/main.cpp | 6 +++--- examples/companion_radio/ui-lvgl/LvglPort.h | 10 +++++++--- solo/wio-tracker-l2/platformio.ini | 3 +++ src/helpers/esp32/InternalFS.h | 15 +++++++++++++++ 6 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 src/helpers/esp32/InternalFS.h diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 15be5fcc..666bbc82 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -81,7 +81,7 @@ void DataStore::begin() { } #if defined(ESP32) - #include + #include #include #elif defined(RP2040_PLATFORM) #include @@ -119,7 +119,7 @@ lfs_ssize_t _getLfsUsedBlockCount(FILESYSTEM* fs) { uint32_t DataStore::getStorageUsedKb() const { #if defined(ESP32) - return SPIFFS.usedBytes() / 1024; + return ESP32_FS.usedBytes() / 1024; #elif defined(RP2040_PLATFORM) FSInfo info; info.usedBytes = 0; @@ -137,7 +137,7 @@ uint32_t DataStore::getStorageUsedKb() const { uint32_t DataStore::getStorageTotalKb() const { #if defined(ESP32) - return SPIFFS.totalBytes() / 1024; + return ESP32_FS.totalBytes() / 1024; #elif defined(RP2040_PLATFORM) FSInfo info; info.totalBytes = 0; @@ -198,7 +198,7 @@ bool DataStore::formatFileSystem() { #elif defined(RP2040_PLATFORM) return LittleFS.format(); #elif defined(ESP32) - bool fs_success = ((fs::SPIFFSFS *)_fs)->format(); + bool fs_success = ((ESP32_FS_CLASS *)_fs)->format(); esp_err_t nvs_err = nvs_flash_erase(); // no need to reinit, will be done by reboot return fs_success && (nvs_err == ESP_OK); #elif defined(SIM_PLATFORM) diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 0e960273..2ecb5e4b 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -37,7 +37,7 @@ class UITask; #elif defined(RP2040_PLATFORM) #include #elif defined(ESP32) -#include +#include #endif #include "DataStore.h" diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 81482a18..baf5db4f 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -54,8 +54,8 @@ static uint32_t _atoi(const char* sp) { #include DataStore store(LittleFS, rtc_clock); #elif defined(ESP32) - #include - DataStore store(SPIFFS, rtc_clock); + #include + DataStore store(ESP32_FS, rtc_clock); #elif defined(SIM_PLATFORM) #include // Real files under ./sim_data/ (relative to the process's cwd) so @@ -271,7 +271,7 @@ void setup() { #endif the_mesh.startInterface(serial_interface); #elif defined(ESP32) - SPIFFS.begin(true); + ESP32_FS.begin(true); store.begin(); the_mesh.begin(); resolveBLEPin( diff --git a/examples/companion_radio/ui-lvgl/LvglPort.h b/examples/companion_radio/ui-lvgl/LvglPort.h index edcd65ea..95ca2a38 100644 --- a/examples/companion_radio/ui-lvgl/LvglPort.h +++ b/examples/companion_radio/ui-lvgl/LvglPort.h @@ -12,7 +12,7 @@ #include #include #include - #include + #include #include #include #include @@ -262,10 +262,14 @@ static bool crashSummary(char* out, size_t n) { #endif } // The internal flash file system (contacts, channels, settings, trail...). +#ifdef ESP32_LITTLEFS +static const char* const FLASH_ROOT = "/littlefs"; +#else static const char* const FLASH_ROOT = "/spiffs"; +#endif static bool flashInfo(uint64_t& total, uint64_t& used) { - total = SPIFFS.totalBytes(); - used = SPIFFS.usedBytes(); + total = ESP32_FS.totalBytes(); + used = ESP32_FS.usedBytes(); return total > 0; } diff --git a/solo/wio-tracker-l2/platformio.ini b/solo/wio-tracker-l2/platformio.ini index 0223c43e..6d8eeaf1 100644 --- a/solo/wio-tracker-l2/platformio.ini +++ b/solo/wio-tracker-l2/platformio.ini @@ -70,6 +70,7 @@ build_flags = -D NEARBY_MAX=64 -D HIST_ARCHIVE ; message history also on the SD card (ui-lvgl/HistoryStore.h) -D GPS_SKYVIEW ; satellites / signal / DOPs for the GPS screen (helpers/sensors/GpsSky.h) + -D ESP32_LITTLEFS ; internal flash as LittleFS, not SPIFFS (helpers/esp32/InternalFS.h) build_src_filter = ${Wio_Tracker_L2.build_src_filter} + + @@ -89,6 +90,7 @@ lib_deps = NetworkClientSecure ; 3.x name of WiFiClientSecure (the header is still there) Preferences Update ; Settings > Firmware update + LittleFS ; The same firmware on the old Arduino-ESP32 2.0.17 (ESP-IDF 4.4), kept for ; comparison while the 3.x one settles. Not published (the name doesn't end in @@ -106,4 +108,5 @@ lib_deps = HTTPClient WiFiClientSecure Preferences + LittleFS diff --git a/src/helpers/esp32/InternalFS.h b/src/helpers/esp32/InternalFS.h new file mode 100644 index 00000000..4db4c1a6 --- /dev/null +++ b/src/helpers/esp32/InternalFS.h @@ -0,0 +1,15 @@ +#pragma once + +// The ESP32's internal filesystem, on the "spiffs" partition: SPIFFS, or with +// -D ESP32_LITTLEFS LittleFS -- far faster for the small files MeshCore keeps +// (a settings save: ~0.5 s on SPIFFS), and safe against power loss. The two +// formats don't mix: switching a board formats the partition on first boot. +#ifdef ESP32_LITTLEFS + #include + #define ESP32_FS LittleFS + #define ESP32_FS_CLASS fs::LittleFSFS +#else + #include + #define ESP32_FS SPIFFS + #define ESP32_FS_CLASS fs::SPIFFSFS +#endif