I2C HAL lock state not properly updated
Hello,
While I was tracking an issue on I2C bus, I found something that seems to be unconsistent in HAL file stm32l4_hal_i2c.c
1 - routines I2C_WaitOn_____UntilTimeout() are called after locking the bus with __HAL_LOCK(hi2c) macro
2- these routines update the lock state in case of error, return and this error to the caller finaly the HAL ends. The caller in that case (error) do not update lock state which is updated by I2C_WaitOn_____UntilTimeout() (=unlock before returning error)
but I found that all path do not update the lock state. for example below the first error do not unlock the bus :
static HAL_StatusTypeDef I2C_WaitOnSTOPFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout,
uint32_t Tickstart)
{
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET)
{
/* Check if an error is detected */
if (I2C_IsErrorOccurred(hi2c, Timeout, Tickstart) != HAL_OK)
{
return HAL_ERROR;
}
/* Check for the Timeout */
if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
{
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
hi2c->State = HAL_I2C_STATE_READY;
hi2c->Mode = HAL_I2C_MODE_NONE;
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
return HAL_ERROR;
}
}
return HAL_OK;
}
My understanding is that
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
is missing before returning the error to the caller. Is it correct?
Regards
