From 62f5834b4736ebd9d98722027787faa399c3354c Mon Sep 17 00:00:00 2001 From: disq <223029+disq@users.noreply.github.com> Date: Sun, 31 May 2026 11:00:17 +0100 Subject: [PATCH] nrf52: enlarge loop_task stack to 8KB to fix LittleFS-in-loop() overflow 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 #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 --- platformio.ini | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9793c32d25..105186e9c2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -82,13 +82,19 @@ extends = arduino_base platform = nordicnrf52 platform_packages = ; fork that includes patch to ble stack to prevent firmware lockup during rapid connect/disconnect (PRs #1177, #1295) - ; plus LittleFS v1.7.2 upgrade - framework-arduinoadafruitnrf52 @ https://github.com/weebl2000/Adafruit_nRF52_Arduino.git#724e00a76e74132a8e30097e96ad4e27c4547b12 ; 1.10700.1 + ; plus LittleFS v1.7.2 upgrade, plus #ifndef guard so LOOP_STACK_SZ (below) is overridable + ; (PR weebl2000/Adafruit_nRF52_Arduino#1 -- repin to weebl2000 once merged & tagged) + framework-arduinoadafruitnrf52 @ https://github.com/disq/Adafruit_nRF52_Arduino.git#f019297fa2c09a3484b482b144e7b187f4226044 extra_scripts = create-uf2.py build_flags = ${arduino_base.build_flags} -D NRF52_PLATFORM -D LFS_NO_ASSERT=1 -D EXTRAFS=1 + ; Enlarge the Arduino loop_task stack (framework default 4KB / 1024 words is too + ; small for LittleFS file opens from loop(), which overflow it and corrupt adjacent + ; heap). 2048 words = 8KB. Requires the framework's LOOP_STACK_SZ #define to be + ; #ifndef-guarded (Adafruit_nRF52_Arduino) so this override is honoured. + -D LOOP_STACK_SZ=2048 lib_deps = ${arduino_base.lib_deps} https://github.com/oltaco/CustomLFS#0.2.2