Bug in stm32f3xx_hal_i2c.c
CubeIDE version 1.4.1
STM32Cube FW_F3 V1.11.0
I had the problem, that my I2C communication (alternating rx/tx on slave) works on the first rx/tx cycle but fails on the second tx.
The transmission skips the first byte and thus sending n-1 bytes. I found out that, after calling I2C_ITSlaveCplt() on line 4744, the execution of the function continues and decrements the XferCount on line 4802.
I fixed the driver as follows (original line 4740-4745):
/* Check if STOPF is set */
if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_STOPF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_STOPI) != RESET))
{
/* Call I2C Slave complete process */
I2C_ITSlaveCplt(hi2c, tmpITFlags);
}/* Check if STOPF is set */
if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_STOPF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_STOPI) != RESET))
{
/* Call I2C Slave complete process */
I2C_ITSlaveCplt(hi2c, tmpITFlags);
// BEGIN BUG FIX
__HAL_UNLOCK(hi2c);
return HAL_OK;
// END BUG FIX
}