Files
meshtastic_firmware/variants/nrf52840/nrf52.ini
T
Ben MeadorsandGitHub b4b1ece8f1 nrf52: fix loop-task stack overflow causing reset on BLE pairing/first-sync (#10944)
The Arduino loop task runs Meshtastic's entire cooperative OSThread
scheduler on the Adafruit core's stock 4 KB (1024-word) stack. The 2.8
first-sync path - AdminModule::handleSetConfig -> saveChanges ->
configChanged -> RadioInterface::reloadConfig -> LR11x0 reconfigure ->
SPI Lock::lock, with vsnprintf/USB-CDC logging frames stacked on top -
overflows it.

SWD fault capture on a T1000-E (pyocd vector_catch=h) proved it: the
loop task's SP was driven 40 bytes BELOW its own pxStack base, the
stack paint was consumed to the floor, and the crash was a BusFault in
xQueueSemaphoreTake dereferencing a semaphore handle that adjacent-heap
corruption had overwritten with log text (0x3f3f207c = "| ??"). The
core's HardFault handler is a bare NVIC_SystemReset, so in the field
this presents as a silent reboot ~seconds after a phone pairs (or a 30 s
zombie hang -> supervision timeout 0x8 when the corruption lands on task
TCBs instead). Also explains the set_time_only -> immediate-NodeInfo
crash variant reported on empty-DB nodes: same task, different deep
chain. 2.7.26 is unaffected because the deep frames (XEdDSA, satellite
map conversion, replay engine) did not exist.

Fix: set -DLOOP_STACK_SZ=2048 (words = 8 KB) for all nrf52840 targets.
Requires the #ifndef guard from meshtastic/Adafruit_nRF52_Arduino#7;
until that merges the flag is a harmless redefinition warning. Validated
on hardware: pairing + full sync completes, stack paint shows healthy
margin under load.

Also fix the boot-time reset-reason log: the core's init() caches
RESETREAS and W1C-clears the register before setup() runs, so the raw
read here has always printed 0. Use readResetReason() instead.
(preFSBegin's RESETREAS==0 gate is intentionally left as-is - its
degenerate GPREGRET-only behavior is what makes lfs recovery work.)
2026-07-08 17:11:32 -05:00

67 lines
3.0 KiB
INI

[nrf52_base]
; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files
platform =
# renovate: datasource=custom.pio depName=platformio/nordicnrf52 packageName=platformio/platform/nordicnrf52
platformio/nordicnrf52@10.12.0
extends = arduino_base
platform_packages =
; our custom Git version with C++17 support in platform.txt
# renovate: datasource=git-refs depName=meshtastic/Adafruit_nRF52_Arduino packageName=meshtastic/Adafruit_nRF52_Arduino gitBranch=master
platformio/framework-arduinoadafruitnrf52 @ https://github.com/meshtastic/Adafruit_nRF52_Arduino#0fd295f13203e93df19d578073646ec32f2bf45a
; Don't renovate toolchain-gccarmnoneeabi
platformio/toolchain-gccarmnoneeabi@~1.90301.0
extra_scripts =
${env.extra_scripts}
extra_scripts/nrf52_extra.py
pre:extra_scripts/nrf52_lto.py
extra_scripts/nrf52_warm_region.py ; post-link guard: image must end below the 12 KB warm-store raw-flash region at 0xEA000-0xED000
build_type = release
build_flags =
-include variants/nrf52840/cpp_overrides/lfs_util.h
${arduino_base.build_flags}
-Wno-unused-variable
-Isrc/platform/nrf52
; The Arduino loop task runs the entire cooperative OSThread scheduler; the core's stock
; 4 KB (1024-word) stack overflows during BLE first-sync (admin config-apply -> radio
; reconfigure with XEdDSA/satmap/log frames stacked) - SWD-proven on T1000-E: SP driven
; 40 B below pxStack, corrupting adjacent heap -> silent HardFault reset on phone pairing.
; 2048 words = 8 KB, validated on hardware. Value is in WORDS; requires the #ifndef guard
; from meshtastic/Adafruit_nRF52_Arduino#7 (harmless redefinition warning until it merges).
-DLOOP_STACK_SZ=2048
-DLFS_NO_ASSERT ; Disable LFS assertions , see https://github.com/meshtastic/firmware/pull/3818
-DMESHTASTIC_EXCLUDE_AUDIO=1
-DMESHTASTIC_EXCLUDE_PAXCOUNTER=1
-DMESHTASTIC_EXCLUDE_PKT_HISTORY_HASH=1 ; drop PacketHistory's 1 KB hash index; O(n) over ~240 records is negligible at LoRa packet rates
-DOLEDDISPLAY_REDUCE_MEMORY ; drop the ThingPulse OLED back buffer (~1 KB); TFT variants must -U this (TFTDisplay.cpp needs buffer_back)
-Os
-std=gnu++17
-flto ; whole-image LTO (~-60KB) on every nrf52840 target; nrf52_lto.py (pre: extra_script) keeps the interrupt handlers out of LTO so they survive
-fmerge-all-constants ; fold identical constants image-wide (~0.7KB; same flag stm32 uses)
build_unflags =
-Ofast
-Og
-ggdb3
-ggdb2
-g3
-g2
-g
-g1
-g0
-std=c++11
-std=gnu++11
build_src_filter =
${arduino_base.build_src_filter} +<platform/nrf52/> -<nimble/> -<mesh/wifi/> -<mesh/api/> -<mesh/http/> -<modules/esp32> -<mesh/eth/> -<mesh/raspihttp> -<serialization/>
lib_deps=
${arduino_base.lib_deps}
${radiolib_base.lib_deps}
# renovate: datasource=github-tags depName=meshtastic/Crypto packageName=meshtastic/Crypto
https://github.com/meshtastic/Crypto/archive/591ff9a690e8168ccb7a36abde8d7783e448d395.zip
lib_ignore =
BluetoothOTA
lvgl