forked from test34/can_wizard
43 lines
1.3 KiB
C
43 lines
1.3 KiB
C
#include "fs.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.
|
|
|
|
void initialize_filesystem(void) {
|
|
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();
|
|
}
|
|
}
|
|
|