Issue on I2C HAL generated by CubeMX
Hello,
I think that I found an issue in the HAL code generated by CubeMx 6.6.1 with STM32L4.
I2C HAL in file stm32l4xx_hal_i2c.c line 6855 there is an infinite loop :
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET)
{
/* Check for the Timeout */
if ((HAL_GetTick() - tickstart) > I2C_TIMEOUT_STOPF)
{
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
hi2c->State = HAL_I2C_STATE_READY;
hi2c->Mode = HAL_I2C_MODE_NONE;
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
status = HAL_ERROR;
}
}
when the time out is reached, states are updated, I2C is released but the loop still continue if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET) remains true.
a break is missing. For me a correct implementation can be something like
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET)
{
/* Check for the Timeout */
if ((HAL_GetTick() - tickstart) > I2C_TIMEOUT_STOPF)
{
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
hi2c->State = HAL_I2C_STATE_READY;
hi2c->Mode = HAL_I2C_MODE_NONE;
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
status = HAL_ERROR;
break; //break the while loop
}
}
Thanks
