I did the following, but failed.
Can anyone give me a hint how to solve the problem?
Step 1. configure platformio.ini
Notice that: board_build.filesytem = littlefs
Code: Select all
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
board_build.filesytem =
board_build.partitions = default_4MB.csv
;board_build.flash_mode = dio
;board_build.f_flash = 80000000L
Notice that we created a partition called "littlefs",
Code: Select all
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x140000,
app1, app, ota_1, 0x150000,0x140000,
littlefs, data, littlefs, 0x290000,0x160000,
coredump, data, coredump,0x3F0000,0x10000,
Notice that in "data" folder, there is a file "index.html", and a subdirectory "subdir" which contains another file "test.txt"
Code: Select all
project_home/data/
index.html
subdir/test.txt
Notice that in the log, platformio create a filesystem image called "" and uploaded it successfully.
Code: Select all
Building FS image from 'data' directory to .pio/build/esp32dev/spiffs.bin
/index.html
/subdir/test.txt
Looking for upload port...
...
Auto-detected: /dev/ttyUSB0
Uploading .pio/build/esp32dev/spiffs.bin
Code: Select all
#include <LittleFS.h>
void EmbeddedFS::setup_embeddedfs() {
// LittleFS.begin(bool formatOnFail, const char *basePath, uint8_t maxOpenFiles, const char *partitionLabel)
if (!LittleFS.begin(true, "/littlefs", 10U, "littlefs")) {
// if (!SPIFFS.begin(true, "/spiffs", 10U, "spiffs")) {
// if (!SPIFFS.begin(true)) {
Serial.printf("\n[WARN] LittleFS mount failed. \n");
return;
}
else {
Serial.printf("\n[INFO] Successfully mounts LittleFS at '%s'. \n",
LittleFS.mountpoint()
);
}
// Verify that the LittleFS file system works well.
// List file directory with 3 levels.
list_dir("/", 3);
}
void EmbeddedFS::list_dir(String dir_name, int levels) {
const char *_dir_name = dir_name.c_str();
Serial.printf("\n[INFO] Listing directory: '%s'\n", dir_name);
Serial.printf("-- Notice that SPIFSS doesn't recognize directories, but it can find the files inside subdirs. --\n\n");
// File root = SPIFFS.open(_dir_name);
File root = LittleFS.open(_dir_name);
if (!root) {
Serial.printf("\n[WARN] Failed to open directory: %s.\n", _dir_name);
return;
}
if (!root.isDirectory()) {
Serial.printf("\n[WARN] '%s' not a directory. \n", _dir_name);
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
list_dir(file.path(), levels - 1);
}
} else {
Serial.printf(" FILE: '%s', SIZE: %d \n", file.name(), file.size());
}
file = root.openNextFile();
}
}
Following is the execution result, which contains bugs.
Code: Select all
[INFO] Successfully mounts LittleFS at '/littlefs'.
[INFO] Listing directory: '/'
-- Notice that SPIFSS doesn't recognize directories, but it can find the files inside subdirs. --
[ 64][E][vfs_api.cpp:23] open(): File system is not mounted
[WARN] Failed to open file '/subdir/test.txt' for writing.
[ 74][E][vfs_api.cpp:23] open(): File system is not mounted
[WARN] Failed to open file '/subdir/test.txt' for reading.
We changed LittleFS.begin(true, "/littlefs", 10U, "littlefs") to LittleFS.begin(true, "/littlefs", 10U, "spiffs"),
More severe bugs are thrown, as following,
Code: Select all
E (20) esp_littlefs: partition "spiffs" could not be found
E (20) esp_littlefs: Failed to initialize LittleFS
[ 51][E][LittleFS.cpp:79] begin(): Mounting LittleFS failed! Error: 261