Fix UI freeze/reboots: LVGL pool to PSRAM, dangling SSID buttons, scan policy
Firmware / build (push) Successful in 4m24s
Firmware / build (push) Successful in 4m24s
- lv_conf: LVGL widget pool 48 KB internal -> 512 KB PSRAM (LV_MEM_POOL_ALLOC). It ran out after a few Settings visits (87% used, 31% frag, 4.5 KB biggest block; lv_mem_buf_get() failed in a label draw - decoded backtrace). Also frees 48 KB of internal RAM: free 16 -> 69 KB, largest block 7.6 -> 31.7 KB - lv_conf: LV_ASSERT_HANDLER abort() instead of while(1), which spun inside the task holding the LVGL lock and froze the UI + console - wifi_manager: SSID buttons clear their g_ssid_buttons[] slot on LV_EVENT_DELETE (SquareLine deletes the Settings screen on leave; stale pointers were lv_obj_del()'d on the next scan). Scan only while the list is on screen and not connected - 10 s background scans caused the display dots - main: `mem` console command (internal heap, PSRAM, LVGL pool) - docs: board page lessons, open-questions #13/#14, ota-updates, CLAUDE.md, log Verified: 10 Settings visits + 9 list rebuilds, pool peak 4%, 0 crashes; user confirms no freeze, no reboot, no dots, swipes better. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+29
-2
@@ -1,5 +1,6 @@
|
||||
#include <Arduino.h>
|
||||
#include <lvgl.h>
|
||||
#include <esp_heap_caps.h>
|
||||
#include "display/lvgl_v8_port.h" // LVGL port layer (for lvgl_port_lock/unlock)
|
||||
#include "modules/display_init.h" // Display initialization module
|
||||
#include "modules/wifi_manager.h" // WiFi manager module
|
||||
@@ -113,10 +114,36 @@ void onDebugToggle(lv_event_t *e)
|
||||
|
||||
} // extern "C"
|
||||
|
||||
// Console lines `cfg` doesn't recognise: diagnostic probe, OTA, Wi-Fi.
|
||||
// `mem`: internal heap, PSRAM, and LVGL's own pool (LV_MEM_SIZE, where every
|
||||
// widget lives). Takes the LVGL lock with a timeout so a hung UI is reported
|
||||
// rather than hanging the console too.
|
||||
static bool memCommand(const char* line) {
|
||||
if (strcmp(line, "mem") != 0) return false;
|
||||
SerialLock::lock();
|
||||
Serial.printf("[mem] internal free %u (largest block %u), PSRAM free %u\n",
|
||||
(unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||
(unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||
SerialLock::unlock();
|
||||
if (!lvgl_port_lock(500)) {
|
||||
Serial.println("[mem] LVGL lock busy > 500 ms - UI task stuck?");
|
||||
return true;
|
||||
}
|
||||
lv_mem_monitor_t m;
|
||||
lv_mem_monitor(&m);
|
||||
lvgl_port_unlock();
|
||||
SerialLock::lock();
|
||||
Serial.printf("[mem] LVGL pool: used %u of %u B (%u%%), frag %u%%, biggest free %u\n",
|
||||
(unsigned)(m.total_size - m.free_size), (unsigned)m.total_size,
|
||||
(unsigned)m.used_pct, (unsigned)m.frag_pct, (unsigned)m.free_biggest_size);
|
||||
SerialLock::unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Console lines `cfg` doesn't recognise: diagnostic probe, OTA, Wi-Fi, mem.
|
||||
static bool consoleExtraCommand(const char* line) {
|
||||
return DiagProbe::handleCommand(line) || Ota::handleCommand(line) ||
|
||||
WiFiManager::handleCommand(line);
|
||||
WiFiManager::handleCommand(line) || memCommand(line);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -217,6 +217,16 @@ static void updateWifiUIState(wifi_state_t state) {
|
||||
* @brief Update SSID list with dynamic buttons
|
||||
* @note This function MUST be called with lvgl_port_lock held
|
||||
*/
|
||||
// The SSID buttons live on the Settings screen, which SquareLine deletes every
|
||||
// time it is left. Each button clears its own slot when LVGL deletes it, so
|
||||
// g_ssid_buttons[] never holds a freed pointer. Before this, the next scan
|
||||
// called lv_obj_del() on already-freed buttons, corrupting LVGL's heap until an
|
||||
// LVGL assert froze the UI (found 2026-09-27).
|
||||
static void onSsidButtonDeleted(lv_event_t* e) {
|
||||
intptr_t i = (intptr_t)lv_event_get_user_data(e);
|
||||
if (i >= 0 && i < WIFI_SCAN_MAX_NETWORKS) g_ssid_buttons[i] = NULL;
|
||||
}
|
||||
|
||||
static void updateSSIDList() {
|
||||
// This function MUST be called with lvgl_port_lock held
|
||||
|
||||
@@ -259,6 +269,7 @@ static void updateSSIDList() {
|
||||
|
||||
// Add click event handler
|
||||
lv_obj_add_event_cb(btn, onSSIDButtonClick, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_add_event_cb(btn, onSsidButtonDeleted, LV_EVENT_DELETE, (void*)(intptr_t)i);
|
||||
|
||||
// Store button reference
|
||||
g_ssid_buttons[i] = btn;
|
||||
@@ -421,9 +432,15 @@ static void wifiTask(void* parameter) {
|
||||
if (g_wifi_state != WIFI_STATE_OFF) {
|
||||
unsigned long current_time = millis();
|
||||
|
||||
// Start scan if requested or periodic scan is due
|
||||
if (g_wifi_scan_requested ||
|
||||
(current_time - g_last_scan_time > WIFI_SCAN_INTERVAL_MS && !scanning)) {
|
||||
// Scan only while the network list is on screen and we're not
|
||||
// connected. Scanning hops the radio across channels (ESP-NOW to B
|
||||
// shares it) and churns Wi-Fi buffers in PSRAM, which the RGB panel
|
||||
// streams from; it used to run every 10 s forever, connected or not,
|
||||
// on any screen. A pending request waits until the list is visible.
|
||||
bool list_on_screen = (uic_Wifi_Container != NULL);
|
||||
bool connected = (WiFi.status() == WL_CONNECTED);
|
||||
if (!scanning && list_on_screen && !connected &&
|
||||
(g_wifi_scan_requested || current_time - g_last_scan_time > WIFI_SCAN_INTERVAL_MS)) {
|
||||
|
||||
Serial.println("Starting WiFi scan...");
|
||||
scanning = true;
|
||||
|
||||
Reference in New Issue
Block a user