From 26f0939cc6cd1afcd59a3deca67c5c7260e7e3f7 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 17 Oct 2024 20:38:46 +0200 Subject: [PATCH] LittleFS.format on ESP32 needs LittleFS.begin() before --- Arduino/CanGrow/CanGrow.ino | 36 +++++++++++++++------- Arduino/CanGrow/include/CanGrow.h | 2 +- Arduino/CanGrow/include/CanGrow_Core.h | 1 + Arduino/CanGrow/include/CanGrow_LittleFS.h | 35 +++++++++++++++++++++ cangrow.sh | 2 +- 5 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 Arduino/CanGrow/include/CanGrow_LittleFS.h diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 3df456b..ba4f006 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -27,16 +27,9 @@ * */ - -/* - * CanGrow includes - */ - -#include "include/CanGrow.h" -#include "include/CanGrow_Core.h" /* - * Libraries + * Libraries include */ // * ESP8266 * @@ -47,8 +40,11 @@ // * ESP32 * #ifdef ESP32 +#include "Arduino.h" #include #include "AsyncTCP.h" +// LittleFS auto format +#define FORMAT_LITTLEFS_IF_FAILED true #endif // https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI @@ -66,6 +62,14 @@ #include "LittleFS.h" +/* + * CanGrow includes + */ + +#include "include/CanGrow.h" +#include "include/CanGrow_Core.h" +#include "include/CanGrow_LittleFS.h" + void setup() { // define output for onboard LED/WIPE pin @@ -118,23 +122,33 @@ void setup() { if(digitalRead(PinWIPE) == HIGH) { #endif Serial.println("!! formatting LittleFS !!"); + + #ifdef ESP32 + LittleFS.begin(); + #endif LittleFS.format(); Panic(); } Serial.println(":: initialise LittleFS ::"); - if(LittleFS.begin()) { - Serial.println(":: LittleFS: successfully initialised"); - } else { + #ifdef ESP8266 + if(!LittleFS.begin()) { + #endif + #ifdef ESP32 + if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)) { + #endif Serial.println("!! LittleFS: failed initialising !!"); + Panic(); } // read the configfile from LittleFS File lfs_configfile = LittleFS.open(configfile, "r"); if(!lfs_configfile) { Serial.println("!! LittleFS: config.json not found, creating it !!"); + lfs_configfile.close(); lfs_configfile = LittleFS.open(configfile, "w"); + lfs_configfile.close(); if(lfs_configfile) { Serial.println(":: LittleFS: config.json successfully created"); // write into the file diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index a45efa3..c3e1c20 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -30,7 +30,7 @@ #include "CanGrow_Version.h" -//#define FORMAT_LITTLEFS_IF_FAILED false + const char* configfile = "config.json"; #ifdef ESP8266 diff --git a/Arduino/CanGrow/include/CanGrow_Core.h b/Arduino/CanGrow/include/CanGrow_Core.h index 157b659..7ac9079 100644 --- a/Arduino/CanGrow/include/CanGrow_Core.h +++ b/Arduino/CanGrow/include/CanGrow_Core.h @@ -29,6 +29,7 @@ // blink fast with the built in LED in an infinite loop void Panic() { + Serial.println("!! PANIC !!"); byte i = 0; while(true) { if(i % 2) { diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h new file mode 100644 index 0000000..81a908c --- /dev/null +++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h @@ -0,0 +1,35 @@ +/* + * + * include/CanGrow_LittleFS.h - LittleFS handling header file + * + * + * MIT License + * + * Copyright (c) 2024 DeltaLima + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifdef ESP8266 + +#endif + +#ifdef ESP32 +#endif diff --git a/cangrow.sh b/cangrow.sh index 340bf5f..560c568 100755 --- a/cangrow.sh +++ b/cangrow.sh @@ -2,7 +2,7 @@ # test -z $TTY && TTY="/dev/ttyUSB0" -test -z $IP && IP="192.168.30.212" +test -z $IP && IP="192.168.4.20" test -z $VER && VER="0.2-dev" test -z $BOARD && BOARD="esp8266:esp8266:d1_mini_clone"