User Tools

Site Tools


littlefs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
littlefs [2024/11/12 10:05] – jwanlittlefs [2025/10/10 10:15] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +LittleFS data are stored inside the Flash memory (not EEPROM) and has 1MB size. 
 +
 +To format:
 +<code>
 +#include <LittleFS.h>
 +
 +void setup() {
 +  Serial.begin(115200);
 +
 +  if (!LittleFS.begin()) {
 +    Serial.println("LittleFS Mount Failed");
 +    return;
 +  }
 +
 +  Serial.println("Formatting LittleFS...");
 +  if (LittleFS.format()) {
 +    Serial.println("LittleFS formatted successfully");
 +  } else {
 +    Serial.println("Failed to format LittleFS");
 +  }
 +}
 +
 +void loop() {
 +  // Your code here
 +}
 +</code>
 +
 Show basic info: Show basic info:
  
Line 9: Line 36:
 void setup() { void setup() {
   Serial.begin(115200);   Serial.begin(115200);
 +
 +  Serial.println();
 +  Serial.println();
 +  Serial.println();
 +
 +  uint32_t chipId = ESP.getChipId();
 +  Serial.print("Chip ID: ");
 +  Serial.println(chipId);
 +  
 +  uint32_t flashSize = ESP.getFlashChipSize();
 +  Serial.print("Flash Chip Size: ");
 +  Serial.print(flashSize / 1024 / 1024);
 +  Serial.println(" MB");
 +
 +  Serial.println();
 +
   LittleFS.begin();   LittleFS.begin();
  
Line 35: Line 78:
   Serial.printf("Listing directory: %s\n", dirname);   Serial.printf("Listing directory: %s\n", dirname);
  
-  File root = fs.open(dirname); +  Dir dir = fs.openDir(dirname); 
-  if (!root) { +  while (dir.next()) { 
-    Serial.println("Failed to open directory"); +    if (dir.isDirectory()) {
-    return; +
-  } +
-  if (!root.isDirectory()) { +
-    Serial.println("Not a directory"); +
-    return; +
-  } +
- +
-  File file = root.openNextFile(); +
-  while (file) { +
-    if (file.isDirectory()) {+
       Serial.print("  DIR : ");       Serial.print("  DIR : ");
-      Serial.println(file.name());+      Serial.println(dir.fileName());
       if (levels) {       if (levels) {
-        listDir(fs, file.name(), levels - 1);+        listDir(fs, dir.fileName().c_str(), levels - 1);
       }       }
     } else {     } else {
       Serial.print("  FILE: ");       Serial.print("  FILE: ");
-      Serial.print(file.name());+      Serial.print(dir.fileName());
       Serial.print("  SIZE: ");       Serial.print("  SIZE: ");
-      Serial.println(file.size());+      Serial.println(dir.fileSize());
     }     }
-    file = root.openNextFile(); 
   }   }
 } }
Line 65: Line 97:
 void setup() { void setup() {
   Serial.begin(115200);   Serial.begin(115200);
-  LittleFS.begin();+  if (!LittleFS.begin()) { 
 +    Serial.println("LittleFS Mount Failed"); 
 +    return; 
 +  }
   listDir(LittleFS, "/", 0);   listDir(LittleFS, "/", 0);
 } }
Line 72: Line 107:
   // Your code here   // Your code here
 } }
- 
 </code> </code>
littlefs.1731405939.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki