diff --git a/main/fs.c b/main/fs.c index 56e0c57..1b57ee9 100644 --- a/main/fs.c +++ b/main/fs.c @@ -1,20 +1,43 @@ #include "fs.h" -#include "esp_vfs_fat.h" +#include "esp_littlefs.h" +#include "esp_err.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" static const char* TAG = "fs"; -/* Console command history can be stored to and loaded from a file. - * The easiest way to do this is to use FATFS filesystem on top of - * wear_levelling library. - */ +// Console command history can be stored to and loaded from a file. void initialize_filesystem(void) { - static wl_handle_t wl_handle; - const esp_vfs_fat_mount_config_t mount_config = {.max_files = 4, .format_if_mount_failed = true}; - const esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(MOUNT_PATH, "storage", &mount_config, &wl_handle); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err)); - return; + ESP_LOGI(TAG, "Initializing LittleFS"); + + esp_vfs_littlefs_conf_t conf = { + .base_path = MOUNT_PATH, + .partition_label = "storage", + .format_if_mount_failed = true, + .dont_mount = false, + }; + + // Use settings defined above to initialize and mount LittleFS filesystem. + // Note: esp_vfs_littlefs_register is an all-in-one convenience function. + esp_err_t ret = esp_vfs_littlefs_register(&conf); + + if (ret != ESP_OK) { + if (ret == ESP_FAIL) { + ESP_LOGE(TAG, "Failed to mount or format filesystem"); + } else if (ret == ESP_ERR_NOT_FOUND) { + ESP_LOGE(TAG, "Failed to find LittleFS partition"); + } else { + ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret)); + } + for (int i = 10; i >= 0; i--) { + printf("Restarting in %d seconds...\n", i); + vTaskDelay(1000 / portTICK_PERIOD_MS); + } + printf("Restarting now.\n"); + fflush(stdout); + esp_restart(); } } diff --git a/main/main.c b/main/main.c index 14d6b54..73a97aa 100644 --- a/main/main.c +++ b/main/main.c @@ -1,25 +1,16 @@ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" -// #include "can.h" -// #include "fs.h" -// #include "console.h" -// #include "xvprintf.h" +#include "can.h" +#include "fs.h" +#include "console.h" +#include "xvprintf.h" void app_main(void) { - printf("Hello world!\n"); - - // init_tx_ringbuf(); - // xTaskCreate(can_task, "can task", 4800, NULL, CONFIG_CAN_TASK_PRIORITY, NULL); - // initialize_filesystem(); - // initialize_console(); - // xTaskCreate(console_task_interactive, "console tsk int", 8000, NULL, CONFIG_CONSOLE_INT_PRIORITY, NULL); - for (int i = 10; i >= 0; i--) { - printf("Restarting in %d seconds...\n", i); - vTaskDelay(1000 / portTICK_PERIOD_MS); - } - printf("Restarting now.\n"); - fflush(stdout); - esp_restart(); + init_tx_ringbuf(); + xTaskCreate(can_task, "can task", 4800, NULL, CONFIG_CAN_TASK_PRIORITY, NULL); + initialize_filesystem(); + initialize_console(); + xTaskCreate(console_task_interactive, "console tsk int", 8000, NULL, CONFIG_CONSOLE_INT_PRIORITY, NULL); } diff --git a/partitions.csv b/partitions.csv index 1c79321..942d31a 100644 --- a/partitions.csv +++ b/partitions.csv @@ -3,4 +3,5 @@ nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, factory, app, factory, 0x10000, 1M, -storage, data, fat, , 1M, +# rename subtype to littlefs after updating to v5.2 +storage, data, spiffs, , 0xF0000,