Cube IDE does not generate I2C Alternate settings for STM32G061.
After spending hours trying to figure out why my I2C lines weren't working and trying my code on a STM32G031 development board, I've noticed that Cube IDE does not generate the following line in the file: stm32g0xx_hal_msp.c.
GPIO_InitStruct.Alternate = GPIO_AF6_I2C1;The generated code for the file: stm32g0xx_hal_msp.c for the STM32G031 chip is as follows:
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_LOW;
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 */
}
}Whereas this isn't the same when configuring the STM32G061 chip with the exact same settings as seen with the STM32G031 chip. With this line missing, the I2C bus always timeouts.
STM32G061's I2C init Function:
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_LOW;
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 */
}
}Is this a generation bug or am I not doing something correctly?
