cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_RxCpltCallback stops getting called, STM32F407G-DISC1

Krippkrupp
Associate II

I'm having an issue with the callback function. For some reason it stops getting called after an uncertain amount of times. Both USART 2 and 3 had this issue initially, but by clearing the overrun error flag in each callback, the callback was called consistently.

This did not help USART 3 though. RX on usart 3 will usually call the callback function twice before the STM needs to be restarted. Sometimes it will only get called once and rarely the callback never gets called.

The difference between USART 2 and 3 are their baudrates at 115200 respectively 3000000 bits/s. Due to the speed of usart 3 I had to reduce the over sampling to 8 samples whilst usart 2 uses 16 samples on over sampling.

This is what my callback looks like.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)	// OK
{
	 if(huart->Instance == USART2) {
		  send_uart("UART2 OK\n");
		  __HAL_UART_CLEAR_OREFLAG(&huart2);
		  HAL_UART_Receive_IT(&huart2, (uint8_t *) getBuffer, 10);
	  } else if (huart->Instance == USART3) {
		  send_uart("UART3 OK\n");
		  __HAL_UART_CLEAR_OREFLAG(&huart3);
		  HAL_UART_Receive_IT(&huart3, (uint8_t *) getBuffer, 100);
	  }
}

Checking the SFRs when debugging shows that the data register for USART3 actually does take in data more than once. But for some reason this doesn't seem to trigger the RxCpltCallback. USART3 is connected to an IMU, which I reset in order to check if the callback is called. I've checked the signals from the IMU with a logic analyser and there's definitely going from the IMU to the STM each time I reset it.

Any idea what could be wrong? Is it better to avoid HAL and write this LL instead?

0 REPLIES 0