Skip to main content
Visitor II
November 15, 2022
Question

Since STM32Cube_FW_F7_V1.17.0 the HAL I2C Functions do not work the same. For a huge project that used to work with no issues on STM32Cube_FW_F7_V1.16.2 the I2C Data line goes low and the Firmware reports an HAL_I2C_ERROR_SIZE. Is there a known bug?

  • November 15, 2022
  • 1 reply
  • 618 views

We are using a STM32F76ZI for a consumer device.

The Firmware used to work fine with no errors.

Since STM32Cube_FW_F7_V1.17.0 the I2C communication does not work all the time reporting random I2C Errors. The most common error is HAL_I2C_ERROR_SIZE that never occurred when using STM32Cube_FW_F7_V1.16.2.

I am trying to find out what is triggering this error to then write a small example so that it can be fixed.

The CLK line remains high and the DATA line goes low when the I2C communication stops working. The errror reported by HAL_I2C_GetError(I2C_HandleTypeDef *hi2c) is almost always HAL_I2C_ERROR_SIZE.

If u already know about the issue let me know so i don't waste time on it.

My solution, for now, is to keep the project on STM32Cube_FW_F7_V1.16.2.

    This topic has been closed for replies.

    1 reply

    Visitor II
    November 16, 2022

    The problem seems to be in static HAL_StatusTypeDef I2C_Mem_ISR_IT(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)

    ....

     else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_TCR) != RESET) && \

              (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TCI) != RESET))

     {

       if ((hi2c->XferCount != 0U) && (hi2c->XferSize == 0U))

       {

         if (hi2c->XferCount > MAX_NBYTE_SIZE)

         {

           hi2c->XferSize = MAX_NBYTE_SIZE;

           I2C_TransferConfig(hi2c, (uint16_t)hi2c->Devaddress, (uint8_t)hi2c->XferSize,

                              I2C_RELOAD_MODE, I2C_NO_STARTSTOP);

         }

         else

         {

           hi2c->XferSize = hi2c->XferCount;

           I2C_TransferConfig(hi2c, (uint16_t)hi2c->Devaddress, (uint8_t)hi2c->XferSize,

                              I2C_AUTOEND_MODE, I2C_NO_STARTSTOP);

         }

       }

       else

       {

         /* Wrong size Status regarding TCR flag event */

         /* Call the corresponding callback to inform upper layer of End of Transfer */

         I2C_ITError(hi2c, HAL_I2C_ERROR_SIZE); //!! < this is the trigger hi2c->XferSize = 2; hi2c->XferCount = 1

       }

     }

    ......

    It seems that all transfers above #define MAX_NBYTE_SIZE  255U Bytes do not work anymore.

    The transfer functions take uint16_t Size. So they sould function with longer buffers.

    That explains the random errors. The transfer sizes are not constant at runtime.

    Could be a lock and interrupt problem.

    I found __HAL_UNLOCK(hi2c) with missing __HAL_LOCK(hi2c) in:

    static void I2C_ITSlaveCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)

    static void I2C_ITListenCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)

    static HAL_StatusTypeDef I2C_WaitOnRXNEFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)

    The following Functions work on but do not do not lock hi2c:

    • HAL_StatusTypeDef HAL_I2C_RegisterCallback(I2C_HandleTypeDef *hi2c, HAL_I2C_CallbackIDTypeDef CallbackID, pI2C_CallbackTypeDef pCallback)
    • HAL_StatusTypeDef HAL_I2C_UnRegisterCallback(I2C_HandleTypeDef *hi2c, HAL_I2C_CallbackIDTypeDef CallbackID)
    • HAL_StatusTypeDef HAL_I2C_UnRegisterAddrCallback(I2C_HandleTypeDef *hi2c)

    Hope it helps to narrow out the issue!

    The code is generated by STM32CubeIDE Version 1.10.1 using STM32Cube_FW_F7_V1.17.0

    Target Device is STM32F765ZITx