2025-05-23 6:40 PM
Hi, newbie here - I have some experience with the f4 series, but am working on a small project for which I would like to try a stm32u0 MCU.
Looking at the stm32u031 20-pin TSSOP, I am confused by something. When I load this MCU in cubeMX, and tick on I2C 1, I see a single pin 'light up' for both SCL and SDA. The datasheet implies I should be able to choose a pin with an alternate function for one of these, but I can't figure out how I might do this....I see pin PA8 seems to have an alternate mapping to PA9, which seems like it might work for i2cSCL, but I don't know how to select it.
I feel like an ***, but I'm unsure how to configure this using cubeMX, or how one is meant to work with these apparently-double-functioned pins?
Thanks!
Solved! Go to Solution.
2025-05-23 7:24 PM
The best thing to do is left click on the pin and do Reset_state so that both pins are not selected. Then left click again to choose either PB8 or PB9 and the appropriate SCL/SCL assigned to it.
For pin#1, you can choose if it's SCL or SDA.
If you choose pin# 1 as SCL (PB8), then pin# 19 (PB7) will be SDA
If you choose pin# 1 as SDA (PB9) , then pin# 18 (PB6) will be SCL
You can always do a search for a specific pin which will highlight it. In this case I've chosen PB8 as SCL. so now I'm looking for I2C1_SDA, which shows PB7 is SDA. So you can left click that pin and select I2C1_SDA
2025-05-23 7:24 PM
The best thing to do is left click on the pin and do Reset_state so that both pins are not selected. Then left click again to choose either PB8 or PB9 and the appropriate SCL/SCL assigned to it.
For pin#1, you can choose if it's SCL or SDA.
If you choose pin# 1 as SCL (PB8), then pin# 19 (PB7) will be SDA
If you choose pin# 1 as SDA (PB9) , then pin# 18 (PB6) will be SCL
You can always do a search for a specific pin which will highlight it. In this case I've chosen PB8 as SCL. so now I'm looking for I2C1_SDA, which shows PB7 is SDA. So you can left click that pin and select I2C1_SDA
2026-05-14 4:04 AM
Hello,
I am also struggling with the pin mapping issue a specially on the STM32U031F8 20pin chip revision A.
I am using the STM32CubeIDE Version: 1.18.1 and the newest STM32U0 libs. The configuration is done with the STM32CubeMX tool.
The goal is to configure the I2C bus on a MCU where no other hardware is currently used. What I see is following:
* Pin mapping issue with the I2C bus on the 20 pin STM32U031F8 !
*
* Working version:
* PB8 I2C2_SCL
* PA6 I2C2_SDA
*
* Following combination wasn't working:
* PA6 I2C3_SDA
* PA7 I2C3_SCL
*
* PA6 I2C2_SDA
* PA7 I2C2_SCL
*
* PB7 I2C2_SDA
* PB8 I2C2_SCL
The not working versions shows green configured SDA and SCL pins on the STM32CubeMX editor.
The result is that the SDA,SCL pins are either grounded or with other configuration the SCL is working only.
According the actual datasheet these configurations with AFx are legitim and possible.
Where is the problem?
Has the STM32U031F8 not public bugs?
I am doing something wrong?
2026-05-14 4:08 AM
To complete the picture I am posting one of the not working generated I2C configuration:
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hi2c->Instance==I2C2)
{
/* USER CODE BEGIN I2C2_MspInit 0 */
/* USER CODE END I2C2_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**I2C2 GPIO Configuration
PA6 ------> I2C2_SDA
PA7 ------> I2C2_SCL
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF3_I2C2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C2_CLK_ENABLE();
/* I2C2 interrupt Init */
HAL_NVIC_SetPriority(I2C2_3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(I2C2_3_IRQn);
/* USER CODE BEGIN I2C2_MspInit 1 */
/* USER CODE END I2C2_MspInit 1 */
}
}
2026-05-14 4:13 AM
The configuration picture