cancel
Showing results for 
Search instead for 
Did you mean: 

Calling HAL_UARTEx_ReceiveToIdle_DMA from HAL_GPIO_EXTI_Callback

pet
Associate

Hello, 

I have a device with a variable message stream in UART and there is the issue that I cannot know when it's stream ends due to gaps (so a single ReceiveIdle won't work). The device has clear framing via an interrupt so I use that.

The final system will have limited DMA channels so keeping a ReceiveIdle always set is wasteful.

As such there is the following workflow:

  1. HAL_GPIO_EXTI_Callback gets a signal there is a new message. That arms the DMA listener.
  2.  On DMA callback, HAL_UART_Receive_IT is armed to catch possible remainder of message.
  3. On HAL_UART_Receive_IT it arms another DMA to get the rest of the stream (instead of doing a byte by byte interrupt, which is slow)
  4. We get another callback and stop the DMA/IT or we loop on IT and DMA.

The issue is if this workflow is safe? Is there an issue arming DMAs on callbacks or IT on DMA callbacks?

Thank you

 

1 REPLY 1
Guenael Cadier
ST Employee

Hi @pet 
Not sure to get the full view in terms of DMA channels availability and constraints, but my understanding of your use case is :
- you need to receive messages that have a minimum part (lets call it A), and optional parts , as B or C. So you have to manage reception of A, A+ B or A+C.

- you cannot use a DMA channel during the whole time ? (otherwise use of HAL_UARTEx_ReceiveToIdle_DMA is recommended with a DMA in circular mode)

so steps in your process are :

1. GPIO Callback => Reception using DMA (using HAL_UART_Receive_DMA which receives a first part of the message ?)

2. DMA callback : calls the HAL_UART_RxCpltCallback (?) => HAL_UART_Receive_IT is called : what length ? 1 ? length of remaining bytes is fixed ?

3. UART RX interrupt => calls DMA reception again (using HAL_UART_Receive_DMA ?)

For this use case I would recommend to use HAL_UARTEx_ReceiveToIdle_DMA with DMA in circular mode, as described in this example.
if not possible, your use case might work but you will have to manage all various cases where HAL_UART_RxCpltCallback will be called (at end of reception either from IT or DMA modes).
Regards