@@ -140,7 +140,7 @@ static void uart_stm32_pm_policy_state_lock_put(const struct device *dev)
140
140
}
141
141
#endif /* CONFIG_PM */
142
142
143
- static inline void uart_stm32_set_baudrate (const struct device * dev , uint32_t baud_rate )
143
+ static inline int uart_stm32_set_baudrate (const struct device * dev , uint32_t baud_rate )
144
144
{
145
145
const struct uart_stm32_config * config = dev -> config ;
146
146
USART_TypeDef * usart = config -> usart ;
@@ -150,18 +150,18 @@ static inline void uart_stm32_set_baudrate(const struct device *dev, uint32_t ba
150
150
151
151
/* Get clock rate */
152
152
if (IS_ENABLED (STM32_UART_DOMAIN_CLOCK_SUPPORT ) && (config -> pclk_len > 1 )) {
153
- if ( clock_control_get_rate (data -> clock ,
154
- (clock_control_subsys_t )& config -> pclken [1 ],
155
- & clock_rate ) < 0 ) {
153
+ int ret = clock_control_get_rate (
154
+ data -> clock , (clock_control_subsys_t )& config -> pclken [1 ], & clock_rate );
155
+ if ( ret < 0 ) {
156
156
LOG_ERR ("Failed call clock_control_get_rate(pclken[1])" );
157
- return ;
157
+ return ret ;
158
158
}
159
159
} else {
160
- if ( clock_control_get_rate (data -> clock ,
161
- (clock_control_subsys_t )& config -> pclken [0 ],
162
- & clock_rate ) < 0 ) {
160
+ int ret = clock_control_get_rate (
161
+ data -> clock , (clock_control_subsys_t )& config -> pclken [0 ], & clock_rate );
162
+ if ( ret < 0 ) {
163
163
LOG_ERR ("Failed call clock_control_get_rate(pclken[0])" );
164
- return ;
164
+ return ret ;
165
165
}
166
166
}
167
167
@@ -181,7 +181,7 @@ static inline void uart_stm32_set_baudrate(const struct device *dev, uint32_t ba
181
181
182
182
if (presc_idx == ARRAY_SIZE (LPUART_PRESCALER_TAB )) {
183
183
LOG_ERR ("Unable to set %s to %d" , dev -> name , baud_rate );
184
- return ;
184
+ return - EINVAL ;
185
185
}
186
186
187
187
presc_val = presc_idx << USART_PRESC_PRESCALER_Pos ;
@@ -191,7 +191,7 @@ static inline void uart_stm32_set_baudrate(const struct device *dev, uint32_t ba
191
191
lpuartdiv = lpuartdiv_calc (clock_rate , baud_rate );
192
192
if (lpuartdiv < LPUART_BRR_MIN_VALUE || lpuartdiv > LPUART_BRR_MASK ) {
193
193
LOG_ERR ("Unable to set %s to %d" , dev -> name , baud_rate );
194
- return ;
194
+ return - EINVAL ;
195
195
}
196
196
#endif /* USART_PRESC_PRESCALER */
197
197
LL_LPUART_SetBaudRate (usart ,
@@ -229,6 +229,7 @@ static inline void uart_stm32_set_baudrate(const struct device *dev, uint32_t ba
229
229
#if HAS_LPUART
230
230
}
231
231
#endif /* HAS_LPUART */
232
+ return 0 ;
232
233
}
233
234
234
235
static inline void uart_stm32_set_parity (const struct device * dev ,
@@ -487,7 +488,7 @@ static inline enum uart_config_flow_control uart_stm32_ll2cfg_hwctrl(uint32_t fc
487
488
return UART_CFG_FLOW_CTRL_NONE ;
488
489
}
489
490
490
- static void uart_stm32_parameters_set (const struct device * dev ,
491
+ static int uart_stm32_parameters_set (const struct device * dev ,
491
492
const struct uart_config * cfg )
492
493
{
493
494
const struct uart_stm32_config * config = dev -> config ;
@@ -501,6 +502,7 @@ static void uart_stm32_parameters_set(const struct device *dev,
501
502
#if HAS_DRIVER_ENABLE
502
503
bool driver_enable = cfg -> flow_ctrl == UART_CFG_FLOW_CTRL_RS485 ;
503
504
#endif
505
+ int ret = 0 ;
504
506
505
507
if (cfg == uart_cfg ) {
506
508
/* Called via (re-)init function, so the SoC either just booted,
@@ -512,7 +514,10 @@ static void uart_stm32_parameters_set(const struct device *dev,
512
514
parity ,
513
515
stopbits );
514
516
uart_stm32_set_hwctrl (dev , flowctrl );
515
- uart_stm32_set_baudrate (dev , cfg -> baudrate );
517
+ ret = uart_stm32_set_baudrate (dev , cfg -> baudrate );
518
+ if (ret < 0 ) {
519
+ return ret ;
520
+ }
516
521
} else {
517
522
/* Called from application/subsys via uart_configure syscall */
518
523
if (parity != uart_stm32_get_parity (dev )) {
@@ -538,10 +543,15 @@ static void uart_stm32_parameters_set(const struct device *dev,
538
543
#endif
539
544
540
545
if (cfg -> baudrate != uart_cfg -> baudrate ) {
541
- uart_stm32_set_baudrate (dev , cfg -> baudrate );
546
+ ret = uart_stm32_set_baudrate (dev , cfg -> baudrate );
547
+ if (ret < 0 ) {
548
+ return ret ;
549
+ }
542
550
uart_cfg -> baudrate = cfg -> baudrate ;
543
551
}
544
552
}
553
+
554
+ return 0 ;
545
555
}
546
556
547
557
#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
@@ -598,10 +608,14 @@ static int uart_stm32_configure(const struct device *dev,
598
608
LL_USART_Disable (usart );
599
609
600
610
/* Set basic parameters, such as data-/stop-bit, parity, and baudrate */
601
- uart_stm32_parameters_set (dev , cfg );
611
+ int ret = uart_stm32_parameters_set (dev , cfg );
602
612
603
613
LL_USART_Enable (usart );
604
614
615
+ if (ret < 0 ) {
616
+ return - ENOTSUP ;
617
+ }
618
+
605
619
/* Upon successful configuration, persist the syscall-passed
606
620
* uart_config.
607
621
* This allows restoring it, should the device return from a low-power
@@ -2090,7 +2104,9 @@ static int uart_stm32_registers_configure(const struct device *dev)
2090
2104
LL_USART_SetTransferDirection (usart , LL_USART_DIRECTION_TX_RX );
2091
2105
2092
2106
/* Set basic parameters, such as data-/stop-bit, parity, and baudrate */
2093
- uart_stm32_parameters_set (dev , uart_cfg );
2107
+ if (uart_stm32_parameters_set (dev , uart_cfg ) < 0 ) {
2108
+ return - EINVAL ;
2109
+ }
2094
2110
2095
2111
/* Enable the single wire / half-duplex mode */
2096
2112
if (config -> single_wire ) {
0 commit comments