This is an issue related to the initialization of the X-CUBE-SMBUS middleware during code initialization.
I have encountered an issue when I tried to use CubeMX to generate code. At the start of a new project, I selected I2C (SMBUS-Alert-mode) and used the X-CUBE-SMBUS middleware. However, some issues occurred during code initialization.
In main.c, it does not execute MX_I2C1_SMBUS_Init();. However, this piece of code must be executed before MX_STACK_SMBUS_Init(); from X-CUBE-SMBUS to ensure proper initialization. Of course, this can be done, for example:
void MX_STACK_SMBUS_Init(void)
{
/* USER CODE BEGIN SMBUS_Init 0 */
MX_I2C1_SMBUS_Init();
/* USER CODE END SMBUS_Init 0 */
/* USER CODE BEGIN SMBUS_Init 1 */
/* USER CODE END SMBUS_Init 1 */
context.CMD_table = (st_command_t *) & PMBUS_COMMANDS_TAB[0];
context.CMD_tableSize = PMBUS_COMMANDS_TAB_SIZE;
context.Device = &SMBUS_HANDLE_instance;
context.SRByte = 0x55U;
context.CurrentCommand = NULL;
/* In SMBUS 10-bit addressing is reserved for future use */
assert_param(SMBUS_HANDLE_instance.Init.AddressingMode == SMBUS_ADDRESSINGMODE_7BIT);
context.OwnAddress = SMBUS_HANDLE_instance.Init.OwnAddress1;
/* Address resolved state */
context.StateMachine = SMBUS_SMS_ARP_AR;
/* checking the HAL slave setting */
assert_param(SMBUS_HANDLE_instance.Init.PeripheralMode != SMBUS_PERIPHERAL_MODE_SMBUS_HOST);
context.StateMachine |= SMBUS_SMS_PEC_ACTIVE;
/* checking the HAL is in accord */
assert_param(SMBUS_HANDLE_instance.Init.PacketErrorCheckMode == SMBUS_PEC_ENABLE);
pcontext = &context;
if (STACK_SMBUS_Init( pcontext ) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SMBUS_Init 2 */
/* USER CODE END SMBUS_Init 2 */
}
Is there a better solution to ensure the smooth execution of X-CUBE-SMBUS during its
usage?
EDITED by ST Moderator, to use </> format option for code sample.
