A bug in the HAL_I2C_IsDeviceReady function in version 1.11.3
engycz opened this issue · 4 comments
I have found a bug in the HAL_I2C_IsDeviceReady function in version 1.11.3 fec141c.
The problem is in the function HAL_I2C_IsDeviceReady on Line 3332. There is a call to the I2C_WaitOnFlagUntilTimeout function . There is a new test for I2C_IsErrorOccurred and if so (the device is not ready and sent NACK), I2C_IsErrorOccurred waits for STOP and returns HAL_ERROR to I2C_WaitOnFlagUntilTimeout. I2C_WaitOnFlagUntilTimeout returns HAL_ERROR to HAL_I2C_IsDeviceReady and it immediately returns HAL_ERROR to the upcoming function without considering the number of Trials from the function parameter.
How To Reproduce
- Write a data block into the EEPROM using the HAL_I2C_Mem_Write function
- Call HAL_I2C_IsDeviceReady with the Trials parameter set to 1000
- HAL_I2C_IsDeviceReady return value is HAL_ERROR, only one busy test is performed
Version 1.11.2 - multiple attempts to test if the device is ready (not busy)
Version 1.11.3 - only one attempt testing if the device is ready (not busy)
ST Internal Reference: 181377
The change that's checked in does not seem to make sense with respect to the new local variable "status". "Status" is set in several places, but it is not returned and it does not seem to affect the logic. The only use of "status" that I can see is in the comparison on line 3370, where it is compared to HAL_ERROR and reset to HAL_OK if the current number of trials is less than the maximum number of trials. But this doesn't affect anything because "status" isn't used anywhere else. Am I missing something?