Part Number: AM263P4-Q1
MCU+ SDK 26.00.00.06, AM263P4-Q1
Short version:
I2C_transfer() returns success after a timeout if enableIntr is set. When this happens, this caused our product to read corrupt data from the rxBuffer since the transaction hadn't actually completed.
Long version:
When calling I2C_transfer() with enableIntr = true, line 480 (in MCU+ SDK source/drivers/i2c/v1/i2c_v1.c) waits on object->transferComplete. If that wait times out, line 485 correctly sets retVal = SystemP_TIMEOUT. But line 509 overwrites it with retVal = transaction->status. That member is written only by I2C_completeCurrTransfer() (line 625), which never runs if the transfer doesn't complete, so it still holds I2C_STS_SUCCESS from I2C_Transaction_init() (line 97).
Lines 489-506 (poll mode) handle this correctly but the interrupt path does not.
One possible fix: transaction->status should only be returned if the wait completes:
else
{
// if the wait didn't complete, return the error already in retVal
if (retVal == SystemP_SUCCESS)
{
retVal = transaction->status;
if (retVal == I2C_STS_SUCCESS) retVal = SystemP_SUCCESS;
else if (retVal == I2C_STS_ERR_TIMEOUT) retVal = SystemP_TIMEOUT;
else retVal = SystemP_FAILURE;
}
}
I also wonder if the defaults for I2C_defaultTransaction (line 97) should be changed from I2C_STS_SUCCESS to I2C_STS_ERR, so a transaction that never reaches the completion callback can never return success on accident.