This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM263P4-Q1: Bad status causes data corruption in MCU+ SDK I2C driver

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.

  • Hi Steven,

    Thank you for the detailed bug report.

    Your analysis is sound and actionable. The core problem you've identified is real: if I2C_transfer() times out in interrupt mode before I2C_completeCurrTransfer() executes, the transaction->status field would indeed still hold its initialized value (I2C_STS_SUCCESS) rather than reflecting the actual timeout condition. This would cause the function to return success when it should return timeout — leading exactly to the data corruption you're seeing.

    I will file an internal ticket for this issue with MCU+SDK team to track to closure.

    In the meantime, your proposed conditional fix (only reading transaction->status if the wait completed successfully) is a reasonable defensive approach. The alternative of changing the default initialization to I2C_STS_ERR is also worth reviewing — it would provide safer fail-safe semantics, though it might have broader implications for the initialization logic.

    Best Regards,

    Zackary Fleenor