@@ -2180,6 +2180,32 @@ static int uart_stm32_init(const struct device *dev)
2180
2180
#endif
2181
2181
}
2182
2182
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
+
2183
2209
#ifdef CONFIG_PM_DEVICE
2184
2210
static void uart_stm32_suspend_setup (const struct device * dev )
2185
2211
{
@@ -2469,8 +2495,9 @@ static struct uart_stm32_data uart_stm32_data_##index = { \
2469
2495
\
2470
2496
PM_DEVICE_DT_INST_DEFINE(index, uart_stm32_pm_action); \
2471
2497
\
2472
- DEVICE_DT_INST_DEFINE (index, \
2498
+ DEVICE_DT_INST_DEINIT_DEFINE (index, \
2473
2499
uart_stm32_init, \
2500
+ uart_stm32_deinit, \
2474
2501
PM_DEVICE_DT_INST_GET(index), \
2475
2502
&uart_stm32_data_##index, &uart_stm32_cfg_##index, \
2476
2503
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \
0 commit comments