Skip to main content
Nandan V
Associate II
July 27, 2021
Solved

[STMCubeIDE] V1.6.1 (using integrated CubeMX) does not properly generate initialisation code for SMBus peripheral

  • July 27, 2021
  • 2 replies
  • 1366 views

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.

This topic has been closed for replies.
Best answer by Amel NASRI

Hi @Community member​ ,

I confirm that issue is fixed when using STM32CubeIDE 1.7.0 and STM32CubeMX 6.3.0. Here the generated code with clock speed parameter set:

static 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.ClockSpeed = 100000;
 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_SLAVE;
 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 */
 
}

-Amel

2 replies

Amel NASRI
Technical Moderator
July 27, 2021

Hi @Community member​ ,

Recently, new versions of STM32CubeIDE and STM32CubeMX are released and several limitations were fixed with these releases.

Could you please check on your side if the problem is still there even with these versions?

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
Nandan V
Nandan VAuthor
Associate II
July 27, 2021

Hi @Amel NASRI​,

I tried with version 1.7.0 which is the latest available version and the issue persists.

Amel NASRI
Technical Moderator
July 27, 2021

Hi @Community member​ ,

That is strange as the issue you are reporting is a known one and in STM32CubeMX release note, we confirm that it was fixed with STM32CubeMX 6.3.0:

0693W00000D0mENQAZ.pngI'll try to check this again on my side. Please make sure that STM32CubeIDE is embedding STM32CubeMX 6.3.0.

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
Amel NASRI
Amel NASRIBest answer
Technical Moderator
July 27, 2021

Hi @Community member​ ,

I confirm that issue is fixed when using STM32CubeIDE 1.7.0 and STM32CubeMX 6.3.0. Here the generated code with clock speed parameter set:

static 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.ClockSpeed = 100000;
 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_SLAVE;
 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 */
 
}

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.