libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
Defined Constants and Types for the STM32F0xx USART More...
Modules | |
USART register base addresses | |
Holds all the U(S)ART peripherals supported. | |
USART Parity Selection | |
USART Tx/Rx Mode Selection | |
USART Stop Bit Selection | |
USART Hardware Flow Control Selection | |
USART Registers | |
U(S)ART convenience Flags | |
We define the "common" lower flag bits using a standard name, allowing them to be used regardless of which usart peripheral version you have. | |
USART_CR1 Values | |
USART_CR2 Values | |
USART_CR3 Values | |
USART_GTPR Values | |
USART_RTOR Values | |
USART_RQR Values | |
USART_ISR Values | |
USART_ICR Values | |
USART_RDR/TDR Values | |
Macros | |
#define | USART_PARITY_MASK (USART_CR1_PS | USART_CR1_PCE) |
#define | USART_MODE_MASK (USART_CR1_RE | USART_CR1_TE) |
#define | USART_CR2_STOPBITS_1 (0x00 << 12) /* 1 stop bit */ |
#define | USART_CR2_STOPBITS_0_5 (0x01 << 12) /* 0.5 stop bits */ |
#define | USART_CR2_STOPBITS_2 (0x02 << 12) /* 2 stop bits */ |
#define | USART_CR2_STOPBITS_1_5 (0x03 << 12) /* 1.5 stop bits */ |
#define | USART_CR2_STOPBITS_MASK (0x03 << 12) |
#define | USART_CR2_STOPBITS_SHIFT 12 |
#define | USART_FLOWCONTROL_MASK (USART_CR3_RTSE | USART_CR3_CTSE) |
Functions | |
void | usart_set_baudrate (uint32_t usart, uint32_t baud) |
USART Set Baudrate. More... | |
void | usart_set_databits (uint32_t usart, uint32_t bits) |
USART Set Word Length. More... | |
void | usart_set_stopbits (uint32_t usart, uint32_t stopbits) |
USART Set Stop Bit(s). More... | |
void | usart_set_parity (uint32_t usart, uint32_t parity) |
USART Set Parity. More... | |
void | usart_set_mode (uint32_t usart, uint32_t mode) |
USART Set Rx/Tx Mode. More... | |
void | usart_set_flow_control (uint32_t usart, uint32_t flowcontrol) |
USART Set Hardware Flow Control. More... | |
void | usart_enable (uint32_t usart) |
USART Enable. More... | |
void | usart_disable (uint32_t usart) |
USART Disable. More... | |
void | usart_send (uint32_t usart, uint16_t data) |
USART Send a Data Word. More... | |
uint16_t | usart_recv (uint32_t usart) |
USART Read a Received Data Word. More... | |
void | usart_wait_send_ready (uint32_t usart) |
USART Wait for Transmit Data Buffer Empty. More... | |
void | usart_wait_recv_ready (uint32_t usart) |
USART Wait for Received Data Available. More... | |
void | usart_send_blocking (uint32_t usart, uint16_t data) |
USART Send Data Word with Blocking. More... | |
uint16_t | usart_recv_blocking (uint32_t usart) |
USART Read a Received Data Word with Blocking. More... | |
void | usart_enable_rx_dma (uint32_t usart) |
USART Receiver DMA Enable. More... | |
void | usart_disable_rx_dma (uint32_t usart) |
USART Receiver DMA Disable. More... | |
void | usart_enable_tx_dma (uint32_t usart) |
USART Transmitter DMA Enable. More... | |
void | usart_disable_tx_dma (uint32_t usart) |
USART Transmitter DMA Disable. More... | |
void | usart_enable_rx_interrupt (uint32_t usart) |
USART Receiver Interrupt Enable. More... | |
void | usart_disable_rx_interrupt (uint32_t usart) |
USART Receiver Interrupt Disable. More... | |
void | usart_enable_tx_interrupt (uint32_t usart) |
USART Transmitter Interrupt Enable. More... | |
void | usart_disable_tx_interrupt (uint32_t usart) |
USART Transmitter Interrupt Disable. More... | |
void | usart_enable_tx_complete_interrupt (uint32_t usart) |
USART Transmission Complete Interrupt Enable. More... | |
void | usart_disable_tx_complete_interrupt (uint32_t usart) |
USART Transmission Complete Interrupt Disable. More... | |
void | usart_enable_idle_interrupt (uint32_t usart) |
USART Idle Interrupt Enable. More... | |
void | usart_disable_idle_interrupt (uint32_t usart) |
USART Idle Interrupt Disable. More... | |
void | usart_enable_error_interrupt (uint32_t usart) |
USART Error Interrupt Enable. More... | |
void | usart_disable_error_interrupt (uint32_t usart) |
USART Error Interrupt Disable. More... | |
bool | usart_get_flag (uint32_t usart, uint32_t flag) |
USART Read a Status Flag. More... | |
Defined Constants and Types for the STM32F0xx USART
LGPL License Terms libopencm3 License
#define USART_CR2_STOPBITS_0_5 (0x01 << 12) /* 0.5 stop bits */ |
Definition at line 77 of file usart_common_all.h.
#define USART_CR2_STOPBITS_1 (0x00 << 12) /* 1 stop bit */ |
Definition at line 76 of file usart_common_all.h.
#define USART_CR2_STOPBITS_1_5 (0x03 << 12) /* 1.5 stop bits */ |
Definition at line 79 of file usart_common_all.h.
#define USART_CR2_STOPBITS_2 (0x02 << 12) /* 2 stop bits */ |
Definition at line 78 of file usart_common_all.h.
#define USART_CR2_STOPBITS_MASK (0x03 << 12) |
Definition at line 80 of file usart_common_all.h.
#define USART_CR2_STOPBITS_SHIFT 12 |
Definition at line 81 of file usart_common_all.h.
#define USART_FLOWCONTROL_MASK (USART_CR3_RTSE | USART_CR3_CTSE) |
Definition at line 95 of file usart_common_all.h.
#define USART_MODE_MASK (USART_CR1_RE | USART_CR1_TE) |
Definition at line 62 of file usart_common_all.h.
#define USART_PARITY_MASK (USART_CR1_PS | USART_CR1_PCE) |
Definition at line 50 of file usart_common_all.h.
void usart_disable | ( | uint32_t | usart | ) |
USART Disable.
At the end of the current frame, the USART is disabled to reduce power.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 195 of file usart_common_all.c.
References USART_CR1.
void usart_disable_error_interrupt | ( | uint32_t | usart | ) |
USART Error Interrupt Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 411 of file usart_common_all.c.
References USART_CR3.
void usart_disable_idle_interrupt | ( | uint32_t | usart | ) |
USART Idle Interrupt Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 387 of file usart_common_all.c.
References USART_CR1.
void usart_disable_rx_dma | ( | uint32_t | usart | ) |
USART Receiver DMA Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 259 of file usart_common_all.c.
References USART_CR3.
void usart_disable_rx_interrupt | ( | uint32_t | usart | ) |
USART Receiver Interrupt Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 314 of file usart_common_all.c.
References USART_CR1.
void usart_disable_tx_complete_interrupt | ( | uint32_t | usart | ) |
USART Transmission Complete Interrupt Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 364 of file usart_common_all.c.
References USART_CR1.
void usart_disable_tx_dma | ( | uint32_t | usart | ) |
USART Transmitter DMA Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 289 of file usart_common_all.c.
References USART_CR3.
void usart_disable_tx_interrupt | ( | uint32_t | usart | ) |
USART Transmitter Interrupt Disable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 338 of file usart_common_all.c.
References USART_CR1.
void usart_enable | ( | uint32_t | usart | ) |
USART Enable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 181 of file usart_common_all.c.
References USART_CR1, and USART_CR1_UE.
void usart_enable_error_interrupt | ( | uint32_t | usart | ) |
USART Error Interrupt Enable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 399 of file usart_common_all.c.
References USART_CR3, and USART_CR3_EIE.
void usart_enable_idle_interrupt | ( | uint32_t | usart | ) |
USART Idle Interrupt Enable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 375 of file usart_common_all.c.
References USART_CR1, and USART_CR1_IDLEIE.
void usart_enable_rx_dma | ( | uint32_t | usart | ) |
USART Receiver DMA Enable.
DMA is available on:
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 247 of file usart_common_all.c.
References USART_CR3, and USART_CR3_DMAR.
void usart_enable_rx_interrupt | ( | uint32_t | usart | ) |
USART Receiver Interrupt Enable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 301 of file usart_common_all.c.
References USART_CR1, and USART_CR1_RXNEIE.
void usart_enable_tx_complete_interrupt | ( | uint32_t | usart | ) |
USART Transmission Complete Interrupt Enable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 351 of file usart_common_all.c.
References USART_CR1, and USART_CR1_TCIE.
void usart_enable_tx_dma | ( | uint32_t | usart | ) |
USART Transmitter DMA Enable.
DMA is available on:
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 277 of file usart_common_all.c.
References USART_CR3, and USART_CR3_DMAT.
void usart_enable_tx_interrupt | ( | uint32_t | usart | ) |
USART Transmitter Interrupt Enable.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 326 of file usart_common_all.c.
References USART_CR1, and USART_CR1_TXEIE.
bool usart_get_flag | ( | uint32_t | usart, |
uint32_t | flag | ||
) |
USART Read a Status Flag.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | flag | Unsigned int32. Status register flag USART_ISR Values. |
Definition at line 300 of file usart_common_v2.c.
References USART_ISR.
uint16_t usart_recv | ( | uint32_t | usart | ) |
USART Read a Received Data Word.
If parity is enabled the MSB (bit 7 or 8 depending on the word length) is the parity bit.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 254 of file usart_common_v2.c.
References USART_RDR, and USART_RDR_MASK.
Referenced by usart_recv_blocking().
uint16_t usart_recv_blocking | ( | uint32_t | usart | ) |
USART Read a Received Data Word with Blocking.
Wait until a data word has been received then return the word.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 227 of file usart_common_all.c.
References usart_recv(), and usart_wait_recv_ready().
void usart_send | ( | uint32_t | usart, |
uint16_t | data | ||
) |
USART Send a Data Word.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | data | unsigned 16 bit. |
Definition at line 237 of file usart_common_v2.c.
References USART_TDR, and USART_TDR_MASK.
Referenced by usart_send_blocking().
void usart_send_blocking | ( | uint32_t | usart, |
uint16_t | data | ||
) |
USART Send Data Word with Blocking.
Blocks until the transmit data buffer becomes empty then writes the next data word for transmission.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | data | unsigned 16 bit. |
Definition at line 211 of file usart_common_all.c.
References usart_send(), and usart_wait_send_ready().
void usart_set_baudrate | ( | uint32_t | usart, |
uint32_t | baud | ||
) |
USART Set Baudrate.
The baud rate is computed from the APB high-speed prescaler clock (for USART1/6) or the APB low-speed prescaler clock (for other USARTs). These values must be correctly set before calling this function (refer to the rcc_clock_setup-* functions in RCC).
Note: For LPUART, baudrates over 2**24 (~16.7 Mbaud) may overflow the calculation and are therefore not supported by this function.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | baud | unsigned 32 bit. Baud rate specified in Hz. |
Definition at line 53 of file usart_common_all.c.
References rcc_get_usart_clk_freq(), and USART_BRR.
void usart_set_databits | ( | uint32_t | usart, |
uint32_t | bits | ||
) |
USART Set 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.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | bits | unsigned 32 bit. Word length in bits 8 or 9. |
Definition at line 89 of file usart_common_all.c.
References USART_CR1, and USART_CR1_M.
void usart_set_flow_control | ( | uint32_t | usart, |
uint32_t | flowcontrol | ||
) |
USART Set Hardware Flow Control.
The flow control bit can be selected as none, RTS, CTS or RTS+CTS.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | flowcontrol | unsigned 32 bit. Flowcontrol USART Hardware Flow Control Selection. |
Definition at line 165 of file usart_common_all.c.
References USART_CR3.
void usart_set_mode | ( | uint32_t | usart, |
uint32_t | mode | ||
) |
USART Set Rx/Tx Mode.
The mode can be selected as Rx only, Tx only or Rx+Tx.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | mode | unsigned 32 bit. Mode USART Tx/Rx Mode Selection. |
Definition at line 146 of file usart_common_all.c.
References USART_CR1.
void usart_set_parity | ( | uint32_t | usart, |
uint32_t | parity | ||
) |
USART Set Parity.
The parity bit can be selected as none, even or odd.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | parity | unsigned 32 bit. Parity USART Parity Selection. |
Definition at line 127 of file usart_common_all.c.
References USART_CR1.
void usart_set_stopbits | ( | uint32_t | usart, |
uint32_t | stopbits | ||
) |
USART Set Stop Bit(s).
The stop bits are specified as 0.5, 1, 1.5 or 2.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
[in] | stopbits | unsigned 32 bit. Stop bits USART Stop Bit Selection. |
Definition at line 108 of file usart_common_all.c.
References USART_CR2.
void usart_wait_recv_ready | ( | uint32_t | usart | ) |
USART Wait for Received Data Available.
Blocks until the receive data buffer holds a valid received data word.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 285 of file usart_common_v2.c.
References USART_ISR, and USART_ISR_RXNE.
Referenced by usart_recv_blocking().
void usart_wait_send_ready | ( | uint32_t | usart | ) |
USART Wait for Transmit Data Buffer Empty.
Blocks until the transmit data buffer becomes empty and is ready to accept the next data word.
[in] | usart | unsigned 32 bit. USART block register address base USART register base addresses |
Definition at line 270 of file usart_common_v2.c.
References USART_ISR, and USART_ISR_TXE.
Referenced by usart_send_blocking().