From 2e5ee76fffa7619efe282351ea5d16a61ddda354 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 2 May 2020 23:02:25 -0700 Subject: [PATCH 1/7] Deprecate SPIFFS, move examples to LittleFS SPIFFS has been a great filesystem, but it has significant problems in many cases (and it's also pretty slow). Development seems to have slowed/stopped on the upstream version, and we're not able to provide support or fix the known issues with it as-is. Deprecate SPIFFS variable. Update all examples to use LittleFS instead of SPIFFS. Also, minor cleanup on very old examples which has obsolete delays waiting for the Serial port to come up, or which were stuck at 9600 baud because of their ancient AVR heritage. Fixes #7095 --- cores/esp8266/FS.h | 2 +- cores/esp8266/spiffs_api.cpp | 6 +- cores/esp8266/spiffs_api.h | 4 +- .../CaptivePortalAdvanced.ino | 2 +- .../examples/eeprom_read/eeprom_read.ino | 3 - .../PostHttpClient/PostHttpClient.ino | 32 +++-- .../examples/FSBrowser/FSBrowser.ino | 4 +- .../HttpHashCredAuth/HttpHashCredAuth.ino | 25 ++-- .../BearSSL_CertStore/BearSSL_CertStore.ino | 11 +- .../BearSSL_CertStore/certs-from-mozilla.py | 2 +- libraries/ESP8266WiFi/keywords.txt | 2 - libraries/ESP8266WiFi/src/CertStoreBearSSL.h | 2 +- .../examples/httpUpdate/httpUpdate.ino | 30 ++--- .../httpUpdateLittleFS.ino} | 30 ++--- .../httpUpdateSecure/httpUpdateSecure.ino | 44 +++--- .../src/ESP8266httpUpdate.cpp | 2 +- .../ESP8266httpUpdate/src/ESP8266httpUpdate.h | 5 +- .../OTA-mDNS-SPIFFS.ino | 9 +- .../data/cl_conf.txt | 0 .../LittleFS/examples/SpeedTest/SpeedTest.ino | 125 ------------------ .../SD/examples/Datalogger/Datalogger.ino | 6 +- libraries/SD/examples/DumpFile/DumpFile.ino | 6 +- libraries/SD/examples/Files/Files.ino | 6 +- libraries/SD/examples/ReadWrite/ReadWrite.ino | 6 +- .../examples/tftbmp/tftbmp.ino | 2 +- .../examples/ConfigFile/ConfigFile.ino | 7 +- 26 files changed, 116 insertions(+), 257 deletions(-) rename libraries/ESP8266httpUpdate/examples/{httpUpdateSPIFFS/httpUpdateSPIFFS.ino => httpUpdateLittleFS/httpUpdateLittleFS.ino} (66%) rename libraries/ESP8266mDNS/examples/{OTA-mDNS-SPIFFS => OTA-mDNS-LittleFS}/OTA-mDNS-SPIFFS.ino (96%) rename libraries/ESP8266mDNS/examples/{OTA-mDNS-SPIFFS => OTA-mDNS-LittleFS}/data/cl_conf.txt (100%) delete mode 100644 libraries/LittleFS/examples/SpeedTest/SpeedTest.ino diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index aa47527812..93ef68ed5a 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -266,7 +266,7 @@ using fs::SPIFFSConfig; #endif //FS_NO_GLOBALS #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS) -extern fs::FS SPIFFS; +extern fs::FS SPIFFS __attribute__((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems."))); #endif #endif //FS_H diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 1f0278bfc5..df3e44245d 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -37,8 +37,8 @@ int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) { return flash_hal_read(addr, size, dst); } - - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" namespace spiffs_impl { @@ -149,6 +149,8 @@ extern "C" void spiffs_request_end(void) SPIFFS.end(); } +#pragma GCC diagnostic pop + #endif // ARDUINO #endif // !CORE_MOCK diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index a40d59b0a8..e6989f41dd 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -171,7 +171,7 @@ class SPIFFSImpl : public FSImpl return false; } _cfg = *static_cast(&cfg); - return true; + return true; } bool begin() override @@ -356,6 +356,8 @@ class SPIFFSImpl : public FSImpl std::unique_ptr _cacheBuf; SPIFFSConfig _cfg; + + int _called = 0; }; #define CHECKFD() while (_fd == 0) { panic(); } diff --git a/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino b/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino index e97dfbc0a4..5f1f5020a1 100644 --- a/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino +++ b/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino @@ -56,7 +56,7 @@ unsigned int status = WL_IDLE_STATUS; void setup() { delay(1000); - Serial.begin(9600); + Serial.begin(115200); Serial.println(); Serial.println("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ diff --git a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino index 5ffbe8240e..3295fecf9f 100644 --- a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino +++ b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -15,9 +15,6 @@ byte value; void setup() { // initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only - } EEPROM.begin(512); } diff --git a/libraries/ESP8266HTTPClient/examples/PostHttpClient/PostHttpClient.ino b/libraries/ESP8266HTTPClient/examples/PostHttpClient/PostHttpClient.ino index 94d57bdbf4..936e235eeb 100644 --- a/libraries/ESP8266HTTPClient/examples/PostHttpClient/PostHttpClient.ino +++ b/libraries/ESP8266HTTPClient/examples/PostHttpClient/PostHttpClient.ino @@ -8,8 +8,6 @@ #include #include -#define USE_SERIAL Serial - /* this can be run with an emulated server on host: cd esp8266-core-root-dir cd tests/host @@ -27,21 +25,21 @@ void setup() { - USE_SERIAL.begin(115200); + Serial.begin(115200); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + Serial.println(); + Serial.println(); + Serial.println(); WiFi.begin(STASSID, STAPSK); while (WiFi.status() != WL_CONNECTED) { delay(500); - USE_SERIAL.print("."); + Serial.print("."); } - USE_SERIAL.println(""); - USE_SERIAL.print("Connected! IP address: "); - USE_SERIAL.println(WiFi.localIP()); + Serial.println(""); + Serial.print("Connected! IP address: "); + Serial.println(WiFi.localIP()); } @@ -52,29 +50,29 @@ void loop() { WiFiClient client; HTTPClient http; - USE_SERIAL.print("[HTTP] begin...\n"); + Serial.print("[HTTP] begin...\n"); // configure traged server and url http.begin(client, "http://" SERVER_IP "/postplain/"); //HTTP http.addHeader("Content-Type", "application/json"); - USE_SERIAL.print("[HTTP] POST...\n"); + Serial.print("[HTTP] POST...\n"); // start connection and send HTTP header and body int httpCode = http.POST("{\"hello\":\"world\"}"); // httpCode will be negative on error if (httpCode > 0) { // HTTP header has been send and Server response header has been handled - USE_SERIAL.printf("[HTTP] POST... code: %d\n", httpCode); + Serial.printf("[HTTP] POST... code: %d\n", httpCode); // file found at server if (httpCode == HTTP_CODE_OK) { const String& payload = http.getString(); - USE_SERIAL.println("received payload:\n<<"); - USE_SERIAL.println(payload); - USE_SERIAL.println(">>"); + Serial.println("received payload:\n<<"); + Serial.println(payload); + Serial.println(">>"); } } else { - USE_SERIAL.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str()); + Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino index beebeb0146..f6aff52c7d 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino @@ -25,8 +25,8 @@ // Select the FileSystem by uncommenting one of the lines below -#define USE_SPIFFS -//#define USE_LITTLEFS +//#define USE_SPIFFS +#define USE_LITTLEFS //#define USE_SDFS // Uncomment the following line to embed a version of the web page in the code diff --git a/libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino b/libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino index e37295b060..c2ceaca53d 100644 --- a/libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino +++ b/libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino @@ -7,10 +7,11 @@ 1. Creating a secure web server using ESP8266ESP8266WebServerSecure 2. Use of HTTP authentication on this secure server 3. A simple web interface to allow an authenticated user to change Credentials - 4. Persisting those credentials through a reboot of the ESP by saving them to SPIFFS without storing them as plain text + 4. Persisting those credentials through a reboot of the ESP by saving them to LittleFS without storing them as plain text */ #include +#include #include #include @@ -23,8 +24,8 @@ const char* ssid = STASSID; const char* wifi_pw = STAPSK; -const String file_credentials = R"(/credentials.txt)"; //SPIFFS file name for the saved credentials -const String change_creds = "changecreds"; //address for a credential change +const String file_credentials = R"(/credentials.txt)"; // LittleFS file name for the saved credentials +const String change_creds = "changecreds"; // Address for a credential change //The ESP8266WebServerSecure requires an encryption certificate and matching key. //These can generated with the bash script available in the ESP8266 Arduino repository. @@ -83,7 +84,7 @@ gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk= ESP8266WebServerSecure server(443); -//These are temporary credentials that will only be used if none are found saved in SPIFFS. +//These are temporary credentials that will only be used if none are found saved in LittleFS. String login = "admin"; const String realm = "global"; String H1 = ""; @@ -92,9 +93,9 @@ String authentication_failed = "User authentication has failed."; void setup() { Serial.begin(115200); - //Initialize SPIFFS to save credentials - if(!SPIFFS.begin()){ - Serial.println("SPIFFS initialization error, programmer flash configured?"); + //Initialize LittleFS to save credentials + if(!LittleFS.begin()){ + Serial.println("LittleFS initialization error, programmer flash configured?"); ESP.restart(); } @@ -187,16 +188,16 @@ void showcredentialpage(){ server.send(200, "text/html", page); } -//Saves credentials to SPIFFS +//Saves credentials to LittleFS void savecredentials(String new_login, String new_password) { //Set global variables to new values login=new_login; H1=ESP8266WebServer::credentialHash(new_login,realm,new_password); - //Save new values to SPIFFS for loading on next reboot + //Save new values to LittleFS for loading on next reboot Serial.println("Saving credentials."); - File f=SPIFFS.open(file_credentials,"w"); //open as a brand new file, discard old contents + File f=LittleFS.open(file_credentials,"w"); //open as a brand new file, discard old contents if(f){ Serial.println("Modifying credentials in file system."); f.println(login); @@ -208,12 +209,12 @@ void savecredentials(String new_login, String new_password) Serial.println("Credentials saved."); } -//loads credentials from SPIFFS +//loads credentials from LittleFS void loadcredentials() { Serial.println("Searching for credentials."); File f; - f=SPIFFS.open(file_credentials,"r"); + f=LittleFS.open(file_credentials,"r"); if(f){ Serial.println("Loading credentials from file system."); String mod=f.readString(); //read the file to a String diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index 20a8a445a9..c8dc9d96c5 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -2,11 +2,11 @@ // // Before running, you must download the set of certs using // the script "certs-from-mozilla.py" (no parameters) -// and then uploading the generated .AR file to SPIFFS or SD. +// and then uploading the generated .AR file to LittleFS or SD. // // You do not need to generate the ".IDX" file listed below, // it is generated automatically when the CertStore object -// is created and written to SD or SPIFFS by the ESP8266. +// is created and written to SD or LittleFS by the ESP8266. // // Why would you need a CertStore? // @@ -37,6 +37,7 @@ #include #include #include +#include #ifndef STASSID #define STASSID "your-ssid" @@ -117,7 +118,7 @@ void setup() { Serial.println(); Serial.println(); - SPIFFS.begin(); + LittleFS.begin(); // If using a SD card or LittleFS, call the appropriate ::begin instead // We start by connecting to a WiFi network @@ -138,10 +139,10 @@ void setup() { setClock(); // Required for X.509 validation - int numCerts = certStore.initCertStore(SPIFFS, PSTR("/certs.idx"), PSTR("/certs.ar")); + int numCerts = certStore.initCertStore(LittleFS, PSTR("/certs.idx"), PSTR("/certs.ar")); Serial.printf("Number of CA certs read: %d\n", numCerts); if (numCerts == 0) { - Serial.printf("No certs found. Did you run certs-from-mozilla.py and upload the SPIFFS directory before running?\n"); + Serial.printf("No certs found. Did you run certs-from-mozilla.py and upload the LittleFS directory before running?\n"); return; // Can't connect to anything w/o certs! } diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py index e423bc25b9..556acb70fa 100755 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py @@ -3,7 +3,7 @@ # This script pulls the list of Mozilla trusted certificate authorities # from the web at the "mozurl" below, parses the file to grab the PEM # for each cert, and then generates DER files in a new ./data directory -# Upload these to a SPIFFS filesystem and use the CertManager to parse +# Upload these to an on-chip filesystem and use the CertManager to parse # and use them for your outgoing SSL connections. # # Script by Earle F. Philhower, III. Released to the public domain. diff --git a/libraries/ESP8266WiFi/keywords.txt b/libraries/ESP8266WiFi/keywords.txt index 16eea24227..ec3c0228bd 100644 --- a/libraries/ESP8266WiFi/keywords.txt +++ b/libraries/ESP8266WiFi/keywords.txt @@ -23,8 +23,6 @@ BearSSL KEYWORD1 X509List KEYWORD1 PrivateKey KEYWORD1 PublicKey KEYWORD1 -CertStoreSPIFFSBearSSL KEYWORD1 -CertStoreSDBearSSL KEYWORD1 Session KEYWORD1 ESP8266WiFiGratuitous KEYWORD1 diff --git a/libraries/ESP8266WiFi/src/CertStoreBearSSL.h b/libraries/ESP8266WiFi/src/CertStoreBearSSL.h index 76d4966e6a..ed3852e2ad 100644 --- a/libraries/ESP8266WiFi/src/CertStoreBearSSL.h +++ b/libraries/ESP8266WiFi/src/CertStoreBearSSL.h @@ -26,7 +26,7 @@ #include // Base class for the certificate stores, which allow use -// of a large set of certificates stored on SPIFFS of SD card to +// of a large set of certificates stored on FS or SD card to // be dynamically used when validating a X509 certificate namespace BearSSL { diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino b/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino index 69ed71fe6b..19c555a235 100644 --- a/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino +++ b/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino @@ -13,8 +13,6 @@ #include #include -#define USE_SERIAL Serial - #ifndef APSSID #define APSSID "APSSID" #define APPSK "APPSK" @@ -24,16 +22,16 @@ ESP8266WiFiMulti WiFiMulti; void setup() { - USE_SERIAL.begin(115200); - // USE_SERIAL.setDebugOutput(true); + Serial.begin(115200); + // Serial.setDebugOutput(true); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + Serial.println(); + Serial.println(); + Serial.println(); for (uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); + Serial.printf("[SETUP] WAIT %d...\n", t); + Serial.flush(); delay(1000); } @@ -44,19 +42,19 @@ void setup() { } void update_started() { - USE_SERIAL.println("CALLBACK: HTTP update process started"); + Serial.println("CALLBACK: HTTP update process started"); } void update_finished() { - USE_SERIAL.println("CALLBACK: HTTP update process finished"); + Serial.println("CALLBACK: HTTP update process finished"); } void update_progress(int cur, int total) { - USE_SERIAL.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total); + Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total); } void update_error(int err) { - USE_SERIAL.printf("CALLBACK: HTTP update fatal error code %d\n", err); + Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err); } @@ -86,15 +84,15 @@ void loop() { switch (ret) { case HTTP_UPDATE_FAILED: - USE_SERIAL.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); + Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: - USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES"); + Serial.println("HTTP_UPDATE_NO_UPDATES"); break; case HTTP_UPDATE_OK: - USE_SERIAL.println("HTTP_UPDATE_OK"); + Serial.println("HTTP_UPDATE_OK"); break; } } diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino b/libraries/ESP8266httpUpdate/examples/httpUpdateLittleFS/httpUpdateLittleFS.ino similarity index 66% rename from libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino rename to libraries/ESP8266httpUpdate/examples/httpUpdateLittleFS/httpUpdateLittleFS.ino index 8e035fde63..6541d047fd 100644 --- a/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino +++ b/libraries/ESP8266httpUpdate/examples/httpUpdateLittleFS/httpUpdateLittleFS.ino @@ -1,5 +1,5 @@ /** - httpUpdateSPIFFS.ino + httpUpdateLittleFS.ino Created on: 05.12.2015 @@ -13,8 +13,6 @@ #include #include -#define USE_SERIAL Serial - ESP8266WiFiMulti WiFiMulti; #ifndef APSSID @@ -24,16 +22,16 @@ ESP8266WiFiMulti WiFiMulti; void setup() { - USE_SERIAL.begin(115200); - // USE_SERIAL.setDebugOutput(true); + Serial.begin(115200); + // Serial.setDebugOutput(true); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + Serial.println(); + Serial.println(); + Serial.println(); for (uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); + Serial.printf("[SETUP] WAIT %d...\n", t); + Serial.flush(); delay(1000); } @@ -46,7 +44,7 @@ void loop() { // wait for WiFi connection if ((WiFiMulti.run() == WL_CONNECTED)) { - USE_SERIAL.println("Update SPIFFS..."); + Serial.println("Update LittleFS..."); WiFiClient client; @@ -58,22 +56,22 @@ void loop() { // value is used to put the LED on. If the LED is on with HIGH, that value should be passed ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW); - t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(client, "http://server/spiffs.bin"); + t_httpUpdate_return ret = ESPhttpUpdate.updateFS(client, "http://server/spiffs.bin"); if (ret == HTTP_UPDATE_OK) { - USE_SERIAL.println("Update sketch..."); + Serial.println("Update sketch..."); ret = ESPhttpUpdate.update(client, "http://server/file.bin"); switch (ret) { case HTTP_UPDATE_FAILED: - USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); + Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: - USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES"); + Serial.println("HTTP_UPDATE_NO_UPDATES"); break; case HTTP_UPDATE_OK: - USE_SERIAL.println("HTTP_UPDATE_OK"); + Serial.println("HTTP_UPDATE_OK"); break; } } diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino b/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino index 9eba1e5140..beb613897c 100644 --- a/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino +++ b/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino @@ -14,8 +14,7 @@ #include #include - -#define USE_SERIAL Serial +#include #ifndef APSSID #define APSSID "APSSID" @@ -34,46 +33,47 @@ BearSSL::CertStore certStore; void setClock() { configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC - USE_SERIAL.print(F("Waiting for NTP time sync: ")); + Serial.print(F("Waiting for NTP time sync: ")); time_t now = time(nullptr); while (now < 8 * 3600 * 2) { yield(); delay(500); - USE_SERIAL.print(F(".")); + Serial.print(F(".")); now = time(nullptr); } - USE_SERIAL.println(F("")); + Serial.println(F("")); struct tm timeinfo; gmtime_r(&now, &timeinfo); - USE_SERIAL.print(F("Current time: ")); - USE_SERIAL.print(asctime(&timeinfo)); + Serial.print(F("Current time: ")); + Serial.print(asctime(&timeinfo)); } void setup() { - USE_SERIAL.begin(115200); - // USE_SERIAL.setDebugOutput(true); + Serial.begin(115200); + // Serial.setDebugOutput(true); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + Serial.println(); + Serial.println(); + Serial.println(); for (uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); + Serial.printf("[SETUP] WAIT %d...\n", t); + Serial.flush(); delay(1000); } WiFi.mode(WIFI_STA); WiFiMulti.addAP(APSSID, APPSK); - SPIFFS.begin(); + LittleFS.begin(); - int numCerts = certStore.initCertStore(SPIFFS, PSTR("/certs.idx"), PSTR("/certs.ar")); - USE_SERIAL.print(F("Number of CA certs read: ")); USE_SERIAL.println(numCerts); + int numCerts = certStore.initCertStore(LittleFS, PSTR("/certs.idx"), PSTR("/certs.ar")); + Serial.print(F("Number of CA certs read: ")); + Serial.println(numCerts); if (numCerts == 0) { - USE_SERIAL.println(F("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?")); + Serial.println(F("No certs found. Did you run certs-from-mozill.py and upload the LittleFS directory before running?")); return; // Can't connect to anything w/o certs! } } @@ -86,7 +86,7 @@ void loop() { BearSSL::WiFiClientSecure client; bool mfln = client.probeMaxFragmentLength("server", 443, 1024); // server must be the same as in ESPhttpUpdate.update() - USE_SERIAL.printf("MFLN supported: %s\n", mfln ? "yes" : "no"); + Serial.printf("MFLN supported: %s\n", mfln ? "yes" : "no"); if (mfln) { client.setBufferSizes(1024, 1024); } @@ -107,15 +107,15 @@ void loop() { switch (ret) { case HTTP_UPDATE_FAILED: - USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); + Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: - USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES"); + Serial.println("HTTP_UPDATE_NO_UPDATES"); break; case HTTP_UPDATE_OK: - USE_SERIAL.println("HTTP_UPDATE_OK"); + Serial.println("HTTP_UPDATE_OK"); break; } } diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index a7fe1934d2..6d14b488b4 100755 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -126,7 +126,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(const String& url, const String } #endif -HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion) +HTTPUpdateResult ESP8266HTTPUpdate::updateiFS(WiFiClient& client, const String& url, const String& currentVersion) { HTTPClient http; http.begin(client, url); diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index ddbd307ad9..f1565cd2c6 100755 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -146,7 +146,10 @@ class ESP8266HTTPUpdate t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const String& httpsFingerprint) __attribute__((deprecated)); t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const uint8_t httpsFingerprint[20]) __attribute__((deprecated)); // BearSSL #endif - t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = ""); + t_httpUpdate_return updateFS(WiFiClient& client, const String& url, const String& currentVersion = ""); + t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = "") __attribute__((deprecated)) { + return updateFS(client, url, currentVersion); + }; // Notification callbacks void onStart(HTTPUpdateStartCB cbOnStart) { _cbStart = cbOnStart; } diff --git a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino b/libraries/ESP8266mDNS/examples/OTA-mDNS-LittleFS/OTA-mDNS-SPIFFS.ino similarity index 96% rename from libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino rename to libraries/ESP8266mDNS/examples/OTA-mDNS-LittleFS/OTA-mDNS-SPIFFS.ino index a03b7cfbad..9d0d861474 100644 --- a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino +++ b/libraries/ESP8266mDNS/examples/OTA-mDNS-LittleFS/OTA-mDNS-SPIFFS.ino @@ -1,5 +1,5 @@ /** - @file OTA-mDNS-SPIFFS.ino + @file OTA-mDNS-LittleFS.ino @author Pascal Gollor (http://www.pgollor.de/cms/) @date 2015-09-18 @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -55,7 +56,7 @@ const char* ap_default_psk = STAPSK; ///< Default PSK. */ bool loadConfig(String *ssid, String *pass) { // open file for reading. - File configFile = SPIFFS.open("/cl_conf.txt", "r"); + File configFile = LittleFS.open("/cl_conf.txt", "r"); if (!configFile) { Serial.println("Failed to open cl_conf.txt."); @@ -115,7 +116,7 @@ bool loadConfig(String *ssid, String *pass) { */ bool saveConfig(String *ssid, String *pass) { // Open config file for writing. - File configFile = SPIFFS.open("/cl_conf.txt", "w"); + File configFile = LittleFS.open("/cl_conf.txt", "w"); if (!configFile) { Serial.println("Failed to open cl_conf.txt for writing"); @@ -158,7 +159,7 @@ void setup() { // Initialize file system. - if (!SPIFFS.begin()) { + if (!LittleFS.begin()) { Serial.println("Failed to mount file system"); return; } diff --git a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/data/cl_conf.txt b/libraries/ESP8266mDNS/examples/OTA-mDNS-LittleFS/data/cl_conf.txt similarity index 100% rename from libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/data/cl_conf.txt rename to libraries/ESP8266mDNS/examples/OTA-mDNS-LittleFS/data/cl_conf.txt diff --git a/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino b/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino deleted file mode 100644 index 5b7dd453a0..0000000000 --- a/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino +++ /dev/null @@ -1,125 +0,0 @@ -// Simple speed test for filesystem objects -// Released to the public domain by Earle F. Philhower, III - -#include - -#define TESTSIZEKB 512 - -void DoTest(FS *fs) { - if (!fs->format()) { - Serial.printf("Unable to format(), aborting\n"); - return; - } - if (!fs->begin()) { - Serial.printf("Unable to begin(), aborting\n"); - return; - } - - uint8_t data[256]; - for (int i = 0; i < 256; i++) { - data[i] = (uint8_t) i; - } - - Serial.printf("Creating %dKB file, may take a while...\n", TESTSIZEKB); - long start = millis(); - File f = fs->open("/testwrite.bin", "w"); - if (!f) { - Serial.printf("Unable to open file for writing, aborting\n"); - return; - } - for (int i = 0; i < TESTSIZEKB; i++) { - for (int j = 0; j < 4; j++) { - f.write(data, 256); - } - } - f.close(); - long stop = millis(); - Serial.printf("==> Time to write %dKB in 256b chunks = %ld milliseconds\n", TESTSIZEKB, stop - start); - - f = fs->open("/testwrite.bin", "r"); - Serial.printf("==> Created file size = %d\n", f.size()); - f.close(); - - Serial.printf("Reading %dKB file sequentially in 256b chunks\n", TESTSIZEKB); - start = millis(); - f = fs->open("/testwrite.bin", "r"); - for (int i = 0; i < TESTSIZEKB; i++) { - for (int j = 0; j < 4; j++) { - f.read(data, 256); - } - } - f.close(); - stop = millis(); - Serial.printf("==> Time to read %dKB sequentially in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000); - - Serial.printf("Reading %dKB file MISALIGNED in flash and RAM sequentially in 256b chunks\n", TESTSIZEKB); - start = millis(); - f = fs->open("/testwrite.bin", "r"); - f.read(); - for (int i = 0; i < TESTSIZEKB; i++) { - for (int j = 0; j < 4; j++) { - f.read(data + 1, 256); - } - } - f.close(); - stop = millis(); - Serial.printf("==> Time to read %dKB sequentially MISALIGNED in flash and RAM in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000); - - - Serial.printf("Reading %dKB file in reverse by 256b chunks\n", TESTSIZEKB); - start = millis(); - f = fs->open("/testwrite.bin", "r"); - for (int i = 0; i < TESTSIZEKB; i++) { - for (int j = 0; j < 4; j++) { - if (!f.seek(256 + 256 * j * i, SeekEnd)) { - Serial.printf("Unable to seek to %d, aborting\n", -256 - 256 * j * i); - return; - } - if (256 != f.read(data, 256)) { - Serial.printf("Unable to read 256 bytes, aborting\n"); - return; - } - } - } - f.close(); - stop = millis(); - Serial.printf("==> Time to read %dKB in reverse in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000); - - - Serial.printf("Writing 64K file in 1-byte chunks\n"); - start = millis(); - f = fs->open("/test1b.bin", "w"); - for (int i = 0; i < 65536; i++) { - f.write((uint8_t*)&i, 1); - } - f.close(); - stop = millis(); - Serial.printf("==> Time to write 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000); - - Serial.printf("Reading 64K file in 1-byte chunks\n"); - start = millis(); - f = fs->open("/test1b.bin", "r"); - for (int i = 0; i < 65536; i++) { - char c; - f.read((uint8_t*)&c, 1); - } - f.close(); - stop = millis(); - Serial.printf("==> Time to read 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000); - - -} - -void setup() { - Serial.begin(115200); - Serial.printf("Beginning LittleFS test\n"); - Serial.flush(); - DoTest(&LittleFS); - Serial.printf("Beginning SPIFFS test\n"); - Serial.flush(); - DoTest(&SPIFFS); -} - -void loop() { - delay(10000); -} diff --git a/libraries/SD/examples/Datalogger/Datalogger.ino b/libraries/SD/examples/Datalogger/Datalogger.ino index fcb7a56e13..a023b63821 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.ino +++ b/libraries/SD/examples/Datalogger/Datalogger.ino @@ -27,11 +27,7 @@ const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only - } - + Serial.begin(115200); Serial.print("Initializing SD card..."); diff --git a/libraries/SD/examples/DumpFile/DumpFile.ino b/libraries/SD/examples/DumpFile/DumpFile.ino index 42bd8bcbb0..3574652890 100644 --- a/libraries/SD/examples/DumpFile/DumpFile.ino +++ b/libraries/SD/examples/DumpFile/DumpFile.ino @@ -27,11 +27,7 @@ const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only - } - + Serial.begin(115200); Serial.print("Initializing SD card..."); diff --git a/libraries/SD/examples/Files/Files.ino b/libraries/SD/examples/Files/Files.ino index cb2c1f1d2a..1c1b83ec20 100644 --- a/libraries/SD/examples/Files/Files.ino +++ b/libraries/SD/examples/Files/Files.ino @@ -24,11 +24,7 @@ File myFile; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only - } - + Serial.begin(115200); Serial.print("Initializing SD card..."); diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.ino b/libraries/SD/examples/ReadWrite/ReadWrite.ino index cd63aa554c..7aa9a40c4b 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.ino +++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -25,11 +25,7 @@ File myFile; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only - } - + Serial.begin(115200); Serial.print("Initializing SD card..."); diff --git a/libraries/TFT_Touch_Shield_V2/examples/tftbmp/tftbmp.ino b/libraries/TFT_Touch_Shield_V2/examples/tftbmp/tftbmp.ino index 2bfc9f1473..4176de59dc 100644 --- a/libraries/TFT_Touch_Shield_V2/examples/tftbmp/tftbmp.ino +++ b/libraries/TFT_Touch_Shield_V2/examples/tftbmp/tftbmp.ino @@ -42,7 +42,7 @@ File bmpFile; void setup() { - Serial.begin(9600); + Serial.begin(115200); pinMode(PIN_SD_CS, OUTPUT); digitalWrite(PIN_SD_CS, HIGH); diff --git a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino index 77bbfabaa9..cb1d25be07 100644 --- a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino +++ b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino @@ -9,9 +9,10 @@ #include #include "FS.h" +#include bool loadConfig() { - File configFile = SPIFFS.open("/config.json", "r"); + File configFile = LittleFS.open("/config.json", "r"); if (!configFile) { Serial.println("Failed to open config file"); return false; @@ -56,7 +57,7 @@ bool saveConfig() { doc["serverName"] = "api.example.com"; doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98"; - File configFile = SPIFFS.open("/config.json", "w"); + File configFile = LittleFS.open("/config.json", "w"); if (!configFile) { Serial.println("Failed to open config file for writing"); return false; @@ -72,7 +73,7 @@ void setup() { delay(1000); Serial.println("Mounting FS..."); - if (!SPIFFS.begin()) { + if (!LittleFS.begin()) { Serial.println("Failed to mount file system"); return; } From 7446ceef39f62700621ea39d579793de92bc7f81 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 3 May 2020 08:49:40 -0700 Subject: [PATCH 2/7] Remove leftover debug code --- cores/esp8266/spiffs_api.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index e6989f41dd..1ea04849e1 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -356,8 +356,6 @@ class SPIFFSImpl : public FSImpl std::unique_ptr _cacheBuf; SPIFFSConfig _cfg; - - int _called = 0; }; #define CHECKFD() while (_fd == 0) { panic(); } From f581360c664c12ced33ac6555087a73bc3dddfd6 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 3 May 2020 08:54:37 -0700 Subject: [PATCH 3/7] Clean up comments in some examples --- .../examples/BearSSL_CertStore/BearSSL_CertStore.ino | 1 - libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index c8dc9d96c5..48bfd0e2c2 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -119,7 +119,6 @@ void setup() { Serial.println(); LittleFS.begin(); - // If using a SD card or LittleFS, call the appropriate ::begin instead // We start by connecting to a WiFi network Serial.print("Connecting to "); diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index 6d14b488b4..f481d79a69 100755 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -126,7 +126,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(const String& url, const String } #endif -HTTPUpdateResult ESP8266HTTPUpdate::updateiFS(WiFiClient& client, const String& url, const String& currentVersion) +HTTPUpdateResult ESP8266HTTPUpdate::updateFS(WiFiClient& client, const String& url, const String& currentVersion) { HTTPClient http; http.begin(client, url); From c3da530d1ef9604ff98a2e5bbde2325d163863f1 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 3 May 2020 09:57:03 -0700 Subject: [PATCH 4/7] Update documentation on SPIFFS deprecation --- doc/boards.rst | 2 +- doc/esp8266wifi/bearssl-client-secure-class.rst | 4 ++-- doc/esp8266wifi/client-secure-class.rst | 11 ++++++----- doc/faq/readme.rst | 4 ++-- doc/filesystem.rst | 10 ++++++++++ doc/installing.rst | 2 +- doc/libraries.rst | 2 +- doc/ota_updates/readme.rst | 2 +- 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/doc/boards.rst b/doc/boards.rst index a27c1d5cfb..7ab98e2513 100644 --- a/doc/boards.rst +++ b/doc/boards.rst @@ -344,7 +344,7 @@ Parameters in Arduino IDE: ~~~~~~~~~~~~~~~~~~~~~~~~~~ - Card: "WEMOS D1 Mini Lite" -- Flash Size: "1M (512K SPIFFS)" +- Flash Size: "1M (512K FS)" - CPU Frequency: "80 Mhz" Power: diff --git a/doc/esp8266wifi/bearssl-client-secure-class.rst b/doc/esp8266wifi/bearssl-client-secure-class.rst index dc6886342a..b145e68a05 100644 --- a/doc/esp8266wifi/bearssl-client-secure-class.rst +++ b/doc/esp8266wifi/bearssl-client-secure-class.rst @@ -102,9 +102,9 @@ The web browser you're using to read this document keeps a list of 100s of certi In many cases your application will know the specific CA it needs to validate web or MQTT servers against (often just a single, self-signing CA private to your institution). Simply load your private CA in a `BearSSL::X509List` and use that as your trust anchor. -However, there are cases where you will not know beforehand which CA you will need (i.e. a user enters a website through a keypad), and you need to keep the list of CAs just like your web browser. In those cases, you need to generate a certificate bundle on the PC while compiling your application, upload the `certs.ar` bundle to SPIFFS or SD when uploading your application binary, and pass it to a `BearSSL::CertStore()` in order to validate TLS peers. +However, there are cases where you will not know beforehand which CA you will need (i.e. a user enters a website through a keypad), and you need to keep the list of CAs just like your web browser. In those cases, you need to generate a certificate bundle on the PC while compiling your application, upload the `certs.ar` bundle to LittleFS or SD when uploading your application binary, and pass it to a `BearSSL::CertStore()` in order to validate TLS peers. -See the `BearSSL_CertStore` example for full details as the `BearSSL::CertStore` requires the creation of a cookie-cutter object for filesystem access (because the SD and SPIFFS filesystems are presently incompatible with each other). At a high level in your `setup()` you will call `BearSSL::initCertStore()` on a global object, and then pass this global certificate store to `client.setCertStore(&gCA)` before every connection attempt to enable it as a validation option. +See the `BearSSL_CertStore` example for full details. Supported Crypto ~~~~~~~~~~~~~~~~ diff --git a/doc/esp8266wifi/client-secure-class.rst b/doc/esp8266wifi/client-secure-class.rst index 22501da4a8..597a198cc7 100644 --- a/doc/esp8266wifi/client-secure-class.rst +++ b/doc/esp8266wifi/client-secure-class.rst @@ -42,23 +42,24 @@ Load client certificate from file system. .. code:: cpp #include + #include #include #include - const char* certyficateFile = "/client.cer"; + const char* certificateFile = "/client.cer"; *setup() or loop()* .. code:: cpp - if (!SPIFFS.begin()) + if (!LittleFS.begin()) { Serial.println("Failed to mount the file system"); return; } - Serial.printf("Opening %s", certyficateFile); - File crtFile = SPIFFS.open(certyficateFile, "r"); + Serial.printf("Opening %s", certificateFile); + File crtFile = LittleFS.open(certificateFile, "r"); if (!crtFile) { Serial.println(" Failed!"); @@ -66,7 +67,7 @@ Load client certificate from file system. WiFiClientSecure client; - Serial.print("Loading %s", certyficateFile); + Serial.print("Loading %s", certificateFile); if (!client.loadCertificate(crtFile)) { Serial.println(" Failed!"); diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index ee76138dff..fda5fb6592 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -79,7 +79,7 @@ perform. It is not listed among libraries verified to work with ESP8266. `Read more `__. -In the IDE, for ESP-12E that has 4M flash, I can choose 4M (1M SPIFFS) or 4M (3M SPIFFS). No matter what I select, the IDE tells me the maximum code space is about 1M. Where does my flash go? +In the IDE, for ESP-12E that has 4M flash, I can choose 4M (1M FS) or 4M (3M FS). No matter what I select, the IDE tells me the maximum code space is about 1M. Where does my flash go? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The reason we cannot have more than 1MB of code in flash has to do with @@ -90,7 +90,7 @@ total, but switching such "banks" on the fly is not easy and efficient, so we don't bother doing that. Besides, no one has so far complained about 1MB of code space being insufficient for practical purposes. -The option to choose 3M or 1M SPIFFS is to optimize the upload time. +The option to choose 3M or 1M filesystem is to optimize the upload time. Uploading 3MB takes a long time so sometimes you can just use 1MB. Other 2MB of flash can still be used with ``ESP.flashRead`` and ``ESP.flashWrite`` APIs if necessary. diff --git a/doc/filesystem.rst b/doc/filesystem.rst index abf47a7ead..57b69d3834 100644 --- a/doc/filesystem.rst +++ b/doc/filesystem.rst @@ -63,6 +63,16 @@ following include to the sketch: #include "FS.h" +SPIFFS Deprecation Warning +-------------------------- + +SPIFFS is currently deprecated and may be removed in future releases of +the core. Please consider moving your code to LittleFS. SPIFFS is not +actively supported anymore by the upstream developer, while LittleFS is +under active development, supports real directories, and is many times +faster for most operations. + + SPIFFS and LittleFS ------------------- diff --git a/doc/installing.rst b/doc/installing.rst index 515fc891f0..cd8e58a7ab 100644 --- a/doc/installing.rst +++ b/doc/installing.rst @@ -244,6 +244,6 @@ BeagleBone, CubieBoard). - `What is PlatformIO? `__ - `PlatformIO IDE `__ - `PlatformIO Core `__ (command line tool) -- `Advanced usage `__ - custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version +- `Advanced usage `__ - custom settings, uploading to LittleFS, Over-the-Air (OTA), staging version - `Integration with Cloud and Standalone IDEs `__ - Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode - `Project Examples `__ diff --git a/doc/libraries.rst b/doc/libraries.rst index fc44d46f5a..8e8bdcb637 100644 --- a/doc/libraries.rst +++ b/doc/libraries.rst @@ -25,7 +25,7 @@ This is a bit different from standard EEPROM class. You need to call ``EEPROM.be ``EEPROM.write`` does not write to flash immediately, instead you must call ``EEPROM.commit()`` whenever you wish to save changes to flash. ``EEPROM.end()`` will also commit, and will release the RAM copy of EEPROM contents. -EEPROM library uses one sector of flash located just after the SPIFFS. +EEPROM library uses one sector of flash located just after the embedded filesystem. `Three examples `__ included. diff --git a/doc/ota_updates/readme.rst b/doc/ota_updates/readme.rst index a783bc782c..35eb931507 100755 --- a/doc/ota_updates/readme.rst +++ b/doc/ota_updates/readme.rst @@ -360,7 +360,7 @@ If this is the case, then most likely ESP module has not been reset after initia The most common causes of OTA failure are as follows: - not enough physical memory on the chip (e.g. ESP01 with 512K flash memory is not enough for OTA). -- too much memory declared for SPIFFS so new sketch will not fit between existing sketch and SPIFFS – see `Update process - memory view <#update-process-memory-view>`__. +- too much memory declared for the filesystem so new sketch will not fit between existing sketch and the filesystem – see `Update process - memory view <#update-process-memory-view>`__. - too little memory declared in Arduino IDE for your selected board (i.e. less than physical size). - not resetting the ESP module after initial upload using serial port. From d588f4f87b6fe4837c472e457755b320b1223e9f Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 3 May 2020 09:59:54 -0700 Subject: [PATCH 5/7] Fix host tests to avoid deprecation warnings --- boards.txt | 4 ++-- tests/host/common/MockUART.cpp | 3 +++ tests/host/common/spiffs_mock.cpp | 6 ++++++ tests/host/core/test_Print.cpp | 13 +++++++------ tests/host/fs/test_fs.cpp | 4 ++++ tools/boards.txt.py | 10 +++++----- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/boards.txt b/boards.txt index 9499d23547..3d2c355c29 100644 --- a/boards.txt +++ b/boards.txt @@ -4960,7 +4960,7 @@ espinotee.menu.baud.3000000.upload.speed=3000000 wifinfo.name=WifInfo wifinfo.build.board=WIFINFO wifinfo.build.variant=wifinfo -wifinfo.menu.ESPModule.ESP07192=ESP07 (1M/192K SPIFFS) +wifinfo.menu.ESPModule.ESP07192=ESP07 (1M/192K FS) wifinfo.menu.ESPModule.ESP07192.build.board=ESP8266_ESP07 wifinfo.menu.ESPModule.ESP07192.build.flash_ld=eagle.flash.1m192.ld wifinfo.menu.ESPModule.ESP07192.build.flash_size=1M @@ -4968,7 +4968,7 @@ wifinfo.menu.ESPModule.ESP07192.build.spiffs_blocksize=4096 wifinfo.menu.ESPModule.ESP07192.build.spiffs_end=0xFB000 wifinfo.menu.ESPModule.ESP07192.build.spiffs_start=0xCB000 wifinfo.menu.ESPModule.ESP07192.upload.maximum_size=827376 -wifinfo.menu.ESPModule.ESP12=ESP12 (4M/1M SPIFFS) +wifinfo.menu.ESPModule.ESP12=ESP12 (4M/1M FS) wifinfo.menu.ESPModule.ESP12.build.board=ESP8266_ESP12 wifinfo.menu.ESPModule.ESP12.build.flash_ld=eagle.flash.4m1m.ld wifinfo.menu.ESPModule.ESP12.build.flash_size=4M diff --git a/tests/host/common/MockUART.cpp b/tests/host/common/MockUART.cpp index 023c775bfc..825a4dc0d6 100644 --- a/tests/host/common/MockUART.cpp +++ b/tests/host/common/MockUART.cpp @@ -88,7 +88,10 @@ uart_do_write_char(const int uart_nr, char c) } else { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" write(uart_nr + 1, &c, 1); +#pragma GCC diagnostic pop w = true; } } diff --git a/tests/host/common/spiffs_mock.cpp b/tests/host/common/spiffs_mock.cpp index 3e85fa06ab..8e73626194 100644 --- a/tests/host/common/spiffs_mock.cpp +++ b/tests/host/common/spiffs_mock.cpp @@ -31,6 +31,9 @@ #define SPIFFS_FILE_NAME "spiffs.bin" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + FS SPIFFS(nullptr); SpiffsMock::SpiffsMock(ssize_t fs_size, size_t fs_block, size_t fs_page, const String& storage) @@ -126,3 +129,6 @@ void SpiffsMock::save () if (::close(fs) == -1) fprintf(stderr, "SPIFFS: closing %s: %s\n", m_storage.c_str(), strerror(errno)); } + +#pragma GCC diagnostic pop + diff --git a/tests/host/core/test_Print.cpp b/tests/host/core/test_Print.cpp index c3cb2f5cd0..e58539c59e 100644 --- a/tests/host/core/test_Print.cpp +++ b/tests/host/core/test_Print.cpp @@ -16,15 +16,16 @@ #include #include #include -#include "../common/spiffs_mock.h" +#include +#include "../common/littlefs_mock.h" #include -// Use a SPIFFS file because we can't instantiate a virtual class like Print +// Use a LittleFS file because we can't instantiate a virtual class like Print TEST_CASE("Print::write overrides all compile properly", "[core][Print]") { - SPIFFS_MOCK_DECLARE(64, 8, 512, ""); - REQUIRE(SPIFFS.begin()); - auto p = SPIFFS.open("test.bin", "w"); + LITTLEFS_MOCK_DECLARE(64, 8, 512, ""); + REQUIRE(LittleFS.begin()); + auto p = LittleFS.open("test.bin", "w"); REQUIRE(p); uint8_t uint8 = 1; uint16_t uint16 = 2; @@ -56,7 +57,7 @@ TEST_CASE("Print::write overrides all compile properly", "[core][Print]") p.write(1); p.close(); - p = SPIFFS.open("test.bin", "r"); + p = LittleFS.open("test.bin", "r"); REQUIRE(p); uint8_t buff[16]; int len = p.read(buff, 16); diff --git a/tests/host/fs/test_fs.cpp b/tests/host/fs/test_fs.cpp index 28dd0bab5b..f25c50e96b 100644 --- a/tests/host/fs/test_fs.cpp +++ b/tests/host/fs/test_fs.cpp @@ -26,6 +26,9 @@ namespace spiffs_test { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #define FSTYPE SPIFFS #define TESTPRE "SPIFFS - " #define TESTPAT "[fs]" @@ -54,6 +57,7 @@ TEST_CASE("SPIFFS checks the config object passed in", "[fs]") REQUIRE_FALSE(SPIFFS.setConfig(d)); REQUIRE_FALSE(LittleFS.setConfig(l)); } +#pragma GCC diagnostic push }; diff --git a/tools/boards.txt.py b/tools/boards.txt.py index d33cbe1fc9..8263191495 100755 --- a/tools/boards.txt.py +++ b/tools/boards.txt.py @@ -29,7 +29,7 @@ # resetmethod_menu_extra menus for additional reset methods # crystalfreq/flashfreq_menu: menus for crystal/flash frequency selection # flashmode_menu: menus for flashmode selection (dio/dout/qio/qout) -# 512K/1M/2M/4M/8M/16M: menus for flash & SPIFFS size +# 512K/1M/2M/4M/8M/16M: menus for flash & FS size # lwip/lwip2 menus for available lwip versions from __future__ import print_function @@ -613,7 +613,7 @@ '~~~~~~~~~~~~~~~~~~~~~~~~~~', '', '- Card: "WEMOS D1 Mini Lite"', - '- Flash Size: "1M (512K SPIFFS)"', + '- Flash Size: "1M (512K FS)"', '- CPU Frequency: "80 Mhz"', # '- Upload Speed: "230400"', '', @@ -696,7 +696,7 @@ 'opts': collections.OrderedDict([ ( '.build.board', 'WIFINFO' ), ( '.build.variant', 'wifinfo' ), - ( '.menu.ESPModule.ESP07192', 'ESP07 (1M/192K SPIFFS)' ), + ( '.menu.ESPModule.ESP07192', 'ESP07 (1M/192K FS)' ), ( '.menu.ESPModule.ESP07192.build.board', 'ESP8266_ESP07' ), ( '.menu.ESPModule.ESP07192.build.flash_size', '1M' ), ( '.menu.ESPModule.ESP07192.build.flash_ld', 'eagle.flash.1m192.ld' ), @@ -704,7 +704,7 @@ ( '.menu.ESPModule.ESP07192.build.spiffs_end', '0xFB000' ), ( '.menu.ESPModule.ESP07192.build.spiffs_blocksize', '4096' ), ( '.menu.ESPModule.ESP07192.upload.maximum_size', '827376' ), - ( '.menu.ESPModule.ESP12', 'ESP12 (4M/1M SPIFFS)' ), + ( '.menu.ESPModule.ESP12', 'ESP12 (4M/1M FS)' ), ( '.menu.ESPModule.ESP12.build.board', 'ESP8266_ESP12' ), ( '.menu.ESPModule.ESP12.build.flash_size', '4M' ), ( '.menu.ESPModule.ESP12.build.flash_ld', 'eagle.flash.4m1m.ld' ), @@ -1316,7 +1316,7 @@ def flash_map (flashsize_kb, fs_kb = 0): else: fs_blocksize = 8192 - # Adjust SPIFFS_end to be a multiple of the block size + # Adjust FS_end to be a multiple of the block size fs_end = fs_blocksize * (int)((fs_end - fs_start)/fs_blocksize) + fs_start; max_ota_size = min(max_upload_size, fs_start / 2) # =(max_upload_size+empty_size)/2 From e61c372b21806c76d4b53d27b1d0a959c1a4ce25 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 3 May 2020 14:15:53 -0700 Subject: [PATCH 6/7] Fix cut-n-paste error --- tests/host/fs/test_fs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/host/fs/test_fs.cpp b/tests/host/fs/test_fs.cpp index f25c50e96b..fb73a6a271 100644 --- a/tests/host/fs/test_fs.cpp +++ b/tests/host/fs/test_fs.cpp @@ -57,7 +57,7 @@ TEST_CASE("SPIFFS checks the config object passed in", "[fs]") REQUIRE_FALSE(SPIFFS.setConfig(d)); REQUIRE_FALSE(LittleFS.setConfig(l)); } -#pragma GCC diagnostic push +#pragma GCC diagnostic pop }; From 19b27bc032be261dad89a7144a5a86e102b50fa9 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 4 May 2020 09:02:45 -0700 Subject: [PATCH 7/7] Restore SpeedTest.ino, adjust to allow custom FSes --- .../LittleFS/examples/SpeedTest/SpeedTest.ino | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 libraries/LittleFS/examples/SpeedTest/SpeedTest.ino diff --git a/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino b/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino new file mode 100644 index 0000000000..5987e10807 --- /dev/null +++ b/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino @@ -0,0 +1,131 @@ +// Simple speed test for filesystem objects +// Released to the public domain by Earle F. Philhower, III + +#include +#include + +// Choose the filesystem to test +// WARNING: The filesystem will be formatted at the start of the test! + +#define TESTFS LittleFS +//#define TESTFS SPIFFS +//#define TESTFS SDFS + +// How large of a file to test +#define TESTSIZEKB 512 + +void DoTest(FS *fs) { + if (!fs->format()) { + Serial.printf("Unable to format(), aborting\n"); + return; + } + if (!fs->begin()) { + Serial.printf("Unable to begin(), aborting\n"); + return; + } + + uint8_t data[256]; + for (int i = 0; i < 256; i++) { + data[i] = (uint8_t) i; + } + + Serial.printf("Creating %dKB file, may take a while...\n", TESTSIZEKB); + long start = millis(); + File f = fs->open("/testwrite.bin", "w"); + if (!f) { + Serial.printf("Unable to open file for writing, aborting\n"); + return; + } + for (int i = 0; i < TESTSIZEKB; i++) { + for (int j = 0; j < 4; j++) { + f.write(data, 256); + } + } + f.close(); + long stop = millis(); + Serial.printf("==> Time to write %dKB in 256b chunks = %ld milliseconds\n", TESTSIZEKB, stop - start); + + f = fs->open("/testwrite.bin", "r"); + Serial.printf("==> Created file size = %d\n", f.size()); + f.close(); + + Serial.printf("Reading %dKB file sequentially in 256b chunks\n", TESTSIZEKB); + start = millis(); + f = fs->open("/testwrite.bin", "r"); + for (int i = 0; i < TESTSIZEKB; i++) { + for (int j = 0; j < 4; j++) { + f.read(data, 256); + } + } + f.close(); + stop = millis(); + Serial.printf("==> Time to read %dKB sequentially in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000); + + Serial.printf("Reading %dKB file MISALIGNED in flash and RAM sequentially in 256b chunks\n", TESTSIZEKB); + start = millis(); + f = fs->open("/testwrite.bin", "r"); + f.read(); + for (int i = 0; i < TESTSIZEKB; i++) { + for (int j = 0; j < 4; j++) { + f.read(data + 1, 256); + } + } + f.close(); + stop = millis(); + Serial.printf("==> Time to read %dKB sequentially MISALIGNED in flash and RAM in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000); + + + Serial.printf("Reading %dKB file in reverse by 256b chunks\n", TESTSIZEKB); + start = millis(); + f = fs->open("/testwrite.bin", "r"); + for (int i = 0; i < TESTSIZEKB; i++) { + for (int j = 0; j < 4; j++) { + if (!f.seek(256 + 256 * j * i, SeekEnd)) { + Serial.printf("Unable to seek to %d, aborting\n", -256 - 256 * j * i); + return; + } + if (256 != f.read(data, 256)) { + Serial.printf("Unable to read 256 bytes, aborting\n"); + return; + } + } + } + f.close(); + stop = millis(); + Serial.printf("==> Time to read %dKB in reverse in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000); + + + Serial.printf("Writing 64K file in 1-byte chunks\n"); + start = millis(); + f = fs->open("/test1b.bin", "w"); + for (int i = 0; i < 65536; i++) { + f.write((uint8_t*)&i, 1); + } + f.close(); + stop = millis(); + Serial.printf("==> Time to write 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000); + + Serial.printf("Reading 64K file in 1-byte chunks\n"); + start = millis(); + f = fs->open("/test1b.bin", "r"); + for (int i = 0; i < 65536; i++) { + char c; + f.read((uint8_t*)&c, 1); + } + f.close(); + stop = millis(); + Serial.printf("==> Time to read 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000); + + +} + +void setup() { + Serial.begin(115200); + Serial.printf("Beginning test\n"); + Serial.flush(); + DoTest(&TESTFS); +} + +void loop() { + delay(10000); +}