Skip to content

Commit

Permalink
stm32/common: Implement support for DE and changing the oversampling …
Browse files Browse the repository at this point in the history
…mode
  • Loading branch information
dragonmux committed Aug 11, 2024
1 parent b7ba56d commit 11f9908
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/libopencm3/stm32/common/usart_common_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@
#define USART_CR1_UE (1 << 0)
/**@}*/

/* 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
/**@}*/

/*------------------------------------------------*/
/** @defgroup usart_cr2_values USART_CR2 Values
@ingroup usart_defines
Expand Down Expand Up @@ -630,4 +640,7 @@ void usart_disable_rx_timeout(uint32_t usart);
void usart_enable_rx_timeout_interrupt(uint32_t usart);
void usart_disable_rx_timeout_interrupt(uint32_t usart);

void usart_enable_diver_enable(uint32_t usart, bool invert);
void usart_set_oversampling(uint32_t usart, uint32_t mode);

END_DECLS
24 changes: 24 additions & 0 deletions lib/stm32/common/usart_common_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,29 @@ bool usart_get_flag(uint32_t usart, uint32_t flag)
return ((USART_ISR(usart) & flag) != 0);
}

/** @brief USART Enable the Driver Enable signal out of the RTS pin
*
* @param[in] usart unsigned 32 bit. USART block register address base @ref
* usart_reg_base
*/
void usart_enable_diver_enable(uint32_t usart, bool invert)
{
uint32_t reg = USART_CR3(usart);
if (invert) {
reg |= USART_CR3_DEP;
} else {
reg &= ~USART_CR3_DEP;
}
reg |= USART_CR3_DEM;
USART_CR3(usart) = reg;
}

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;
}

/**@}*/

0 comments on commit 11f9908

Please sign in to comment.