5

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?

Akay
  • 1,092
  • 12
  • 32

3 Answers3

4

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.

A.R.C.
  • 910
  • 11
  • 22
  • This is extremely helpful. I have struggled with this issue for 2 different projects and I have seen others spin their wheels for weeks. Thank you so much for the link and advice. – Spectrem Sep 10 '20 at 16:57
3

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

0___________
  • 60,014
  • 4
  • 34
  • 74
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/21046088) – Mustapha Larhrouch Oct 05 '18 at 10:00
  • 2
    @MustaphaLarhrouch It does for people who do the STM32 uC development. I do not see any uC related experience in your bio and SO answers. So how can you judge it as a web developer? – 0___________ Oct 05 '18 at 10:35
  • 2
    BTW - Any DV explanation? – 0___________ Oct 05 '18 at 10:39
0

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.

denis krasutski
  • 618
  • 4
  • 9