adafruit / adafruit/Adafruit_nRF52_Arduino

Feature Request: Configurable InternalFS Size via LFS_Config.h

Open
#859 0 comments 0 reactions 0 assignees View on GitHub
Feature
Dominant language
C
Stars
698
Forks
572
PR merge metrics
No merged PRs in 30d

Description

### Is your feature request related to a problem? Please describe.

The current InternalFileSystem implementation hard-codes the filesystem size to 7 pages (28KB). For projects requiring more persistent storage, this fixed size may be insufficient. Currently, the only way to increase the filesystem size is to modify the library source directly, which breaks on library updates and complicates project distribution.

### Describe the solution you'd like

Allow users to configure the LittleFS size by:

1. Creating a LFS_Config.h file in their sketch folder with:
#define LFS_FLASH_PAGES 32 // 32 pages = 128KB
2. Or passing a compiler flag: -DLFS_FLASH_PAGES=32

The implementation uses __has_include() to conditionally include the user's config file, falling back to the default 7 pages if not present. The flash start address is computed dynamically so the filesystem always ends right before the bootloader, regardless of size.

### Describe alternatives you've considered

- Separate Filesystem: Wear Leveling is split and less effective

### Additional context

Patch summary:
// User creates LFS_Config.h in sketch folder:
#define LFS_FLASH_PAGES 32 // 32 pages = 128KB

// Library automatically includes it if present:
#if __has_include("LFS_Config.h")
#include "LFS_Config.h"
#endif

// Computes address so FS ends before bootloader:
#define LFS_FLASH_ADDR (0xF4000 - LFS_FLASH_TOTAL_SIZE)

---

### Patch:

```
--- nrf52_framework/1.1.12/libraries/InternalFileSytem/src/InternalFileSystem.cpp 2026-01-01 23:35:31.238828649 +0000
+++ InternalFileSystem_1.1.12/src/InternalFileSystem.cpp 2026-01-01 09:34:08.036726471 +0000
@@ -25,13 +25,31 @@
#include "InternalFileSystem.h"
#include "flash/flash_nrf5x.h"

+//--------------------------------------------------------------------+
+// CONFIGURABLE FILESYSTEM SIZE
+// Options to set LFS_FLASH_PAGES:
+// 1. Create "LFS_Config.h" in your sketch folder with:
+// #define LFS_FLASH_PAGES 64
+// 2. Or use compiler flag: -DLFS_FLASH_PAGES=64
+// Default: 7 pages (28KB), Max for nRF52840: 71 pages (284KB)
+//--------------------------------------------------------------------+
+#if __has_include("LFS_Config.h")
+#include "LFS_Config.h"
+#endif
+
+#ifndef LFS_FLASH_PAGES
+#define LFS_FLASH_PAGES 7 // Default: 7 pages = 28KB
+#endif
+
+#define LFS_FLASH_TOTAL_SIZE (LFS_FLASH_PAGES * FLASH_NRF52_PAGE_SIZE)
+
+// Compute start address so filesystem ends right before bootloader
#ifdef NRF52840_XXAA
-#define LFS_FLASH_ADDR 0xED000
+#define LFS_FLASH_ADDR (0xF4000 - LFS_FLASH_TOTAL_SIZE) // Bootloader at 0xF4000
#else
-#define LFS_FLASH_ADDR 0x6D000
+#define LFS_FLASH_ADDR (0x74000 - LFS_FLASH_TOTAL_SIZE) // Bootloader at 0x74000
#endif

-#define LFS_FLASH_TOTAL_SIZE (7*FLASH_NRF52_PAGE_SIZE)
#define LFS_BLOCK_SIZE 128

//--------------------------------------------------------------------+

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in nrf52_framework/1.1.12/libraries/InternalFileSytem/src/InternalFileSystem.cpp and inspect the existing filesystem-size constants and nRF52 flash layout. Verify how configuration from LFS_Config.h or compiler flags should affect supported builds, and confirm that the filesystem ends before the bootloader while retaining the default size when no configuration is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.