ESP32 文件系统初始化代码示例 (LittleFS)
此示例代码负责挂载文件系统,或在没有文件系统时创建文件系统。
littlefs_init.cpp
#pragma once
#include <stddef.h>
// InitFilesystem() 在文件系统可用时将此设置为 true。
extern volatile bool filesystemOK;
void InitFilesystem();littlefs_init_impl.cpp
#include "FS.h"
#include "LittleFS.h"
volatile bool filesystemOK = false;
void InitFilesystem() {
// 初始化 LittleFS
if (!LittleFS.begin(false /* false: Do not format if mount failed */)) {
Serial.println("挂载 LittleFS 失败");
if (!LittleFS.begin(true /* true: format */)) {
Serial.println("格式化 LittleFS 失败");
} else {
Serial.println("LittleFS 格式化成功");
filesystemOK = true;
}
} else { // 初始挂载成功
filesystemOK = true;
}
}Check out similar posts by category:
C/C++, ESP8266/ESP32
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow