From 55c477bb2c344aeed6eccdf4520293878580e5fd Mon Sep 17 00:00:00 2001 From: Florian Vaussard Date: Mon, 1 May 2017 15:22:06 +0200 Subject: [PATCH] pinmux: stm32f4: Compile out unused pinmux It is useless to include the pinmux for a peripheral if it is not enabled in the Kconfig. This is unnecessary and it increases the size of the binary. Define macros that will default to void if the associated Kconfig is not enabled. Change-Id: I0857fcef335c75b8bb6d537fd859f93d5be4a228 Signed-off-by: Florian Vaussard --- arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c | 45 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c b/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c index 3033deeccb7..a17aba57287 100644 --- a/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c +++ b/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c @@ -15,32 +15,63 @@ #define PAD(AF, func) \ [AF - 1] = func +#define _PINMUX_PWM(pin, port, chan) \ + PAD(STM32F4_PINMUX_FUNC_##pin##_PWM##port##_CH##chan,\ + STM32F4X_PIN_CONFIG_AF_PUSH_UP), + +#define _PINMUX_UART(pin, port, dir) \ + PAD(STM32F4_PINMUX_FUNC_##pin##_##port##_##dir, \ + STM32F4X_PIN_CONFIG_AF_PUSH_UP), + +/* Blank pinmux by default */ +#define PINMUX_PWM2(pin, chan) +#define PINMUX_UART1(pin, dir) +#define PINMUX_UART2(pin, dir) + +#ifdef CONFIG_PWM_STM32_2 + #undef PINMUX_PWM2 + #define PINMUX_PWM2(pin, chan) _PINMUX_PWM(pin, 2, chan) +#endif + +#ifdef CONFIG_UART_STM32_PORT_1 + #undef PINMUX_UART1 + #define PINMUX_UART1(pin, dir) _PINMUX_UART(pin, USART1, dir) +#endif + +#ifdef CONFIG_UART_STM32_PORT_2 + #undef PINMUX_UART2 + #define PINMUX_UART2(pin, dir) _PINMUX_UART(pin, USART2, dir) +#endif + +#define PINMUX_PWM(pin, pwm, chan) PINMUX_##pwm(pin, chan) +#define PINMUX_UART(pin, port, dir) PINMUX_##port(pin, dir) + static const stm32_pin_func_t pin_pa0_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PA0_PWM2_CH1, STM32F4X_PIN_CONFIG_AF_PUSH_UP), + PINMUX_PWM(PA0, PWM2, 1) }; static const stm32_pin_func_t pin_pa2_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PA2_USART2_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), + PINMUX_UART(PA2, UART2, TX) }; static const stm32_pin_func_t pin_pa3_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PA3_USART2_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), + PINMUX_UART(PA3, UART2, RX) }; static const stm32_pin_func_t pin_pa9_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PA9_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), + PINMUX_UART(PA9, UART1, TX) }; static const stm32_pin_func_t pin_pa10_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PA10_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP) + PINMUX_UART(PA10, UART1, RX) }; static const stm32_pin_func_t pin_pb6_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PB6_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), + PINMUX_UART(PB6, UART1, TX) }; static const stm32_pin_func_t pin_pb7_funcs[] = { - PAD(STM32F4_PINMUX_FUNC_PB7_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), + PINMUX_UART(PB7, UART1, RX) }; /**