cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476RG UART with DMA using Reception Till Idle

Devesh
Associate

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

}

}

 

2 REPLIES 2
Peter BENSCH
ST Employee

Welcome @Devesh, to the community!

At least the initialisation of USART2 (UART_HWCONTROL_RTS_CTS) differs from USART1, USART3 and USART4 (UART_HWCONTROL_NONE). This is probably the cause of your problem.

Hope that helps?

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

@Peter BENSCH , thanks for your solution.

I disabled the USART2 HWCONTROL_RTS_CTS, but still i am facing the same issue.

Actually, the code works fine for lower baud rates (9600 & 115200 bps), but doesn't work at higher baud rates. (i checked the support of baud rates available, so that won't be problem)

It returns me perfect size when the data is upto 16 bits in length, but after that, it doesn't work properly(even though buffer size for receiving is 275).

But the same code works properly for other USRAT.