Browse Source

stm32/usart: Implemented a function to get the current databits setting for a USART

pull/1483/head
dragonmux 2 years ago
committed by Piotr Esden-Tempski
parent
commit
0241982fb4
  1. 1
      include/libopencm3/stm32/common/usart_common_all.h
  2. 21
      lib/stm32/common/usart_common_all.c

1
include/libopencm3/stm32/common/usart_common_all.h

@ -100,6 +100,7 @@ BEGIN_DECLS
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);
void usart_set_parity(uint32_t usart, uint32_t parity);
void usart_set_mode(uint32_t usart, uint32_t mode);

21
lib/stm32/common/usart_common_all.c

@ -95,6 +95,27 @@ void usart_set_databits(uint32_t usart, uint32_t bits)
}
}
/*---------------------------------------------------------------------------*/
/** @brief USART Get Word Length.
The word length is set to 8 or 9 bits. Note that the last bit will be a parity
bit if parity is enabled, in which case the data length will be 7 or 8 bits
respectively.
@param[in] usart unsigned 32 bit. USART block register address base @ref
usart_reg_base
@returns unsigned 32 bit Word length in bits 8 or 9.
*/
uint32_t usart_get_databits(uint32_t usart)
{
const uint32_t reg32 = USART_CR1(usart) & USART_CR1_M;
if (reg32)
return 9;
else
return 8;
}
/*---------------------------------------------------------------------------*/
/** @brief USART Set Stop Bit(s).

Loading…
Cancel
Save