From 15199dc711616b8190219afafc07f5ae529dbe15 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 29 May 2024 15:43:24 +0200 Subject: [PATCH] protect unconnected USB-CDC from being used found a few more places where Serial was used without first checking if its connected. Arduino docs: `if (Serial)` indicates whether or not the USB CDC serial connection is open. For all non-USB CDC ports, this will always return true --- tools/ESP32-Chip_info.hpp | 2 ++ wled00/wled_serial.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/ESP32-Chip_info.hpp b/tools/ESP32-Chip_info.hpp index 893165985a..417ee44915 100644 --- a/tools/ESP32-Chip_info.hpp +++ b/tools/ESP32-Chip_info.hpp @@ -543,6 +543,8 @@ void show_psram_info_part2(void) void showRealSpeed() { //Serial.begin(115200); + if (!Serial) return; // Avoid writing to unconnected USB-CDC + Serial.flush(); Serial.println(F("\n")); for(int aa=0; aa<65; aa++) Serial.print("="); Serial.println(); diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index 221f21ad85..9361891b5a 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -42,6 +42,7 @@ void updateBaudRate(uint32_t rate){ // RGB LED data return as JSON array. Slow, but easy to use on the other end. void sendJSON(){ if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) { + if (!Serial) return; // WLEDMM avoid writing to unconnected USB-CDC uint16_t used = strip.getLengthTotal(); Serial.write('['); for (uint16_t i=0; i