UART timeout in DMA Circular mode.
Hi, I have a question about UART + DMA.
I have a sensor that needs to send data to my STM32. When the sensor is stimulated, for the duration of the event, it sends a byte approximately every 1 ms.
To receive the data there are no problems, I used DMA and when the HAL_UART_RxCpltCallback function is called I copy the data into the main buffer in an external memory.
An event can also be quite long, and the DMA buffer is filled and data copied to main buffer dozens of times. The problem is how to know when an event has ended.
The first thing I tried is to use the IDLE LINE interrupt, but since the data comes in slowly, the interrupt is generated practically every byte. So, the first question then is: is there a way to set the UART idle time before the IDLE LINE interrupt is called?
Currently the way I use is: through a timer and a flag I check when the HAL_UART_RxCpltCallback function is no longer called for a certain time, at which point I copy in the main buffer what is left in the DMA buffer and consider the event concluded. But it is a complicated and inefficient way, looking in the UART functions I saw one called HAL_UART_EnableReceiverTimeout, the second question therefore is: can I set a timeout on the UART while working in DMA circular mode?
What I would like is that as long as the data arrives, the HAL_UART_RxCpltCallback function is called regularly, but if for a certain time, for example 200 ms, no data arrives, even if the DMA buffer is not full, the interrupt is still called (or even another interrupt callback).
If anyone can help me with these two questions it would help me a lot.
Thanks in advance.