Skip to content

Commit 31a6e31

Browse files
knthmcarlescufi
authored andcommitted
drivers: serial: stm32: Refactor for PM handling
Move clock enable and register configuration to their own functions in preparation for later uart_stm32_reinit function that will use these in addition to uart_stm32_init. Signed-off-by: Kenneth J. Miller <[email protected]>
1 parent c8ffeb4 commit 31a6e31

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

drivers/serial/uart_stm32.c

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,23 +1805,10 @@ static const struct uart_driver_api uart_stm32_driver_api = {
18051805
#endif /* CONFIG_UART_ASYNC_API */
18061806
};
18071807

1808-
/**
1809-
* @brief Initialize UART channel
1810-
*
1811-
* This routine is called to reset the chip in a quiescent state.
1812-
* It is assumed that this function is called only once per UART.
1813-
*
1814-
* @param dev UART device struct
1815-
*
1816-
* @return 0
1817-
*/
1818-
static int uart_stm32_init(const struct device *dev)
1808+
static int uart_stm32_clocks_enable(const struct device *dev)
18191809
{
18201810
const struct uart_stm32_config *config = dev->config;
18211811
struct uart_stm32_data *data = dev->data;
1822-
struct uart_config *uart_cfg = data->uart_cfg;
1823-
uint32_t ll_parity;
1824-
uint32_t ll_datawidth;
18251812
int err;
18261813

18271814
__uart_stm32_get_clock(dev);
@@ -1848,11 +1835,16 @@ static int uart_stm32_init(const struct device *dev)
18481835
}
18491836
}
18501837

1851-
/* Configure dt provided device signals when available */
1852-
err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
1853-
if (err < 0) {
1854-
return err;
1855-
}
1838+
return 0;
1839+
}
1840+
1841+
static int uart_stm32_registers_configure(const struct device *dev)
1842+
{
1843+
const struct uart_stm32_config *config = dev->config;
1844+
struct uart_stm32_data *data = dev->data;
1845+
struct uart_config *uart_cfg = data->uart_cfg;
1846+
uint32_t ll_parity;
1847+
uint32_t ll_datawidth;
18561848

18571849
LL_USART_Disable(config->usart);
18581850

@@ -1956,6 +1948,40 @@ static int uart_stm32_init(const struct device *dev)
19561948
}
19571949
#endif /* !USART_ISR_REACK */
19581950

1951+
return 0;
1952+
}
1953+
1954+
/**
1955+
* @brief Initialize UART channel
1956+
*
1957+
* This routine is called to reset the chip in a quiescent state.
1958+
* It is assumed that this function is called only once per UART.
1959+
*
1960+
* @param dev UART device struct
1961+
*
1962+
* @return 0
1963+
*/
1964+
static int uart_stm32_init(const struct device *dev)
1965+
{
1966+
const struct uart_stm32_config *config = dev->config;
1967+
int err;
1968+
1969+
err = uart_stm32_clocks_enable(dev);
1970+
if (err < 0) {
1971+
return err;
1972+
}
1973+
1974+
/* Configure dt provided device signals when available */
1975+
err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
1976+
if (err < 0) {
1977+
return err;
1978+
}
1979+
1980+
err = uart_stm32_registers_configure(dev);
1981+
if (err < 0) {
1982+
return err;
1983+
}
1984+
19591985
#if defined(CONFIG_PM) || \
19601986
defined(CONFIG_UART_INTERRUPT_DRIVEN) || \
19611987
defined(CONFIG_UART_ASYNC_API)

0 commit comments

Comments
 (0)