From a1555c43a09bc10a1c6528c1de07bab62f8be729 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:26:03 +0100 Subject: [PATCH] move ws LEDs preview buffer into PSRAM * set DYNAMICBUFFER_USE_PSRAM in build_flags => enable PSRAM support in AsyncWebServerWLED --- platformio.ini | 4 ++++ wled00/ws.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/platformio.ini b/platformio.ini index bc2b06f8..8c19addb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -450,6 +450,7 @@ build_flagsV4 = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=9472 ;; WLEDMM increase stack by 1.25Kb, as audioreactive needs bigger SETTINGS_STACK_BUF_SIZE -D CONFIG_ASYNC_TCP_STACK_SIZE=9472 ;; *sigh* newer asyncTCP uses this instead of .._TASK_.. + ;; -D DYNAMICBUFFER_USE_PSRAM ;; experimental: tell asyncWebServer to prefer PSRAM for buffers (works with non-PSRAM boards, too) ; -D WLEDMM_TWOPATH ;; use I2S1 as the second bus --> slightly faster on some setups ; -D WLEDMM_SLOWPATH ;; don't use I2S for LED bus ; -DARDUINO_USB_CDC_ON_BOOT=0 ;; mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3 @@ -486,6 +487,7 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=9472 ;; WLEDMM increase stack by 1.25Kb, as audioreactive needs bigger SETTINGS_STACK_BUF_SIZE -D CONFIG_ASYNC_TCP_STACK_SIZE=9472 ;; *sigh* newer asyncTCP uses this instead of .._TASK_.. + -D DYNAMICBUFFER_USE_PSRAM ;; experimental: tell asyncWebServer to prefer PSRAM for buffers (works with non-PSRAM boards, too) -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3 ; -D WLEDMM_TWOPATH ;; use I2S1 as the second bus --> slightly faster on some setups ; -D WLEDMM_SLOWPATH ;; don't use I2S for LED bus @@ -521,6 +523,7 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=8614 ;; WLEDMM increase stack by 1Kb, as audioreactive needs bigger SETTINGS_STACK_BUF_SIZE -D CONFIG_ASYNC_TCP_STACK_SIZE=8614 ;; *sigh* newer asyncTCP uses this instead of .._TASK_.. + -D DYNAMICBUFFER_USE_PSRAM ;; experimental: tell asyncWebServer to prefer PSRAM for buffers (works with non-PSRAM boards, too) -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 -DCO -DARDUINO_USB_MODE=0 ;; this flag is mandatory for ESP32-S2 ! @@ -580,6 +583,7 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=9472 ;; WLEDMM increase stack by 1.25Kb, as audioreactive needs bigger SETTINGS_STACK_BUF_SIZE -D CONFIG_ASYNC_TCP_STACK_SIZE=9472 ;; *sigh* newer asyncTCP uses this instead of .._TASK_.. + -D DYNAMICBUFFER_USE_PSRAM ;; experimental: tell asyncWebServer to prefer PSRAM for wsBuffer (works with non-PSRAM boards, too) -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_DFU_ON_BOOT=0 -DCO ;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry: diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 246d09bc..e92ffa69 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -5,6 +5,10 @@ */ #ifdef WLED_ENABLE_WEBSOCKETS +#ifdef DYNAMICBUFFER_USE_PSRAM +#warning "DYNAMICBUFFER_USE_PSRAM is experimental" +#endif + static volatile uint16_t wsLiveClientId = 0; // WLEDMM added "static" static volatile unsigned long wsLastLiveTime = 0; // WLEDMM //uint8_t* wsFrameBuffer = nullptr; @@ -222,7 +226,11 @@ static bool sendLiveLedsWs(uint32_t wsClient) // WLEDMM added "static" #ifdef ESP8266 constexpr size_t MAX_LIVE_LEDS_WS = 256U; #else + #if !defined(BOARD_HAS_PSRAM) || !defined(DYNAMICBUFFER_USE_PSRAM) constexpr size_t MAX_LIVE_LEDS_WS = 4096U; //WLEDMM use 4096 as max matrix size + #else + constexpr size_t MAX_LIVE_LEDS_WS = 4096 * 2; //WLEDMM better preview on PSRAM boards + #endif #endif size_t used;// = strip.getLengthTotal(); size_t n;// = ((used -1)/MAX_LIVE_LEDS_WS) +1; //only serve every n'th LED if count over MAX_LIVE_LEDS_WS