Skip to main content
DCorn
Associate II
February 23, 2022
Question

I am using STM32H7 SPI4 with RTOS. when I call errorcode = HAL_SPI_Receive(&hspi4, pbRecv,ulLen,100); I occasionally returns an error The error is OVR and time out. How can you get OVR when polling SPI?

  • February 23, 2022
  • 2 replies
  • 1009 views

..

This topic has been closed for replies.

2 replies

TDK
February 23, 2022

Receive-only mode sends the clock continuously and code is not fast enough to keep up at high data rates. Instead, use HAL_SPI_TransmitReceive with dummy data to receive an exact number of bytes.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DCorn
DCornAuthor
Associate II
February 23, 2022

That was not the solution the SPI is configured as full Master so when you can HAL_SPI_Receive it then calls HAL_SPI_TransmitReceive. I found out by testing the HAL function is not Thread safe. I changed the code to use HAL_SPI_TransmitReceive_IT. It also has the same issue. If you add code to stop RTOS interrupting the code it works

void SPI4_IRQHandler(void)

{

 /* USER CODE BEGIN SPI4_IRQn 0 */

   

   UBaseType_t uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();

 /* USER CODE END SPI4_IRQn 0 */

 HAL_SPI_IRQHandler(&hspi4);

 taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);

 /* USER CODE BEGIN SPI4_IRQn 1 */

 /* USER CODE END SPI4_IRQn 1 */

}