nrf52: fix LittleFS-in-loop() stack overflow via larger loop_task stack#41
Open
disq wants to merge 1 commit into
Open
nrf52: fix LittleFS-in-loop() stack overflow via larger loop_task stack#41disq wants to merge 1 commit into
disq wants to merge 1 commit into
Conversation
Pin the framework to disq/Adafruit_nRF52_Arduino@f019297 (= weebl2000 meshcore-patches 724e00a plus an #ifndef guard around LOOP_STACK_SZ; PR weebl2000/Adafruit_nRF52_Arduino#1) and set -D LOOP_STACK_SZ=2048 (words = 8KB) in [nrf52_base]. The framework default loop_task stack (256*4 = 1024 words = 4KB) is too small for LittleFS file opens from loop() (e.g. ClientACL::saveSessionKeys after the LittleFS v1.7.2 upgrade), which overflow it (~4.7KB peak) and corrupt the adjacent heap object, causing a hardfault. The unconditional #define previously made -DLOOP_STACK_SZ impossible to override; the guarded framework lets this flag take effect across every nRF52 build, including BLE companion. Repin to weebl2000/Adafruit_nRF52_Arduino once meshcore-dev#1 is merged and tagged. Validated: RAK_3401_repeater and Xiao_nrf52_companion_radio_ble build clean with no -Wmacro-redefined, confirming the 8KB override is honoured. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix nRF52 stack overflow on LittleFS file opens from
loop()Problem
nRF52 repeaters crash / go silent after admin or session activity (reproducible on
dev_pluswithMESH_PACKET_LOGGING+MESH_DEBUGon a RAK3401). It's a stack overflow on the framework's Arduinoloop_task:loop()onloop_taskwith a 4KB stack (LOOP_STACK_SZ = 256*4).the_mesh.loop()→ClientACL::saveSessionKeys→Adafruit_LittleFS::open()puts largelfs_dir/lfs_infostructs on the stack; measured peak ~4.7KB overruns the 4KB chunk and corrupts the heap object directly below it (observed: the RadioLibModule*), causing a hardfault/lockup.The LittleFS v1.6 → v1.7.2 upgrade is the trigger: it enlarged the file-open path's stack footprint enough to cross the 4KB limit. That's why this reproduces on
dev_plus(LittleFS 1.7.2) but not ondev(still 1.6).This root cause is general to every nRF52 build that touches the filesystem from
loop()— repeater, room server, and BLE/USB companion alike — not repeater-specific.Fix
Give
loop_taska bigger stack via a build flag, covering all nRF52 examples at once with no per-example code:-D LOOP_STACK_SZ=2048(2048 words = 8KB; measured peak ~4.7KB + headroom) in[nrf52_base].LOOP_STACK_SZwas an unconditional#define, so the flag alone was discarded (-Wmacro-redefined). This PR therefore pins the framework to a build with a one-line#ifndefguard that makes the value overridable: Make LOOP_STACK_SZ overridable from the build (#ifndef guard) Adafruit_nRF52_Arduino#1.Dependency / pin
Interim-pinned to
disq/Adafruit_nRF52_Arduino@f019297(= the currentmeshcore-patches724e00a+ the#ifndefguard). Once weebl2000/Adafruit_nRF52_Arduino#1 is merged and tagged, repin[nrf52_base]back toweebl2000/...at the new tag.Validation
Built against the pinned guarded framework —
RAK_3401_repeater(the exactMESH_PACKET_LOGGING+MESH_DEBUGcrash config) andXiao_nrf52_companion_radio_ble— both build cleanly with no-Wmacro-redefined, confirming the 8KB override is honored across nRF52 examples including BLE companion. With the default (no-D) the framework stack is unchanged at 4KB.On-hardware: flash a RAK3401/RAK4631 repeater and drive the previously-crashing workload (admin sync, neighbour discover, repeated LoRa status requests) for several minutes — expect no LoRa-silence / lockup. Optional gdb: walk the
0xa5a5a5a5canary fromloop_task'spxStack— expect the high-water mark well under 8KB.Supersedes
This replaces the per-example FreeRTOS worker-task approach (PR #40) with a single framework-level fix that covers all nRF52 builds.