Showing results for 
Search instead for 
Did you mean: 

STM32 SMBUS Stack Unexpected Behaviour


We're performing a block procedure call and struggled with odd SMBus-stack behaviour.

#define BLK_PRC_CALL ((uint8_t)0x90) /*!< Block process call - write, then read, variable sizes */


We incorrectly assumed the stack would read the response length from the slave after the initial write in the HAL_SMBUS_MasterRxCpltCallback.  However, due to the conditional on line eight below, the receive length will be zero if you fail to set cmnd_master_RX_size in the st_command_t structure.  The logic will ignore the returned length in pStackContext->Buffer[1] as it is always greater than cmnd_master_Rx_size (zero when not set).

stm32_SMBUS_stack.c HAL_SMBUS_MasterRxCpltCallback:307


          Reception next
          Usually there is something left to be read, we continue on position 2 of the IO buffer
        pStackContext->StateMachine |= SMBUS_SMS_RECEIVE;
        size = pStackContext->Buffer[1];
        /* Applying upper limit on read size */
        if ( size > pStackContext->CurrentCommand->cmnd_master_Rx_size )
          size = pStackContext->CurrentCommand->cmnd_master_Rx_size;
        HAL_SMBUS_Master_Receive_IT( hsmbus, pStackContext->SlaveAddress, &(pStackContext->Buffer[2]), (uint16_t)size,
                                     SMBUS_LAST_FRAME_NO_PEC  | ( pStackContext->StateMachine & SMBUS_SMS_PEC_ACTIVE ));


The application note (an4502) on page 18 makes no references to this field being mandatory for variable or fixed-length requests.

4.3.4 cmnd_master_Rx_size
Number of bytes transmitted in the slave response.

Is this an oversight in the documentation or a flaw in the SMBus stack?