/**
* @brief Transmit an amount of data in blocking mode.
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
* the configuration information for SPI module.
* @param pData: pointer to data buffer
* @param Size: amount of data to be sent
* @param Timeout: Timeout duration
* @retval HAL status
*/
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
/* Init tickstart for timeout management*/
tickstart = HAL_GetTick();
/* Timeout management */
if((Timeout == 0U) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout)))
{
errorcode = HAL_TIMEOUT;
goto error;
}
- Setteing the timeout to 1ms, the actual value is <1ms. Some times the value is very close to 0, and leads to error.
- The value of timeout should be >= 2ms, but the instructions for use are not special.
- This issue still exists in the latest version STMCUBEMX V5.5.0. Hope to fix it in a future release.
- An effective solution is to replace "> = Timeout" with "> Timeout".
/* Timeout management */
if((Timeout == 0U) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) > Timeout)))
{
errorcode = HAL_TIMEOUT;
goto error;
}