From 48a83558747f950d055911c1ef92d224c63f2d3b Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 15 Aug 2022 17:58:18 +0100 Subject: [PATCH] stm32/usart: Implemented a function to get the current stop bits setting for a USART --- .../libopencm3/stm32/common/usart_common_all.h | 1 + lib/stm32/common/usart_common_all.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libopencm3/stm32/common/usart_common_all.h b/include/libopencm3/stm32/common/usart_common_all.h index a86a91fb..c41a2267 100644 --- a/include/libopencm3/stm32/common/usart_common_all.h +++ b/include/libopencm3/stm32/common/usart_common_all.h @@ -102,6 +102,7 @@ void usart_set_baudrate(uint32_t usart, uint32_t baud); void usart_set_databits(uint32_t usart, uint32_t bits); uint32_t usart_get_databits(uint32_t usart); void usart_set_stopbits(uint32_t usart, uint32_t stopbits); +uint32_t usart_get_stopbits(uint32_t usart); void usart_set_parity(uint32_t usart, uint32_t parity); void usart_set_mode(uint32_t usart, uint32_t mode); void usart_set_flow_control(uint32_t usart, uint32_t flowcontrol); diff --git a/lib/stm32/common/usart_common_all.c b/lib/stm32/common/usart_common_all.c index 6fcbf191..49e1f20b 100644 --- a/lib/stm32/common/usart_common_all.c +++ b/lib/stm32/common/usart_common_all.c @@ -135,6 +135,22 @@ void usart_set_stopbits(uint32_t usart, uint32_t stopbits) USART_CR2(usart) = reg32; } +/*---------------------------------------------------------------------------*/ +/** @brief USART Get Stop Bit(s). + +The stop bits are specified as 0.5, 1, 1.5 or 2. + +@param[in] usart unsigned 32 bit. USART block register address base @ref +usart_reg_base +@returns unsigned 32 bit Stop bits @ref usart_cr2_stopbits. +*/ + +uint32_t usart_get_stopbits(uint32_t usart) +{ + const uint32_t reg32 = USART_CR2(usart); + return reg32 & USART_CR2_STOPBITS_MASK; +} + /*---------------------------------------------------------------------------*/ /** @brief USART Set Parity.