From 5470809c23bc8a860d909e0dd59e8b004d0f91c7 Mon Sep 17 00:00:00 2001 From: copercini Date: Mon, 2 Oct 2017 15:45:52 -0300 Subject: [PATCH 1/2] Print error when serial number is invalid --- cores/esp32/HardwareSerial.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index a053bf227cf..efcefda66a2 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -14,6 +14,10 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in if(_uart) { end(); } + if(0 > _uart_nr || _uart_nr > 2) { + log_e("Serial number is invalid, please use 0, 1 or 2"); + end(); + } if(_uart_nr == 0 && rxPin < 0 && txPin < 0) { rxPin = 3; txPin = 1; From ce419a003fcb207550ea180dfcc593a1aae19589 Mon Sep 17 00:00:00 2001 From: copercini Date: Tue, 3 Oct 2017 09:43:26 -0300 Subject: [PATCH 2/2] Move to the first check, change end by return --- cores/esp32/HardwareSerial.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index efcefda66a2..500bff46fdd 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -11,11 +11,11 @@ HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL) {} void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin) { - if(_uart) { - end(); - } if(0 > _uart_nr || _uart_nr > 2) { log_e("Serial number is invalid, please use 0, 1 or 2"); + return; + } + if(_uart) { end(); } if(_uart_nr == 0 && rxPin < 0 && txPin < 0) {