Skip to content

Commit ac77af3

Browse files
author
Florian Vaussard
committed
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 <florian.vaussard@heig-vd.ch>
1 parent af27ad5 commit ac77af3

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,63 @@
1515
#define PAD(AF, func) \
1616
[AF - 1] = func
1717

18+
#define PINMUX_PWM(port, chan, pin) \
19+
PAD(STM32F4_PINMUX_FUNC_##pin##_PWM##port##_CH##chan,\
20+
STM32F4X_PIN_CONFIG_AF_PUSH_UP),
21+
22+
#define PINMUX_UART(port, dir, pin) \
23+
PAD(STM32F4_PINMUX_FUNC_##pin##_##port##_##dir, \
24+
STM32F4X_PIN_CONFIG_AF_PUSH_UP),
25+
26+
/* Blank pinmux by default */
27+
#define PINMUX_PWM2(pin, chan)
28+
#define PINMUX_UART1(dir, pin)
29+
#define PINMUX_UART2(dir, pin)
30+
31+
#ifdef CONFIG_PWM_STM32_2
32+
#undef PINMUX_PWM2
33+
#define PINMUX_PWM2(pin, chan) PINMUX_PWM(2, chan, pin)
34+
#endif
35+
36+
#ifdef CONFIG_UART_STM32_PORT_1
37+
#undef PINMUX_UART1
38+
#define PINMUX_UART1(dir, pin) PINMUX_UART(USART1, dir, pin)
39+
#endif
40+
41+
#ifdef CONFIG_UART_STM32_PORT_2
42+
#undef PINMUX_UART2
43+
#define PINMUX_UART2(dir, pin) PINMUX_UART(USART2, dir, pin)
44+
#endif
45+
46+
#define PINMUX_UART_TX(pin, port) PINMUX_UART##port(TX, pin)
47+
#define PINMUX_UART_RX(pin, port) PINMUX_UART##port(RX, pin)
48+
1849
static const stm32_pin_func_t pin_pa0_funcs[] = {
19-
PAD(STM32F4_PINMUX_FUNC_PA0_PWM2_CH1, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
50+
PINMUX_PWM2(PA0, 1)
2051
};
2152

2253
static const stm32_pin_func_t pin_pa2_funcs[] = {
23-
PAD(STM32F4_PINMUX_FUNC_PA2_USART2_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
54+
PINMUX_UART_TX(PA2, 2)
2455
};
2556

2657
static const stm32_pin_func_t pin_pa3_funcs[] = {
27-
PAD(STM32F4_PINMUX_FUNC_PA3_USART2_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
58+
PINMUX_UART_RX(PA3, 2)
2859
};
2960

3061
static const stm32_pin_func_t pin_pa9_funcs[] = {
31-
PAD(STM32F4_PINMUX_FUNC_PA9_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
62+
PINMUX_UART_TX(PA9, 1)
3263
};
3364

3465
static const stm32_pin_func_t pin_pa10_funcs[] = {
35-
PAD(STM32F4_PINMUX_FUNC_PA10_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP)
66+
PINMUX_UART_RX(PA10, 1)
3667
};
3768

3869
static const stm32_pin_func_t pin_pb6_funcs[] = {
39-
PAD(STM32F4_PINMUX_FUNC_PB6_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
70+
PINMUX_UART_TX(PB6, 1)
4071
};
4172

4273
static const stm32_pin_func_t pin_pb7_funcs[] = {
43-
PAD(STM32F4_PINMUX_FUNC_PB7_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
74+
PINMUX_UART_RX(PB7, 1)
4475
};
4576

4677
/**

0 commit comments

Comments
 (0)