[STMCubeIDE] V1.6.1 (using integrated CubeMX) does not properly generate initialisation code for SMBus peripheral
I am using an STM32F407 controller and have configured I2C1 as SMBus.
However after configuration in the IDE, the initialization code generated for I2C1 is as follows:
void MX_I2C1_SMBUS_Init(void)
{
/* USER CODE BEGIN I2C1_Init 0 */
/* USER CODE END I2C1_Init 0 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END I2C1_Init 1 */
hsmbus1.Instance = I2C1;
hsmbus1.Init.OwnAddress1 = 0;
hsmbus1.Init.AddressingMode = SMBUS_ADDRESSINGMODE_7BIT;
hsmbus1.Init.DualAddressMode = SMBUS_DUALADDRESS_DISABLE;
hsmbus1.Init.OwnAddress2 = 0;
hsmbus1.Init.GeneralCallMode = SMBUS_GENERALCALL_DISABLE;
hsmbus1.Init.NoStretchMode = SMBUS_NOSTRETCH_DISABLE;
hsmbus1.Init.PacketErrorCheckMode = SMBUS_PEC_DISABLE;
hsmbus1.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_HOST;
if (HAL_SMBUS_Init(&hsmbus1) != HAL_OK)
{
Error_Handler();
}
/** configuration Alert Mode
*/
if (HAL_SMBUS_EnableAlert_IT(&hsmbus1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}On running the code in debug mode the following assertion fails:
assert_param(IS_SMBUS_CLOCK_SPEED(hsmbus->Init.ClockSpeed));On closer inspection, 'ClockSpeed' was zero.
In the above function, 'MX_I2C1_SMBUS_Init', the clock speed is not set and I believe it should've been done by the IDE.
I have to manually set the clock speed to get this to work which is not evident.
However, it can't because it is not receiving this input from the user while configuring the peripheral.
Please correct me if I am doing something wrong or missing a step here.
Otherwise, please fix this issue. It is incredibly confusing.