From 43016390510e23422b0abcf432ceef2479a05f41 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 7 Oct 2024 09:56:20 -0300 Subject: [PATCH] fix(uart) 2.0.x Core: fixes serialEventRun() to avoid calling available() if serialEvent() is not declared (#10429) * fix(uart): applies #10428 to 2.0.x core * fix(uart): there is no usb serial event in 2.0.x --- cores/esp32/HardwareSerial.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 178f69ca9bb..28061d5f6b5 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -23,16 +23,13 @@ #endif void serialEvent(void) __attribute__((weak)); -void serialEvent(void) {} #if SOC_UART_NUM > 1 void serialEvent1(void) __attribute__((weak)); -void serialEvent1(void) {} #endif /* SOC_UART_NUM > 1 */ #if SOC_UART_NUM > 2 void serialEvent2(void) __attribute__((weak)); -void serialEvent2(void) {} #endif /* SOC_UART_NUM > 2 */ #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) @@ -50,19 +47,13 @@ HardwareSerial Serial2(2); void serialEventRun(void) { -#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event - if(HWCDCSerial.available()) HWCDCSerialEvent(); -#endif -#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event - if(USBSerial.available()) USBSerialEvent(); -#endif // UART0 is default serialEvent() - if(Serial.available()) serialEvent(); + if(serialEvent && Serial.available()) serialEvent(); #if SOC_UART_NUM > 1 - if(Serial1.available()) serialEvent1(); + if(serialEvent1 && Serial1.available()) serialEvent1(); #endif #if SOC_UART_NUM > 2 - if(Serial2.available()) serialEvent2(); + if(serialEvent2 && Serial2.available()) serialEvent2(); #endif } #endif