2024-05-27 06:56 AM - edited 2024-05-27 07:08 AM
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?
Solved! Go to Solution.
2024-08-13 01:56 AM
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.
2024-08-13 01:56 AM
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.