UART flush doesn't clear RX buffer

ESP-Shadow
Posts: 2
Joined: Mon Feb 07, 2022 6:53 am

UART flush doesn't clear RX buffer

Postby ESP-Shadow » Mon Feb 07, 2022 7:30 am

ESP-IDF version: 4.4
ESP: ESP32-WROOM-32D

Background: I'm trying to make a program that communicates through UART with another device. The other device is usually constantly sending data, which I want to ignore, and only actually process it's messages, when I'm awaiting a response to one of my UART messages.

The problem: I start the UART at the start of the program, but after some time, the RX FIFO buffer gets filled up and can no longer receive any messages. I would expect that the RX FIFO buffer being a ring buffer it would just start overwriting old data when it gets full or at the very least calling uart_flush_input(UART_PORT) before writing my message and waiting for the other devices reply would clear the whole RX FIFO buffer, but it does not.

I have tried setting up the UART events example to see what happens. If I leave the part where it constantly reads the data while it's being received, everything is fine, but if I remove it, but leave the part where when it reaches overflow and it flushes, it gets filled up and stuck. The ESP will happily receive the messages at the start but after receiving a "Ring buffer full" and then "HW FIFO overflow", the FIFO overflow event keeps popping up every time I receive a message and I cannot actually read any data.

So, is uart_flush_input() supposed to do something else, or is it supposed to clear the whole UART RX buffer but is not working correctly?

AngelVer
Posts: 4
Joined: Thu Mar 12, 2020 10:54 am

Re: UART flush doesn't clear RX buffer

Postby AngelVer » Tue Feb 08, 2022 9:32 am

We found similar issue using ESP-IDF v4.3.1 on a ESP32-WROOM.

After a while receiving messages through the UART, the event "UART_FULL_BUFFER" triggers and the uart stop receiving messages, when its supposed to be a circular buffer. In other hand the uart_flush() seems that not clean the buffer, so after a UART_FULL_BUFFER event the uart is blocked until the ESP32 reboot.

If we set a bigger RX buffer the problem seems to be delayed in time, but ends up happening anyway.

Someone know how to fix the problem?

ESP-Shadow
Posts: 2
Joined: Mon Feb 07, 2022 6:53 am

Re: UART flush doesn't clear RX buffer

Postby ESP-Shadow » Tue Feb 22, 2022 8:09 am

It would appear that this (https://github.com/espressif/esp-idf/issues/8445) issue solves our problem

jkingdon
Posts: 20
Joined: Wed Jun 15, 2016 2:51 pm

Re: UART flush doesn't clear RX buffer

Postby jkingdon » Sat Mar 26, 2022 1:34 am

Many thanks - this problem has been driving me up the wall for weeks, so it's great to know the solution is on it's way.

Who is online

Users browsing this forum: Baidu [Spider] and 344 guests