ESP32 UART rx idle timeout not working in driver

biterror
Posts: 31
Joined: Thu Apr 30, 2020 11:00 am

ESP32 UART rx idle timeout not working in driver

Postby biterror » Tue Jan 26, 2021 5:45 pm

I'm trying to use the UART receive idle timeout (uart_set_rx_timeout() etc.) with RS485. I see the timeout interrupt is enabled in UART registers (I'm using UART1 now) and I added some debug code in the UART interrupt routine so I can see that the TOUT interrupt is actually triggered - and it is. However, when I try to read the incoming data using uart_read_bytes(), the TOUT timeout doesn't return the data to the task - uart_read_bytes() only returns when the buffer becomes full.

Looking at the uart_read_bytes() source, it calls xRingbufferReceive() and I guess xRingbufferReceive() knows nothing about the TOUT interrupt, so it sleeps until the call timeouts or buffer becomes full. I believe the timeout functionality is completely missing from the UART driver. I just cloned the latest repository and this is still the case.

However, the ESP32 RS485 example uses uart_read_bytes() and uart_set_rx_timeout() and gives you the impression that the rx idle timeout has been implemented in the driver.

Am I missing something here or does the driver really lack support for the idle timeout?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 UART rx idle timeout not working in driver

Postby WiFive » Wed Jan 27, 2021 7:12 am

Tout interrupt causes isr to copy data into ringbuffer

biterror
Posts: 31
Joined: Thu Apr 30, 2020 11:00 am

Re: ESP32 UART rx idle timeout not working in driver

Postby biterror » Wed Jan 27, 2021 10:00 am

Thanks for the reply. Yes it does, but my task does not wake up because uart_read_bytes() still blocks although there is data available. I need the task to wake up as soon as tout interrupt occurs so I can process the incoming message. Without this, the tout interrupt is useless.

Giovagiova
Posts: 2
Joined: Sun Jan 31, 2021 6:22 pm

Re: ESP32 UART rx idle timeout not working in driver

Postby Giovagiova » Sun May 02, 2021 5:37 pm

I am interested to know if you have found the solution to the problem you described as I have the same problem and I cannot find the solution using ISR rx timeout.Thank you.

xgvargas
Posts: 2
Joined: Wed Jul 13, 2022 5:29 pm

Re: ESP32 UART rx idle timeout not working in driver

Postby xgvargas » Wed Jul 13, 2022 5:38 pm

It's an old question, but here is my solution in case someone else is having this kind of issue.

We do not need to relay on IDF to solve that.

Simple create a FreeRTOS semaphore with xSemaphoreCreateBinary, and take it inside your task using xSemaphoreTake.

Then, from inside the TOUT interrupt give that semaphore using xSemaphoreGiveFromISR.

Who is online

Users browsing this forum: MattWork and 63 guests