From f52e706c95af52205d6f11bc046f6acbb76d7e06 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sat, 25 Mar 2023 21:10:15 +0100 Subject: [PATCH] minor improvements for debugging * Info page: status of Serial (can be disconnected on new MCUs), and owner of RX/TX pins * improved handling of Serial (don't write if not connected) * added min available stack size to debug output (esp32 only) * webserver show remaining stack size * webserver: show string buffer usage --- wled00/data/index.js | 2 ++ wled00/json.cpp | 6 ++++++ wled00/wled.cpp | 29 ++++++++++++++++++++++------- wled00/wled_server.cpp | 10 ++++++++++ wled00/ws.cpp | 2 ++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/wled00/data/index.js b/wled00/data/index.js index 766cd820..bf86d6d8 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -676,6 +676,8 @@ function populateInfo(i) ${urows} ${urows===""?'':'
'} ${i.opt&0x100?inforow("Net Serial ☾",""):''} +${i.serialOnline?inforow(i.serialOnline,"TX="+i.sTX,"; RX="+i.sRX):""} +${i.opt&0x100?'
':''} ${inforow("Build",i.vid)} ${inforow("Estimated current",pwru)} ${inforow("Average FPS",i.leds.fps)} diff --git a/wled00/json.cpp b/wled00/json.cpp index 61fabbff..2115d962 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -972,6 +972,12 @@ void serializeInfo(JsonObject root) default: root[F("e32flashtext")] = F(" (other)"); break; } #endif + #if defined(WLED_DEBUG) || defined(WLED_DEBUG_HOST) || defined(SR_DEBUG) || defined(SR_STATS) + // WLEDMM add status of Serial, incuding pin alloc + root[F("serialOnline")] = Serial ? (canUseSerial()?F("Serial ready"):F("Serial in use")) : F("Serial disconected"); // "Disconnected" may happen on boards with USB CDC + root[F("sRX")] = pinManager.isPinAllocated(hardwareRX) ? pinManager.getPinOwnerText(hardwareRX): F("free"); + root[F("sTX")] = pinManager.isPinAllocated(hardwareTX) ? pinManager.getPinOwnerText(hardwareTX): F("free"); + #endif // end WLEDMM root[F("uptime")] = millis()/1000 + rolloverMillis*4294967; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 0ba201b5..f52d7c34 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -198,6 +198,9 @@ void WLED::loop() DEBUG_PRINT(F("Runtime: ")); DEBUG_PRINTLN(millis()); DEBUG_PRINT(F("Unix time: ")); toki.printTime(toki.getTime()); DEBUG_PRINT(F("Free heap: ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + #ifdef ARDUINO_ARCH_ESP32 + DEBUG_PRINT(pcTaskGetTaskName(NULL)); DEBUG_PRINT(F(" free stack ")); DEBUG_PRINTLN(uxTaskGetStackHighWaterMark(NULL)); + #endif #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) if (psramFound()) { //DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB"); @@ -292,17 +295,17 @@ void WLED::setup() #else #endif #if defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT) - delay(2500); // allow CDC USB serial to initialise + if (!Serial) delay(2500); // WLEDMM allow CDC USB serial to initialise #endif #if ARDUINO_USB_CDC_ON_BOOT - delay(2500); // WLEDMM: always allow CDC USB serial to initialise + if (!Serial) delay(2500); // WLEDMM: always allow CDC USB serial to initialise Serial.println("wait 1"); // waiting a bit longer ensures that a debug messages are shown in serial monitor - delay(2500); + if (!Serial) delay(2500); Serial.println("wait 2"); - delay(2500); + if (!Serial) delay(2500); - Serial.flush(); + if (Serial) Serial.flush(); // WLEDMM Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later // WLEDMM: redirect debug output to HWCDC Serial0.setDebugOutput(false); @@ -403,6 +406,12 @@ void WLED::setup() DEBUG_PRINTLN(ESP.getCoreVersion()); #endif DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); +#ifdef ARDUINO_ARCH_ESP32 + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0) // unfortunately not availeable in older framework versions + USER_PRINT(F("\nArduino max stack ")); USER_PRINTLN(getArduinoLoopTaskStackSize()); + #endif + USER_PRINT(pcTaskGetTaskName(NULL)); USER_PRINT(F(" free stack ")); USER_PRINTLN(uxTaskGetStackHighWaterMark(NULL)); +#endif #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) if (psramFound()) { @@ -456,6 +465,9 @@ void WLED::setup() registerUsermods(); DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + #ifdef ARDUINO_ARCH_ESP32 + DEBUG_PRINT(pcTaskGetTaskName(NULL)); DEBUG_PRINT(F(" free stack ")); DEBUG_PRINTLN(uxTaskGetStackHighWaterMark(NULL)); + #endif for (uint8_t i=1; iurl().c_str()); //WLEDMM: want to see if client connects to wled, for netdebug also wants to know server + #ifdef ARDUINO_ARCH_ESP32 + USER_PRINT(pcTaskGetTaskName(NULL)); USER_PRINT(F(" min free stack ")); USER_PRINTLN(uxTaskGetStackHighWaterMark(NULL)); + #endif if (captivePortal(request)) return; serveIndexOrWelcome(request); }); @@ -551,6 +554,13 @@ void serveSettingsJS(AsyncWebServerRequest* request) strcat_P(buf,PSTR("function GetV(){var d=document;")); getSettingsJS(request, subPage, buf+strlen(buf)); // this may overflow by 35bytes!!! WLEDMM add request strcat_P(buf,PSTR("}")); + + #ifdef ARDUINO_ARCH_ESP32 + DEBUG_PRINT(F("ServeSettingsJS: ")); + DEBUG_PRINT(pcTaskGetTaskName(NULL)); DEBUG_PRINT(F(" min free stack ")); DEBUG_PRINT(uxTaskGetStackHighWaterMark(NULL)); + DEBUG_PRINTF(PSTR(" bytes.\tString buffer usage: %4d of %d bytes\n"), strlen(buf)+1, SETTINGS_STACK_BUF_SIZE+37); + #endif + request->send(200, "application/javascript", buf); } diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 6db459ac..ef676ca5 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -117,6 +117,8 @@ void sendDataWs(AsyncWebSocketClient * client) DEBUG_PRINTLN(F("Out of memory (WS)!")); return; } + #else + //DEBUG_PRINT(pcTaskGetTaskName(NULL)); DEBUG_PRINT(F(" min free stack ")); DEBUG_PRINT(uxTaskGetStackHighWaterMark(NULL)); #endif buffer = ws.makeBuffer(len); // will not allocate correct memory sometimes on ESP8266 #ifdef ESP8266