From 0a8faa83d992ba88375913d0ed7957e47ef7f74a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 29 Dec 2023 07:27:02 +1100 Subject: [PATCH] HAL_ChibiOS: allow for up to 12.5MBps on H7 UARTs use 8x oversampling instead of 16x oversampling --- libraries/AP_HAL_ChibiOS/UARTDriver.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index 6593dffe7e..a04537fdbd 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -430,6 +430,18 @@ void UARTDriver::_begin(uint32_t b, uint16_t rxS, uint16_t txS) sercfg.cr2 = _cr2_options; sercfg.cr3 = _cr3_options; +#if defined(STM32H7) + /* + H7 defaults to 16x oversampling. To get the highest + possible baudrates we need to drop back to 8x + oversampling. The H7 UART clock is 100MHz. This allows + for up to 12.5MBps on H7 UARTs + */ + if (_baudrate > 100000000UL / 16U) { + sercfg.cr1 |= USART_CR1_OVER8; + } +#endif + #ifndef HAL_UART_NODMA if (rx_dma_enabled) { sercfg.cr1 |= USART_CR1_IDLEIE;