I'm writing log data to a LittleFS file on the ESP8266, calling flush after each write. On the ESP8266 if there is a power failure before `file.close()` is called, the data is synced to flash and can be read back. On the ESP32 it is not, the file has 0 Bytes.
I loosely understand why, its to do with how LFS stages the content and when `sync()` gets called. This thread is relevant https://github.com/littlefs-project/littlefs/issues/344
My question is, whats (or rather where) is different between the ESP32 and ESP8266? What code or configuration settings are different between the two?
LFS looks to be precompiled in the arduino-esp32 source which isn't helpful, whereas the ESP8266 uses sources from https://github.com/ARMmbed/littlefs.git
What is the ESP32 doing, why is the behaviour different and how to I get it to behave like the ESP8266?
In the absence of an answer to the above, at least, what sources are used to compile LFS for the ESP32 Arduino project?
Thanks
Code below that repro's the issue
Code: Select all
#include <LittleFS.h>
File currentLog;
#define DELAY 200
uint64_t lastMillis = 0;
uint8_t loopBuffer[6] = {0};
uint16_t counter = 0;
void setup() {
Serial.begin(115200);
if (!LittleFS.begin())
{
Serial.println("LittleFS mount failed");
return;
}
currentLog = LittleFS.open("test", "r");
auto size = currentLog.size();
auto rows = size > 0 ? (size - 65) / 6 : 0;
Serial.print("Opened previous log of size: ");
Serial.print(size);
Serial.print(" bytes, found ");
Serial.print(rows);
Serial.println(" rows");
currentLog.close();
Serial.println("Waiting 5 secs...");
delay(5000);
currentLog = LittleFS.open("test", "w");
lastMillis = millis();
}
void loop() {
uint64_t now = millis();
if(now < lastMillis + DELAY)
return;
lastMillis = now;
currentLog.write(loopBuffer, 6);
currentLog.flush();
Serial.print("Looped: ");
Serial.println(counter++);
}