Skip to content

Commit 15199dc

Browse files
committed
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
1 parent 6a93f46 commit 15199dc

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

tools/ESP32-Chip_info.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ void show_psram_info_part2(void)
543543

544544
void showRealSpeed() {
545545
//Serial.begin(115200);
546+
if (!Serial) return; // Avoid writing to unconnected USB-CDC
547+
546548
Serial.flush();
547549
Serial.println(F("\n"));
548550
for(int aa=0; aa<65; aa++) Serial.print("="); Serial.println();

wled00/wled_serial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void updateBaudRate(uint32_t rate){
4242
// RGB LED data return as JSON array. Slow, but easy to use on the other end.
4343
void sendJSON(){
4444
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) {
45+
if (!Serial) return; // WLEDMM avoid writing to unconnected USB-CDC
4546
uint16_t used = strip.getLengthTotal();
4647
Serial.write('[');
4748
for (uint16_t i=0; i<used; i++) {
@@ -55,6 +56,7 @@ void sendJSON(){
5556
// RGB LED data returned as bytes in TPM2 format. Faster, and slightly less easy to use on the other end.
5657
void sendBytes(){
5758
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) {
59+
if (!Serial) return; // WLEDMM avoid writing to unconnected USB-CDC
5860
Serial.write(0xC9); Serial.write(0xDA);
5961
uint16_t used = strip.getLengthTotal();
6062
uint16_t len = used*3;

0 commit comments

Comments
 (0)