aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c')
-rw-r--r--os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c b/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c
index 4b5f20836..e4d521bd7 100644
--- a/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c
+++ b/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c
@@ -213,17 +213,26 @@ static uint8_t sd_out_buflp1[STM32_SERIAL_LPUART1_OUT_BUF_SIZE];
* @param[in] config the architecture-dependent serial driver configuration
*/
static void usart_init(SerialDriver *sdp, const SerialConfig *config) {
+ uint32_t fck;
USART_TypeDef *u = sdp->usart;
/* Baud rate setting.*/
#if STM32_SERIAL_USE_LPUART1
- if ( sdp == &LPSD1 )
- {
- u->BRR = (uint32_t)( ( (uint64_t)sdp->clock * 256 ) / config->speed);
+ if ( sdp == &LPSD1 ) {
+ fck = (uint32_t)(((uint64_t)sdp->clock * 256 ) / config->speed);
}
else
#endif
- u->BRR = (uint32_t)(sdp->clock / config->speed);
+ {
+ fck = (uint32_t)(sdp->clock / config->speed);
+ }
+
+ /* Correcting USARTDIV when oversampling by 8 instead of 16.
+ Fraction is still 4 bits wide, but only lower 3 bits used.
+ Mantissa is doubled, but Fraction is left the same.*/
+ if (config->cr1 & USART_CR1_OVER8)
+ fck = ((fck & ~7) * 2) | (fck & 7);
+ u->BRR = fck;
/* Note that some bits are enforced.*/
u->CR2 = config->cr2 | USART_CR2_LBDIE;