cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Receive() doesn't timeout

Bryan Guo
Associate II
Posted on April 26, 2017 at 16:18

Hi all,

I found my call HAL_UART_Receive() doesn't timeout.  Do you have any suggestion what I forget configure?

In CubeMX, I add uart2 and tim2 and I add my timer callback as this.

/* USER CODE BEGIN 4 */

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){

sprintf(aTxBuffer,'\r\nSTM32CubeMX rocks %d times \t', ++nbtime);

HAL_UART_Transmit(&huart2,(uint8_t *) aTxBuffer, strlen(aTxBuffer), 5000);

//printf('input:\r\n');

HAL_UART_Receive(&huart2,(uint8_t *) aRxBuffer, 10, 500);

HAL_UART_Transmit(&huart2,(uint8_t *) ack, 11, 5000);

}

/* USER CODE END 4 */

If I input 10 characters, the code works well.  However, if I don't input any thing,  

HAL_UART_Receive() will not return. I believe it should return in 5000 ms. Do you have any idea about this?

PS: I'm using STM32L072. 

#hal_uart_receive() #uart
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 26, 2017 at 17:40

Calling blocking functions in interrupt context is always a really bad plan.

You are going to need to ensure that the ticker interrupt used for the timeout preempts anything that is relying on it.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

1 REPLY 1
Posted on April 26, 2017 at 17:40

Calling blocking functions in interrupt context is always a really bad plan.

You are going to need to ensure that the ticker interrupt used for the timeout preempts anything that is relying on it.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..