cancel
Showing results for 
Search instead for 
Did you mean: 

Errors in HAL SMBus driver for STM32F4 ?

IMedv
Associate

Hello

II've been working on Host SMBus mode using STM32F417 and HAL F4 version 1.25.

When debugging errors on bus I found next code in function SMBUS_MasterTransmit_BTF (file stm32f4xx_hal_smbus.c line 2020).

/* Call TxCpltCallback() directly if no stop mode is set */
      if (((CurrentXferOptions != SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) || (CurrentXferOptions != SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC)) && ((CurrentXferOptions != SMBUS_LAST_FRAME_NO_PEC) || (CurrentXferOptions != SMBUS_LAST_FRAME_WITH_PEC)) && (CurrentXferOptions != SMBUS_NO_OPTION_FRAME))
      {
        __HAL_SMBUS_DISABLE_IT(hsmbus, SMBUS_IT_EVT | SMBUS_IT_BUF | SMBUS_IT_ERR);
 
        hsmbus->PreviousState = SMBUS_STATE_MASTER_BUSY_TX;
        hsmbus->Mode = HAL_SMBUS_MODE_NONE;
        hsmbus->State = HAL_SMBUS_STATE_READY;
 
#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
        hsmbus->MasterTxCpltCallback(hsmbus);
#else
        HAL_SMBUS_MasterTxCpltCallback(hsmbus);
#endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
      }
      else /* Generate Stop condition then Call TxCpltCallback() */
      {
        /* Disable EVT, BUF and ERR interrupt */
        __HAL_SMBUS_DISABLE_IT(hsmbus, SMBUS_IT_EVT | SMBUS_IT_BUF | SMBUS_IT_ERR);
 
        /* Generate Stop */
        SET_BIT(hsmbus->Instance->CR1, I2C_CR1_STOP);
 
        hsmbus->PreviousState = HAL_SMBUS_STATE_READY;
        hsmbus->State = HAL_SMBUS_STATE_READY;
        hsmbus->Mode = HAL_SMBUS_MODE_NONE;
#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
        hsmbus->MasterTxCpltCallback(hsmbus);
#else
        HAL_SMBUS_MasterTxCpltCallback(hsmbus);
#endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
      }

In my opinion condition in test CurrentXferOptions  (in line 1 in snippet) is always true. And no Stop generated when last frame is detected.

I am right please?

Similar situation is in function SMBUS_MasterTransmit_TXE.

I found one small error calling two times same handler. ( function SMBUS_ITError )

    /* Call user error callback */
    HAL_SMBUS_ErrorCallback(hsmbus);          
#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
    hsmbus->ErrorCallback(hsmbus);
#else
    HAL_SMBUS_ErrorCallback(hsmbus);
#endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */

With regards

Ivan

0 REPLIES 0