added littlefs support

This commit is contained in:
okhsunrog 2024-02-23 12:06:10 +03:00
parent d7d2a6780d
commit 25a99bf94b
3 changed files with 45 additions and 30 deletions

View file

@ -1,20 +1,43 @@
#include "fs.h" #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"; static const char* TAG = "fs";
/* Console command history can be stored to and loaded from a file. // 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.
*/
void initialize_filesystem(void) { void initialize_filesystem(void) {
static wl_handle_t wl_handle; ESP_LOGI(TAG, "Initializing LittleFS");
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); esp_vfs_littlefs_conf_t conf = {
if (err != ESP_OK) { .base_path = MOUNT_PATH,
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err)); .partition_label = "storage",
return; .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();
} }
} }

View file

@ -1,25 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
// #include "can.h" #include "can.h"
// #include "fs.h" #include "fs.h"
// #include "console.h" #include "console.h"
// #include "xvprintf.h" #include "xvprintf.h"
void app_main(void) { void app_main(void) {
printf("Hello world!\n"); init_tx_ringbuf();
xTaskCreate(can_task, "can task", 4800, NULL, CONFIG_CAN_TASK_PRIORITY, NULL);
// init_tx_ringbuf(); initialize_filesystem();
// xTaskCreate(can_task, "can task", 4800, NULL, CONFIG_CAN_TASK_PRIORITY, NULL); initialize_console();
// initialize_filesystem(); xTaskCreate(console_task_interactive, "console tsk int", 8000, NULL, CONFIG_CONSOLE_INT_PRIORITY, NULL);
// 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();
} }

View file

@ -3,4 +3,5 @@
nvs, data, nvs, 0x9000, 0x6000, nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000, phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M, factory, app, factory, 0x10000, 1M,
storage, data, fat, , 1M, # rename subtype to littlefs after updating to v5.2
storage, data, spiffs, , 0xF0000,

1 # Name, Type, SubType, Offset, Size, Flags
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, 0x10000, 1M,
6 storage, data, fat, , 1M, # rename subtype to littlefs after updating to v5.2
7 storage, data, spiffs, , 0xF0000,