libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usart.h
Go to the documentation of this file.
1/**
2 * @brief USART definitions for the Qorvo PAC55xx series of microcontrollers
3 *
4 * @addtogroup PAC55xx_usart USART
5 * @ingroup PAC55xx_defines
6 * @author Kevin Stefanik <kevin@allocor.tech>
7 * LGPL License Terms @ref lgpl_license
8 * @date 25 Feb 2020
9 *
10 * Definitions in this file come from the PAC55XX Family User Guide Rev 1.23
11 * by Active-Semi dated November 19, 2019. TX and RX hardware buffer sizes
12 * are both 16 bytes.
13 */
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * Copyright (C) 2020 Kevin Stefanik <kevin@allocor.tech>
18 *
19 * This library is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with this library. If not, see <http://www.gnu.org/licenses/>.
31 */
32#ifndef LIBOPENCM3_PAC55XX_USART_H_
33#define LIBOPENCM3_PAC55XX_USART_H_
34
37
38/**@{*/
39
40/** @defgroup usart_registers Registers
41@{*/
42/** Receive Buffer Register RO, only bits 7:0 used */
43#define USART_RBR(usart_base) MMIO32((usart_base) + 0x0000)
44/** Transmit Holding Register WO, only bits 7:0 used */
45#define USART_THR(usart_base) MMIO32((usart_base) + 0x0004)
46/** Divisor Latch Register RW, default 0000 0001h, only bits 15:0 used.*/
47#define USART_DLR(usart_base) MMIO32((usart_base) + 0x0008)
48/** Interrupt Enable Register RW, default 0000 0000h */
49#define USART_IER(usart_base) MMIO32((usart_base) + 0x000C)
50/** Interrupt Identification Register RO, default 0000 0001h */
51#define USART_IIR(usart_base) MMIO32((usart_base) + 0x0010)
52/** FIFO Control Register RW, default 0000 0000h */
53#define USART_FCR(usart_base) MMIO32((usart_base) + 0x0014)
54/** Line control Register RW, default 0000 0000h */
55#define USART_LCR(usart_base) MMIO32((usart_base) + 0x0018)
56/** Line Status Register RO, default 0000 0060h */
57#define USART_LSR(usart_base) MMIO32((usart_base) + 0x0020)
58/** Scratch Pad Register RW, only bits 7:0 used */
59#define USART_SCR(usart_base) MMIO32((usart_base) + 0x0028)
60/** Enhanced Mode Register RW, default 0000 000h */
61#define USART_EFR(usart_base) MMIO32((usart_base) + 0x002C)
62/**@}*/
63
64/** @defgroup usart_ier_bits Interrupt Enable Register bits
65@{*/
66/** Enable RX line status interrupt */
67#define USART_IER_RLSIE BIT2
68/** Enable the TX Holding Empty interrupt */
69#define USART_IER_THRIE BIT1
70/** Enable the RX Buffer Register Interrupt */
71#define USART_IER_RBRIE BIT0
72/**@}*/
73
74/** @defgroup usart_iir_bits Interrupt ID Register bits
75@{*/
76/** This bit is active low to indicate an interrupt is pending */
77#define USART_IIR_INTSTATUS BIT0
78/** TX Holding Register Empty */
79#define USART_IIR_TXEMPTY (0x02)
80/** Receive Data Available */
81#define USART_IIR_RXAVAIL (0x04)
82/** Receive Line Status */
83#define USART_IIR_RXLINESTAT (0x06)
84/** Receive FIFO Character Time-out */
85#define USART_IIR_RXTIMEOUT (0x0C)
86/**@}*/
87
88/** @defgroup usart_fcr_bits FIFO Control Register bits
89@{*/
90/** Enable both UART RX and TX FIFOs, must be set before writing rest of FCR */
91#define USART_FCR_FIFOEN BIT0
92/** RX FIFO Reset. Write 1 to clear. This bit is self-clearing. */
93#define USART_FCR_RXFIFORST BIT1
94/** TX FIFO Reset. Write 1 to clear. This bit is self-clearing. */
95#define USART_FCR_TXFIFORST BIT2
96#define USART_FCR_TXTL_MASK (3)
97#define USART_FCR_TXTL_SHIFT 4
98/** TX Trigger Level */
99#define USART_FCR_TXTL(txtl) (((txtl) & USART_FCR_TXTL_MASK) << USART_FCR_TXTL_SHIFT)
100#define USART_FCR_RXTL_MASK (3)
101#define USART_FCR_RXTL_SHIFT 6
102/** RX Trigger Level */
103#define USART_FCR_RXTL(rxtl) (((rxtl) & USART_FCR_RXTL_MASK) << USART_FCR_RXTL_SHIFT)
104#define USART_FIFO_TRIG_1CHAR (0)
105#define USART_FIFO_TRIG_4CHAR (1)
106#define USART_FIFO_TRIG_8CHAR (2)
107#define USART_FIFO_TRIG_14CHAR (3)
108/**@}*/
109
110/** @defgroup usart_lcr_bits Line Control Register bits
111@{*/
112/** LCR:WLS 5-bit character length */
113#define USART_DATABITS_5 (0)
114/** LCR:WLS 6-bit character length */
115#define USART_DATABITS_6 (0x01)
116/** LCR:WLS 7-bit character length */
117#define USART_DATABITS_7 (0x02)
118/** LCR:WLS 8-bit character length */
119#define USART_DATABITS_8 (0x03)
120/** LCR:PSEL & LCR:PEN Odd parity */
121#define USART_PSELPEN_ODD (0x01)
122/** LCR:PSEL & LCR:PEN Even parity */
123#define USART_PSELPEN_EVEN (0x03)
124/** LCR:PSEL & LCR:PEN Force 1 stick parity */
125#define USART_PSELPEN_FORCE1 (0x05)
126/** LCR:PSEL & LCR:PEN Force 0 stick parity */
127#define USART_PSELPEN_FORCE0 (0x07)
128/** LCR:PSEL & LCR:PEN Disable parity */
129#define USART_PARITY_DISABLE (0)
130/** LCR:PSEL & LCR:PEN Odd parity */
131#define USART_PARITY_ODD USART_PSELPEN_ODD
132/** LCR:PSEL & LCR:PEN Even parity */
133#define USART_PARITY_EVEN USART_PSELPEN_EVEN
134/** LCR:PSEL & LCR:PEN Force 1 stick parity */
135#define USART_PARITY_FORCE1 USART_PSELPEN_FORCE1
136/** LCR:PSEL & LCR:PEN Force 0 stick parity */
137#define USART_PARITY_FORCE0 USART_PSELPEN_FORCE0
138/** LCR:SBS Use 1 stop bit */
139#define USART_STOPBITS_1 (0)
140/** LCR:SBS Use 1.5 stop bit when databits is 5 */
141#define USART_STOPBITS_1P5 USART_LCR_SBS
142/** LCR:SBS Use 2 stop bits */
143#define USART_STOPBITS_2 USART_LCR_SBS
144#define USART_LCR_WLS_MASK (3)
145/** Word length select: 5-8 databits */
146#define USART_LCR_WLS(wls) ((wls) & USART_LCR_WLS_MASK)
147/** Set LCR:SBS for 1.5 or 2 stop bits, Clear for 1 stop bit */
148#define USART_LCR_SBS BIT2
149/** Enable parity checking */
150#define USART_LCR_PEN BIT3
151#define USART_LCR_PSELPEN_MASK (7)
152#define USART_LCR_PSELPEN_SHIFT 3
153/** LCR:PSEL and LCR:PEN control parity */
154#define USART_LCR_PSELPEN(psel) (((psel) & USART_LCR_PSELPEN_MASK) << USART_LCR_PSELPEN_SHIFT)
155/** Break Control: Enabling this bit forces TX to logic 0 */
156#define USART_LCR_BCON BIT6
157/**@}*/
158
159/** @defgroup usart_lsr_bits Line Status Register bits
160@{*/
161/** Receiver Data Ready */
162#define USART_LSR_RDR BIT0
163/** Overrun Error */
164#define USART_LSR_OE BIT1
165/** Parity Error */
166#define USART_LSR_PE BIT2
167/** Framing Error */
168#define USART_LSR_FE BIT3
169/** Break Interrupt */
170#define USART_LSR_BI BIT4
171/** Transmitter Holding Register Empty */
172#define USART_LSR_THRE BIT5
173/** Transmitter Empty */
174#define USART_LSR_TEMT BIT6
175/** Error in RX FIFO */
176#define USART_LSR_RXFE BIT7
177/**@}*/
178
179/** TX FIFO depth */
180#define USART_TX_FIFO_DEPTH (16)
181/** RX FIFO depth */
182#define USART_RX_FIFO_DETPH (16)
183
184/** Enable Enhanced Mode to use TX and RX FIFO trigger level interrupts */
185#define USART_EFR_ENMODE BIT4
186
187/**@}*/
188
190
191uint32_t usart_set_baudrate(uint32_t usart, uint32_t baud);
192void usart_configure_lcr(uint32_t usart, uint8_t data_bits, uint8_t stop_bits,
193 uint8_t parity);
194void usart_break_enable(uint32_t usart);
195void usart_break_disable(uint32_t usart);
196void usart_enhanced_enable(uint32_t usart);
197void usart_enhanced_disable(uint32_t usart);
198void usart_set_fifo_depth(uint32_t usart, uint8_t tx_depth, uint8_t rx_depth);
199void usart_send(uint32_t usart, uint8_t data);
200uint8_t usart_recv(uint32_t usart);
201void usart_enable_rx_interrupt(uint32_t usart);
202void usart_disable_rx_interrupt(uint32_t usart);
203void usart_enable_tx_interrupt(uint32_t usart);
204void usart_disable_tx_interrupt(uint32_t usart);
205void usart_enable_rls_interrupt(uint32_t usart);
206void usart_disable_rls_interrupt(uint32_t usart);
207void usart_fifo_enable(uint32_t usart);
208void usart_fifo_disable(uint32_t usart);
209void usart_clear_tx_fifo(uint32_t usart);
210void usart_clear_rx_fifo(uint32_t usart);
211
213
214#endif /* LIBOPENCM3_PAC55XX_USART_H_ */
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void usart_enable_rls_interrupt(uint32_t usart)
Enable RX Line Status Interrupt Enable the RX Line Status interrupt.
Definition: usart.c:172
void usart_fifo_enable(uint32_t usart)
Enable FIFOs Enable both TX and RX FIFOs.
Definition: usart.c:98
uint8_t usart_recv(uint32_t usart)
Read byte from the RX FIFO.
Definition: usart.c:132
void usart_enable_tx_interrupt(uint32_t usart)
Enable TX Interrupt Enable the TX Holding Register Empty interrupt.
Definition: usart.c:156
void usart_set_fifo_depth(uint32_t usart, uint8_t tx_depth, uint8_t rx_depth)
Set the TX and RX FIFO depth.
Definition: usart.c:115
void usart_enhanced_enable(uint32_t usart)
Enable Enhanced Mode Enable enhanced mode to generate interrupts when FIFO thresholds in FCR are reac...
Definition: usart.c:82
void usart_clear_tx_fifo(uint32_t usart)
Clear the TX FIFO Clears the TX FIFO.
Definition: usart.c:188
void usart_disable_rx_interrupt(uint32_t usart)
Disable RX Interrupts Disable both the Receive Data Available and Character Timeout interrupts.
Definition: usart.c:148
uint32_t usart_set_baudrate(uint32_t usart, uint32_t baud)
USART Set Baudrate The baud rate is computed assuming a peripheral clock of 150MHz.
Definition: usart.c:39
void usart_send(uint32_t usart, uint8_t data)
Write byte to TX FIFO.
Definition: usart.c:124
void usart_configure_lcr(uint32_t usart, uint8_t data_bits, uint8_t stop_bits, uint8_t parity)
USART Configure Line Control Register This register sets the data bits, stop bits,...
Definition: usart.c:55
void usart_clear_rx_fifo(uint32_t usart)
Clear the RX FIFO Clears the RX FIFO.
Definition: usart.c:196
void usart_enable_rx_interrupt(uint32_t usart)
Enable RX Interrupts Enable both the Receive Data Available and Character Timeout interrupts.
Definition: usart.c:140
void usart_fifo_disable(uint32_t usart)
Disable FIFOs Disable both TX and RX FIFOs.
Definition: usart.c:106
void usart_break_enable(uint32_t usart)
Enable Break Control Enables break control bit that forces TX pin to logic low.
Definition: usart.c:66
void usart_disable_rls_interrupt(uint32_t usart)
Disable RX Line Status Interrupt Disable the RX Line Status interrupt.
Definition: usart.c:180
void usart_enhanced_disable(uint32_t usart)
Disable Enhanced Mode Disable enhanced mode to generate interrupts when FIFO thresholds in FCR are re...
Definition: usart.c:90
void usart_break_disable(uint32_t usart)
Disable Break Control Disables break control bit that forces TX pin to logic low.
Definition: usart.c:74
void usart_disable_tx_interrupt(uint32_t usart)
Disable TX Interrupt Disable the TX Holding Register Empty interrupt.
Definition: usart.c:164