From 94411df91f28afa76b67b2046db5e1d8f3fdb678 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 29 Apr 2024 11:05:09 +0100 Subject: [PATCH] stm32/common: Implemented oversampling control support for the F2/F4 parts --- .../libopencm3/stm32/common/usart_common_f24.h | 16 ++++++++++++++++ lib/stm32/common/usart_common_f124.c | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/include/libopencm3/stm32/common/usart_common_f24.h b/include/libopencm3/stm32/common/usart_common_f24.h index 1d226fa7..df87c6e7 100644 --- a/include/libopencm3/stm32/common/usart_common_f24.h +++ b/include/libopencm3/stm32/common/usart_common_f24.h @@ -89,6 +89,16 @@ specific memorymap.h header before including this header file.*/ /* OVER8: Oversampling mode */ #define USART_CR1_OVER8 (1 << 15) +/* CR1_OVER8 values */ +/****************************************************************************/ +/** @defgroup usart_cr1_oversampling USART Oversampling Mode Selection +@ingroup STM32F_usart_defines + +@{*/ +#define USART_OVERSAMPLING_8 USART_CR1_OVER8 +#define USART_OVERSAMPLING_16 0U +/**@}*/ + /* --- USART_CR3 values ---------------------------------------------------- */ /* ONEBIT: One sample bit method enable */ @@ -96,6 +106,12 @@ specific memorymap.h header before including this header file.*/ #define USART_BRR_UPPER_MASK (0x0000fff0U) #define USART_BRR_LOWER_MASK (0x0000000fU) + +BEGIN_DECLS + +void usart_set_oversampling(uint32_t usart, uint32_t mode); + +END_DECLS #endif /** @cond */ #else diff --git a/lib/stm32/common/usart_common_f124.c b/lib/stm32/common/usart_common_f124.c index 653b23e2..32f21e49 100644 --- a/lib/stm32/common/usart_common_f124.c +++ b/lib/stm32/common/usart_common_f124.c @@ -110,5 +110,14 @@ bool usart_get_flag(uint32_t usart, uint32_t flag) return ((USART_SR(usart) & flag) != 0); } +#ifdef LIBOPENCM3_USART_COMMON_F24_H +void usart_set_oversampling(uint32_t usart, uint32_t mode) +{ + if (mode) + USART_CR1(usart) |= USART_CR1_OVER8; + else + USART_CR1(usart) &= ~USART_CR1_OVER8; +} +#endif /**@}*/