libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
Enabling and configuring the UART More...
Functions | |
void | uart_enable (uint32_t uart) |
Enable the UART. More... | |
void | uart_disable (uint32_t uart) |
Disable the UART. More... | |
void | uart_set_baudrate (uint32_t uart, uint32_t baud) |
Set UART baudrate. More... | |
void | uart_set_databits (uint32_t uart, uint8_t databits) |
Set UART databits. More... | |
void | uart_set_stopbits (uint32_t uart, uint8_t stopbits) |
Set UART stopbits. More... | |
void | uart_set_parity (uint32_t uart, enum uart_parity parity) |
Set UART parity. More... | |
void | uart_set_flow_control (uint32_t uart, enum uart_flowctl flow) |
Set the flow control scheme. More... | |
void | uart_clock_from_piosc (uint32_t uart) |
Clock the UART module from the internal oscillator. More... | |
void | uart_clock_from_sysclk (uint32_t uart) |
Clock the UART module from the system clock. More... | |
Enabling and configuring the UART
Enabling the UART is a two step process. The GPIO on which the UART resides must be enabled, and the UART pins must be configured as alternate function, digital pins. Pins must also be muxed to the appropriate alternate function. This is done with the GPIO API.
The second step involves enabling and the UART itself. The UART should be disabled while it is being configured.
For example, to enable UART1 at 115200 8n1 with hardware flow control:
void uart_clock_from_piosc | ( | uint32_t | uart | ) |
Clock the UART module from the internal oscillator.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 238 of file uart.c.
References UART_CC, and UART_CC_CS_PIOSC.
void uart_clock_from_sysclk | ( | uint32_t | uart | ) |
Clock the UART module from the system clock.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 248 of file uart.c.
References UART_CC, and UART_CC_CS_SYSCLK.
void uart_disable | ( | uint32_t | uart | ) |
Disable the UART.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 103 of file uart.c.
References UART_CTL.
void uart_enable | ( | uint32_t | uart | ) |
Enable the UART.
Enable the UART. The Rx and Tx lines are also enabled.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 93 of file uart.c.
References UART_CTL, UART_CTL_RXE, UART_CTL_TXE, and UART_CTL_UARTEN.
void uart_set_baudrate | ( | uint32_t | uart, |
uint32_t | baud | ||
) |
Set UART baudrate.
[in] | uart | UART block register address base UART register base addresses |
[in] | baud | Baud rate in bits per second (bps).* |
Definition at line 114 of file uart.c.
References rcc_get_system_clock_frequency(), UART_CC, UART_CC_CS_PIOSC, UART_FBRD, and UART_IBRD.
void uart_set_databits | ( | uint32_t | uart, |
uint8_t | databits | ||
) |
Set UART databits.
[in] | uart | UART block register address base UART register base addresses |
[in] | databits | number of data bits per transmission. |
Definition at line 139 of file uart.c.
References UART_LCRH.
void uart_set_flow_control | ( | uint32_t | uart, |
enum uart_flowctl | flow | ||
) |
Set the flow control scheme.
Set the flow control scheme by enabling or disabling RTS and CTS lines. This will only have effect if the given UART supports the RTS and CTS lines.
[in] | uart | UART block register address base UART register base addresses |
[in] | flow | The flow control scheme to use (none, RTS, CTS or both) UART_FLOWCTL_RTS – enable the RTS line UART_FLOWCTL_CTS – enable the CTS line UART_FLOWCTL_RTS_CTS – enable both RTS and CTS lines |
Definition at line 216 of file uart.c.
References UART_CTL, UART_CTL_CTSEN, UART_CTL_RTSEN, UART_FLOWCTL_CTS, UART_FLOWCTL_RTS, and UART_FLOWCTL_RTS_CTS.
void uart_set_parity | ( | uint32_t | uart, |
enum uart_parity | parity | ||
) |
Set UART parity.
[in] | uart | UART block register address base UART register base addresses |
[in] | bits | the requested parity scheme. |
Definition at line 175 of file uart.c.
References UART_LCRH, UART_LCRH_EPS, UART_LCRH_PEN, UART_LCRH_SPS, UART_PARITY_EVEN, UART_PARITY_NONE, UART_PARITY_ODD, UART_PARITY_STICK_0, and UART_PARITY_STICK_1.
void uart_set_stopbits | ( | uint32_t | uart, |
uint8_t | stopbits | ||
) |
Set UART stopbits.
[in] | uart | UART block register address base UART register base addresses |
[in] | bits | the requested number of stopbits, either 1 or 2. |
Definition at line 160 of file uart.c.
References UART_LCRH, and UART_LCRH_STP2.