@@ -465,6 +465,7 @@ static int uart_stm32_configure(const struct device *dev,
465465{
466466 const struct uart_stm32_config * config = dev -> config ;
467467 struct uart_stm32_data * data = dev -> data ;
468+ struct uart_config * uart_cfg = data -> uart_cfg ;
468469 const uint32_t parity = uart_stm32_cfg2ll_parity (cfg -> parity );
469470 const uint32_t stopbits = uart_stm32_cfg2ll_stopbits (config , cfg -> stop_bits );
470471 const uint32_t databits = uart_stm32_cfg2ll_databits (cfg -> data_bits ,
@@ -536,9 +537,9 @@ static int uart_stm32_configure(const struct device *dev,
536537 }
537538#endif
538539
539- if (cfg -> baudrate != data -> baud_rate ) {
540+ if (cfg -> baudrate != uart_cfg -> baudrate ) {
540541 uart_stm32_set_baudrate (dev , cfg -> baudrate );
541- data -> baud_rate = cfg -> baudrate ;
542+ uart_cfg -> baudrate = cfg -> baudrate ;
542543 }
543544
544545 LL_USART_Enable (config -> usart );
@@ -549,8 +550,9 @@ static int uart_stm32_config_get(const struct device *dev,
549550 struct uart_config * cfg )
550551{
551552 struct uart_stm32_data * data = dev -> data ;
553+ struct uart_config * uart_cfg = data -> uart_cfg ;
552554
553- cfg -> baudrate = data -> baud_rate ;
555+ cfg -> baudrate = uart_cfg -> baudrate ;
554556 cfg -> parity = uart_stm32_ll2cfg_parity (uart_stm32_get_parity (dev ));
555557 cfg -> stop_bits = uart_stm32_ll2cfg_stopbits (
556558 uart_stm32_get_stopbits (dev ));
@@ -1817,6 +1819,7 @@ static int uart_stm32_init(const struct device *dev)
18171819{
18181820 const struct uart_stm32_config * config = dev -> config ;
18191821 struct uart_stm32_data * data = dev -> data ;
1822+ struct uart_config * uart_cfg = data -> uart_cfg ;
18201823 uint32_t ll_parity ;
18211824 uint32_t ll_datawidth ;
18221825 int err ;
@@ -1868,18 +1871,18 @@ static int uart_stm32_init(const struct device *dev)
18681871 /* Determine the datawidth and parity. If we use other parity than
18691872 * 'none' we must use datawidth = 9 (to get 8 databit + 1 parity bit).
18701873 */
1871- if (config -> parity == 2 ) {
1874+ if (uart_cfg -> parity == 2 ) {
18721875 /* 8 databit, 1 parity bit, parity even */
18731876 ll_parity = LL_USART_PARITY_EVEN ;
18741877 ll_datawidth = LL_USART_DATAWIDTH_9B ;
1875- } else if (config -> parity == 1 ) {
1878+ } else if (uart_cfg -> parity == 1 ) {
18761879 /* 8 databit, 1 parity bit, parity odd */
18771880 ll_parity = LL_USART_PARITY_ODD ;
18781881 ll_datawidth = LL_USART_DATAWIDTH_9B ;
18791882 } else { /* Default to 8N0, but show warning if invalid value */
1880- if (config -> parity != 0 ) {
1883+ if (uart_cfg -> parity != 0 ) {
18811884 LOG_WRN ("Invalid parity setting '%d'."
1882- "Defaulting to 'none'." , config -> parity );
1885+ "Defaulting to 'none'." , uart_cfg -> parity );
18831886 }
18841887 /* 8 databit, parity none */
18851888 ll_parity = LL_USART_PARITY_NONE ;
@@ -1892,12 +1895,12 @@ static int uart_stm32_init(const struct device *dev)
18921895 ll_parity ,
18931896 LL_USART_STOPBITS_1 );
18941897
1895- if (config -> hw_flow_control ) {
1898+ if (uart_cfg -> flow_ctrl ) {
18961899 uart_stm32_set_hwctrl (dev , LL_USART_HWCONTROL_RTS_CTS );
18971900 }
18981901
18991902 /* Set the default baudrate */
1900- uart_stm32_set_baudrate (dev , data -> baud_rate );
1903+ uart_stm32_set_baudrate (dev , uart_cfg -> baudrate );
19011904
19021905 /* Enable the single wire / half-duplex mode */
19031906 if (config -> single_wire ) {
@@ -2141,13 +2144,25 @@ PINCTRL_DT_INST_DEFINE(index); \
21412144static const struct stm32_pclken pclken_##index[] = \
21422145 STM32_DT_INST_CLOCKS(index);\
21432146 \
2147+ static struct uart_config uart_cfg_##index = { \
2148+ .baudrate = DT_INST_PROP_OR(index, current_speed, \
2149+ STM32_UART_DEFAULT_BAUDRATE), \
2150+ .parity = DT_INST_ENUM_IDX_OR(index, parity, \
2151+ STM32_UART_DEFAULT_PARITY), \
2152+ .stop_bits = DT_INST_ENUM_IDX_OR(index, stop_bits, \
2153+ STM32_UART_DEFAULT_STOP_BITS), \
2154+ .data_bits = DT_INST_ENUM_IDX_OR(index, data_bits, \
2155+ STM32_UART_DEFAULT_DATA_BITS), \
2156+ .flow_ctrl = DT_INST_PROP(index, hw_flow_control) \
2157+ ? UART_CFG_FLOW_CTRL_RTS_CTS \
2158+ : UART_CFG_FLOW_CTRL_NONE, \
2159+ }; \
2160+ \
21442161static const struct uart_stm32_config uart_stm32_cfg_##index = { \
21452162 .usart = (USART_TypeDef *)DT_INST_REG_ADDR(index), \
21462163 .reset = RESET_DT_SPEC_GET(DT_DRV_INST(index)), \
21472164 .pclken = pclken_##index, \
21482165 .pclk_len = DT_INST_NUM_CLOCKS(index), \
2149- .hw_flow_control = DT_INST_PROP(index, hw_flow_control), \
2150- .parity = DT_INST_ENUM_IDX_OR(index, parity, UART_CFG_PARITY_NONE), \
21512166 .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
21522167 .single_wire = DT_INST_PROP_OR(index, single_wire, false), \
21532168 .tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false), \
@@ -2162,7 +2177,7 @@ static const struct uart_stm32_config uart_stm32_cfg_##index = { \
21622177}; \
21632178 \
21642179static struct uart_stm32_data uart_stm32_data_##index = { \
2165- .baud_rate = DT_INST_PROP( index, current_speed), \
2180+ .uart_cfg = &uart_cfg_## index, \
21662181 UART_DMA_CHANNEL(index, rx, RX, PERIPHERAL, MEMORY) \
21672182 UART_DMA_CHANNEL(index, tx, TX, MEMORY, PERIPHERAL) \
21682183}; \
0 commit comments