cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_RxCpltCallback not called in DMA

_alaBaster
Associate III

Hi Everybody, 

  • USART interrupt enabled
  • DMA interrupt enabled
  • USART2_RX circular 
  • USART2_TX normal

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);
}

 

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USART2_UART_Init();
 
  memset((uint8_t *) &uartBuffer, 0, sizeof(uartBuffer)); // Clear buffer
  HAL_UARTEx_ReceiveToIdle_DMA(&huart2,(uint8_t *) &uartBuffer, UART_BUFFER_SIZE);
 
  while (1)
  {
    HAL_Delay(1000);
  }
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.
   */
}

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

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.
   */
}

 

If you feel a post has answered your question, please click "Accept as Solution".
_alaBaster
Associate III

okay thanks.

When I instead use the HAL_UART_Receive_DMA, no callback is triggered at the end, isnt it?

TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".