From 36eb52059293e82eb30923d838fae44d19407ea9 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:39:12 +0100 Subject: [PATCH] reduce RAM needs for -S2, user message on heap emergency actions --- wled00/const.h | 2 +- wled00/wled.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/wled00/const.h b/wled00/const.h index a89e2298..bb8c7a98 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -448,7 +448,7 @@ #if defined(ARDUINO_ARCH_ESP32C3) #define JSON_BUFFER_SIZE 44000 // WLEDMM - max 44KB on -C3 with PSRAM (chip has 400kb RAM) #else - #define JSON_BUFFER_SIZE 32000 // WLEDMM - max 32KB on -S2 with PSRAM (chip has 320kb RAM) + #define JSON_BUFFER_SIZE 28000 // WLEDMM - max 28KB on -S2 with PSRAM (chip has 320kb RAM) #endif #else #define JSON_BUFFER_SIZE 54000 // WLEDMM (was 60000) slightly reduced to avoid build error "region dram0_0_seg overflowed" diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 4c2f6c87..0e9afc5e 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1180,16 +1180,19 @@ void WLED::handleConnection() #ifdef ARDUINO_ARCH_ESP32 // reconnect WiFi to clear stale allocations if heap gets too low if (now - heapTime > 5000) { // WLEDMM: updated with better logic for small heap available by block, not total. - // uint32_t heap = ESP.getFreeHeap(); +#if defined(ARDUINO_ARCH_ESP32S2) + uint32_t heap = ESP.getFreeHeap(); // WLEDMM works better on -S2 +#else uint32_t heap = heap_caps_get_largest_free_block(0x1800); // WLEDMM: This is a better metric for free heap. +#endif if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) { - DEBUG_PRINT(F("Heap too low! (step 2, force reconnect): ")); - DEBUG_PRINTLN(heap); + USER_PRINT(F("Heap too low! (step 2, force reconnect): ")); + USER_PRINTLN(heap); forceReconnect = true; strip.purgeSegments(true); // remove all but one segments from memory } else if (heap < MIN_HEAP_SIZE) { - DEBUG_PRINT(F("Heap too low! (step 1, flush unread UDP): ")); - DEBUG_PRINTLN(heap); + USER_PRINT(F("Heap too low! (step 1, flush unread UDP): ")); + USER_PRINTLN(heap); strip.purgeSegments(); notifierUdp.flush(); rgbUdp.flush();