16_USART_DMA_sender/main.cpp
/**
 * Set USART baud rate
 * @param usart    USART instance
 * @param baudrate Required baud rate
 */
Set USART baud rate
@param usart    USART instance
@param baudrate Required baud rate
Set USART baud rate @param usart USART instance @param baudrate Required baud rate
static void SetUsartBaudRate(USART_TypeDef *const usart,
                             const uint32_t baudrate) {
  uint32_t bus_clock;
  float mantissa;
  uint32_t fraction;
  if ((usart == USART1) || (usart == USART6)) {
    bus_clock = GetPCLK2Frequency();
  } else {
    bus_clock = GetPCLK1Frequency();
  }
  mantissa = bus_clock / (16.0f * baudrate);
  fraction = (uint32_t)((mantissa - (uint32_t)mantissa) * 16u);
  usart->BRR = (USART_BRR_DIV_Mantissa & ((uint32_t)mantissa << 4u)) |
               (USART_BRR_DIV_Fraction & fraction);
}
static void SetUsartBaudRate ( USART_TypeDef * const usart , const uint32_t baudrate ) { uint32_t bus_clock ; float mantissa ; uint32_t fraction ; if ( ( usart == USART1 ) || ( usart == USART6 ) ) { bus_clock = GetPCLK2Frequency ( ) ; } else { bus_clock = GetPCLK1Frequency ( ) ; } mantissa = bus_clock / ( 16.0f * baudrate ) ; fraction = ( uint32_t ) ( ( mantissa - ( uint32_t ) mantissa ) * 16u ) ; usart -> BRR = ( USART_BRR_DIV_Mantissa & ( ( uint32_t ) mantissa << 4u ) ) | ( USART_BRR_DIV_Fraction & fraction ) ; }
Set USART baud rate
 @param usart    USART instance
 @param baudrate Required baud rate
Set USART baud rate @param usart USART instance @param baudrate Required baud rate
/* Get bus clock for current USART */ /* Set baud rate */