From 12ca9e8b521127c5455b8e45b463371cc0cc6d3d Mon Sep 17 00:00:00 2001 From: chemicstry Date: Tue, 3 Jul 2018 18:54:08 +0300 Subject: [PATCH] Port UART reset fix from ESP-IDF (#1408) --- cores/esp32/esp32-hal-uart.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index bcf9d045..d8d13295 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -315,11 +315,14 @@ void uartFlush(uart_t* uart) UART_MUTEX_LOCK(); while(uart->dev->status.txfifo_cnt); - uart->dev->conf0.txfifo_rst = 1; - uart->dev->conf0.txfifo_rst = 0; + //Due to hardware issue, we can not use fifo_rst to reset uart fifo. + //See description about UART_TXFIFO_RST and UART_RXFIFO_RST in <> v2.6 or later. + + // we read the data out and make `fifo_len == 0 && rd_addr == wr_addr`. + while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) { + READ_PERI_REG(UART_FIFO_REG(uart->num)); + } - uart->dev->conf0.rxfifo_rst = 1; - uart->dev->conf0.rxfifo_rst = 0; UART_MUTEX_UNLOCK(); }