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); }