cancel
Showing results for 
Search instead for 
Did you mean: 

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?

DCorn
Associate III
 
2 REPLIES 2
TDK
Guru

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
Associate III

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 */

}