lorol / LITTLEFS

LittleFS library for arduino-esp32
GNU General Public License v2.0
166 stars 68 forks source link

delay needed after Serial.begin #21

Closed galed3e3 closed 3 years ago

galed3e3 commented 3 years ago

Adafruit ESP32 Feather Arduino IDE v. 1.8.13 ESP core v. 1.0.5 from Arduino Board Manager LittleFS_esp32 v. 1.0.5 from Arduino Library Manager

If there is no delay after Serial.begin, then some of the prints do not show up on the serial monitor.

For example, with two files in LittleFS and no delay, sometimes I get this:

FILE: /parrot.bmp   SIZE: 61496

dir test complete

and sometimes this:

  FILE: /graph.bmp  SIZE: 307254
  FILE: /parrot.bmp SIZE: 61496

dir test complete

But with a delay(500), I get this, as expected:

starting LitFS
Listing directory: /
  FILE: /graph.bmp  SIZE: 307254
  FILE: /parrot.bmp SIZE: 61496

dir test complete

The code:

#include <Arduino.h>
#include "FS.h"
#include <LITTLEFS.h>

void setup()
{
  Serial.begin(115200);

  delay(500);   //<------------------------!!!!!!!!!!!!!!!!!!!!!!!

  Serial.println("starting LitFS");
  if (!LITTLEFS.begin()) {
    Serial.println("LitFS mount failed");
    return;
  }
  listDir(LITTLEFS, "/", 3);
  Serial.println("");
  Serial.println( "dir test complete" );
}

void loop() {
}

void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
  Serial.printf("Listing directory: %s\r\n", dirname);

  File root = fs.open(dirname);
  if (!root) {
    Serial.println("- failed to open directory");
    return;
  }
  if (!root.isDirectory()) {
    Serial.println(" - not a directory");
    return;
  }

  File file = root.openNextFile();
  while (file) {
    if (file.isDirectory()) {
      Serial.print("  DIR : ");
      Serial.println(file.name());
      if (levels) {
        listDir(fs, file.name(), levels - 1);
      }
    } else {
      Serial.print("  FILE: ");
      Serial.print(file.name());
      Serial.print("\tSIZE: ");
      Serial.println(file.size());
    }
    file = root.openNextFile();
  }
}
galed3e3 commented 3 years ago

Never mind. Same problem with this little program, so not a Little FS issue.

void setup() {
  Serial.begin(115200);
  //delay(500); // needed to see the following
  Serial.println("starting...");
}

void loop() {
}