Fix Task WDT crashes: LVGL priority starvation + BLE WDT false positives

Two root causes for frequent device reboots:

1. LVGL task (priority 2) starved loopTask (priority 1) on core 1.
   During heavy screen rendering, loopTask couldn't run for 30+ seconds,
   triggering the Task WDT. Fixed by lowering LVGL to priority 1 so
   FreeRTOS round-robins both tasks fairly.

2. BLE task was registered with the 30s Task WDT, but blocking NimBLE
   GATT operations (connect + service discovery + subscribe + read) can
   legitimately take 30-60s total. Removed BLE task from WDT since
   NimBLE has its own internal ~30s timeouts per GATT operation.

Also added ble_hs_synced() guards to write(), read(), notify(),
writeCharacteristic(), discoverServices(), and enableNotifications()
to prevent use-after-free on stale NimBLE client pointers during
host resets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
torlando-tech
2026-03-04 14:11:51 -05:00
co-authored by Claude Opus 4.6
parent d9411fb4bb
commit c80e63dee9
3 changed files with 50 additions and 17 deletions
+4 -3
View File
@@ -655,9 +655,10 @@ void setup_lvgl_and_ui() {
INFO("LVGL initialized");
// Start LVGL on its own FreeRTOS task for responsive UI
// Core 1, priority 2 (higher than default to ensure smooth rendering)
// All LVGL API calls from other code are protected by mutex (LVGL_LOCK)
if (!UI::LVGL::LVGLInit::start_task(2, 1)) {
// Core 1, priority 1 (same as loopTask — round-robin scheduling).
// Previously priority 2, but this starved loopTask of CPU time during
// heavy rendering, causing 30s WDT timeouts on loopTask.
if (!UI::LVGL::LVGLInit::start_task(1, 1)) {
ERROR("Failed to start LVGL task!");
while (1) delay(1000);
}