cancel
Showing results for 
Search instead for 
Did you mean: 

Why SPI_WaitOnFlagUntilTimeout fails and return timeout?

ilias
Associate II

Hello,

I am using STM32F401 and specific SPI_TxCloseIRQHandler :

 * @version V1.1.0

 * @date   19-June-2014

As slave, this function fails in this:

/* Wait until Busy flag is reset before disabling SPI */

   if(SPI_WaitOnFlagUntilTimeout(hspi, SPI_FLAG_BSY, SET, SPI_TIMEOUT_VALUE) != HAL_OK)

   {

     hspi->ErrorCode |= HAL_SPI_ERROR_FLAG;

   }

I have mentioned that this does not always happen. So I, don't understand why sometimes happens.

2 REPLIES 2
Imen.D
ST Employee

Hello @ilias​ ,

I think you are using an old HAL version.

Please update the package firmware and use the last version STM32Cube_FW_F4_V1.23.0

Kind Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
ilias
Associate II

Hello Imen.

Thanks for your answer. I have just updated the HaL drivers, but I am still getting the same error. Now the HAL_TIMEOUT is occurred from the SPI_WaitFlagStateUntilTimeout().

Bare in mind that that this error occasionally happens and not always.

After the complete of a transmission from Slave's part, SPI_TxCloseIRQHandler is called.

It waits until TXE is set, and then disable TXE and ERR interrupts.

Then it checks the end of transmission and this is the point that fails (sometimes).

   uint32_t tickstart = 0U;

 __IO uint32_t count = SPI_DEFAULT_TIMEOUT * (SystemCoreClock / 24U / 1000U);

 /* Init tickstart for timeout management*/

 tickstart = HAL_GetTick();

 

 /* Wait until TXE flag is set */

 do

 {

   if(count-- == 0U)

   {

     SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);

     break;

   }

 }

 while((hspi->Instance->SR & SPI_FLAG_TXE) == RESET);

 /* Check the end of the transaction */

 if(SPI_CheckFlag_BSY(hspi, SPI_DEFAULT_TIMEOUT, tickstart)!=HAL_OK)

 {

   SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);

 }