2024-08-29 06:03 AM
Hi Everybody,
Simplifying code to the essential part here, code is receiving the bytes in the circular buffer but it does not jump to HAL_UART_RxCpltCallback. Could someone please give some hints, what am I missing here?
#define UART_BUFFER_SIZE 4
__IO uint8_t uartBuffer[UART_BUFFER_SIZE];
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_USART2_UART_Init(void);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_Delay(1000);
HAL_UARTEx_ReceiveToIdle_DMA(&huart2,(uint8_t *) &uartBuffer, UART_BUFFER_SIZE);
}
Solved! Go to Solution.
2024-08-29 06:09 AM - edited 2024-08-29 06:10 AM
The HAL_UARTEx_ReceiveToIdle_DMA function will call the HAL_UARTEx_RxEventCallback callback, not HAL_UART_RxCpltCallback.
See example (non-funcitonal) weak implementation here:
/**
* @brief Reception Event Callback (Rx event notification called after use of advanced reception service).
* @PAram huart UART handle
* @PAram Size Number of data available in application reception buffer (indicates a position in
* reception buffer until which, data are available)
* @retval None
*/
__weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
UNUSED(Size);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_UARTEx_RxEventCallback can be implemented in the user file.
*/
}
2024-08-29 06:09 AM - edited 2024-08-29 06:10 AM
The HAL_UARTEx_ReceiveToIdle_DMA function will call the HAL_UARTEx_RxEventCallback callback, not HAL_UART_RxCpltCallback.
See example (non-funcitonal) weak implementation here:
/**
* @brief Reception Event Callback (Rx event notification called after use of advanced reception service).
* @PAram huart UART handle
* @PAram Size Number of data available in application reception buffer (indicates a position in
* reception buffer until which, data are available)
* @retval None
*/
__weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
UNUSED(Size);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_UARTEx_RxEventCallback can be implemented in the user file.
*/
}
2024-08-29 07:21 AM
okay thanks.
When I instead use the HAL_UART_Receive_DMA, no callback is triggered at the end, isnt it?
2024-08-29 07:28 AM
When you use HAL_UART_Receive_DMA, then HAL_UART_RxCpltCallback will be called when the reception is complete. It will not be called until you receive all and exactly the number of characters you ask for.