diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini
index 6c6bd8738..f41ef0edc 100644
--- a/arch/nrf52/nrf52.ini
+++ b/arch/nrf52/nrf52.ini
@@ -9,6 +9,7 @@ build_flags =
-DSERIAL_BUFFER_SIZE=1024
-Wno-unused-variable
-Isrc/platform/nrf52
+ -DLFS_NO_ASSERT ; Disable LFS assertions , see https://github.com/meshtastic/firmware/pull/3818
build_src_filter =
${arduino_base.build_src_filter} - - - - - - - - - -
diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp
index d5ca72142..96aad1a9a 100644
--- a/src/FSCommon.cpp
+++ b/src/FSCommon.cpp
@@ -205,6 +205,62 @@ void rmDir(const char *dirname)
#endif
}
+bool fsCheck()
+{
+#if defined(ARCH_NRF52)
+ size_t write_size = 0;
+ size_t read_size = 0;
+ char buf[32] = {0};
+
+ Adafruit_LittleFS_Namespace::File file(FSCom);
+ const char *text = "meshtastic fs test";
+ size_t text_length = strlen(text);
+ const char *filename = "/meshtastic.txt";
+
+ LOG_DEBUG("Try create file .\n");
+ if (file.open(filename, FILE_O_WRITE)) {
+ write_size = file.write(text);
+ } else {
+ LOG_DEBUG("Open file failed .\n");
+ goto FORMAT_FS;
+ }
+
+ if (write_size != text_length) {
+ LOG_DEBUG("Text bytes do not match .\n");
+ file.close();
+ goto FORMAT_FS;
+ }
+
+ file.close();
+
+ if (!file.open(filename, FILE_O_READ)) {
+ LOG_DEBUG("Open file failed .\n");
+ goto FORMAT_FS;
+ }
+
+ read_size = file.readBytes(buf, text_length);
+ if (read_size != text_length) {
+ LOG_DEBUG("Text bytes do not match .\n");
+ file.close();
+ goto FORMAT_FS;
+ }
+
+ if (memcmp(buf, text, text_length) != 0) {
+ LOG_DEBUG("The written bytes do not match the read bytes .\n");
+ file.close();
+ goto FORMAT_FS;
+ }
+ return true;
+FORMAT_FS:
+ LOG_DEBUG("Format FS ....\n");
+ FSCom.format();
+ FSCom.begin();
+ return false;
+#else
+ return true;
+#endif
+}
+
void fsInit()
{
#ifdef FSCom
@@ -219,15 +275,29 @@ void fsInit()
* nRF52840 has a certain chance of automatic formatting failure.
* Try to create a file after initializing the file system. If the creation fails,
* it means that the file system is not working properly. Please format it manually again.
+ * To check the normality of the file system, you need to disable the LFS_NO_ASSERT assertion.
+ * Otherwise, the assertion will be entered at the moment of reading or opening, and the FS will not be formatted.
* */
- Adafruit_LittleFS_Namespace::File file(FSCom);
- const char *filename = "/meshtastic.txt";
- if (!file.open(filename, FILE_O_WRITE)) {
- LOG_DEBUG("Format ....");
- FSCom.format();
- FSCom.begin();
- } else {
- file.close();
+ bool ret = false;
+ uint8_t retry = 3;
+
+ while (retry--) {
+ ret = fsCheck();
+ if (ret) {
+ LOG_DEBUG("File system check is OK.\n");
+ break;
+ }
+ delay(10);
+ }
+
+ // It may not be possible to reach this step.
+ // Add a loop here to prevent unpredictable situations from happening.
+ // Can add a screen to display error status later.
+ if (!ret) {
+ while (1) {
+ LOG_ERROR("The file system is damaged and cannot proceed to the next step.\n");
+ delay(1000);
+ }
}
#else
LOG_DEBUG("Filesystem files:\n");
diff --git a/variants/t-echo/platformio.ini b/variants/t-echo/platformio.ini
index c036a39a2..5bd56598b 100644
--- a/variants/t-echo/platformio.ini
+++ b/variants/t-echo/platformio.ini
@@ -17,6 +17,7 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/t-echo
-DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates
; -DEINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated
-DEINK_BACKGROUND_USES_FAST ; (Optional) Use FAST refresh for both BACKGROUND and RESPONSIVE, until a limit is reached.
+
build_src_filter = ${nrf52_base.build_src_filter} +<../variants/t-echo>
lib_deps =
${nrf52840_base.lib_deps}