STM32L476RG UART with DMA using Reception Till Idle
I've encountered an issue while implementing code on an STM32L476RG Nucleo board to receive variable-length data from Tera Term using USART2 in asynchronous mode. The baud rate is set to 1 Mbps with a 16 MHz sysclk. However, the code doesn't accurately determine the size of the data sent and gets stuck afterward. Surprisingly, the same code works flawlessly when using USART1 with identical configurations.
I don't know the reason why?
Below is the code snippet of main.c and callback:
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_USART1_UART_Init();
MX_USART3_UART_Init();
MX_UART4_Init();
/* USER CODE BEGIN 2 */
if(HAL_UARTEx_ReceiveToIdle_DMA(&huart2, Data_Buffer, Size_Buff) != HAL_OK)
{
Error_Handler();
}
__HAL_DMA_DISABLE_IT(&hdma_usart2_rx,DMA_IT_HT);
/*-------Callback handled--------*/
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
if(huart->Instance == USART2)
{
if(HAL_UARTEx_ReceiveToIdle_DMA(&huart2, Data_Buffer, Size_Buff) != HAL_OK)
{
Error_Handler();
}
__HAL_DMA_DISABLE_IT(&hdma_usart2_rx,DMA_IT_HT);
rx_size+=Size;
uint8_t buff[20];
sprintf(buff,"\n%d\n",rx_size);
HAL_UART_Transmit_DMA(&huart2, buff, 10);
}
}
