@@ -2180,6 +2180,33 @@ 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
+
2193
+ /* Reset UART to default state using RCC */
2194
+ (void )reset_line_toggle_dt (& config -> reset );
2195
+
2196
+ (void )clock_control_off (data -> clock , (clock_control_subsys_t )& config -> pclken [0 ]);
2197
+
2198
+ (void )pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_RESET );
2199
+
2200
+ #ifdef CONFIG_UART_ASYNC_API
2201
+ (void )device_put (data -> dma_tx .dma_dev );
2202
+ (void )device_put (data -> dma_rx .dma_dev );
2203
+ #endif
2204
+ (void )device_put (config -> reset .dev );
2205
+ (void )device_put (data -> clock );
2206
+
2207
+ return 0 ;
2208
+ }
2209
+
2183
2210
#ifdef CONFIG_PM_DEVICE
2184
2211
static void uart_stm32_suspend_setup (const struct device * dev )
2185
2212
{
@@ -2469,8 +2496,9 @@ static struct uart_stm32_data uart_stm32_data_##index = { \
2469
2496
\
2470
2497
PM_DEVICE_DT_INST_DEFINE(index, uart_stm32_pm_action); \
2471
2498
\
2472
- DEVICE_DT_INST_DEFINE (index, \
2499
+ DEVICE_DT_INST_DEINIT_DEFINE (index, \
2473
2500
uart_stm32_init, \
2501
+ uart_stm32_deinit, \
2474
2502
PM_DEVICE_DT_INST_GET(index), \
2475
2503
&uart_stm32_data_##index, &uart_stm32_cfg_##index, \
2476
2504
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \
0 commit comments