libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usart_common_all.h
Go to the documentation of this file.
1/** @addtogroup usart_defines
2 *
3 * @author @htmlonly &copy; @endhtmlonly 2009 Uwe Hermann <uwe@hermann-uwe.de>
4 *
5 */
6/*
7 * This file is part of the libopencm3 project.
8 *
9 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
10 *
11 * This library is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/**@{*/
26
27/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA USART.H
28The order of header inclusion is important. usart.h includes the device
29specific memorymap.h header before including this header file.*/
30
31/** @cond */
32#if defined(LIBOPENCM3_USART_H)
33/** @endcond */
34#ifndef LIBOPENCM3_USART_COMMON_ALL_H
35#define LIBOPENCM3_USART_COMMON_ALL_H
36
37
38/* --- Convenience defines ------------------------------------------------- */
39
40/* CR1_PCE / CR1_PS combined values */
41/****************************************************************************/
42/** @defgroup usart_cr1_parity USART Parity Selection
43@ingroup STM32F_usart_defines
44
45@{*/
46#define USART_PARITY_NONE 0x00
47#define USART_PARITY_EVEN USART_CR1_PCE
48#define USART_PARITY_ODD (USART_CR1_PS | USART_CR1_PCE)
49/**@}*/
50#define USART_PARITY_MASK (USART_CR1_PS | USART_CR1_PCE)
51
52/* CR1_TE/CR1_RE combined values */
53/****************************************************************************/
54/** @defgroup usart_cr1_mode USART Tx/Rx Mode Selection
55@ingroup STM32F_usart_defines
56
57@{*/
58#define USART_MODE_RX USART_CR1_RE
59#define USART_MODE_TX USART_CR1_TE
60#define USART_MODE_TX_RX (USART_CR1_RE | USART_CR1_TE)
61/**@}*/
62#define USART_MODE_MASK (USART_CR1_RE | USART_CR1_TE)
63
64/****************************************************************************/
65/** @defgroup usart_cr2_stopbits USART Stop Bit Selection
66@ingroup STM32F_usart_defines
67
68@{*/
69#define USART_STOPBITS_1 USART_CR2_STOPBITS_1 /* 1 stop bit */
70#define USART_STOPBITS_0_5 USART_CR2_STOPBITS_0_5 /* .5 stop bit */
71#define USART_STOPBITS_2 USART_CR2_STOPBITS_2 /* 2 stop bits */
72#define USART_STOPBITS_1_5 USART_CR2_STOPBITS_1_5 /* 1.5 stop bit*/
73/**@}*/
74
75/* STOP[13:12]: STOP bits */
76#define USART_CR2_STOPBITS_1 (0x00 << 12) /* 1 stop bit */
77#define USART_CR2_STOPBITS_0_5 (0x01 << 12) /* 0.5 stop bits */
78#define USART_CR2_STOPBITS_2 (0x02 << 12) /* 2 stop bits */
79#define USART_CR2_STOPBITS_1_5 (0x03 << 12) /* 1.5 stop bits */
80#define USART_CR2_STOPBITS_MASK (0x03 << 12)
81#define USART_CR2_STOPBITS_SHIFT 12
82
83
84/* CR3_CTSE/CR3_RTSE combined values */
85/****************************************************************************/
86/** @defgroup usart_cr3_flowcontrol USART Hardware Flow Control Selection
87@ingroup STM32F_usart_defines
88
89@{*/
90#define USART_FLOWCONTROL_NONE 0x00
91#define USART_FLOWCONTROL_RTS USART_CR3_RTSE
92#define USART_FLOWCONTROL_CTS USART_CR3_CTSE
93#define USART_FLOWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE)
94/**@}*/
95#define USART_FLOWCONTROL_MASK (USART_CR3_RTSE | USART_CR3_CTSE)
96
97/* --- Function prototypes ------------------------------------------------- */
98
100
101void usart_set_baudrate(uint32_t usart, uint32_t baud);
102void usart_set_databits(uint32_t usart, uint32_t bits);
103void usart_set_stopbits(uint32_t usart, uint32_t stopbits);
104void usart_set_parity(uint32_t usart, uint32_t parity);
105void usart_set_mode(uint32_t usart, uint32_t mode);
106void usart_set_flow_control(uint32_t usart, uint32_t flowcontrol);
107void usart_enable(uint32_t usart);
108void usart_disable(uint32_t usart);
109void usart_send(uint32_t usart, uint16_t data);
110uint16_t usart_recv(uint32_t usart);
111void usart_wait_send_ready(uint32_t usart);
112void usart_wait_recv_ready(uint32_t usart);
113void usart_send_blocking(uint32_t usart, uint16_t data);
114uint16_t usart_recv_blocking(uint32_t usart);
115void usart_enable_rx_dma(uint32_t usart);
116void usart_disable_rx_dma(uint32_t usart);
117void usart_enable_tx_dma(uint32_t usart);
118void usart_disable_tx_dma(uint32_t usart);
119void usart_enable_rx_interrupt(uint32_t usart);
120void usart_disable_rx_interrupt(uint32_t usart);
121void usart_enable_tx_interrupt(uint32_t usart);
122void usart_disable_tx_interrupt(uint32_t usart);
123void usart_enable_tx_complete_interrupt(uint32_t usart);
124void usart_disable_tx_complete_interrupt(uint32_t usart);
125void usart_enable_idle_interrupt(uint32_t usart);
126void usart_disable_idle_interrupt(uint32_t usart);
127void usart_enable_error_interrupt(uint32_t usart);
128void usart_disable_error_interrupt(uint32_t usart);
129bool usart_get_flag(uint32_t usart, uint32_t flag);
130
132
133#endif
134/** @cond */
135#else
136#warning "usart_common_all.h should not be included directly, only via usart.h"
137#endif
138/** @endcond */
139/**@}*/
140
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void usart_disable_idle_interrupt(uint32_t usart)
USART Idle Interrupt Disable.
uint16_t usart_recv(uint32_t usart)
USART Read a Received Data Word.
void usart_enable_error_interrupt(uint32_t usart)
USART Error Interrupt Enable.
void usart_enable_rx_dma(uint32_t usart)
USART Receiver DMA Enable.
void usart_send(uint32_t usart, uint16_t data)
USART Send a Data Word.
void usart_enable_tx_interrupt(uint32_t usart)
USART Transmitter Interrupt Enable.
void usart_wait_recv_ready(uint32_t usart)
USART Wait for Received Data Available.
void usart_set_parity(uint32_t usart, uint32_t parity)
USART Set Parity.
void usart_disable_tx_dma(uint32_t usart)
USART Transmitter DMA Disable.
void usart_disable_rx_dma(uint32_t usart)
USART Receiver DMA Disable.
void usart_wait_send_ready(uint32_t usart)
USART Wait for Transmit Data Buffer Empty.
void usart_disable_rx_interrupt(uint32_t usart)
USART Receiver Interrupt Disable.
void usart_disable(uint32_t usart)
USART Disable.
void usart_set_mode(uint32_t usart, uint32_t mode)
USART Set Rx/Tx Mode.
void usart_set_databits(uint32_t usart, uint32_t bits)
USART Set Word Length.
void usart_set_baudrate(uint32_t usart, uint32_t baud)
USART Set Baudrate.
uint16_t usart_recv_blocking(uint32_t usart)
USART Read a Received Data Word with Blocking.
void usart_enable_rx_interrupt(uint32_t usart)
USART Receiver Interrupt Enable.
void usart_enable_idle_interrupt(uint32_t usart)
USART Idle Interrupt Enable.
void usart_disable_tx_complete_interrupt(uint32_t usart)
USART Transmission Complete Interrupt Disable.
void usart_set_stopbits(uint32_t usart, uint32_t stopbits)
USART Set Stop Bit(s).
void usart_enable(uint32_t usart)
USART Enable.
void usart_disable_error_interrupt(uint32_t usart)
USART Error Interrupt Disable.
void usart_enable_tx_dma(uint32_t usart)
USART Transmitter DMA Enable.
void usart_enable_tx_complete_interrupt(uint32_t usart)
USART Transmission Complete Interrupt Enable.
void usart_set_flow_control(uint32_t usart, uint32_t flowcontrol)
USART Set Hardware Flow Control.
void usart_disable_tx_interrupt(uint32_t usart)
USART Transmitter Interrupt Disable.
void usart_send_blocking(uint32_t usart, uint16_t data)
USART Send Data Word with Blocking.
bool usart_get_flag(uint32_t usart, uint32_t flag)
USART Read a Status Flag.