From cde3298c54dc7a5f8c91269ce5ede99b9432ce5c Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:41:11 +0100 Subject: [PATCH] MM experimental - build flag to move ALL json into PSRAM -DALL_JSON_TO_PSRAM -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON on -S2, this *doubles* the PSRAM utilization! before: heap used 85%, PSRAM used 13kb / 21kb after: heap used 60%, PSRAM used 41kb / 65kb !! --- platformio.ini | 5 +++++ wled00/wled.cpp | 16 +++++++++++++++- wled00/wled.h | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 882be3c5..ad5fec29 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1591,6 +1591,7 @@ build_flags = ${esp32_4MB_V4_S_base.esp32_build_flags} -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup -D WLEDMM_FASTPATH ; WLEDMM experimental option. Reduces audio lag (latency), and allows for faster LED framerates. May break compatibility with previous versions. -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON ;; -D WLED_USE_PSRAM ;; WLED_USE_PSRAM causes major slow-down (slow LEDs) on some ESP32 boards + ;; -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap. -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes -D WLED_DISABLE_HUESYNC ; RAM 122 bytes; FLASH 6308 bytes -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes @@ -1625,6 +1626,7 @@ build_flags = ${esp32_4MB_V4_S_base.esp32_build_flags} ;;${Speed_Flags.build_flags} ;; optimize for speed instead of size --> over 100% flash, but works with 256KB filesystem (alternative partitions file) -D WLEDMM_FASTPATH ; WLEDMM experimental option. Reduces audio lag (latency), and allows for faster LED framerates. May break compatibility with previous versions. -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON ;; -D WLED_USE_PSRAM ;; WLED_USE_PSRAM causes major slow-down (slow LEDs) on some ESP32 boards + ;; -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap. ;;-D CONFIG_ESP32_REV_MIN=3 ;; disables PSRAM bug workarounds in the core, reducing the code size and improving overall performance. -D WLED_RELEASE_NAME=esp32_4MB_PSRAM_REV3_S -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET @@ -1826,12 +1828,14 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags} -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 ${common_mm.build_flags_S} -Wno-misleading-indentation -Wno-format-truncation + -DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM -D WLED_RELEASE_NAME=esp32S2_4MB_UF2_S -DARDUINO_USB_CDC_ON_BOOT=1 ;; mandatory, otherwise USB does not work!! -D WLED_DISABLE_ADALIGHT ;; disables serial protocols when using CDC USB (Serial RX will receive junk commands, unless its pulled down by resistor) -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 -D SERVERNAME='"WLED-S2"' -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON ;; -D WLED_USE_PSRAM + -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap. -D WLED_DISABLE_LOXONE ;; FLASH 1272 bytes -D WLED_DISABLE_HUESYNC ;; RAM 122 bytes; FLASH 6308 bytes -D WLED_DISABLE_ALEXA ;; RAM 116 bytes; FLASH 13524 bytes @@ -1882,6 +1886,7 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags} -Wno-misleading-indentation -Wno-format-truncation -D WLED_RELEASE_NAME=esp32s2_4MB_M -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON ;; -D WLED_USE_PSRAM + ;; -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap. -DLOLIN_WIFI_FIX -DWLEDMM_WIFI_POWERON_HACK ;; seems to work much better with this -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 -D WLED_DISABLE_ADALIGHT ;; disables serial protocols, as the board only has CDC USB diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 0e9afc5e..f4bf0c4a 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -382,6 +382,19 @@ void WLED::loop() ESP.wdtFeed(); #endif #endif + +#if 0 +// MM experiment - JSON garbagecollect once per minute. Warning: may crash at random + static unsigned long last_gc_time = 0; + if ((millis() - last_gc_time) > 60000) { // once in 60 seconds + if (!suspendStripService && !doInitBusses && !loadLedmap && !presetsActionPending()) { // make sure no strip or segments are being updated atm + if ((jsonBufferLock == 0) && (fileDoc == nullptr)) { // make sure JSON buffer is availeable + USER_PRINTLN(F("JSON gabage collection (regular).")); + doc.garbageCollect(); // WLEDMM experimental - trigger garbage collection on JSON doc memory pool. + last_gc_time = millis(); + } } } +#endif + } #if defined(ARDUINO_ARCH_ESP32) && defined(WLEDMM_FASTPATH) @@ -606,7 +619,8 @@ pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), Pin if(dmxEnablePin > 0) pinManager.allocatePin(dmxEnablePin, true, PinOwner::DMX); #endif -#if 0 && defined(WLED_USE_PSRAM_JSON) +#if defined(ALL_JSON_TO_PSRAM) && defined(WLED_USE_PSRAM_JSON) + USER_PRINTLN(F("JSON gabage collection (initial).")); doc.garbageCollect(); // WLEDMM experimental - this seems to move the complete doc[] into PSRAM #endif diff --git a/wled00/wled.h b/wled00/wled.h index 78a29989..8bce0ceb 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -788,13 +788,13 @@ WLED_GLOBAL int8_t spi_sclk _INIT(HW_PIN_CLOCKSPI); #endif // global ArduinoJson buffer -#if 0 && defined(WLED_USE_PSRAM_JSON) +#if defined(ALL_JSON_TO_PSRAM) && defined(WLED_USE_PSRAM_JSON) // WLEDMM experimental : always use dynamic JSON - #warning experimental - trying to always use dynamic JSON #ifndef WLED_DEFINE_GLOBAL_VARS WLED_GLOBAL PSRAMDynamicJsonDocument doc; #else WLED_GLOBAL PSRAMDynamicJsonDocument doc(JSON_BUFFER_SIZE); + #warning experimental - trying to always use dynamic JSON #endif #else WLED_GLOBAL StaticJsonDocument doc;