From 346d2ab92facb19c46bbba677c2cf65c005f0720 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Wed, 12 Aug 2020 13:33:30 +0200 Subject: [PATCH] drivers/uart: stm32f1: Add remap support for dt configured pinctrl On stm32f1 series, device pinctrl configuration could be modified thanks to remapping capability. Remapping allows to provide alternate pinctrl configuration to a peripheral device and applies to all impacted pins. So, specifically for stm32f1 series, apply remapping when required before proceeding with pin configuration. Additionally, because remapping is defined individually for each pin, apply a function on pinctrl configuration to check remapping setting coherency accorss pins. Signed-off-by: Erwan Gouriou --- drivers/serial/uart_stm32.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index e08e2472e5b..b3d1a038010 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -680,6 +680,46 @@ static int uart_stm32_init(const struct device *dev) /* Configure dt provided device signals when available */ if (config->pinctrl_list_size != 0) { +#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) + int remap; + /* Check that remap configuration is coherent across pins */ + remap = stm32_dt_pinctrl_remap_check(config->pinctrl_list, + config->pinctrl_list_size); + if (remap < 0) { + return remap; + } + + /* A valid remapping configuration is provided */ + /* Apply remapping before proceeding with pin configuration */ + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); + + switch ((uint32_t)UART_STRUCT(dev)) { +#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) + case DT_REG_ADDR(DT_NODELABEL(usart1)): + if (remap == REMAP_FULL) { + LL_GPIO_AF_EnableRemap_USART1(); + } + break; +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) + case DT_REG_ADDR(DT_NODELABEL(usart2)): + if (remap == REMAP_FULL) { + LL_GPIO_AF_EnableRemap_USART2(); + } + break; +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart3), okay) + case DT_REG_ADDR(DT_NODELABEL(usart3)): + if (remap == REMAP_FULL) { + LL_GPIO_AF_EnableRemap_USART3(); + } else if (remap == REMAP_1) { + LL_GPIO_AF_RemapPartial_USART3(); + } + break; +#endif + } +#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */ + stm32_dt_pinctrl_configure(config->pinctrl_list, config->pinctrl_list_size); }