Skip to content

Commit 4cce923

Browse files
committed
[LittleFS] Support for LittleFS
LittleFS can be built in custom 16M build env. See esp8266/Arduino#5932
1 parent 5ce3e2f commit 4cce923

13 files changed

+292
-175
lines changed

platformio.ini

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,17 @@ build_flags = ${esp82xx_defaults.build_flags} -DARDUINO_ESP8266_RE
116116
117117
build_flags = ${esp82xx_2_5_0.build_flags}
118118

119+
120+
; No idea how to make it multi-platform.
121+
; After initial download, go to the .platformio/packages/framework... directory
122+
; and type: git submodule update
123+
[core_2_5_1_littlefs]
124+
platform = https://github.com/TD-er/platform-espressif8266.git#patch/v2.0.3_littlefs
125+
build_flags = ${esp82xx_2_5_0.build_flags} -DCORE_POST_2_6_0 -DLITTLE_FS
126+
119127
[core_stage]
120128
platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
121-
build_flags = ${esp82xx_2_5_0.build_flags}
129+
build_flags = ${esp82xx_2_5_0.build_flags} -DCORE_POST_2_6_0
122130

123131

124132
[core_esp32_0_12_0]
@@ -179,6 +187,10 @@ build_unflags =
179187
build_flags = ${core_stage.build_flags} ${common.build_flags} -DARDUINO_ESP8266_RELEASE='"2.6.0-dev"'
180188
platform = ${core_stage.platform}
181189

190+
[test_littlefs]
191+
build_unflags =
192+
build_flags = ${core_2_5_1_littlefs.build_flags} ${common.build_flags} -DARDUINO_ESP8266_RELEASE='"2.6.0-dev"'
193+
platform = ${core_2_5_1_littlefs.platform}
182194

183195

184196
[normal]
@@ -371,9 +383,49 @@ board_build.flash_mode = dout
371383
targets = ${common.targets}
372384

373385

386+
;;; NORMAL (STABLE) ***************************************************
387+
; Custom defined build ;
388+
; Hint: Also look at USE_CUSTOM_H ;
389+
; *********************************************************************
390+
391+
; NORMAL: 4096k version --------------------------
392+
[env:custom_ESP8266_4M]
393+
platform = ${normal_beta.platform}
394+
lib_deps = ${common.lib_deps}
395+
lib_ignore = ${common.lib_ignore}
396+
lib_ldf_mode = ${common.lib_ldf_mode}
397+
lib_archive = ${common.lib_archive}
398+
framework = ${common.framework}
399+
upload_speed = ${common.upload_speed}
400+
monitor_speed = ${common.monitor_speed}
401+
board = ${esp8266_4M.board}
402+
board_build.f_cpu = ${esp8266_4M.board_build.f_cpu}
403+
board_build.flash_mode = ${esp8266_4M.board_build.flash_mode}
404+
build_unflags = ${esp8266_4M.build_unflags}
405+
build_flags = ${esp8266_4M.build_flags} ${normal_beta.build_flags} -DPLUGIN_BUILD_CUSTOM
406+
targets = ${common.targets}
407+
extra_scripts = pre:pre_extra_script.py
408+
409+
[env:custom_ESP8266_16M]
410+
platform = ${test_littlefs.platform}
411+
lib_deps = ${common.lib_deps}
412+
lib_ignore = ${common.lib_ignore}
413+
lib_ldf_mode = ${common.lib_ldf_mode}
414+
lib_archive = ${common.lib_archive}
415+
framework = ${common.framework}
416+
upload_speed = ${common.upload_speed}
417+
monitor_speed = ${common.monitor_speed}
418+
board = ${esp8266_16M.board}
419+
board_build.f_cpu = ${esp8266_16M.board_build.f_cpu}
420+
board_build.flash_mode = ${esp8266_16M.board_build.flash_mode}
421+
build_unflags = ${esp8266_16M.build_unflags}
422+
build_flags = ${esp8266_16M.build_flags} ${test_littlefs.build_flags} -DPLUGIN_BUILD_CUSTOM
423+
targets = ${common.targets}
424+
extra_scripts = pre:pre_extra_script.py
425+
374426

375-
;;; NORMAL (STABLE) ; ****; ****; ****; ****; ****; ****; ****; ****; ****; ****; ****;;;;
376-
; normal version with stable plugins ;
427+
;;; NORMAL (STABLE) ***************************************************
428+
; normal version with stable plugins ;
377429
; *********************************************************************
378430

379431
; NORMAL: 1024k version --------------------------
@@ -820,7 +872,7 @@ build_flags = ${esp8266_4M.build_flags} ${normal_beta.build_flags}
820872
targets = ${common.targets}
821873

822874
[env:normal_core_260_sdk222_alpha_ESP8266_4M]
823-
platform = ${testing_beta.platform}
875+
platform = ${normal_beta.platform}
824876
lib_deps = ${common.lib_deps}
825877
lib_ignore = ${common.lib_ignore}
826878
lib_ldf_mode = ${common.lib_ldf_mode}

pre_extra_script.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Import("env")
2+
3+
# access to global construction environment
4+
#print env
5+
6+
# Dump construction environment (for debug purpose)
7+
#print env.Dump()
8+
9+
# append extra flags to global build environment
10+
# which later will be used to build:
11+
# - project source code
12+
# - frameworks
13+
# - dependent libraries
14+
env.Append(CPPDEFINES=[
15+
"PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x",
16+
"CONTROLLER_SET_ALL",
17+
"NOTIFIER_SET_NONE",
18+
"PLUGIN_SET_ONLY_SWITCH",
19+
"USES_P002", # ADC
20+
"USES_P028", # BME280
21+
"USES_P036", # FrameOLED
22+
"USES_P049", # MHZ19
23+
"USES_P052", # SenseAir
24+
"USES_P056", # SDS011-Dust
25+
"USES_P082", # GPS
26+
27+
("WEBSERVER_RULES_DEBUG", "0")
28+
])

src/ESPEasy-Globals.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ void setBitToUL(uint32_t& number, byte bitnr, bool value);
491491
void serialHelper_getGpioNames(struct EventStruct *event, bool rxOptional=false, bool txOptional=false);
492492

493493
fs::File tryOpenFile(const String& fname, const String& mode);
494+
//String FileError(int line, const char * fname);
494495

495496
enum SettingsType {
496497
BasicSettings_Type = 0,
@@ -565,10 +566,19 @@ bool showSettingsFileLayout = false;
565566
extern "C" {
566567
#include "spi_flash.h"
567568
}
568-
extern "C" uint32_t _SPIFFS_start;
569-
extern "C" uint32_t _SPIFFS_end;
570-
extern "C" uint32_t _SPIFFS_page;
571-
extern "C" uint32_t _SPIFFS_block;
569+
570+
#ifdef LITTLE_FS
571+
#include "LittleFS.h"
572+
extern "C" uint32_t _FS_start;
573+
extern "C" uint32_t _FS_end;
574+
extern "C" uint32_t _FS_page;
575+
extern "C" uint32_t _FS_block;
576+
#else
577+
extern "C" uint32_t _SPIFFS_start;
578+
extern "C" uint32_t _SPIFFS_end;
579+
extern "C" uint32_t _SPIFFS_page;
580+
extern "C" uint32_t _SPIFFS_block;
581+
#endif
572582
#ifdef FEATURE_MDNS
573583
#include <ESP8266mDNS.h>
574584
#endif
@@ -2095,13 +2105,14 @@ unsigned long timingstats_last_reset = 0;
20952105
#define WIFI_NOTCONNECTED_STATS 40
20962106
#define LOAD_TASK_SETTINGS 41
20972107
#define TRY_OPEN_FILE 42
2098-
#define SPIFFS_GC_SUCCESS 43
2099-
#define SPIFFS_GC_FAIL 44
2100-
#define RULES_PROCESSING 45
2101-
#define GRAT_ARP_STATS 46
2102-
#define BACKGROUND_TASKS 47
2103-
#define HANDLE_SCHEDULER_IDLE 48
2104-
#define HANDLE_SCHEDULER_TASK 49
2108+
#define CLEARFILE_STATS 43
2109+
#define SPIFFS_GC_SUCCESS 44
2110+
#define SPIFFS_GC_FAIL 45
2111+
#define RULES_PROCESSING 46
2112+
#define GRAT_ARP_STATS 47
2113+
#define BACKGROUND_TASKS 48
2114+
#define HANDLE_SCHEDULER_IDLE 49
2115+
#define HANDLE_SCHEDULER_TASK 50
21052116

21062117

21072118

@@ -2117,6 +2128,7 @@ String getMiscStatsName(int stat) {
21172128
switch (stat) {
21182129
case LOADFILE_STATS: return F("Load File");
21192130
case SAVEFILE_STATS: return F("Save File");
2131+
case CLEARFILE_STATS: return F("Clear File");
21202132
case LOOP_STATS: return F("Loop");
21212133
case PLUGIN_CALL_50PS: return F("Plugin call 50 p/s");
21222134
case PLUGIN_CALL_10PS: return F("Plugin call 10 p/s");
@@ -2348,7 +2360,7 @@ void addPredefinedRules(const GpioFactorySettingsStruct& gpio_settings);
23482360
// may not filter the ifdef checks properly.
23492361
// Also the functions use a lot of global defined variables, so include at the end of this file.
23502362
#include "ESPEasyWiFiEvent.h"
2351-
#define SPIFFS_CHECK(result, fname) if (!(result)) { return(FileError(__LINE__, fname)); }
2363+
#define FS_RES_CHECK(result, fname) if (!(result)) { return(FileError(__LINE__, fname)); }
23522364
#include "WebServer_Rules.h"
23532365

23542366
#endif /* ESPEASY_GLOBALS_H_ */

src/ESPEasy.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void setup()
159159
APModeStationDisconnectedHandler = WiFi.onSoftAPModeStationDisconnected(onDisonnectedAPmode);
160160
#endif
161161

162-
if (SpiffsSectors() < 32)
162+
if (FS_sectorCount() < 32)
163163
{
164164
serialPrintln(F("\nNo (or too small) SPIFFS area..\nSystem Halted\nPlease reflash with 128k SPIFFS minimum!"));
165165
while (true)
@@ -577,7 +577,7 @@ void loop()
577577
runPeriodicalMQTT();
578578
flushAndDisconnectAllClients();
579579

580-
SPIFFS.end();
580+
FILESYSTEMTYPE.end();
581581

582582
deepSleep(Settings.Delay);
583583
//deepsleep will never return, its a special kind of reboot

src/ESPEasyRTC.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct RTC_cache_handler_struct
289289
initRTCcache_data();
290290
for (int i=0; i < 2; ++i) {
291291
String fname = createCacheFilename(RTC_cache.readFileNr);
292-
if (SPIFFS.exists(fname)) {
292+
if (FILESYSTEMTYPE.exists(fname)) {
293293
if (i != 0) {
294294
// First attempt failed, so stored read position is not valid
295295
RTC_cache.readPos = 0;
@@ -318,7 +318,7 @@ struct RTC_cache_handler_struct
318318
fname = createCacheFilename(peekfilenr);
319319
}
320320
islast = peekfilenr > RTC_cache.writeFileNr;
321-
if (SPIFFS.exists(fname)) {
321+
if (FILESYSTEMTYPE.exists(fname)) {
322322
return fname;
323323
}
324324
return "";
@@ -331,7 +331,7 @@ struct RTC_cache_handler_struct
331331
String fname = createCacheFilename(RTC_cache.readFileNr);
332332
if (tryDeleteFile(fname)) {
333333
#ifdef RTC_STRUCT_DEBUG
334-
String log = F("RTC : Removed file from SPIFFS: ");
334+
String log = F("RTC : Removed file from FS: ");
335335
log += fname;
336336
addLog(LOG_LEVEL_INFO, String(log));
337337
#endif
@@ -461,9 +461,9 @@ private:
461461
// if (storageLocation != CACHE_STORAGE_SPIFFS) {
462462
// return false;
463463
// }
464-
if (SpiffsFull()) {
464+
if (FS_full()) {
465465
#ifdef RTC_STRUCT_DEBUG
466-
addLog(LOG_LEVEL_ERROR, String(F("RTC : SPIFFS full")));
466+
addLog(LOG_LEVEL_ERROR, String(F("RTC : FS full")));
467467
#endif
468468
return false;
469469
}
@@ -478,7 +478,7 @@ private:
478478
// Open file to write
479479
initRTCcache_data();
480480
if (updateRTC_filenameCounters()) {
481-
if (writeerror || SpiffsFreeSpace() < ((2 * CACHE_FILE_MAX_SIZE) + SpiffsBlocksize())) {
481+
if (writeerror || FS_freeSpace() < ((2 * CACHE_FILE_MAX_SIZE) + FS_blockSize())) {
482482
// Not enough room for another file, remove the oldest one.
483483
deleteOldestCacheBlock();
484484
}

src/ESPEasyRules.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void checkRuleSets() {
4040
#endif
4141
fileName += x + 1;
4242
fileName += F(".txt");
43-
if (SPIFFS.exists(fileName))
43+
if (FILESYSTEMTYPE.exists(fileName))
4444
activeRuleSets[x] = true;
4545
else
4646
activeRuleSets[x] = false;
@@ -88,7 +88,7 @@ void rulesProcessing(String &event) {
8888
} else {
8989
String fileName = EventToFileName(event);
9090
// if exists processed the rule file
91-
if (SPIFFS.exists(fileName))
91+
if (FILESYSTEMTYPE.exists(fileName))
9292
rulesProcessingFile(fileName, event);
9393
#ifndef BUILD_NO_DEBUG
9494
else
@@ -139,7 +139,7 @@ String rulesProcessingFile(const String &fileName, String &event) {
139139
}
140140

141141
fs::File f = tryOpenFile(fileName, "r+");
142-
SPIFFS_CHECK(f, fileName.c_str());
142+
FS_RES_CHECK(f, fileName.c_str());
143143

144144
String line = "";
145145
bool match = false;
@@ -157,7 +157,7 @@ String rulesProcessingFile(const String &fileName, String &event) {
157157
for (int x = 0; x < len; x++) {
158158
data = buf[x];
159159

160-
SPIFFS_CHECK(data >= 0, fileName.c_str());
160+
FS_RES_CHECK(data >= 0, fileName.c_str());
161161

162162
if (data != 10) {
163163
line += char(data);

0 commit comments

Comments
 (0)