From 6e0e2c4396a25f03862f36d1f8aec8e26251e04b Mon Sep 17 00:00:00 2001 From: mooiweertje Date: Sat, 15 Nov 2025 07:55:34 +0100 Subject: [PATCH] spiffsToLittlefs --- .github/workflows/main.yml | 4 ++-- .gitmodules | 3 +++ .vscode/c_cpp_properties.json | 2 +- components/littlefs | 1 + main/CMakeLists.txt | 4 +++- main/main.cpp | 2 +- main/storage.cpp | 32 ++++++++++++++++++-------------- main/storage.h | 2 +- main/trip.cpp | 2 +- partitions.csv | 10 +++++----- sdkconfig.defaults | 2 +- sdkconfig.supermini | 6 +++--- 12 files changed, 40 insertions(+), 30 deletions(-) create mode 160000 components/littlefs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4066e8f..a1d037c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,9 @@ name: CI on: push: - branches: [ "master" ] + branches: [ "**" ] pull_request: - branches: [ "master" ] + branches: [ "**" ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.gitmodules b/.gitmodules index 8664b7b..dab1ef7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "components/esp32-button"] path = components/esp32-button url = https://github.com/void-spark/esp32-button.git +[submodule "components/littlefs"] + path = components/littlefs + url = https://github.com/joltwallet/esp_littlefs.git diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3e21a85..72c25a2 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -98,7 +98,7 @@ "${workspaceFolder}/sdk/idf/components/soc/esp32/include", "${workspaceFolder}/sdk/idf/components/soc/include", "${workspaceFolder}/sdk/idf/components/spi_flash/include", - "${workspaceFolder}/sdk/idf/components/spiffs/include", + "${workspaceFolder}/sdk/idf/components/littlefs/include", "${workspaceFolder}/sdk/idf/components/tcp_transport/include", "${workspaceFolder}/sdk/idf/components/ulp/ulp_common/include", "${workspaceFolder}/sdk/idf/components/ulp/ulp_common/include/esp32", diff --git a/components/littlefs b/components/littlefs new file mode 160000 index 0000000..8274371 --- /dev/null +++ b/components/littlefs @@ -0,0 +1 @@ +Subproject commit 8274371dc5912196f66ac3e71dbb6291760cb8b0 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index ab0e6c1..d98875c 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,4 @@ idf_component_register(SRC_DIRS "." "states" - INCLUDE_DIRS ".") + INCLUDE_DIRS "." + REQUIRES esp32-button driver littlefs esp_timer nvs_flash esp_adc +) \ No newline at end of file diff --git a/main/main.cpp b/main/main.cpp index d319148..20f855a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -229,7 +229,7 @@ static void my_task(void *pvParameter) { adc_init(); #endif - init_spiffs(); + init_littlefs(); initUart(); diff --git a/main/storage.cpp b/main/storage.cpp index 8c9570d..8a6c2b9 100644 --- a/main/storage.cpp +++ b/main/storage.cpp @@ -1,27 +1,31 @@ #include #include "esp_log.h" -#include "esp_spiffs.h" +#include "esp_littlefs.h" #include "storage.h" static const char *TAG = "storage"; -#define CALIBRATION_FILE "/spiffs/calibration.bin" +#define CALIBRATION_FILE "/littlefs/calibration.bin" -void init_spiffs() { - ESP_LOGI(TAG, "Initializing SPIFFS"); +void init_littlefs() { + ESP_LOGI(TAG, "Initializing LittleFS"); - esp_vfs_spiffs_conf_t spiffs_conf = {}; - spiffs_conf.base_path = "/spiffs"; - spiffs_conf.partition_label = NULL; - spiffs_conf.max_files = 5; - spiffs_conf.format_if_mount_failed = true; + esp_vfs_littlefs_conf_t conf = { + .base_path = "/littlefs", + .partition_label = "littlefs", // moet overeenkomen met je partitions.csv + .partition = NULL, + .format_if_mount_failed = true, + .read_only = false, + .dont_mount = false, + .grow_on_mount = true + }; - ESP_ERROR_CHECK(esp_vfs_spiffs_register(&spiffs_conf)); + ESP_ERROR_CHECK(esp_vfs_littlefs_register(&conf)); size_t total = 0, used = 0; - esp_err_t ret = esp_spiffs_info(spiffs_conf.partition_label, &total, &used); - if(ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); + esp_err_t ret = esp_littlefs_info(conf.partition_label, &total, &used); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to get LittleFS partition information (%s)", esp_err_to_name(ret)); } else { ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used); } @@ -80,4 +84,4 @@ bool writeData(const char * path, void * source, size_t size) { fclose(fp); return true; -} +} \ No newline at end of file diff --git a/main/storage.h b/main/storage.h index 65c3a42..0734089 100644 --- a/main/storage.h +++ b/main/storage.h @@ -2,7 +2,7 @@ #include -void init_spiffs(); +void init_littlefs(); // Is a calibration file stored? bool calibrationFileExists(); diff --git a/main/trip.cpp b/main/trip.cpp index 2e555dd..50e7da7 100644 --- a/main/trip.cpp +++ b/main/trip.cpp @@ -1,7 +1,7 @@ #include "storage.h" #include "trip.h" -#define DISTANCE_FILE "/spiffs/distance.bin" +#define DISTANCE_FILE "/littleFS/distance.bin" struct distancesStruct { // Trip-1 in 10m increments diff --git a/partitions.csv b/partitions.csv index 7fbc28b..6f1bbda 100644 --- a/partitions.csv +++ b/partitions.csv @@ -1,5 +1,5 @@ -# Name, Type, SubType, Offset, Size, Flags -nvs, data, nvs, , 0x4000, -phy_init, data, phy, , 0x1000, -factory, app, factory, , 1M, -spiffs, data, spiffs, , 1M, +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, , 0x4000, +phy_init, data, phy, , 0x1000, +factory, app, factory, , 1M, +littlefs, data, littlefs, , 1M, \ No newline at end of file diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 6d5b1e8..260dfe5 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -4,7 +4,7 @@ CONFIG_ION_CU3=y # My chips are 4MB flash, once you use OTA this settings matters CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -# Set up partitions for SPIFFS +# Set up partitions for littlefs CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" diff --git a/sdkconfig.supermini b/sdkconfig.supermini index 7b1ba63..0f2b1db 100644 --- a/sdkconfig.supermini +++ b/sdkconfig.supermini @@ -24,15 +24,15 @@ CONFIG_ION_LIGHT=n CONFIG_ION_LIGHT_PIN=1 CONFIG_ION_LIGHT_PIN_INVERTED=n -CONFIG_ION_RELAY=n +CONFIG_ION_RELAY=y CONFIG_ION_RELAY_PIN=0 CONFIG_ION_RELAY_PIN_INVERTED=n CONFIG_ESP32C3_DEFAULT_CPU_FREQ_160=y CONFIG_ION_ADC=y -# ADC channel 1 is pin 4 -CONFIG_ION_ADC_CHAN=4 +# ADC channel 1 is pin 2 +CONFIG_ION_ADC_CHAN=2 # The scale of the divider, times 1000, from APM power module CONFIG_ION_DIVIDER_SCALE=10829