lm4f/uart: Implement uart_get_baudrate
This commit is contained in:
@@ -443,6 +443,7 @@ enum uart_fifo_tx_trigger_level {
|
|||||||
BEGIN_DECLS
|
BEGIN_DECLS
|
||||||
|
|
||||||
void uart_set_baudrate(uint32_t uart, uint32_t baud);
|
void uart_set_baudrate(uint32_t uart, uint32_t baud);
|
||||||
|
uint32_t uart_get_baudrate(uint32_t uart);
|
||||||
void uart_set_databits(uint32_t uart, uint8_t databits);
|
void uart_set_databits(uint32_t uart, uint8_t databits);
|
||||||
uint8_t uart_get_databits(uint32_t uart);
|
uint8_t uart_get_databits(uint32_t uart);
|
||||||
void uart_set_stopbits(uint32_t uart, uint8_t stopbits);
|
void uart_set_stopbits(uint32_t uart, uint8_t stopbits);
|
||||||
|
|||||||
@@ -130,6 +130,25 @@ void uart_set_baudrate(uint32_t uart, uint32_t baud)
|
|||||||
UART_FBRD(uart) = div % 64;
|
UART_FBRD(uart) = div % 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get UART baudrate
|
||||||
|
*
|
||||||
|
* @param[in] uart UART block register address base @ref uart_reg_base
|
||||||
|
* @return Baud rate in bits per second (bps)
|
||||||
|
*/
|
||||||
|
uint32_t uart_get_baudrate(uint32_t uart)
|
||||||
|
{
|
||||||
|
/* Are we running off the internal clock or system clock? */
|
||||||
|
const uint32_t clock = UART_CC(uart) == UART_CC_CS_PIOSC ? 16000000U : rcc_get_system_clock_frequency();
|
||||||
|
|
||||||
|
/* Read back divisor parts. Baudrate = clock/16 / (ibrd+fbrd/64). */
|
||||||
|
const uint16_t ibrd = UART_IBRD(uart);
|
||||||
|
const uint16_t fbrd = UART_FBRD(uart);
|
||||||
|
uint32_t div = ibrd * 64U + fbrd;
|
||||||
|
/* Recalculate the actual baudrate. Note that 4 comes from 1/(16/64). */
|
||||||
|
return 4U * clock / div;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Set UART databits
|
* \brief Set UART databits
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user