Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions firmware/esp32-d0.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ board_build.partitions = boards/ESP32_4MB_NO_OTA.csv
; board_build.partitions = min_spiffs.csv
build_flags = ${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32=1
-D HTTPD_STACK_SIZE=6144 ; a bit more as there are no app tasks atm
-D LOLIN_WIFI_FIX ; some boards have wifi issues if this is not defined, this sets WIFI_POWER_8_5dBm
; -D LED_BUILTIN=2
; -D KEY_BUILTIN=0
Expand All @@ -103,6 +104,7 @@ board_build.partitions = boards/ESP32_4MB_NO_OTA.csv
; board_build.partitions = min_spiffs.csv
build_flags = ${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32=1
-D HTTPD_STACK_SIZE=6144 ; a bit more as there are no app tasks atm
-D LOLIN_WIFI_FIX ; some boards have wifi issues if this is not defined, this sets WIFI_POWER_8_5dBm
-D ARDUINO_USB_CDC_ON_BOOT=0 ; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (needed on "classic ESP32")
-DBOARD_HAS_PSRAM
Expand Down
116 changes: 0 additions & 116 deletions firmware/esp32-p4.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,119 +86,3 @@ lib_deps = ${esp32-p4-base.lib_deps}
; E (3783) H_SDIO_DRV: sdio card init failed

; FreeRTOS: FreeRTOS Task "sdio_read" should not return, Aborting now!


; [env:esp32-p4-8MB_troyhacks_personal]
; ;; THIS IS PIOARDUINO NOW, NOT PLATFORMIO!
; ; build_src_filter = +<**/*.c>
; ; +<**/*.cpp>
; ; +<**/*.S>
; ; -<**/dmx*>
; ; -<**/async-mqtt-client/**>
; ; -<**/methods/Esp32_i2s*>
; ; -<**/espalexa/**>
; ; -<**/DS1307RTC*>
; ; -<**/dependencies/dmx>
; ; platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.30-2/platform-espressif32.zip ;; https://github.com/troyhacks/platform-espressif32#Arduino/IDF5
; ; platform_packages = framework-arduinoespressif32 @ https://github.com/troyhacks/arduino-esp32#feature/esp32p4
; ; framework-arduinoespressif32-libs @ https://github.com/troyhacks/esp32-arduino-libs#main
; ; toolchain-riscv32-esp @ https://github.com/espressif/crosstool-NG/releases/download/esp-14.2.0_20241119/riscv32-esp-elf-14.2.0_20241119-x86_64-w64-mingw32.zip
; board_build.arduino.upstream_packages = no
; board = esp32-p4-evboard
; board_build.mcu = esp32p4
; board_build.f_cpu = 360000000L
; board_build.f_flash = 80000000L
; ; board_build.arduino.memory_type = qio_opi
; build_unflags = -O2
; build_flags = ${esp32-p4-base.build_flags}
; -Ofast
; -ffast-math
; -mstrict-align
; -fipa-pta
; -freorder-blocks
; -fno-jump-tables
; -fno-tree-switch-conversion
; -Wwrite-strings
; -fstrict-volatile-bitfields
; -D WLEDMM_FASTPATH
; -D WLEDMM_REMAP_AT_OUTPUT
; -D PARLIO
; ; -D WLED_DISABLE_LOGGING
; ; -D PARLIO_TIMER
; ; -D PARLIO_AUTO_OVERCLOCK
; -D WLED_DANGEROUS_OPTIMIZATIONS
; -D ARDUINO_EVENT_RUNNING_CORE=0
; -D CONFIG_ASYNC_TCP_RUNNING_CORE=0
; ; If you don't set PARLIO_PINS it's OK, it just sets all pins to disabled. Still "outputs" tho.
; -D PARLIO_PINS=2,3,4,5,6,20,21,22,23,26,27,32,33,36,47,48 ;; GPIOs beyond 36 require some special ESP32-P4 LDO code or 47,48 don't work- added to WLED::setup()!
; -D IMAGECACHE_BG_PRIORITY=1 ;; 1 is the lowst real priority, least run. 5 slows other things down.
; -D CORE_DEBUG_LEVEL=0 ;; ESP_LOG_VERBOSE ;; ESP_LOG_VERBOSE == 5
; -D WLED_USE_ETHERNET ;; Coexistence is slower but both work now. Ethernet is preferred automatically.
; -D WLED_USE_ETHERNET_ONLY ;; Disable WiFi for performance reasons - on the P4 it needs high priority background tasks to talk to the C6
; ; -D WLED_DEBUG
; -D NDEBUG ;; comment this out if REALLY debugging for things like Parallel IO, PPA, etc
; -D ARTNET_TIMER
; -D MAX_LEDS=65535 ;; 18432
; -D MAX_LEDS_PER_BUS=65535 ;; 18432
; -D MAX_LED_MEMORY=64000000 ;; times ONE HUNDRED
; -D DEFAULT_LED_TYPE=TYPE_NET_ARTNET_RGB
; -D LEDPIN=192 ;; at least get 192.x.x.x set properly for Art-Net
; -D BTNPIN=46 ;; Boot button is on GPIO 35 and works as a "button", but polling it messes up Ethernet.
; -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=30000
; -D BOARD_HAS_PSRAM
; -D WLED_USE_PSRAM
; ; -D WLED_USE_PSRAM_JSON
; ; -D ALL_JSON_TO_PSRAM
; -Wno-deprecated-declarations
; -Wno-attributes
; -D ESP_PLATFORM=1
; -D WLED_USE_MY_CONFIG
; -g
; -D FASTLED_NO_FASTLED
; -D WLED_RELEASE_NAME=ESP32-P4_16MB
; -D WLED_WATCHDOG_TIMEOUT=100 ;; Setting >0 will make the watchdog not panic. Workaround for now.
; -D USERMOD_AUDIOREACTIVE
; -D USERMOD_AUTO_PLAYLIST
; -D UM_AUDIOREACTIVE_USE_ESPDSP_FFT
; -D SR_DMTYPE=9 ;; 9 = ES8311 (new) which is the codec chip on the ESP32-P4 EV board
; -D SR_ENABLE_DEFAULT
; ; -D TROYHACKS_FAILSAFE_BUSSES ;; in case you have a bus type causing resets during testing, turn this on, upload, busses will be removed at boot. Then reflash without this flag.
; -D WLED_DISABLE_INFRARED
; -D WLED_DISABLE_ESPNOW ;; not working yet due to API changes in v5.3
; -D WLED_DISABLE_ALEXA
; -D WLED_DISABLE_HUESYNC
; -D WLED_DISABLE_MQTT
; -D WLED_DISABLE_LOXONE
; -D WLED_DISABLE_ADALIGHT ;; this no longer disables serial receive
; -D CONFIG_ADC_SUPPRESS_DEPRECATE_WARN
; -D CONFIG_I2S_SUPPRESS_DEPRECATE_WARN
; -D WLED_DISABLE_IMPROV_WIFISCAN
; -D USERMOD_ANIMARTRIX # needs to be changed from int to uint32_t in the base class: virtual void setPixelColor(uint32_t index, rgb pixel) = 0;
; ; -D WLEDMM_NO_MAP_RESET
; ; -D WLED_DEBUG_MAPS
; ; -D ES8311_ADDR=0x18
; lib_deps = ${esp32-p4-base.lib_deps}
; ; https://github.com/Makuna/NeoPixelBus#CORE3 ;; https://github.com/troyhacks/NeoPixelBus#CORE3
; ; https://github.com/softhack007/FastLED.git#ESP32-C6
; ; https://github.com/troyhacks/ESPAsyncWebServer ;; #v2.3.0 ;; https://github.com/softhack007/ESPAsyncWebServer.git#ESP32-C6
; ; https://github.com/netmindz/animartrix.git#e6b7509b391cab97b59b8eb19580e67d4203ae7d # needs to be changed from int to uint32_t in the base class: virtual void setPixelColor(uint32_t index, rgb pixel) = 0;
; lib_ignore = IRremoteESP8266
; ; WebServer
; SD
; SD_MMC
; board_build.partitions = boards/TROYP4_ESP32_8MB_1500KB_FS.csv ;; WLED_ESP32_8MB.csv
; board_build.flash_mode = qio
; ; monitor_filters = esp32_exception_decoder, colorize
; ; monitor_speed = 115200
; upload_speed = 921600
; ; framework = arduino
; ; lib_compat_mode = strict
; ; extra_scripts =
; ; pre:pio-scripts/set_version.py
; ; pre:pio-scripts/build-html.py
; ; post:pio-scripts/output_bins.py
; ; post:pio-scripts/strip-floats.py
; ; pre:pio-scripts/user_config_copy.py
; ; pre:pio-scripts/load_usermods.py
; ; pre:pio-scripts/build_ui.py
; ; post:pio-scripts/validate_modules.py ;; double-check the build output usermods
11 changes: 0 additions & 11 deletions firmware/esp32-s3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ lib_deps = ${esp32-s3-base.lib_deps}
; Flash: [======= ] 71.4% (used 2245914 bytes from 3145728 bytes)


; [env:esp32-s3-devkitc-1-n16r8vVD]
; extends = env:esp32-s3-devkitc-1-n16r8v
; build_flags =
; ${env:esp32-s3-devkitc-1-n16r8v.build_flags}
; ${HP_VIRTUAL_DRIVER.build_flags}
; ; -D ML_LIVE_MAPPING
; lib_deps =
; ${env:esp32-s3-devkitc-1-n16r8v.lib_deps}
; ${HP_VIRTUAL_DRIVER.lib_deps}


[env:esp32-s3-zero-n4r2]
; board = esp32-s3-zero-n4r2
board_build.psram = enabled
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/EthernetSettingsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define ETHERNET_EVENT_DELAY 500

#define ETHERNET_SETTINGS_FILE "/config/ethernetSettings.json"
#define ETHERNET_SETTINGS_FILE "/.config/ethernetSettings.json"
#define ETHERNET_SETTINGS_SERVICE_PATH "/rest/ethernetSettings"

#define EVENT_ETHERNET "ethernet"
Expand Down
10 changes: 9 additions & 1 deletion src/MoonBase/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ bool ModuleState::checkReOrderSwap(JsonString parent, JsonVariant stateData, Jso
newStateIndex = parkedAtIndex; // e.g. 1 is stored in 0

if (newStateIndex != newIndex && onReOrderSwap) {
#if FT_ENABLED(FT_MOONLIGHT)
// runInAppTask_mutexChecker++;
// if (runInAppTask_mutexChecker > 1) EXT_LOGE(MB_TAG, "runInAppTask_mutexChecker %d", runInAppTask_mutexChecker);
std::lock_guard<std::mutex> lock(runInAppTask_mutex);
runInAppTask.push_back([&, stateIndex, newIndex]() { onReOrderSwap(stateIndex, newIndex); });
// runInAppTask_mutexChecker--;
// runInAppTask_mutexChecker--;
#else
onReOrderSwap(stateIndex, newIndex);
#endif
}

if (parkedFromIndex == UINT8_MAX) parkedFromIndex = newIndex; // the index of value in the array stored in the parking spot
Expand All @@ -131,13 +135,17 @@ void Module::execOnUpdate(UpdatedItem& updatedItem) {
}

// EXT_LOGD(ML_TAG, "%s[%d]%s[%d].%s = %s -> %s", updatedItem.parent[0].c_str(), updatedItem.index[0], updatedItem.parent[1].c_str(), updatedItem.index[1], updatedItem.name.c_str(), updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
#if FT_ENABLED(FT_MOONLIGHT)
// runInAppTask_mutexChecker++;
// if (runInAppTask_mutexChecker > 1) EXT_LOGE(MB_TAG, "runInAppTask_mutexChecker %d", runInAppTask_mutexChecker);
std::lock_guard<std::mutex> lock(runInAppTask_mutex);
runInAppTask.push_back([&, updatedItem]() mutable { // mutable as updatedItem is called by reference (&)
onUpdate(updatedItem);
});
// runInAppTask_mutexChecker--;
#else
onUpdate(updatedItem);
#endif
}

bool ModuleState::compareRecursive(JsonString parent, JsonVariant stateData, JsonVariant newData, UpdatedItem& updatedItem, uint8_t depth, uint8_t index) {
Expand Down
2 changes: 2 additions & 0 deletions src/MoonBase/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ void setBitValue(uint8_t* byteArray, size_t n, bool value) {
byteArray[byteIndex] &= ~(1 << bitIndex);
}

#if FT_MOONLIGHT
std::vector<std::function<void()>> runInAppTask; // see .h
std::mutex runInAppTask_mutex; // see .h
// int runInAppTask_mutexChecker = 0;
#endif

#if USE_M5UNIFIED
#include "moonmanpng.h"
Expand Down
2 changes: 2 additions & 0 deletions src/MoonBase/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,11 @@ void freeMBObject(T* obj) {
freeMB(obj, "object");
}

#if FT_MOONLIGHT
extern std::vector<std::function<void()>> runInAppTask; // functions to be called in main loopTask (to avoid https to run out of stack space). No , VectorRAMAllocator<std::function<void()> see main.cpp
extern std::mutex runInAppTask_mutex; // protect the runInAppTask vectors
// extern int runInAppTask_mutexChecker;
#endif

// to use in effect and on display
#if USE_M5UNIFIED
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void setup() {
// 🌙
xTaskCreateUniversal(effectTask, // task function
"AppEffectTask", // name
(psramFound() ? 6 : 4) * 1024, // d0-tuning... stack size (without livescripts we can do with 12...). updated from 4 to 6 to support preset loop
(psramFound() ? 6 : 3) * 1024, // d0-tuning... stack size (without livescripts we can do with 12...). updated from 4 to 6 to support preset loop
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

Verify stack sufficiency and update misleading comment.

The effectTask stack size for non-PSRAM boards has been reduced from 4KB to 3KB (25% reduction). The inline comment states "updated from 4 to 6 to support preset loop," which appears to contradict the actual change.

Concerns:

  1. The 1KB reduction could lead to stack overflow if the task requires the full 4KB
  2. The comment is confusing and doesn't accurately describe the change

Please verify that 3KB is sufficient for effectTask on non-PSRAM ESP32-D0 boards, and update the comment to accurately reflect the stack size changes.


🏁 Script executed:

#!/bin/bash
# Search for any stack overflow detection or watermark checks
rg -nP --type=cpp 'uxTaskGetStackHighWaterMark|Stack.*overflow|stack.*remain' -A 2

Length of output: 2731



🏁 Script executed:

#!/bin/bash
# Get context around line 295 in src/main.cpp to see task creation
sed -n '280,310p' src/main.cpp

Length of output: 1610


🏁 Script executed:

#!/bin/bash
# Search for effectTask definition and its operations
rg -nP --type=cpp 'effectTask|void.*effect' -A 5 | head -100

Length of output: 2173


🏁 Script executed:

#!/bin/bash
# Look for any stack-related warnings or past issues with this task
rg -nP --type=cpp 'effect.*stack|effectTask.*size' -B 2 -A 2

Length of output: 0



🏁 Script executed:

#!/bin/bash
# Get full effectTask implementation
sed -n '121,145p' src/main.cpp

Length of output: 753


🏁 Script executed:

#!/bin/bash
# Search for layerP.step() to understand call depth
rg -nP --type=cpp 'layerP\.step|void step\(' -A 3 | head -80

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for any comments mentioning stack tuning or the "4 to 6" or "4 to 3" change
rg -nP --type=cpp 'tuning|preset.*loop|stack.*size' -B 1 -A 1

Length of output: 1185



🏁 Script executed:

#!/bin/bash
# Find layerP.loop implementation - likely in layer-related files
find src -name "*.h" -o -name "*.cpp" | xargs grep -l "layerP" | head -5

Length of output: 146


🏁 Script executed:

#!/bin/bash
# Search for loop() method definition in layer files
rg -nP --type=cpp 'void loop\(\)|void loop20ms\(\)' -B 2 -A 8 | head -100

Length of output: 7897


🏁 Script executed:

#!/bin/bash
# Check git log/blame for this line to see what was actually changed
git log -p --all -S "updated from 4 to" -- src/main.cpp 2>/dev/null | head -100

Length of output: 59


Fix misleading comment and verify 3KB stack is sufficient.

The effectTask stack size was reduced from 4KB to 3KB for non-PSRAM boards (25% reduction). The inline comment stating "updated from 4 to 6" is incorrect—the actual change is 4→3 for non-PSRAM (PSRAM remains 6KB unchanged).

Concerns:

  1. Comment contradicts the code change and must be corrected
  2. The 1KB reduction on non-PSRAM requires validation that 3KB suffices for effectTask's layerP.loop() call chain

Update the comment to accurately reflect: "reduced from 4 to 3 for non-PSRAM to..." and verify the stack is adequate or document the tradeoffs made.

🤖 Prompt for AI Agents
In src/main.cpp around line 295, the inline comment next to the effectTask stack
size is incorrect and misleading (it currently says "updated from 4 to 6" while
the code uses 6KB for PSRAM and 3KB for non-PSRAM); update the comment to
accurately state that non-PSRAM boards were reduced from 4KB to 3KB while PSRAM
remains 6KB, and explain the reason/tradeoff (e.g., to save RAM while accepting
tighter stack headroom). Then verify 3KB is sufficient by exercising
effectTask's call chain (specifically layerP.loop() and its callees) under
worst-case conditions (deep recursion, large local buffers, debug builds) using
an instrumented run or stack high-water mark check; if stack overflows or margin
is too small, either increase the non-PSRAM stack back to 4KB or refactor to
reduce stack usage, and document the chosen outcome in the comment.

NULL, // parameter
3, // priority (between 5 and 10: ASYNC_WORKER_TASK_PRIORITY and Restart/Sleep), don't set it higher then 10...
&effectTaskHandle, // task handle
Expand All @@ -301,7 +301,7 @@ void setup() {

xTaskCreateUniversal(driverTask, // task function
"AppDriverTask", // name
(psramFound() ? 6 : 3) * 1024, // d0-tuning... stack size
(psramFound() ? 6 : 4) * 1024, // d0-tuning... stack size
NULL, // parameter
3, // priority (between 5 and 10: ASYNC_WORKER_TASK_PRIORITY and Restart/Sleep), don't set it higher then 10...
&driverTaskHandle, // task handle
Expand Down