summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEziotao <[email protected]>2023-04-03 13:12:48 +0800
committerMan, Jianting (Meco) <[email protected]>2023-04-03 10:14:52 -0400
commitce346d798bdde941021cf631f275dfd48ad8b75e (patch)
tree9143783f29fbc857bc78bb7342d978d9577af66c
parentd6c1b75e42ac91c292ebb53de617e60bf904949f (diff)
modify the sampling rate to increase the actual baud rate(drv_usart.c/drv_usart_v2.c)
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_usart.c4
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c5
2 files changed, 8 insertions, 1 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c
index 6569872ef8..13001b4bc0 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c
@@ -108,7 +108,11 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
uart->handle.Instance = uart->config->Instance;
uart->handle.Init.BaudRate = cfg->baud_rate;
uart->handle.Init.Mode = UART_MODE_TX_RX;
+#ifdef USART_CR1_OVER8
+ uart->handle.Init.OverSampling = cfg->baud_rate > 5000000 ? UART_OVERSAMPLING_8 : UART_OVERSAMPLING_16;
+#else
uart->handle.Init.OverSampling = UART_OVERSAMPLING_16;
+#endif /* USART_CR1_OVER8 */
switch (cfg->flowcontrol)
{
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c
index 486a338545..9da522cb3f 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c
@@ -116,11 +116,14 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
RT_ASSERT(cfg != RT_NULL);
uart = rt_container_of(serial, struct stm32_uart, serial);
-
uart->handle.Instance = uart->config->Instance;
uart->handle.Init.BaudRate = cfg->baud_rate;
uart->handle.Init.Mode = UART_MODE_TX_RX;
+#ifdef USART_CR1_OVER8
+ uart->handle.Init.OverSampling = cfg->baud_rate > 5000000 ? UART_OVERSAMPLING_8 : UART_OVERSAMPLING_16;
+#else
uart->handle.Init.OverSampling = UART_OVERSAMPLING_16;
+#endif /* USART_CR1_OVER8 */
switch (cfg->data_bits)
{