libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
common/uart.h
Go to the documentation of this file.
1/** @addtogroup uart_defines
2 *
3 * @author @htmlonly &copy; @endhtmlonly 2016 Maxim Sloyko <maxims@google.com>
4 * @author @htmlonly &copy; @endhtmlonly 2021 Eduard Drusa <ventyl86 at netkosice dot sk>
5 *
6 **/
7
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * Copyright (C) 2017-2018 Unicore MX project<dev(at)lists(dot)unicore-mx(dot)org>
12 * Copyright (C) 2021 Eduard Drusa <ventyl86(at)netkosice(dot)sk>
13 *
14 * This library is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this library. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
33
34/**@{*/
35
36/* Universal Asynchronous Receiver/Transmitter */
37
38/** @addtogroup uart_block UART instance
39 * @{
40 */
41#define UART0 UART0_BASE
42
43/**@}*/
44
45/* Tasks */
46
47#define UART_TASK_STARTRX(uart) MMIO32((uart) + 0x000)
48#define UART_TASK_STOPRX(uart) MMIO32((uart) + 0x004)
49#define UART_TASK_STARTTX(uart) MMIO32((uart) + 0x008)
50#define UART_TASK_STOPTX(uart) MMIO32((uart) + 0x00C)
51#define UART_TASK_SUSPEND(uart) MMIO32((uart) + 0x01C)
52
53/* Events */
54
55#define UART_EVENT_CTS(uart) MMIO32((uart) + 0x100)
56#define UART_EVENT_NCTS(uart) MMIO32((uart) + 0x104)
57#define UART_EVENT_RXDRDY(uart) MMIO32((uart) + 0x108)
58#define UART_EVENT_TXDRDY(uart) MMIO32((uart) + 0x11C)
59#define UART_EVENT_ERROR(uart) MMIO32((uart) + 0x124)
60#define UART_EVENT_RXTO(uart) MMIO32((uart) + 0x144)
61
62/* Registers */
63
64#define UART_INTEN(uart) _PERIPH_INTEN(uart)
65#define UART_INTENSET(uart) _PERIPH_INTENSET(uart)
66#define UART_INTENCLR(uart) _PERIPH_INTENCLR(uart)
67#define UART_ERRORSRC(uart) MMIO32((uart) + 0x480)
68#define UART_ENABLE(uart) MMIO32((uart) + 0x500)
69#define UART_PSELRTS(uart) MMIO32((uart) + 0x508)
70#define UART_PSELTXD(uart) MMIO32((uart) + 0x50C)
71#define UART_PSELCTS(uart) MMIO32((uart) + 0x510)
72#define UART_PSELRXD(uart) MMIO32((uart) + 0x514)
73#define UART_RXD(uart) MMIO32((uart) + 0x518)
74#define UART_TXD(uart) MMIO32((uart) + 0x51C)
75#define UART_BAUDRATE(uart) MMIO32((uart) + 0x524)
76#define UART_CONFIG(uart) MMIO32((uart) + 0x56C)
77
78/* Register Contents */
79
80/** @addtogroup uart_inten UART interrupt sources
81 * @{
82 */
83#define UART_INTEN_CTS (1 << 0)
84#define UART_INTEN_NCTS (1 << 1)
85#define UART_INTEN_RXDRDY (1 << 2)
86#define UART_INTEN_TXDRDY (1 << 7)
87#define UART_INTEN_ERROR (1 << 9)
88#define UART_INTEN_RXTO (1 << 17)
89
90/**@}*/
91
92#define UART_ERRORSRC_OVERRUN (1 << 0)
93#define UART_ERRORSRC_PARITY (1 << 1)
94#define UART_ERRORSRC_FRAMING (1 << 2)
95#define UART_ERRORSRC_BREAK (1 << 3)
96
97#define UART_ENABLE_ENABLED (4)
98#define UART_ENABLE_DISABLED (0)
99#define UART_CONFIG_HWFC (1)
100#define UART_CONFIG_PARITY (7 << 1)
101
102#define UART_PSEL_OFF (0xff)
103#define UART_MAX_PIN (31)
104#define UART_PSEL_VAL(p) (p <= UART_MAX_PIN ? (uint32_t) p : 0xffffffff)
105
106
108 UART_BAUD_1200 = 0x0004F000,
109 UART_BAUD_2400 = 0x0009D000,
110 UART_BAUD_4800 = 0x0013B000,
111 UART_BAUD_9600 = 0x00275000,
112 UART_BAUD_14400 = 0x003B0000,
113 UART_BAUD_19200 = 0x004EA000,
114 UART_BAUD_28800 = 0x0075F000,
115 UART_BAUD_38400 = 0x009D5000,
116 UART_BAUD_57600 = 0x00EBF000,
117 UART_BAUD_76800 = 0x013A9000,
118 UART_BAUD_115200 = 0x01D7E000,
119 UART_BAUD_230400 = 0x03AFB000,
120 UART_BAUD_250000 = 0x04000000,
121 UART_BAUD_460800 = 0x075F7000,
122 UART_BAUD_921600 = 0x0EBEDFA4,
123 UART_BAUD_1M = 0x10000000,
124};
125
126
128
129void uart_enable(uint32_t uart);
130void uart_disable(uint32_t uart);
131void uart_configure(uint32_t uart,
132uint32_t txd, uint32_t rxd, uint32_t rts, uint32_t cts,
133enum uart_baud br, bool enable_parity);
134void uart_set_baudrate(uint32_t uart, enum uart_baud br);
135void uart_set_parity(uint32_t uart, int parity);
136void uart_set_flow_control(uint32_t uart, int flow);
137void uart_send_stop(uint32_t uart);
138
139void uart_start_tx(uint32_t uart);
140void uart_stop_tx(uint32_t uart);
141void uart_send(uint32_t uart, uint16_t byte);
142void uart_start_rx(uint32_t uart);
143void uart_stop_rx(uint32_t uart);
144uint16_t uart_recv(uint32_t uart);
145void uart_set_pins(uint32_t uart, uint32_t rx, uint32_t tx, uint32_t cts, uint32_t rts);
146
148
149/**@}*/
150
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void uart_disable(uint32_t uart)
Disable the peripheral.
Definition: uart.c:49
void uart_send_stop(uint32_t uart)
void uart_set_parity(uint32_t uart, int parity)
Definition: uart.c:131
void uart_set_pins(uint32_t uart, uint32_t rx, uint32_t tx, uint32_t cts, uint32_t rts)
Select GPIO pins to be used by this peripheral.
Definition: uart.c:97
void uart_stop_tx(uint32_t uart)
Definition: uart.c:151
uint16_t uart_recv(uint32_t uart)
Definition: uart.c:161
void uart_set_baudrate(uint32_t uart, enum uart_baud br)
Definition: uart.c:126
void uart_stop_rx(uint32_t uart)
Definition: uart.c:166
void uart_set_flow_control(uint32_t uart, int flow)
Definition: uart.c:136
uart_baud
Definition: common/uart.h:107
void uart_send(uint32_t uart, uint16_t byte)
Definition: uart.c:146
void uart_enable(uint32_t uart)
Enable the peripheral.
Definition: uart.c:40
void uart_start_tx(uint32_t uart)
Definition: uart.c:141
void uart_start_rx(uint32_t uart)
Definition: uart.c:156
void uart_configure(uint32_t uart, uint32_t txd, uint32_t rxd, uint32_t rts, uint32_t cts, enum uart_baud br, bool enable_parity)
Configure UART parameters in single call.
Definition: uart.c:67
@ UART_BAUD_19200
Definition: common/uart.h:113
@ UART_BAUD_230400
Definition: common/uart.h:119
@ UART_BAUD_1200
Definition: common/uart.h:108
@ UART_BAUD_2400
Definition: common/uart.h:109
@ UART_BAUD_921600
Definition: common/uart.h:122
@ UART_BAUD_115200
Definition: common/uart.h:118
@ UART_BAUD_28800
Definition: common/uart.h:114
@ UART_BAUD_38400
Definition: common/uart.h:115
@ UART_BAUD_57600
Definition: common/uart.h:116
@ UART_BAUD_460800
Definition: common/uart.h:121
@ UART_BAUD_9600
Definition: common/uart.h:111
@ UART_BAUD_4800
Definition: common/uart.h:110
@ UART_BAUD_1M
Definition: common/uart.h:123
@ UART_BAUD_76800
Definition: common/uart.h:117
@ UART_BAUD_250000
Definition: common/uart.h:120
@ UART_BAUD_14400
Definition: common/uart.h:112