changed partition to littlefs, not working yet

This commit is contained in:
Emanuele Trabattoni
2026-04-08 17:10:30 +02:00
parent 12e1e8e7a4
commit 97bce90ba6
5 changed files with 30 additions and 23 deletions

View File

@@ -0,0 +1,6 @@
# ESP32 Partition Table
# Name, Type, SubType, Offset, Size
nvs, data, nvs, 0x9000, 0x4000
phy_init, data, phy, 0xd000, 0x1000
factory, app, factory, 0x10000, 0x300000
littlefs, data, littlefs, 0x310000, 0xCF0000
1 # ESP32 Partition Table
2 # Name, Type, SubType, Offset, Size
3 nvs, data, nvs, 0x9000, 0x4000
4 phy_init, data, phy, 0xd000, 0x1000
5 factory, app, factory, 0x10000, 0x300000
6 littlefs, data, littlefs, 0x310000, 0xCF0000

View File

@@ -10,8 +10,8 @@
[env:esp32-s3-devkitc1-n16r8]
board = esp32-s3-devkitc1-n16r8
board_build.partitions = partitions/no_ota_10mb_spiffs.csv
board_build.filesystem = spiffs
board_build.partitions = partitions/no_ota_10mb_littlefs.csv
board_build.filesystem = littlefs
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
framework = arduino
lib_deps =
@@ -21,7 +21,7 @@ lib_deps =
me-no-dev/AsyncTCP@^3.3.2
me-no-dev/ESPAsyncWebServer@^3.6.0
upload_protocol = esptool
upload_port = COM8
upload_port = COM4
upload_speed = 921600
monitor_port = COM4
monitor_speed = 921600

View File

@@ -126,30 +126,30 @@ void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::file
// Initialize SPIFFS
if (!SAVE_HISTORY_TO_SPIFFS)
return;
// auto spiffs_guard = SPIFFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
// auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
if (SPIFFS.totalBytes() - SPIFFS.usedBytes() < min_free) // check if at least 1MB is free for saving history
if (LittleFS.totalBytes() - LittleFS.usedBytes() < min_free) // check if at least 1MB is free for saving history
{
LOG_ERROR("Not enough space in SPIFFS to save history");
return;
}
std::filesystem::path file_path = file_name;
if (file_name.root_path() != "/spiffs")
file_path = std::filesystem::path("/spiffs") / file_name;
if (file_name.root_path() != "/littlefs")
file_path = std::filesystem::path("/littlefs") / file_name;
auto save_flags = std::ios::out;
if (first_save && SPIFFS.exists(file_path.c_str()))
if (first_save && LittleFS.exists(file_path.c_str()))
{
first_save = false;
save_flags |= std::ios::trunc; // overwrite existing file
SPIFFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS
LOG_INFO("Saving history to SPIFFS, new file:", file_path.c_str());
LittleFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS
LOG_INFO("Saving history to LittleFS, new file:", file_path.c_str());
}
else
{
save_flags |= std::ios::app; // append to new file
LOG_INFO("Saving history to SPIFFS, appending to existing file:", file_path.c_str());
LOG_INFO("Saving history to LittleFS, appending to existing file:", file_path.c_str());
}
std::ofstream ofs(file_path, save_flags);
@@ -197,5 +197,5 @@ void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::file
}
ofs.close();
LOG_INFO("Ignition A history saved to SPIFFS, records written: ", history.size());
LOG_INFO("Ignition A history saved to LittleFS, records written: ", history.size());
}

View File

@@ -4,7 +4,7 @@
// System Includes
#include <Arduino.h>
#include <DebugLog.h>
#include <SPIFFS.h>
#include <LittleFS.h>
#include <string>
#include <fstream>
#include <filesystem>
@@ -24,22 +24,22 @@ struct dataSaveParams
const std::filesystem::path file_path;
};
class SPIFFSGuard
class LITTLEFSGuard
{
public:
SPIFFSGuard()
LITTLEFSGuard()
{
if (!SPIFFS.begin(true))
if (!LittleFS.begin(true))
{
LOG_ERROR("Failed to mount SPIFFS");
LOG_ERROR("Failed to mount LittleFS");
}
LOG_INFO("SPIFFS mounted successfully");
}
~SPIFFSGuard()
~LITTLEFSGuard()
{
SPIFFS.end();
LOG_INFO("SPIFFS unmounted successfully");
LittleFS.end();
LOG_INFO("LittleFS unmounted successfully");
}
};

View File

@@ -94,6 +94,7 @@ void loop()
// global variables
bool running = true;
const uint32_t max_queue = 128;
const uint32_t filter_k = 10;
PSRAMVector<ignitionBoxStatus> ignA_history_0(max_history);
PSRAMVector<ignitionBoxStatus> ignA_history_1(max_history);
auto *active_history = &ignA_history_0;
@@ -221,15 +222,15 @@ void loop()
int64_t last = esp_timer_get_time();
uint32_t missed_firings12 = 0;
uint32_t missed_firings34 = 0;
ignitionBoxStatusAverage ignA_avg(max_queue); // moving average calculator for ignition box A with a window of 100 samples
ignitionBoxStatusAverage ignA_avg(filter_k); // moving average calculator for ignition box A with a window of 100 samples
AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
ws.onEvent(onWsEvent);
server.addHandler(&ws);
auto spiffs_guard = SPIFFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
server.begin();
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)