Skip to content

Commit cde3298

Browse files
committed
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 !!
1 parent ca9644f commit cde3298

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

platformio.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ build_flags = ${esp32_4MB_V4_S_base.esp32_build_flags}
15911591
-D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup
15921592
-D WLEDMM_FASTPATH ; WLEDMM experimental option. Reduces audio lag (latency), and allows for faster LED framerates. May break compatibility with previous versions.
15931593
-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
1594+
;; -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap.
15941595
-D WLED_DISABLE_LOXONE ; FLASH 1272 bytes
15951596
-D WLED_DISABLE_HUESYNC ; RAM 122 bytes; FLASH 6308 bytes
15961597
-D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes
@@ -1625,6 +1626,7 @@ build_flags = ${esp32_4MB_V4_S_base.esp32_build_flags}
16251626
;;${Speed_Flags.build_flags} ;; optimize for speed instead of size --> over 100% flash, but works with 256KB filesystem (alternative partitions file)
16261627
-D WLEDMM_FASTPATH ; WLEDMM experimental option. Reduces audio lag (latency), and allows for faster LED framerates. May break compatibility with previous versions.
16271628
-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
1629+
;; -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap.
16281630
;;-D CONFIG_ESP32_REV_MIN=3 ;; disables PSRAM bug workarounds in the core, reducing the code size and improving overall performance.
16291631
-D WLED_RELEASE_NAME=esp32_4MB_PSRAM_REV3_S
16301632
-D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET
@@ -1826,12 +1828,14 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags}
18261828
-D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0
18271829
${common_mm.build_flags_S}
18281830
-Wno-misleading-indentation -Wno-format-truncation
1831+
-DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM
18291832
-D WLED_RELEASE_NAME=esp32S2_4MB_UF2_S
18301833
-DARDUINO_USB_CDC_ON_BOOT=1 ;; mandatory, otherwise USB does not work!!
18311834
-D WLED_DISABLE_ADALIGHT ;; disables serial protocols when using CDC USB (Serial RX will receive junk commands, unless its pulled down by resistor)
18321835
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0
18331836
-D SERVERNAME='"WLED-S2"'
18341837
-DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON ;; -D WLED_USE_PSRAM
1838+
-DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap.
18351839
-D WLED_DISABLE_LOXONE ;; FLASH 1272 bytes
18361840
-D WLED_DISABLE_HUESYNC ;; RAM 122 bytes; FLASH 6308 bytes
18371841
-D WLED_DISABLE_ALEXA ;; RAM 116 bytes; FLASH 13524 bytes
@@ -1882,6 +1886,7 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags}
18821886
-Wno-misleading-indentation -Wno-format-truncation
18831887
-D WLED_RELEASE_NAME=esp32s2_4MB_M
18841888
-DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON ;; -D WLED_USE_PSRAM
1889+
;; -DALL_JSON_TO_PSRAM ;; WLEDMM experimental --> try to force all JSON stuff into PSRAM; gives more free heap.
18851890
-DLOLIN_WIFI_FIX -DWLEDMM_WIFI_POWERON_HACK ;; seems to work much better with this
18861891
-DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1
18871892
-D WLED_DISABLE_ADALIGHT ;; disables serial protocols, as the board only has CDC USB

wled00/wled.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,19 @@ void WLED::loop()
382382
ESP.wdtFeed();
383383
#endif
384384
#endif
385+
386+
#if 0
387+
// MM experiment - JSON garbagecollect once per minute. Warning: may crash at random
388+
static unsigned long last_gc_time = 0;
389+
if ((millis() - last_gc_time) > 60000) { // once in 60 seconds
390+
if (!suspendStripService && !doInitBusses && !loadLedmap && !presetsActionPending()) { // make sure no strip or segments are being updated atm
391+
if ((jsonBufferLock == 0) && (fileDoc == nullptr)) { // make sure JSON buffer is availeable
392+
USER_PRINTLN(F("JSON gabage collection (regular)."));
393+
doc.garbageCollect(); // WLEDMM experimental - trigger garbage collection on JSON doc memory pool.
394+
last_gc_time = millis();
395+
} } }
396+
#endif
397+
385398
}
386399

387400
#if defined(ARDUINO_ARCH_ESP32) && defined(WLEDMM_FASTPATH)
@@ -606,7 +619,8 @@ pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), Pin
606619
if(dmxEnablePin > 0) pinManager.allocatePin(dmxEnablePin, true, PinOwner::DMX);
607620
#endif
608621

609-
#if 0 && defined(WLED_USE_PSRAM_JSON)
622+
#if defined(ALL_JSON_TO_PSRAM) && defined(WLED_USE_PSRAM_JSON)
623+
USER_PRINTLN(F("JSON gabage collection (initial)."));
610624
doc.garbageCollect(); // WLEDMM experimental - this seems to move the complete doc[] into PSRAM
611625
#endif
612626

wled00/wled.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,13 @@ WLED_GLOBAL int8_t spi_sclk _INIT(HW_PIN_CLOCKSPI);
788788
#endif
789789

790790
// global ArduinoJson buffer
791-
#if 0 && defined(WLED_USE_PSRAM_JSON)
791+
#if defined(ALL_JSON_TO_PSRAM) && defined(WLED_USE_PSRAM_JSON)
792792
// WLEDMM experimental : always use dynamic JSON
793-
#warning experimental - trying to always use dynamic JSON
794793
#ifndef WLED_DEFINE_GLOBAL_VARS
795794
WLED_GLOBAL PSRAMDynamicJsonDocument doc;
796795
#else
797796
WLED_GLOBAL PSRAMDynamicJsonDocument doc(JSON_BUFFER_SIZE);
797+
#warning experimental - trying to always use dynamic JSON
798798
#endif
799799
#else
800800
WLED_GLOBAL StaticJsonDocument<JSON_BUFFER_SIZE> doc;

0 commit comments

Comments
 (0)