I2C Bug in STM32CubeF2 Firmware Package V1.4.0
Hi folks,
my application crashes occasionally with the above mentioned firmware package when data is transmitted to I2C devices.
The crash is caused by following code in HAL_I2C_Master_Transmit:
while(hi2c->XferSize > 0U)
{
/* Wait until TXE flag is set */
if(I2C_WaitOnTXEFlagUntilTimeout(hi2c, Timeout, tickstart) != HAL_OK)
{
...
}
/* Write data to DR */
hi2c->Instance->DR = (*hi2c->pBuffPtr++);
hi2c->XferCount--;
hi2c->
XferSize
--;if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (
Size
!= 0U)){
You can get here when
I2C_FLAG_BTF
is set due to delay (interrupt) andXferSize
== 0 because the wrong var (Size
) is checked. This results inXferSize
wrapping around to 0xffff. The transmit loops continues and usually thepBuffPtr
runs beyond bounds causing a bus error./* Write data to DR */
hi2c->Instance->DR = (*hi2c->pBuffPtr++);
hi2c->XferCount--;
hi2c->XferSize--;
}
This code fragment can be found several times in stm32f2xx_hal_i2c.c.
I temporarily went back to Rev 1.3.0.
Christian