From c9d954531043acf0853bd9c403f08bed1b746eb8 Mon Sep 17 00:00:00 2001 From: xiongyu Date: Wed, 3 Jun 2020 12:24:55 +0800 Subject: [PATCH] bugfix(uart): fix esp32 uart fifo_cnt bug When using DPort to read fifo, fifo_cnt is not credible, we need to calculate the real cnt based on the fifo read and write pointer. When using AHB to read FIFO, we can use fifo_cnt to indicate the data length in fifo. --- components/driver/uart.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/driver/uart.c b/components/driver/uart.c index f45e417de..27e13bca0 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -865,6 +865,17 @@ static void uart_rx_intr_handler_default(void *param) || (uart_intr_status & UART_AT_CMD_CHAR_DET_INT_ST_M) ) { rx_fifo_len = uart_reg->status.rxfifo_cnt; + typeof(uart_reg->mem_rx_status) rx_status = uart_reg->mem_rx_status; + + // When using DPort to read fifo, fifo_cnt is not credible, we need to calculate the real cnt based on the fifo read and write pointer. + // When using AHB to read FIFO, we can use fifo_cnt to indicate the data length in fifo. + if (rx_status.wr_addr > rx_status.rd_addr) { + rx_fifo_len = rx_status.wr_addr - rx_status.rd_addr; + } else if (rx_status.wr_addr < rx_status.rd_addr) { + rx_fifo_len = (rx_status.wr_addr + 128) - rx_status.rd_addr; + } else { + rx_fifo_len = rx_fifo_len > 0 ? 128 : 0; + } if(pat_flg == 1) { uart_intr_status |= UART_AT_CMD_CHAR_DET_INT_ST_M; pat_flg = 0;