cancel
Showing results for 
Search instead for 
Did you mean: 

How are the I2C3 pins being initialized by the visual configurator?

Rodo
Senior

Hi all,

I have a STM32F746 disco board and I'm trying to understand what the visual configurator (VC) does and doesn't do. I created an blank demo project for the board and I answer yes to the "initialize the board to default..." (or something like that).

There is only one function created by the VC: MX_GPIO_Init(). I can see all the code inside it that initializes various pins. The I2C3 pins (SDA and SCL) are there too. The VC does *not* have the I2C3 enabled.

Then, I enabled the I2C3 in the VC and saved. Now the code for the pins for the I2C3 is no longer inside MX_GPIO_Init(). In fact, is nowhere to be found ... by me... but the I2C3 works fine.

Where is the code to initialize the pins for the I2C3 when I enable I2C3 in VC?


BTW I'm calling the VC the window that opens up in STM32CubeIDE when you click on the ".ioc" file. Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Principal III

Hi,

look in src file stm32xxxx_hal_msp.c :

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(hi2c->Instance==I2C1)
  {
  /* USER CODE BEGIN I2C1_MspInit 0 */

  /* USER CODE END I2C1_MspInit 0 */

    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**I2C1 GPIO Configuration
    PB6     ------> I2C1_SCL
    PB7     ------> I2C1_SDA
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* Peripheral clock enable */
    __HAL_RCC_I2C1_CLK_ENABLE();
  /* USER CODE BEGIN I2C1_MspInit 1 */

  /* USER CODE END I2C1_MspInit 1 */
  }

}

+ dont forget to set scl+sda pins pullups ! + use extra pullups for higher speed.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
STTwo-32
ST Employee

Hello @Rodo 

First,  what you are calling VC is CubeMX. You can use it inside Cube to do some configurations and modifications on the interfaces initialisation, configuration,... It can also do the same thing for other IDEs (IAR, keil) by using it direclly to start your project. Then, it will generate the code on the IDE that you are going to use.

For the I2C3, when you cnonfigure this IP or ut is cinfigured by default, the Pin initialisation is inside the

HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) 

But the I2C3 configurations are iside the MX_I2C3_Init() fonction.

Best Regards.

STTwo-32 

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.

AScha.3
Principal III

Hi,

look in src file stm32xxxx_hal_msp.c :

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(hi2c->Instance==I2C1)
  {
  /* USER CODE BEGIN I2C1_MspInit 0 */

  /* USER CODE END I2C1_MspInit 0 */

    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**I2C1 GPIO Configuration
    PB6     ------> I2C1_SCL
    PB7     ------> I2C1_SDA
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* Peripheral clock enable */
    __HAL_RCC_I2C1_CLK_ENABLE();
  /* USER CODE BEGIN I2C1_MspInit 1 */

  /* USER CODE END I2C1_MspInit 1 */
  }

}

+ dont forget to set scl+sda pins pullups ! + use extra pullups for higher speed.

If you feel a post has answered your question, please click "Accept as Solution".