STM32CubeMX generated code inconsistency when changing I2C pins to another GPIO Port
Dear All,
I have a nucleo-l010rb board and I am generating a code to read 24C512 EEPROM on I2C.
I have tried CubeMX Firmware Version 1.12.1 and 1.11.3.
When I generate the code for the IDE default PA9 and PA10 following is the HAL_I2C_MspInit function generated in stm32l0xx_hal_msp.c file.
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_GPIOA_CLK_ENABLE();
/**I2C1 GPIO Configuration
PA9 ------> I2C1_SCL
PA10 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_I2C1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C1_CLK_ENABLE();
/* USER CODE BEGIN I2C1_MspInit 1 */
/* USER CODE END I2C1_MspInit 1 */
}
}Now when I want to change from PA9/PA10 to PB8/PB9 for the same I2C1 following is the HAL_I2C_MspInit function generated in stm32l0xx_hal_msp.c file.
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
PB8 ------> I2C1_SCL
*/
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 */
}
}I updated this code manually for PB8/PB9 on the lines of PA9/PA10 and only then I was able to get I2C working.
There is another set of I2C pins as well on PB6/PB7 and for those pins as well the code generated is as generated for PB8/PB9.
I want to know why is there such a discrepancy when I am changing pins for the same peripheral.
This is happening in the latest and the previous version of the Cube repository.
Is this normal? or what am I missing over here.
This wasted my 3-4 days and much more for my junior engineers.
Can anyone from ST enlighten us on this?
Regards