From 68a2d89e715c9c70c0cfcd4da978a0825adf2509 Mon Sep 17 00:00:00 2001 From: Scott Bezek Date: Sun, 18 Jun 2023 14:33:24 -0700 Subject: [PATCH] Swap out SPIFFS for FFAT, which doesn't suffer from performance issues --- ...-4MB-spiffs.csv => partitions-4MB-fat.csv} | 2 +- firmware/src/configuration.cpp | 14 ++++---- firmware/src/configuration.h | 33 +++++++++++-------- firmware/src/motor_task.cpp | 2 +- platformio.ini | 3 +- 5 files changed, 30 insertions(+), 24 deletions(-) rename firmware/{partitions-4MB-spiffs.csv => partitions-4MB-fat.csv} (89%) diff --git a/firmware/partitions-4MB-spiffs.csv b/firmware/partitions-4MB-fat.csv similarity index 89% rename from firmware/partitions-4MB-spiffs.csv rename to firmware/partitions-4MB-fat.csv index 0234f0e..4bfa7f0 100644 --- a/firmware/partitions-4MB-spiffs.csv +++ b/firmware/partitions-4MB-fat.csv @@ -8,4 +8,4 @@ otadata, data, ota, 0xe000, 8K, ota_0, 0, ota_0, 0x10000, 1408K, ota_1, 0, ota_1, 0x170000, 1408K, uf2, app, factory,0x2d0000, 256K, -spiffs, data, spiffs, 0x310000, 960K, \ No newline at end of file +ffat, data, fat, 0x310000, 960K, \ No newline at end of file diff --git a/firmware/src/configuration.cpp b/firmware/src/configuration.cpp index abb58d4..fa71397 100644 --- a/firmware/src/configuration.cpp +++ b/firmware/src/configuration.cpp @@ -1,4 +1,4 @@ -#include +#include #include "pb_decode.h" #include "pb_encode.h" @@ -21,12 +21,12 @@ Configuration::~Configuration() { bool Configuration::loadFromDisk() { SemaphoreGuard lock(mutex_); - SPIFFSGuard spiffs(logger_); - if (!spiffs.ok_) { + FatGuard fatGuard(logger_); + if (!fatGuard.mounted_) { return false; } - File f = SPIFFS.open(CONFIG_PATH); + File f = FFat.open(CONFIG_PATH); if (!f) { log("Failed to read config file"); return false; @@ -77,11 +77,11 @@ bool Configuration::saveToDisk() { return false; } - SPIFFSGuard spiffs(logger_); - if (!spiffs.ok_) { + FatGuard fatGuard(logger_); + if (!fatGuard.mounted_) { return false; } - File f = SPIFFS.open(CONFIG_PATH, FILE_WRITE); + File f = FFat.open(CONFIG_PATH, FILE_WRITE); if (!f) { log("Failed to read config file"); return false; diff --git a/firmware/src/configuration.h b/firmware/src/configuration.h index 37ab452..e788db8 100644 --- a/firmware/src/configuration.h +++ b/firmware/src/configuration.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include "proto_gen/smartknob.pb.h" @@ -31,27 +31,32 @@ class Configuration { void log(const char* msg); }; -class SPIFFSGuard { +class FatGuard { public: - SPIFFSGuard(Logger* logger) : logger_(logger) { - if (!SPIFFS.begin(true)) { - if (logger != nullptr) { - logger->log("Failed to mount SPIFFS"); + FatGuard(Logger* logger) : logger_(logger) { + if (!FFat.begin(true)) { + if (logger_ != nullptr) { + logger_->log("Failed to mount FFat"); } return; } - ok_ = true; + if (logger_ != nullptr) { + logger_->log("Mounted FFat"); + } + mounted_ = true; } - ~SPIFFSGuard() { - if (ok_) { - SPIFFS.end(); - logger_->log("Unmounted SPIFFS"); + ~FatGuard() { + if (mounted_) { + FFat.end(); + if (logger_ != nullptr) { + logger_->log("Unmounted FFat"); + } } } - SPIFFSGuard(SPIFFSGuard const&)=delete; - SPIFFSGuard& operator=(SPIFFSGuard const&)=delete; + FatGuard(FatGuard const&)=delete; + FatGuard& operator=(FatGuard const&)=delete; - bool ok_ = false; + bool mounted_ = false; private: Logger* logger_; diff --git a/firmware/src/motor_task.cpp b/firmware/src/motor_task.cpp index 5657d1b..5787e30 100644 --- a/firmware/src/motor_task.cpp +++ b/firmware/src/motor_task.cpp @@ -22,7 +22,7 @@ static const float IDLE_CORRECTION_MAX_ANGLE_RAD = 5 * PI / 180; static const float IDLE_CORRECTION_RATE_ALPHA = 0.0005; -MotorTask::MotorTask(const uint8_t task_core, Configuration& configuration) : Task("Motor", 3200, 1, task_core), configuration_(configuration) { +MotorTask::MotorTask(const uint8_t task_core, Configuration& configuration) : Task("Motor", 4000, 1, task_core), configuration_(configuration) { queue_ = xQueueCreate(5, sizeof(Command)); assert(queue_ != NULL); } diff --git a/platformio.ini b/platformio.ini index 2f0fd35..b3e6e8b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -40,6 +40,7 @@ build_flags = [env:view] extends = base_config board = esp32doit-devkit-v1 +board_build.partitions = default_ffat.csv lib_deps = ${base_config.lib_deps} askuric/Simple FOC @ 2.2.0 @@ -130,7 +131,7 @@ build_flags = extends = base_config platform = espressif32@6.3.1 board = adafruit_feather_esp32s3 -board_build.partitions = firmware/partitions-4MB-spiffs.csv +board_build.partitions = firmware/partitions-4MB-fat.csv lib_deps = ${base_config.lib_deps} askuric/Simple FOC@^2.3.0