Skip to content

Commit ab7b99a

Browse files
committed
[DNM] drivers: serial: stm32: add deinit implementation
Implement de-init for STM32 serial driver. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
1 parent 0cbf08d commit ab7b99a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

drivers/serial/uart_stm32.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,32 @@ static int uart_stm32_init(const struct device *dev)
21802180
#endif
21812181
}
21822182

2183+
static int uart_stm32_deinit(const struct device *dev)
2184+
{
2185+
const struct uart_stm32_config *config = dev->config;
2186+
struct uart_stm32_data *data = dev->data;
2187+
USART_TypeDef *usart = config->usart;
2188+
2189+
/* TODO: is this correct? */
2190+
while (!LL_USART_IsActiveFlag_TC(usart)) {}
2191+
2192+
/* Reset UART to default state using RCC */
2193+
(void)reset_line_toggle_dt(&config->reset);
2194+
2195+
(void)clock_control_off(data->clock, (clock_control_subsys_t)&config->pclken[0]);
2196+
2197+
(void)pinctrl_apply_state(config->pcfg, PINCTRL_STATE_RESET);
2198+
2199+
#ifdef CONFIG_UART_ASYNC_API
2200+
(void)device_put(data->dma_tx.dma_dev);
2201+
(void)device_put(data->dma_rx.dma_dev);
2202+
#endif
2203+
(void)device_put(config->reset.dev);
2204+
(void)device_put(data->clock);
2205+
2206+
return 0;
2207+
}
2208+
21832209
#ifdef CONFIG_PM_DEVICE
21842210
static void uart_stm32_suspend_setup(const struct device *dev)
21852211
{
@@ -2469,8 +2495,9 @@ static struct uart_stm32_data uart_stm32_data_##index = { \
24692495
\
24702496
PM_DEVICE_DT_INST_DEFINE(index, uart_stm32_pm_action); \
24712497
\
2472-
DEVICE_DT_INST_DEFINE(index, \
2498+
DEVICE_DT_INST_DEINIT_DEFINE(index, \
24732499
uart_stm32_init, \
2500+
uart_stm32_deinit, \
24742501
PM_DEVICE_DT_INST_GET(index), \
24752502
&uart_stm32_data_##index, &uart_stm32_cfg_##index, \
24762503
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \

0 commit comments

Comments
 (0)