diff --git a/arch/arm/soc/st_stm32/stm32f1/soc_config.c b/arch/arm/soc/st_stm32/stm32f1/soc_config.c index 2d7df713316..bc98d4abb02 100644 --- a/arch/arm/soc/st_stm32/stm32f1/soc_config.c +++ b/arch/arm/soc/st_stm32/stm32f1/soc_config.c @@ -12,39 +12,121 @@ #include #include -static const stm32_pin_func_t pin_pa9_funcs[] = { - [STM32F1_PINMUX_FUNC_PA9_USART1_TX - 1] = - STM32F10X_PIN_CONFIG_AF_PUSH_PULL, -}; +#define PAD(AF, func) \ + [AF - 1] = func -static const stm32_pin_func_t pin_pa10_funcs[] = { - [STM32F1_PINMUX_FUNC_PA10_USART1_RX - 1] = - STM32F10X_PIN_CONFIG_BIAS_HIGH_IMPEDANCE, -}; +#define _PINMUX_PWM(pin, port, chan) \ + PAD(STM32F1_PINMUX_FUNC_##pin##_PWM##port##_CH##chan,\ + STM32F10X_PIN_CONFIG_AF_PUSH_PULL), + +#define _PINMUX_UART_TX(pin, port) \ + PAD(STM32F1_PINMUX_FUNC_##pin##_##port##_TX, \ + STM32F10X_PIN_CONFIG_AF_PUSH_PULL), + +#define _PINMUX_UART_RX(pin, port) \ + PAD(STM32F1_PINMUX_FUNC_##pin##_##port##_RX, \ + STM32F10X_PIN_CONFIG_BIAS_HIGH_IMPEDANCE), + +#define _PINMUX_I2C(pin, port, line) \ + PAD(STM32F1_PINMUX_FUNC_##pin##_I2C##port##_##line, \ + STM32F10X_PIN_CONFIG_AF_OPEN_DRAIN), + +/* Blank pinmux by default */ +#define PINMUX_I2C1(pin, line) +#define PINMUX_I2C2(pin, line) +#define PINMUX_PWM1(pin, chan) +#define PINMUX_UART1_TX(pin) +#define PINMUX_UART1_RX(pin) +#define PINMUX_UART2_TX(pin) +#define PINMUX_UART2_RX(pin) +#define PINMUX_UART3_TX(pin) +#define PINMUX_UART3_RX(pin) + +#ifdef CONFIG_I2C_1 + #undef PINMUX_I2C1 + #define PINMUX_I2C1(pin, line) _PINMUX_I2C(pin, 1, line) +#endif + +#ifdef CONFIG_I2C_2 + #undef PINMUX_I2C2 + #define PINMUX_I2C2(pin, line) _PINMUX_I2C(pin, 2, line) +#endif + +#ifdef CONFIG_PWM_STM32_1 + #undef PINMUX_PWM1 + #define PINMUX_PWM1(pin, chan) _PINMUX_PWM(pin, 1, chan) +#endif + +#ifdef CONFIG_UART_STM32_PORT_1 + #undef PINMUX_UART1_TX + #undef PINMUX_UART1_RX + #define PINMUX_UART1_TX(pin) _PINMUX_UART_TX(pin, USART1) + #define PINMUX_UART1_RX(pin) _PINMUX_UART_RX(pin, USART1) +#endif + +#ifdef CONFIG_UART_STM32_PORT_2 + #undef PINMUX_UART2_TX + #undef PINMUX_UART2_RX + #define PINMUX_UART2_TX(pin) _PINMUX_UART_TX(pin, USART2) + #define PINMUX_UART2_RX(pin) _PINMUX_UART_RX(pin, USART2) +#endif + +#ifdef CONFIG_UART_STM32_PORT_3 + #undef PINMUX_UART3_TX + #undef PINMUX_UART3_RX + #define PINMUX_UART3_TX(pin) _PINMUX_UART_TX(pin, USART3) + #define PINMUX_UART3_RX(pin) _PINMUX_UART_RX(pin, USART3) +#endif + +#define PINMUX_PWM(pin, pwm, chan) PINMUX_##pwm(pin, chan) +#define PINMUX_UART_TX(pin, port) PINMUX_##port##_TX(pin) +#define PINMUX_UART_RX(pin, port) PINMUX_##port##_RX(pin) +#define PINMUX_I2C(pin, i2c, line) PINMUX_##i2c(pin, line) static const stm32_pin_func_t pin_pa2_funcs[] = { - [STM32F1_PINMUX_FUNC_PA2_USART2_TX - 1] = - STM32F10X_PIN_CONFIG_AF_PUSH_PULL, + PINMUX_UART_TX(PA2, UART2) }; static const stm32_pin_func_t pin_pa3_funcs[] = { - [STM32F1_PINMUX_FUNC_PA3_USART2_RX - 1] = - STM32F10X_PIN_CONFIG_BIAS_HIGH_IMPEDANCE, -}; - -static const stm32_pin_func_t pin_pb10_funcs[] = { - [STM32F1_PINMUX_FUNC_PB10_USART3_TX - 1] = - STM32F10X_PIN_CONFIG_AF_PUSH_PULL, -}; - -static const stm32_pin_func_t pin_pb11_funcs[] = { - [STM32F1_PINMUX_FUNC_PB11_USART3_RX - 1] = - STM32F10X_PIN_CONFIG_BIAS_HIGH_IMPEDANCE, + PINMUX_UART_RX(PA3, UART2) }; static const stm32_pin_func_t pin_pa8_funcs[] = { - [STM32F1_PINMUX_FUNC_PA8_PWM1_CH1 - 1] = - STM32F10X_PIN_CONFIG_AF_PUSH_PULL, + PINMUX_PWM(PA8, PWM1, 1) +}; + +static const stm32_pin_func_t pin_pa9_funcs[] = { + PINMUX_UART_TX(PA9, UART1) +}; + +static const stm32_pin_func_t pin_pa10_funcs[] = { + PINMUX_UART_RX(PA10, UART1) +}; + +static const stm32_pin_func_t pin_pb6_funcs[] = { + PINMUX_I2C(PB6, I2C1, SCL) +}; + +static const stm32_pin_func_t pin_pb7_funcs[] = { + PINMUX_I2C(PB6, I2C1, SDA) +}; + +static const stm32_pin_func_t pin_pb8_funcs[] = { + PINMUX_I2C(PB8, I2C1, SCL) +}; + +static const stm32_pin_func_t pin_pb9_funcs[] = { + PINMUX_I2C(PB9, I2C1, SDA) +}; + +static const stm32_pin_func_t pin_pb10_funcs[] = { + PINMUX_UART_TX(PB10, UART3) + PINMUX_I2C(PB10, I2C2, SCL) +}; + +static const stm32_pin_func_t pin_pb11_funcs[] = { + PINMUX_UART_RX(PB11, UART3) + PINMUX_I2C(PB11, I2C2, SDA) }; /** @@ -56,6 +138,10 @@ static struct stm32_pinmux_conf pins[] = { STM32_PIN_CONF(STM32_PIN_PA8, pin_pa8_funcs), STM32_PIN_CONF(STM32_PIN_PA9, pin_pa9_funcs), STM32_PIN_CONF(STM32_PIN_PA10, pin_pa10_funcs), + STM32_PIN_CONF(STM32_PIN_PB6, pin_pb6_funcs), + STM32_PIN_CONF(STM32_PIN_PB7, pin_pb7_funcs), + STM32_PIN_CONF(STM32_PIN_PB8, pin_pb8_funcs), + STM32_PIN_CONF(STM32_PIN_PB9, pin_pb9_funcs), STM32_PIN_CONF(STM32_PIN_PB10, pin_pb10_funcs), STM32_PIN_CONF(STM32_PIN_PB11, pin_pb11_funcs), }; diff --git a/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c b/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c index 5731526eb1d..53c87bd2e17 100644 --- a/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c +++ b/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c @@ -23,7 +23,14 @@ PAD(STM32F4_PINMUX_FUNC_##pin##_##port##_##dir, \ STM32F4X_PIN_CONFIG_AF_PUSH_UP), +#define _PINMUX_I2C(pin, port, line) \ + PAD(STM32F4_PINMUX_FUNC_##pin##_I2C##port##_##line, \ + STM32F4X_PIN_CONFIG_AF_OPEN_UP), + /* Blank pinmux by default */ +#define PINMUX_I2C1(pin, line) +#define PINMUX_I2C2(pin, line) +#define PINMUX_I2C3(pin, line) #define PINMUX_PWM2(pin, chan) #define PINMUX_UART1(pin, dir) #define PINMUX_UART2(pin, dir) @@ -36,6 +43,21 @@ #define PINMUX_UART9(pin, dir) #define PINMUX_UART10(pin, dir) +#ifdef CONFIG_I2C_1 + #undef PINMUX_I2C1 + #define PINMUX_I2C1(pin, line) _PINMUX_I2C(pin, 1, line) +#endif + +#ifdef CONFIG_I2C_2 + #undef PINMUX_I2C2 + #define PINMUX_I2C2(pin, line) _PINMUX_I2C(pin, 2, line) +#endif + +#ifdef CONFIG_I2C_3 + #undef PINMUX_I2C3 + #define PINMUX_I2C3(pin, line) _PINMUX_I2C(pin, 3, line) +#endif + #ifdef CONFIG_PWM_STM32_2 #undef PINMUX_PWM2 #define PINMUX_PWM2(pin, chan) _PINMUX_PWM(pin, 2, chan) @@ -93,6 +115,7 @@ #define PINMUX_PWM(pin, pwm, chan) PINMUX_##pwm(pin, chan) #define PINMUX_UART(pin, port, dir) PINMUX_##port(pin, dir) +#define PINMUX_I2C(pin, i2c, line) PINMUX_##i2c(pin, line) /* Port A */ static const stm32_pin_func_t pin_pa0_funcs[] = { @@ -114,6 +137,7 @@ static const stm32_pin_func_t pin_pa3_funcs[] = { static const stm32_pin_func_t pin_pa8_funcs[] = { PINMUX_UART(PA8, UART7, RX) + PINMUX_I2C(PA8, I2C3, SCL) }; static const stm32_pin_func_t pin_pa9_funcs[] = { @@ -143,10 +167,12 @@ static const stm32_pin_func_t pin_pa15_funcs[] = { static const stm32_pin_func_t pin_pb3_funcs[] = { PINMUX_UART(PB3, UART1, RX) PINMUX_UART(PB3, UART7, RX) + PINMUX_I2C(PB3, I2C2, SDA) }; static const stm32_pin_func_t pin_pb4_funcs[] = { PINMUX_UART(PB4, UART7, TX) + PINMUX_I2C(PB4, I2C3, SDA) }; static const stm32_pin_func_t pin_pb5_funcs[] = { @@ -156,26 +182,32 @@ static const stm32_pin_func_t pin_pb5_funcs[] = { static const stm32_pin_func_t pin_pb6_funcs[] = { PINMUX_UART(PB6, UART1, TX) PINMUX_UART(PB6, UART5, TX) + PINMUX_I2C(PB6, I2C1, SCL) }; static const stm32_pin_func_t pin_pb7_funcs[] = { PINMUX_UART(PB7, UART1, RX) + PINMUX_I2C(PB7, I2C1, SDA) }; static const stm32_pin_func_t pin_pb8_funcs[] = { PINMUX_UART(PB8, UART5, RX) + PINMUX_I2C(PB8, I2C1, SCL) }; static const stm32_pin_func_t pin_pb9_funcs[] = { PINMUX_UART(PB9, UART5, TX) + PINMUX_I2C(PB9, I2C1, SDA) }; static const stm32_pin_func_t pin_pb10_funcs[] = { PINMUX_UART(PB10, UART3, TX) + PINMUX_I2C(PB10, I2C2, SCL) }; static const stm32_pin_func_t pin_pb11_funcs[] = { PINMUX_UART(PB11, UART3, RX) + PINMUX_I2C(PB11, I2C2, SDA) }; static const stm32_pin_func_t pin_pb12_funcs[] = { @@ -199,6 +231,10 @@ static const stm32_pin_func_t pin_pc7_funcs[] = { PINMUX_UART(PC7, UART6, RX) }; +static const stm32_pin_func_t pin_pc9_funcs[] = { + PINMUX_I2C(PC9, I2C3, SDA) +}; + static const stm32_pin_func_t pin_pc10_funcs[] = { PINMUX_UART(PC10, UART3, TX) }; @@ -274,7 +310,16 @@ static const stm32_pin_func_t pin_pe8_funcs[] = { PINMUX_UART(PE8, UART7, TX) }; +#ifdef GPIOF /* Port F */ +static const stm32_pin_func_t pin_pf0_funcs[] = { + PINMUX_I2C(PF0, I2C2, SDA) +}; + +static const stm32_pin_func_t pin_pf1_funcs[] = { + PINMUX_I2C(PF1, I2C2, SCL) +}; + static const stm32_pin_func_t pin_pf6_funcs[] = { PINMUX_UART(PF6, UART7, RX) }; @@ -290,7 +335,9 @@ static const stm32_pin_func_t pin_pf8_funcs[] = { static const stm32_pin_func_t pin_pf9_funcs[] = { PINMUX_UART(PF9, UART8, TX) }; +#endif +#ifdef GPIOG /* Port G */ static const stm32_pin_func_t pin_pg0_funcs[] = { PINMUX_UART(PG0, UART9, RX) @@ -315,6 +362,23 @@ static const stm32_pin_func_t pin_pg12_funcs[] = { static const stm32_pin_func_t pin_pg14_funcs[] = { PINMUX_UART(PG14, UART6, TX) }; +#endif + +/* Port H */ +static const stm32_pin_func_t pin_ph4_funcs[] = { + PINMUX_I2C(PH4, I2C2, SCL) +}; + +static const stm32_pin_func_t pin_ph5_funcs[] = { + PINMUX_I2C(PH5, I2C2, SDA) +}; + +static const stm32_pin_func_t pin_ph7_funcs[] = { + PINMUX_I2C(PH7, I2C3, SCL) +}; +static const stm32_pin_func_t pin_ph8_funcs[] = { + PINMUX_I2C(PH8, I2C3, SDA) +}; /** * @brief pin configuration @@ -349,6 +413,7 @@ static const struct stm32_pinmux_conf pins[] = { STM32_PIN_CONF(STM32_PIN_PC5, pin_pc5_funcs), STM32_PIN_CONF(STM32_PIN_PC6, pin_pc6_funcs), STM32_PIN_CONF(STM32_PIN_PC7, pin_pc7_funcs), + STM32_PIN_CONF(STM32_PIN_PC9, pin_pc9_funcs), STM32_PIN_CONF(STM32_PIN_PC10, pin_pc10_funcs), STM32_PIN_CONF(STM32_PIN_PC11, pin_pc11_funcs), STM32_PIN_CONF(STM32_PIN_PC12, pin_pc12_funcs), @@ -372,12 +437,17 @@ static const struct stm32_pinmux_conf pins[] = { STM32_PIN_CONF(STM32_PIN_PE7, pin_pe7_funcs), STM32_PIN_CONF(STM32_PIN_PE8, pin_pe8_funcs), +#ifdef GPIOF /* Port F */ + STM32_PIN_CONF(STM32_PIN_PF0, pin_pf0_funcs), + STM32_PIN_CONF(STM32_PIN_PF1, pin_pf1_funcs), STM32_PIN_CONF(STM32_PIN_PF6, pin_pf6_funcs), STM32_PIN_CONF(STM32_PIN_PF7, pin_pf7_funcs), STM32_PIN_CONF(STM32_PIN_PF8, pin_pf8_funcs), STM32_PIN_CONF(STM32_PIN_PF9, pin_pf9_funcs), +#endif +#ifdef GPIOG /* Port G */ STM32_PIN_CONF(STM32_PIN_PG0, pin_pg0_funcs), STM32_PIN_CONF(STM32_PIN_PG1, pin_pg1_funcs), @@ -385,6 +455,13 @@ static const struct stm32_pinmux_conf pins[] = { STM32_PIN_CONF(STM32_PIN_PG11, pin_pg11_funcs), STM32_PIN_CONF(STM32_PIN_PG12, pin_pg12_funcs), STM32_PIN_CONF(STM32_PIN_PG14, pin_pg14_funcs), +#endif + + /* Port H */ + STM32_PIN_CONF(STM32_PIN_PH4, pin_ph4_funcs), + STM32_PIN_CONF(STM32_PIN_PH5, pin_ph5_funcs), + STM32_PIN_CONF(STM32_PIN_PH7, pin_ph7_funcs), + STM32_PIN_CONF(STM32_PIN_PH8, pin_ph8_funcs), }; int stm32_get_pin_config(int pin, int func) diff --git a/drivers/pinmux/stm32/pinmux_stm32f1.h b/drivers/pinmux/stm32/pinmux_stm32f1.h index 8d3ddad458a..ef986a87bed 100644 --- a/drivers/pinmux/stm32/pinmux_stm32f1.h +++ b/drivers/pinmux/stm32/pinmux_stm32f1.h @@ -20,8 +20,14 @@ #define STM32F1_PINMUX_FUNC_PD5_USART2_TX STM32_PINMUX_FUNC_ALT_2 #define STM32F1_PINMUX_FUNC_PD6_USART2_RX STM32_PINMUX_FUNC_ALT_2 +#define STM32F1_PINMUX_FUNC_PB6_I2C1_SCL STM32_PINMUX_FUNC_ALT_1 +#define STM32F1_PINMUX_FUNC_PB7_I2C1_SDA STM32_PINMUX_FUNC_ALT_1 +#define STM32F1_PINMUX_FUNC_PB8_I2C1_SCL STM32_PINMUX_FUNC_ALT_2 +#define STM32F1_PINMUX_FUNC_PB9_I2C1_SDA STM32_PINMUX_FUNC_ALT_2 #define STM32F1_PINMUX_FUNC_PB10_USART3_TX STM32_PINMUX_FUNC_ALT_1 #define STM32F1_PINMUX_FUNC_PB11_USART3_RX STM32_PINMUX_FUNC_ALT_1 +#define STM32F1_PINMUX_FUNC_PB10_I2C2_SCL STM32_PINMUX_FUNC_ALT_1 +#define STM32F1_PINMUX_FUNC_PB11_I2C2_SDA STM32_PINMUX_FUNC_ALT_1 #define STM32F1_PINMUX_FUNC_PA8_PWM1_CH1 STM32_PINMUX_FUNC_ALT_2 diff --git a/drivers/pinmux/stm32/pinmux_stm32f3.h b/drivers/pinmux/stm32/pinmux_stm32f3.h index b80d3b1a042..f38f951dc47 100644 --- a/drivers/pinmux/stm32/pinmux_stm32f3.h +++ b/drivers/pinmux/stm32/pinmux_stm32f3.h @@ -36,4 +36,7 @@ #define STM32F3_PINMUX_FUNC_PB10_USART3_TX STM32_PINMUX_FUNC_ALT_7 #endif +#define STM32F3_PINMUX_FUNC_PB8_I2C1_SCL STM32_PINMUX_FUNC_ALT_4 +#define STM32F3_PINMUX_FUNC_PB9_I2C1_SDA STM32_PINMUX_FUNC_ALT_4 + #endif /* _STM32F3_PINMUX_H_ */ diff --git a/drivers/pinmux/stm32/pinmux_stm32f4.h b/drivers/pinmux/stm32/pinmux_stm32f4.h index 818b32aaedc..0e9474bfb8f 100644 --- a/drivers/pinmux/stm32/pinmux_stm32f4.h +++ b/drivers/pinmux/stm32/pinmux_stm32f4.h @@ -21,6 +21,7 @@ #define STM32F4_PINMUX_FUNC_PA3_USART2_RX STM32_PINMUX_FUNC_ALT_7 +#define STM32F4_PINMUX_FUNC_PA8_I2C3_SCL STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PA8_UART7_RX STM32_PINMUX_FUNC_ALT_8 #define STM32F4_PINMUX_FUNC_PA9_USART1_TX STM32_PINMUX_FUNC_ALT_7 @@ -39,22 +40,30 @@ /* Port B */ #define STM32F4_PINMUX_FUNC_PB3_USART1_RX STM32_PINMUX_FUNC_ALT_7 #define STM32F4_PINMUX_FUNC_PB3_UART7_RX STM32_PINMUX_FUNC_ALT_8 +#define STM32F4_PINMUX_FUNC_PB3_I2C2_SDA STM32_PINMUX_FUNC_ALT_9 #define STM32F4_PINMUX_FUNC_PB4_UART7_TX STM32_PINMUX_FUNC_ALT_8 +#define STM32F4_PINMUX_FUNC_PB4_I2C3_SDA STM32_PINMUX_FUNC_ALT_9 #define STM32F4_PINMUX_FUNC_PB5_UART5_RX STM32_PINMUX_FUNC_ALT_11 +#define STM32F4_PINMUX_FUNC_PB6_I2C1_SCL STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PB6_USART1_TX STM32_PINMUX_FUNC_ALT_7 #define STM32F4_PINMUX_FUNC_PB6_UART5_TX STM32_PINMUX_FUNC_ALT_11 +#define STM32F4_PINMUX_FUNC_PB7_I2C1_SDA STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PB7_USART1_RX STM32_PINMUX_FUNC_ALT_7 +#define STM32F4_PINMUX_FUNC_PB8_I2C1_SCL STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PB8_UART5_RX STM32_PINMUX_FUNC_ALT_11 +#define STM32F4_PINMUX_FUNC_PB9_I2C1_SDA STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PB9_UART5_TX STM32_PINMUX_FUNC_ALT_11 +#define STM32F4_PINMUX_FUNC_PB10_I2C2_SCL STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PB10_USART3_TX STM32_PINMUX_FUNC_ALT_7 +#define STM32F4_PINMUX_FUNC_PB11_I2C2_SDA STM32_PINMUX_FUNC_ALT_4 #define STM32F4_PINMUX_FUNC_PB11_USART3_RX STM32_PINMUX_FUNC_ALT_7 #define STM32F4_PINMUX_FUNC_PB12_UART5_RX STM32_PINMUX_FUNC_ALT_11 @@ -68,6 +77,8 @@ #define STM32F4_PINMUX_FUNC_PC7_USART6_RX STM32_PINMUX_FUNC_ALT_8 +#define STM32F4_PINMUX_FUNC_PC9_I2C3_SDA STM32_PINMUX_FUNC_ALT_4 + #define STM32F4_PINMUX_FUNC_PC10_USART3_TX STM32_PINMUX_FUNC_ALT_7 #define STM32F4_PINMUX_FUNC_PC11_USART3_RX STM32_PINMUX_FUNC_ALT_7 @@ -108,6 +119,10 @@ #define STM32F4_PINMUX_FUNC_PE8_UART7_TX STM32_PINMUX_FUNC_ALT_8 /* Port F */ +#define STM32F4_PINMUX_FUNC_PF0_I2C2_SDA STM32_PINMUX_FUNC_ALT_4 + +#define STM32F4_PINMUX_FUNC_PF1_I2C2_SCL STM32_PINMUX_FUNC_ALT_4 + #define STM32F4_PINMUX_FUNC_PF6_UART7_RX STM32_PINMUX_FUNC_ALT_8 #define STM32F4_PINMUX_FUNC_PF7_UART7_TX STM32_PINMUX_FUNC_ALT_8 @@ -129,4 +144,14 @@ #define STM32F4_PINMUX_FUNC_PG14_USART6_TX STM32_PINMUX_FUNC_ALT_8 +/* Port H */ + +#define STM32F4_PINMUX_FUNC_PH4_I2C2_SCL STM32_PINMUX_FUNC_ALT_4 + +#define STM32F4_PINMUX_FUNC_PH5_I2C2_SDA STM32_PINMUX_FUNC_ALT_4 + +#define STM32F4_PINMUX_FUNC_PH7_I2C3_SCL STM32_PINMUX_FUNC_ALT_4 + +#define STM32F4_PINMUX_FUNC_PH8_I2C3_SDA STM32_PINMUX_FUNC_ALT_4 + #endif /* _STM32F4_PINMUX_H_ */