In your HAL_UART_RxCpltCallback() function, you can act differently depending upon the UART peripheral.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if (huart->Instance == USART1) {
// USART1
} else if (huart->Instance == USART2) {
// USART2
} else if (huart->Instance == USART3) {
// USART3
} else if (huart->Instance == UART4) {
// UART4
}
}
Same is possible with HAL_UART_TxCpltCallback as well.
STM32 uart callback in c++ - Stack Overflow
how to register separate callback function for each UART port in stm32 - Stack Overflow
hal library - STM32 HAL Implementing UART receive Interrupt - Electrical Engineering Stack Exchange
STM32 HAL UARTEx_ReceiveToIdle_DMA: USART IDLE IRQ fires but never calls RxEventCallback
Videos
In your HAL_UART_RxCpltCallback() function, you can act differently depending upon the UART peripheral.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if (huart->Instance == USART1) {
// USART1
} else if (huart->Instance == USART2) {
// USART2
} else if (huart->Instance == USART3) {
// USART3
} else if (huart->Instance == UART4) {
// UART4
}
}
Same is possible with HAL_UART_TxCpltCallback as well.
Yes, If you are using HAL, there are a host of functions for differnt callbacks,
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart);
void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart);
void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart);
You have to pass the UART_HandleTypeDef instance which specifies the UART instance you are trying to use.
Title:
STM32 HAL UARTEx_ReceiveToIdle_DMA: USART IDLE IRQ fires but never calls RxEventCallback (DMA TC preempts?)
Body:
Hi everyone,
I’m using an STM32 (F4/F7) in half-duplex + data-inverted mode with the HAL extended API:
HAL_UARTEx_ReceiveToIdle_DMA(&huart1, dma_buf, 64);
My callback looks like:
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) {
// copy Size bytes from dma_buf into my ring buffer…
HAL_UARTEx_ReceiveToIdle_DMA(huart, dma_buf, 64);
}Observed behavior:
-
USART1_IRQHandler fires on IDLE → runs HAL_UART_IRQHandler(&huart1)
-
Immediately after, DMA2_Stream2_IRQHandler fires → runs HAL_DMA_IRQHandler(&hdma_usart1_rx)
-
HAL_UARTEx_RxEventCallback never runs, so no data gets processed
What I’ve checked:
-
Callback signature matches the HAL’s weak declaration
-
Swapped NVIC priorities (USART1 IRQ vs. DMA2_Stream2 IRQ) and even disabled the DMA IRQ
Debug video:
Watch the step-through on YouTube
Questions:
-
Does USART1_IRQn have to be higher priority than DMA2_Stream2_IRQn for RxEventCallback to fire?
-
Any hidden HAL state or flags I’ve missed?
-
Has anyone successfully combined half-duplex + data-invert + ReceiveToIdle_DMA on STM32?
Thanks in advance for any tips!