Skip to content

Commit a1bef8b

Browse files
committed
improve Serial repeated begin/baud change
1 parent 4495659 commit a1bef8b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Diff for: cores/esp32/HardwareSerial.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL) {}
1111

1212
void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin)
1313
{
14+
if(_uart) {
15+
end();
16+
}
1417
if(_uart_nr == 0 && rxPin < 0 && txPin < 0) {
1518
rxPin = 3;
1619
txPin = 1;

Diff for: cores/esp32/esp32-hal-uart.c

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ void uartEnd(uart_t* uart)
223223

224224
UART_MUTEX_LOCK();
225225
if(uart->queue != NULL) {
226+
uint8_t c;
227+
while(xQueueReceive(uart->queue, &c, 0));
226228
vQueueDelete(uart->queue);
227229
}
228230

0 commit comments

Comments
 (0)