diff --git a/boards/common/stm32f103c8/include/periph_conf.h b/boards/common/stm32f103c8/include/periph_conf.h index 2f56a63677..297948a65b 100644 --- a/boards/common/stm32f103c8/include/periph_conf.h +++ b/boards/common/stm32f103c8/include/periph_conf.h @@ -155,7 +155,8 @@ static const uart_conf_t uart_config[] = { /** @} */ /** - * @name I2C configuration + * @name I2C configuration + * @note This board may require external pullup resistors for i2c operation. * @{ */ static const i2c_conf_t i2c_config[] = { diff --git a/boards/nucleo-f103rb/include/periph_conf.h b/boards/nucleo-f103rb/include/periph_conf.h index 3863bfbed5..d48875edca 100644 --- a/boards/nucleo-f103rb/include/periph_conf.h +++ b/boards/nucleo-f103rb/include/periph_conf.h @@ -144,7 +144,8 @@ static const uart_conf_t uart_config[] = { /** @} */ /** - * @name I2C configuration + * @name I2C configuration + * @note This board may require external pullup resistors for i2c operation. * @{ */ static const i2c_conf_t i2c_config[] = { diff --git a/cpu/stm32_common/periph/i2c_2.c b/cpu/stm32_common/periph/i2c_2.c index f89ea229db..39ab925982 100644 --- a/cpu/stm32_common/periph/i2c_2.c +++ b/cpu/stm32_common/periph/i2c_2.c @@ -109,6 +109,14 @@ void i2c_init(i2c_t dev) gpio_init(i2c_config[dev].scl_pin, GPIO_OD_PU); gpio_init(i2c_config[dev].sda_pin, GPIO_OD_PU); #ifdef CPU_FAM_STM32F1 + /* This is needed in case the remapped pins are used */ + if (i2c_config[dev].scl_pin == GPIO_PIN(PORT_B, 8) || + i2c_config[dev].sda_pin == GPIO_PIN(PORT_B, 9)) { + /* The remapping periph clock must first be enabled */ + RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; + /* Then the remap can occur */ + AFIO->MAPR |= AFIO_MAPR_I2C1_REMAP; + } gpio_init_af(i2c_config[dev].scl_pin, GPIO_AF_OUT_OD); gpio_init_af(i2c_config[dev].sda_pin, GPIO_AF_OUT_OD); #else