can_wizard/main/fs.c

44 lines
1.3 KiB
C
Raw Normal View History

2023-11-22 11:48:03 +00:00
#include "fs.h"
2024-02-23 09:06:10 +00:00
#include "esp_littlefs.h"
#include "esp_err.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
2023-11-22 11:48:03 +00:00
static const char* TAG = "fs";
2024-02-23 09:06:10 +00:00
// Console command history can be stored to and loaded from a file.
2023-11-22 11:48:03 +00:00
void initialize_filesystem(void) {
2024-02-23 09:06:10 +00:00
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();
2023-11-22 11:48:03 +00:00
}
}