From 78de4b70edc50df991b12ee0cd13640f8fc12ad9 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 13 Sep 2019 14:00:53 -0400 Subject: [PATCH] Implemented working I2C on F412. --- .../stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c | 2 +- ports/stm32f4/common-hal/busio/I2C.c | 4 +++- ports/stm32f4/peripherals/stm32f4/stm32f412zx/periph.c | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c index 54f444a71a..df312fc29b 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c +++ b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c @@ -247,7 +247,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) PB6 ------> I2C1_SCL PB7 ------> I2C1_SDA */ - GPIO_InitStruct.Pin = I2C1_SCL_Pin|I2C1_SDA_Pin; + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c index c338d1ea0d..3d9f729db1 100644 --- a/ports/stm32f4/common-hal/busio/I2C.c +++ b/ports/stm32f4/common-hal/busio/I2C.c @@ -57,7 +57,9 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, break; #endif } - } else if (mcu_i2c_list[i]->scl_pin == scl) { + } + + if (mcu_i2c_list[i]->scl_pin == scl) { switch (mcu_i2c_list[i]->i2c_index) { case 1: I2Cx_check = I2C1; break; diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/periph.c b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/periph.c index 068c434826..d3c4a8317b 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/periph.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/periph.c @@ -34,6 +34,8 @@ //const mcu_i2c_periph_obj_t periph_I2C2 = I2C(1, NO_ALT, SDA(PB,11), SCL(PB,10)); //const mcu_i2c_periph_obj_t periph_I2C3 = I2C(1, NO_ALT, SDA(PB,9), SCL(PB,8)); +//WARNING: The STM32F412 has a bunch of repeated ones on AF9 so BEWARE + const mcu_i2c_periph_obj_t periph_I2C1_0 = I2C(1, 0, &pin_PB07, &pin_PB06); const mcu_i2c_periph_obj_t periph_I2C1_1 = I2C(1, 1, &pin_PB09, &pin_PB08); const mcu_i2c_periph_obj_t periph_I2C2 = I2C(1, NO_ALT, &pin_PB11, &pin_PB10); //not on LQFP100