From f92903d1f4f3628af61d570872b79ebfb0c06a1d Mon Sep 17 00:00:00 2001 From: Wessel Nieboer Date: Wed, 4 Mar 2026 22:09:20 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Update=20LittleFS=20v1.6=20=E2=86=92=20v1.7?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copied from littlefs-project/littlefs/v1.7.2 Co-Authored-By: liquidraver <504870+liquidraver@users.noreply.github.com> --- .../Adafruit_LittleFS/src/littlefs/lfs.c | 74 +++++++++---------- .../Adafruit_LittleFS/src/littlefs/lfs.h | 9 ++- .../Adafruit_LittleFS/src/littlefs/lfs_util.h | 13 +--- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/libraries/Adafruit_LittleFS/src/littlefs/lfs.c b/libraries/Adafruit_LittleFS/src/littlefs/lfs.c index daba21486..ed7f6876c 100644 --- a/libraries/Adafruit_LittleFS/src/littlefs/lfs.c +++ b/libraries/Adafruit_LittleFS/src/littlefs/lfs.c @@ -888,7 +888,7 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir, } // check that entry has not been moved - if (entry->d.type & 0x80) { + if (!lfs->moving && entry->d.type & 0x80) { int moved = lfs_moved(lfs, &entry->d.u); if (moved < 0 || moved) { return (moved < 0) ? moved : LFS_ERR_NOENT; @@ -1644,6 +1644,11 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, file->pos = file->size; } + if (file->pos + size > LFS_FILE_MAX) { + // larger than file limit? + return LFS_ERR_FBIG; + } + if (!(file->flags & LFS_F_WRITING) && file->pos > file->size) { // fill with zeros lfs_off_t pos = file->pos; @@ -1730,24 +1735,24 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, return err; } - // update pos + // find new pos + lfs_soff_t npos = file->pos; if (whence == LFS_SEEK_SET) { - file->pos = off; + npos = off; } else if (whence == LFS_SEEK_CUR) { - if (off < 0 && (lfs_off_t)-off > file->pos) { - return LFS_ERR_INVAL; - } - - file->pos = file->pos + off; + npos = file->pos + off; } else if (whence == LFS_SEEK_END) { - if (off < 0 && (lfs_off_t)-off > file->size) { - return LFS_ERR_INVAL; - } + npos = file->size + off; + } - file->pos = file->size + off; + if (npos < 0 || npos > LFS_FILE_MAX) { + // file position out of range + return LFS_ERR_INVAL; } - return file->pos; + // update pos + file->pos = npos; + return npos; } int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { @@ -1879,11 +1884,9 @@ int lfs_remove(lfs_t *lfs, const char *path) { err = lfs_dir_fetch(lfs, &dir, entry.d.u.dir); if (err) { return err; - } /* else if (dir.d.size != sizeof(dir.d)+4) { + } else if (dir.d.size != sizeof(dir.d)+4) { return LFS_ERR_NOTEMPTY; - } adafruit: allow to remove non-empty folder, - According to below issue, comment these 2 line won't corrupt filesystem - https://github.com/ARMmbed/littlefs/issues/43 */ + } } // remove the entry @@ -1924,7 +1927,14 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { // find old entry lfs_dir_t oldcwd; lfs_entry_t oldentry; - int err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath); + int err = lfs_dir_find(lfs, &oldcwd, &oldentry, &(const char *){oldpath}); + if (err) { + return err; + } + + // mark as moving + oldentry.d.type |= 0x80; + err = lfs_dir_update(lfs, &oldcwd, &oldentry, NULL); if (err) { return err; } @@ -1937,11 +1947,9 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { return err; } - bool prevexists = (err != LFS_ERR_NOENT); - bool samepair = (lfs_paircmp(oldcwd.pair, newcwd.pair) == 0); - // must have same type - if (prevexists && preventry.d.type != oldentry.d.type) { + bool prevexists = (err != LFS_ERR_NOENT); + if (prevexists && preventry.d.type != (0x7f & oldentry.d.type)) { return LFS_ERR_ISDIR; } @@ -1958,18 +1966,6 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { } } - // mark as moving - oldentry.d.type |= 0x80; - err = lfs_dir_update(lfs, &oldcwd, &oldentry, NULL); - if (err) { - return err; - } - - // update pair if newcwd == oldcwd - if (samepair) { - newcwd = oldcwd; - } - // move to new location lfs_entry_t newentry = preventry; newentry.d = oldentry.d; @@ -1988,10 +1984,13 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { } } - // update pair if newcwd == oldcwd - if (samepair) { - oldcwd = newcwd; + // fetch old pair again in case dir block changed + lfs->moving = true; + err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath); + if (err) { + return err; } + lfs->moving = false; // remove old entry err = lfs_dir_remove(lfs, &oldcwd, &oldentry); @@ -2089,6 +2088,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { lfs->files = NULL; lfs->dirs = NULL; lfs->deorphaned = false; + lfs->moving = false; return 0; diff --git a/libraries/Adafruit_LittleFS/src/littlefs/lfs.h b/libraries/Adafruit_LittleFS/src/littlefs/lfs.h index 7dd36046e..9c3174e7d 100644 --- a/libraries/Adafruit_LittleFS/src/littlefs/lfs.h +++ b/libraries/Adafruit_LittleFS/src/littlefs/lfs.h @@ -21,7 +21,7 @@ extern "C" // Software library version // Major (top-nibble), incremented on backwards incompatible changes // Minor (bottom-nibble), incremented on feature additions -#define LFS_VERSION 0x00010006 +#define LFS_VERSION 0x00010007 #define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16)) #define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0)) @@ -49,6 +49,11 @@ typedef uint32_t lfs_block_t; #define LFS_NAME_MAX 255 #endif +// Max file size in bytes +#ifndef LFS_FILE_MAX +#define LFS_FILE_MAX 2147483647 +#endif + // Possible error codes, these are negative to allow // valid positive return values enum lfs_error { @@ -61,6 +66,7 @@ enum lfs_error { LFS_ERR_ISDIR = -21, // Entry is a dir LFS_ERR_NOTEMPTY = -39, // Dir is not empty LFS_ERR_BADF = -9, // Bad file number + LFS_ERR_FBIG = -27, // File too large LFS_ERR_INVAL = -22, // Invalid parameter LFS_ERR_NOSPC = -28, // No space left on device LFS_ERR_NOMEM = -12, // No more memory available @@ -280,6 +286,7 @@ typedef struct lfs { lfs_free_t free; bool deorphaned; + bool moving; } lfs_t; diff --git a/libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h b/libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h index 14e265305..b2dc23714 100644 --- a/libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h +++ b/libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h @@ -30,13 +30,6 @@ #ifndef LFS_NO_ASSERT #include #endif - -#if !CFG_DEBUG -#define LFS_NO_DEBUG -#define LFS_NO_WARN -#define LFS_NO_ERROR -#endif - #if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR) #include #endif @@ -168,8 +161,7 @@ void lfs_crc(uint32_t *crc, const void *buffer, size_t size); // Allocate memory, only used if buffers are not provided to littlefs static inline void *lfs_malloc(size_t size) { #ifndef LFS_NO_MALLOC - extern void *pvPortMalloc( size_t xWantedSize ); - return pvPortMalloc(size); + return malloc(size); #else (void)size; return NULL; @@ -179,8 +171,7 @@ static inline void *lfs_malloc(size_t size) { // Deallocate memory, only used if buffers are not provided to littlefs static inline void lfs_free(void *p) { #ifndef LFS_NO_MALLOC - extern void vPortFree( void *pv ); - vPortFree(p); + free(p); #else (void)p; #endif From 14e2c335c2e0c25f634df94c3961da80f0ba217c Mon Sep 17 00:00:00 2001 From: Wessel Nieboer Date: Wed, 4 Mar 2026 22:09:53 +0100 Subject: [PATCH 2/4] fix moving not being set to false bug --- libraries/Adafruit_LittleFS/src/littlefs/lfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Adafruit_LittleFS/src/littlefs/lfs.c b/libraries/Adafruit_LittleFS/src/littlefs/lfs.c index ed7f6876c..c2c992c36 100644 --- a/libraries/Adafruit_LittleFS/src/littlefs/lfs.c +++ b/libraries/Adafruit_LittleFS/src/littlefs/lfs.c @@ -1987,10 +1987,10 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { // fetch old pair again in case dir block changed lfs->moving = true; err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath); + lfs->moving = false; if (err) { return err; } - lfs->moving = false; // remove old entry err = lfs_dir_remove(lfs, &oldcwd, &oldentry); From 6de1f0ddb35339038aceb295fe46d793bece7af1 Mon Sep 17 00:00:00 2001 From: Wessel Nieboer Date: Wed, 4 Mar 2026 22:13:05 +0100 Subject: [PATCH 3/4] fix bluefruit semaphore Co-Authored-By: taco Co-Authored-By: liquidraver <504870+liquidraver@users.noreply.github.com> --- libraries/Bluefruit52Lib/src/BLEConnection.cpp | 11 +++++++++++ libraries/Bluefruit52Lib/src/BLEConnection.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libraries/Bluefruit52Lib/src/BLEConnection.cpp b/libraries/Bluefruit52Lib/src/BLEConnection.cpp index 0f6a4d1e5..91ec7d08e 100644 --- a/libraries/Bluefruit52Lib/src/BLEConnection.cpp +++ b/libraries/Bluefruit52Lib/src/BLEConnection.cpp @@ -54,6 +54,7 @@ BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* e _peer_addr = evt_connected->peer_addr; _role = evt_connected->role; + _hvn_qsize = hvn_qsize; _hvn_sem = xSemaphoreCreateCounting(hvn_qsize, hvn_qsize); _wrcmd_sem = xSemaphoreCreateCounting(wrcmd_qsize, wrcmd_qsize); @@ -304,6 +305,16 @@ void BLEConnection::_eventHandler(ble_evt_t* evt) switch(evt->header.evt_id) { case BLE_GAP_EVT_DISCONNECTED: + // Restore notification semaphore to full count + // This fixes lockup when disconnect occurs with notifications in flight + while (uxSemaphoreGetCount(_hvn_sem) < _hvn_qsize) { + xSemaphoreGive(_hvn_sem); + } + // Release indication semaphore if waiting + if (_hvc_sem) { + _hvc_received = false; + xSemaphoreGive(_hvc_sem); + } // mark as disconnected _connected = false; break; diff --git a/libraries/Bluefruit52Lib/src/BLEConnection.h b/libraries/Bluefruit52Lib/src/BLEConnection.h index d69d52f5e..025687f3c 100644 --- a/libraries/Bluefruit52Lib/src/BLEConnection.h +++ b/libraries/Bluefruit52Lib/src/BLEConnection.h @@ -51,6 +51,7 @@ class BLEConnection uint16_t _sup_timeout; uint16_t _data_length; uint8_t _phy; + uint8_t _hvn_qsize; uint8_t _role; uint16_t _ediv; From 724e00a76e74132a8e30097e96ad4e27c4547b12 Mon Sep 17 00:00:00 2001 From: Wessel Nieboer Date: Wed, 4 Mar 2026 22:25:42 +0100 Subject: [PATCH 4/4] Add PlatformIO package manifest --- package.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 000000000..09c4048c9 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "framework-arduinoadafruitnrf52", + "version": "1.10700.1", + "description": "Arduino framework for Adafruit nRF52 boards (MeshCore fork with LittleFS v1.7.2 and Bluefruit fixes)" +}