2026-05-21 7:46 AM
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:
The issue is if this workflow is safe? Is there an issue arming DMAs on callbacks or IT on DMA callbacks?
Thank you
2026-06-02 12:50 AM
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
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.