cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Correct way to use HAL_UART_Receive_IT?

seed
Associate III
Posted on September 09, 2015 at 11:02

Hi,

I have read some of the previous related issues, but I am still confused. How do I use the uart interrupts in a correct way (using hal)? I need to receive each single character since don't know the length.

I have modified the UART TwoBoards_ComIT example to a dummy rx application that doesn't do anything except beeing in receive mode. The application will get stuck if I send more than 3 characters(I tested from realTerm). Sending each character one by one works fine.

while(1)

{    

  UartReady = RESET;

  if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, 1) != HAL_OK)

  {

    Error_Handler();

  }

  while (UartReady != SET)

  {

      BSP_LED_On(LED2);

      HAL_Delay(100);

      BSP_LED_Off(LED2);

      HAL_Delay(100);

      BSP_LED_On(LED2);

      HAL_Delay(100);

      BSP_LED_Off(LED2);

      HAL_Delay(500);

  }

}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)

{

    UartReady = SET;

}
3 REPLIES 3
Amel NASRI
ST Employee
Posted on September 09, 2015 at 11:43

Hi Seed,

It is not so clear how ''The application will get stuck if you send more than 3 characters'':

- at which level exactly?

- are there any error flag set in USART registers?

- isn't the problem root cause coming from transmitter side?

-Mayla-

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.

seed
Associate III
Posted on September 09, 2015 at 14:00

Hi,

Sorry for the bad description of the problem. It does not get stuck. I get buffer overflow error reported in HAL_UART_IRQHandler and HAL_UART_ErrorCallback is called. If I send 3 bytes I get buffer overflow using receive size 1, but if I change the code below to receive 3 bytes(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, 3) ) I do not get buffer overflow. I will investigate futher, but I guess it is not reading fast enough and then I guess I need to modify hal implementation? Any suggestions?

/Jonas

seed
Associate III
Posted on September 10, 2015 at 09:47

Hi,

It seems like the hal implementation for uart IT not inted for the use case if you do not know the length of the reciving bytes. I will go for the DMA solution using circular buffer mode then I don't think I need to patch the hal implementation.