cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 SMBUS Stack Unexpected Behaviour

corvusoft
Associate

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 */

corvusoft_0-1716816961234.png

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Bubbles
ST Employee

Hi @corvusoft,

I'm the author of the AN4502. I must admit your assumption makes sense - most people would probably put zero where there is undefined data length. I'm coming from security background and I'm being more cautions when someone is asking for more data than the command is specified to support. So I decided to put maximum allowed data to the command table definition, but did not document that clearly.

I'm sorry for the inconvenience and I'm marking this part of documentation for an update in next release.

Thanks a lot for the time you took writing the feedback. It's much appreciated.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Bubbles
ST Employee

Hi @corvusoft,

I'm the author of the AN4502. I must admit your assumption makes sense - most people would probably put zero where there is undefined data length. I'm coming from security background and I'm being more cautions when someone is asking for more data than the command is specified to support. So I decided to put maximum allowed data to the command table definition, but did not document that clearly.

I'm sorry for the inconvenience and I'm marking this part of documentation for an update in next release.

Thanks a lot for the time you took writing the feedback. It's much appreciated.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.