Akay
Akay

Reputation: 1132

Intentional receive complete UART DMA interrupt after specified timeout

I have configured a UART to receive in DMA mode where the size of the buffer is around 64 bytes. So, basically, the HAL_UART_RxCpltCallback() DMA receive complete interrupt will only fire when 64 chars are received.

Is there a way in STM32 through which I can configure a timeout for DMA Rx where when the buffer is only partially filled (i.e. less than 64 chars are received) and we don't receive anymore chars for a specified timeout, the DMA will then raise the same HAL_UART_RxCpltCallback() based interrupt to let the consumer consume whatever partial data is currently received on the UART?

Upvotes: 5

Views: 3945

Answers (3)

denis krasutski
denis krasutski

Reputation: 637

in order to get a count of transferred bytes, you can use DMA_CNDTRx or DMA_SxNDTR register (name different for STM family, where x - channel number ).

This register decrements after each DMA transfer. Once the transfer is completed, this register can either stay at zero or be reloaded automatically by the value previously programmed if the channel is configured in autoreload mode.

Unfortunately, STM HAL doesn't provide API, you should implement it yourself.

Upvotes: 0

A.R.C.
A.R.C.

Reputation: 920

You can use the UART Idle detection interrupt in parallel to the DMA interrupt. I have used this multiple times with ST32F0xx processors and it is working perfectly. There Idle detection should be available on F4 and F7 processors too.

There are some tutorials in the internet which target your problem and also provide the solution with the Idle detection. E.g. check out this one this one.

Upvotes: 4

0___________
0___________

Reputation: 67476

It's easy but you have to use USART receiver timeout interrupt instead. enter image description here

Upvotes: 3

Related Questions