OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [docs/] [datasheet/] [soc_uart.adoc] - Blame information for rev 68

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 zero_gravi
<<<
2
:sectnums:
3
==== Primary Universal Asynchronous Receiver and Transmitter (UART0)
4
 
5
[cols="<3,<3,<4"]
6
[frame="topbot",grid="none"]
7
|=======================
8
| Hardware source file(s): | neorv32_uart.vhd |
9
| Software driver file(s): | neorv32_uart.c |
10
|                          | neorv32_uart.h |
11
| Top entity port:         | `uart0_txd_o` | serial transmitter output UART0
12
|                          | `uart0_rxd_i` | serial receiver input UART0
13
|                          | `uart0_rts_o` | flow control: RX ready to receive
14
|                          | `uart0_cts_i` | flow control: TX allowed to send
15 65 zero_gravi
| Configuration generics:  | _IO_UART0_EN_   | implement UART0 when _true_
16
|                          | _UART0_RX_FIFO_ | RX FIFO depth (power of 2, min 1)
17
|                          | _UART0_TX_FIFO_ | TX FIFO depth (power of 2, min 1)
18
| CPU interrupts:          | fast IRQ channel 2 | RX interrupt
19
|                          | fast IRQ channel 3 | TX interrupt (see <<_processor_interrupts>>)
20 60 zero_gravi
|=======================
21
 
22 65 zero_gravi
The UART is a standard serial interface mainly used to establish a communication channel between a host computer
23
computer/user and an application running on the embedded processor.
24
 
25
The NEORV32 UARTs feature independent transmitter and receiver with a fixed frame configuration of 8 data bits,
26
an optional parity bit (even or odd) and a fixed stop bit. The actual transmission rate - the Baudrate - is
27
programmable via software. Optional FIFOs with custom sizes can be configured for the transmitter and receiver
28
independently.
29
 
30
The UART features two memory-mapped registers `CTRL` and `DATA`, which are used for configuration, status
31
check and data transfer.
32
 
33
[NOTE]
34 60 zero_gravi
Please note that ALL default example programs and software libraries of the NEORV32 software
35
framework (including the bootloader and the runtime environment) use the primary UART
36 65 zero_gravi
(_UART0_) as default user console interface.
37 60 zero_gravi
 
38 65 zero_gravi
 
39 60 zero_gravi
**Theory of Operation**
40
 
41 66 zero_gravi
UART0 is enabled by setting the _UART_CTRL_EN_ bit in the UART0 control register `CTRL`. The Baud rate
42 65 zero_gravi
is configured via a 12-bit _UART_CTRL_BAUDxx_ baud prescaler (`baud_prsc`) and a 3-bit _UART_CTRL_PRSCx_
43
clock prescaler (`clock_prescaler`) that scales the processor's primary clock (_f~main~_).
44 60 zero_gravi
 
45 65 zero_gravi
.UART0 prescaler configuration
46 60 zero_gravi
[cols="<4,^1,^1,^1,^1,^1,^1,^1,^1"]
47
[options="header",grid="rows"]
48
|=======================
49 64 zero_gravi
| **`UART_CTRL_PRSCx`**       | `0b000` | `0b001` | `0b010` | `0b011` | `0b100` | `0b101` | `0b110` | `0b111`
50 60 zero_gravi
| Resulting `clock_prescaler` |       2 |       4 |       8 |      64 |     128 |    1024 |    2048 |    4096
51
|=======================
52
 
53 66 zero_gravi
_**Baud rate**_ = (_f~main~[Hz]_ / `clock_prescaler`) / (`baud_prsc` + 1)
54 60 zero_gravi
 
55 64 zero_gravi
A new transmission is started by writing the data byte to be send to the lowest byte of the `DATA` register. The
56
transfer is completed when the _UART_CTRL_TX_BUSY_ control register flag returns to zero. A new received byte
57 65 zero_gravi
is available when the _UART_DATA_AVAIL_ flag of the `DATA` register is set. A "frame error" in a received byte
58
(invalid stop bit) is indicated via the _UART_DATA_FERR_ flag in the `DATA` register. The flag is cleared by
59
reading the `DATA` register.
60 60 zero_gravi
 
61 66 zero_gravi
[TIP]
62
A transmission (RX or TX) can be terminated at any time by disabling the UART module
63
by clearing the _UART_CTRL_EN_ control register bit.
64 60 zero_gravi
 
65 66 zero_gravi
 
66 65 zero_gravi
**RX and TX FIFOs**
67 60 zero_gravi
 
68 65 zero_gravi
UART0 provides optional FIFO buffers for the transmitter and the receiver. The _UART0_RX_FIFO_ generic defines
69
the depth of the RX FIFO (for receiving data) while the _UART0_TX_FIFO_ defines the depth of the TX FIFO
70
(for sending data). Both generics have to be a power of two with a minimal allowed value of 1. This minimal
71
value will implement simple "double-buffering" instead of full-featured FIFOs.
72
Both FIFOs are cleared whenever UART0 is disabled (clearing _UART_CTRL_EN_ in `CTRL`).
73 60 zero_gravi
 
74 65 zero_gravi
The state of both FIFO (_empty_, _at lest half-full_, _full_) is available via the _UART_CTRL_?X_EMPTY_,
75
 _UART_CTRL_?X_HALF_ and _UART_CTRL_*X_FULL_ flags in the `CTRL` register.
76 60 zero_gravi
 
77 65 zero_gravi
If the RX FIFO is already full and new data is received by the receiver unit, the _UART_DATA_OVERR_ flag
78
in the `DATA` register is set indicating an "overrun". This flag is cleared by reading the `DATA` register.
79 60 zero_gravi
 
80 66 zero_gravi
[NOTE]
81
In contrast to other FIFO-equipped peripherals, software **cannot** determine the UART's FIFO size configuration
82
by reading specific control register bits (simply because there are no bits left in the control register).
83 60 zero_gravi
 
84
 
85 65 zero_gravi
**Hardware Flow Control - RTS/CTS**
86 60 zero_gravi
 
87 65 zero_gravi
UART0 supports optional hardware flow control using the standard CTS (clear to send) and/or RTS (ready to send
88
/ ready to receive "RTR") signals. Both hardware control flow mechanisms can be enabled individually.
89 60 zero_gravi
 
90 65 zero_gravi
* If **RTS hardware flow control** is enabled by setting the _UART_CTRL_RTS_EN_ control register flag, the UART
91
will pull the `uart0_rts_o` signal low if the UART's receiver is ready to receive new data.
92
As long as this signal is low the connected device can send new data. `uart0_rts_o` is always LOW if the UART is disabled.
93
The RTS line is de-asserted (going high) as soon as the start bit of a new incoming char has been
94
detected.
95 60 zero_gravi
 
96 65 zero_gravi
* If **CTS hardware flow control** is enabled by setting the _UART_CTRL_CTS_EN_ control register flag, the UART's
97
transmitter will not start sending a new data until the `uart0_cts_i` signal goes low. During this time, the UART busy flag
98
_UART_CTRL_TX_BUSY_ remains set. If `uart0_cts_i` is asserted, no new data transmission will be started by the UART.
99
The state of the `uart0_cts_i` signal has no effect on a transmission being already in progress. Application software can check
100 64 zero_gravi
the current state of the `uart0_cts_o` input signal via the _UART_CTRL_CTS_ control register flag.
101 60 zero_gravi
 
102
 
103 65 zero_gravi
**Parity Modes**
104
 
105
An optional parity bit can be added to the data stream if the _UART_CTRL_PMODE1_ flag is set.
106
When _UART_CTRL_PMODE0_ is zero, the UART operates in "even parity" mode. If this flag is set, the UART operates in "odd parity" mode.
107
Parity errors in received data are indicated via the _UART_DATA_PERR_ flag in the `DATA` register. This flag is updated with each new
108
received character and is cleared by reading the `DATA` register.
109
 
110
 
111 68 zero_gravi
**UART Interrupts**
112 60 zero_gravi
 
113 68 zero_gravi
UART0 features two independent interrupt for signaling certain RX and TX conditions. The behavior of these conditions differs
114
based on the configured FIFO sizes. If the according FIFO size is greater than 1, the _UART_CTRL_RX_IRQ_ and _UART_CTRL_TX_IRQ_
115
`CTRL` flags allow a more fine-grained IRQ configuration. An interrupt can only become pending if the according interrupt
116
condition is fulfilled and the UART is enabled at all.
117 60 zero_gravi
 
118 68 zero_gravi
* If _UART0_RX_FIFO_ is exactly 1, the RX interrupt goes pending when data _becomes_ available in the RX FIFO
119
(-> _UART_CTRL_RX_EMPTY_ clears). _UART_CTRL_RX_IRQ_ is hardwired to `0` in this case.
120
* If _UART0_TX_FIFO_ is exactly 1, the TX interrupt goes pending when at least one entry in the TX FIFO _becomes_ free
121
(-> _UART_CTRL_TX_FULL_ clears). _UART_CTRL_TX_IRQ_ is hardwired to `0` in this case.
122 60 zero_gravi
 
123 68 zero_gravi
* If _UART0_RX_FIFO_ is greater than 1: If _UART_CTRL_RX_IRQ_ is `0` the RX interrupt goes pending when data _becomes_
124
available in the RX FIFO (-> _UART_CTRL_RX_EMPTY_ clears). If _UART_CTRL_RX_IRQ_ is `1` the RX interrupt becomes pending
125
the RX FIFO _becomes_ at least half-full (-> _UART_CTRL_RX_HALF_ sets).
126
* If _UART0_TX_FIFO_ is greater than 1: If _UART_CTRL_TX_IRQ_ is `0` the TX interrupt goes pending when at least one entry
127
in the TX FIFO _becomes_ free (-> _UART_CTRL_TX_FULL_ clears). If _UART_CTRL_TX_IRQ_ is `1` the TX interrupt goes pending
128
when the RX FIFO _becomes_ less than half-full (-> _UART_CTRL_TX_HALF_ clears).
129 65 zero_gravi
 
130 68 zero_gravi
A **pending RX interrupt** request is cleared by any of the following operations:
131
* read access to `NEORV32_UART0.DATA` (for example to read incoming data)
132
* write access to `NEORV32_UART0.CTRL`
133
* disabling the UART module
134 65 zero_gravi
 
135 68 zero_gravi
A **pending TX interrupt** request is cleared by any of the following operations:
136
* write access to `NEORV32_UART0.DATA` (for example to send more data)
137
* write access to `NEORV32_UART0.CTRL`
138
* disabling the UART module
139 65 zero_gravi
 
140 68 zero_gravi
[TIP]
141
A dummy write to to the control register (i.e. `NEORV32_UART0.DATA = NEORV32_UART0.DATA`)
142
can be executed to acknowledge any interrupt.
143
 
144
 
145 60 zero_gravi
**Simulation Mode**
146
 
147 64 zero_gravi
The default UART0 operation will transmit any data written to the `DATA` register via the serial TX line at
148 65 zero_gravi
the defined baud rate via the physical link. To accelerate UART0 output during simulation
149
(and also to dump large amounts of data) the UART0 features a _simulation mode_.
150 60 zero_gravi
 
151 65 zero_gravi
Simulation mode is enabled by setting the _UART_CTRL_SIM_MODE_ bit in the UART0's control register
152
`CTRL`. Any other UART0 configuration bits are irrelevant for this mode but UART0 has to be enabled via the
153
_UART_CTRL_EN_ bit. There will be no physical UART0 transmissions via `uart0_txd_o` at all when
154
simulation mode is enabled. Furthermore, no interrupts (RX & TX) will be triggered.
155 60 zero_gravi
 
156 65 zero_gravi
When the simulation mode is enabled any data written to `DATA[7:0]` is
157
directly output as ASCII char to the simulator console. Additionally, all chars are also stored to a text file
158
`neorv32.uart0.sim_mode.text.out` in the simulation home folder.
159 60 zero_gravi
 
160 65 zero_gravi
Furthermore, the whole 32-bit word written to `DATA[31:0]` is stored as plain 8-char hexadecimal value to a
161
second text file `neorv32.uart0.sim_mode.data.out` also located in the simulation home folder.
162
 
163 60 zero_gravi
[TIP]
164 65 zero_gravi
More information regarding the simulation-mode of the UART0 can be found in the User Guide
165 62 zero_gravi
section https://stnolting.github.io/neorv32/ug/#_simulating_the_processor[Simulating the Processor].
166 60 zero_gravi
 
167 65 zero_gravi
 
168 64 zero_gravi
.UART0 register map (`struct NEORV32_UART0`)
169 60 zero_gravi
[cols="<6,<7,<10,^2,<18"]
170
[options="header",grid="all"]
171
|=======================
172
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
173 65 zero_gravi
.21+<| `0xffffffa0` .21+<| `NEORV32_UART0.CTRL` <|`11:0` _UART_CTRL_BAUDxx_ ^| r/w <| 12-bit BAUD value configuration value
174
                                                <|`12` _UART_CTRL_SIM_MODE_ ^| r/w <| enable **simulation mode**
175
                                                <|`13` _UART_CTRL_RX_EMPTY_ ^| r/- <| RX FIFO is empty
176
                                                <|`14` _UART_CTRL_RX_HALF_  ^| r/- <| RX FIFO is at least half-full
177
                                                <|`15` _UART_CTRL_RX_FULL_  ^| r/- <| RX FIFO is full
178
                                                <|`16` _UART_CTRL_TX_EMPTY_ ^| r/- <| TX FIFO is empty
179
                                                <|`17` _UART_CTRL_TX_HALF_  ^| r/- <| TX FIFO is at least half-full
180
                                                <|`18` _UART_CTRL_TX_FULL_  ^| r/- <| TX FIFO is full
181
                                                <|`19` -                    ^| r/- <| _reserved_, read as zero
182
                                                <|`20` _UART_CTRL_RTS_EN_   ^| r/w <| enable RTS hardware flow control
183
                                                <|`21` _UART_CTRL_CTS_EN_   ^| r/w <| enable CTS hardware flow control
184
                                                <|`22` _UART_CTRL_PMODE0_   ^| r/w .2+<| parity bit enable and configuration (`00`/`01`= no parity; `10`=even parity; `11`=odd parity)
185
                                                <|`23` _UART_CTRL_PMODE1_   ^| r/w
186
                                                <|`24` _UART_CTRL_PRSC0_    ^| r/w .3+<| 3-bit baudrate clock prescaler select
187
                                                <|`25` _UART_CTRL_PRSC1_    ^| r/w
188
                                                <|`26` _UART_CTRL_PRSC2_    ^| r/w
189
                                                <|`27` _UART_CTRL_CTS_      ^| r/- <| current state of UART's CTS input signal
190
                                                <|`28` _UART_CTRL_EN_       ^| r/w <| UART enable
191
                                                <|`29` _UART_CTRL_RX_IRQ_   ^| r/w <| RX IRQ mode: `1`=FIFO at least half-full; `0`=FIFO not empty
192
                                                <|`30` _UART_CTRL_TX_IRQ_   ^| r/w <| TX IRQ mode: `1`=FIFO less than half-full; `0`=FIFO not full
193
                                                <|`31` _UART_CTRL_TX_BUSY_  ^| r/- <| transmitter busy flag
194 64 zero_gravi
.6+<| `0xffffffa4` .6+<| `NEORV32_UART0.DATA` <|`7:0` _UART_DATA_MSB_ : _UART_DATA_LSB_ ^| r/w <| receive/transmit data (8-bit)
195
                                              <|`31:0` -                ^| -/w <| **simulation data output**
196
                                              <|`28` _UART_DATA_PERR_   ^| r/- <| RX parity error
197
                                              <|`29` _UART_DATA_FERR_   ^| r/- <| RX data frame error (stop bit nt set)
198
                                              <|`30` _UART_DATA_OVERR_  ^| r/- <| RX data overrun
199
                                              <|`31` _UART_DATA_AVAIL_  ^| r/- <| RX data available when set
200 60 zero_gravi
|=======================
201
 
202
 
203
 
204
<<<
205
// ####################################################################################################################
206
:sectnums:
207
==== Secondary Universal Asynchronous Receiver and Transmitter (UART1)
208
 
209
[cols="<3,<3,<4"]
210
[frame="topbot",grid="none"]
211
|=======================
212
| Hardware source file(s): | neorv32_uart.vhd |
213
| Software driver file(s): | neorv32_uart.c |
214
|                          | neorv32_uart.h |
215
| Top entity port:         | `uart1_txd_o` | serial transmitter output UART1
216
|                          | `uart1_rxd_i` | serial receiver input UART1
217
|                          | `uart1_rts_o` | flow control: RX ready to receive
218
|                          | `uart1_cts_i` | flow control: TX allowed to send
219 65 zero_gravi
| Configuration generics:  | _IO_UART1_EN_   | implement UART1 when _true_
220
|                          | _UART1_RX_FIFO_ | RX FIFO depth (power of 2, min 1)
221
|                          | _UART1_TX_FIFO_ | TX FIFO depth (power of 2, min 1)
222
| CPU interrupts:          | fast IRQ channel 4 | RX interrupt
223
|                          | fast IRQ channel 5 | TX interrupt (see <<_processor_interrupts>>)
224 60 zero_gravi
|=======================
225
 
226 65 zero_gravi
 
227 60 zero_gravi
**Theory of Operation**
228
 
229
The secondary UART (UART1) is functional identical to the primary UART (<<_primary_universal_asynchronous_receiver_and_transmitter_uart0>>).
230 65 zero_gravi
Obviously, UART1 has different addresses for the control register (`CTRL`) and the data register (`DATA`) - see the register map below.
231
The register's bits/flags use the same bit positions and naming as for the primary UART. The RX and TX interrupts of UART1 are
232
mapped to different CPU fast interrupt (FIRQ) channels.
233 60 zero_gravi
 
234 65 zero_gravi
 
235 60 zero_gravi
**Simulation Mode**
236
 
237
The secondary UART (UART1) provides the same simulation options as the primary UART. However,
238
output data is written to UART1-specific files: `neorv32.uart1.sim_mode.text.out` is used to store
239
plain ASCII text and `neorv32.uart1.sim_mode.data.out` is used to store full 32-bit hexadecimal
240 65 zero_gravi
data words.
241 60 zero_gravi
 
242 65 zero_gravi
 
243 64 zero_gravi
.UART1 register map (`struct NEORV32_UART1`)
244 60 zero_gravi
[cols="<6,<7,<10,^2,<18"]
245
[options="header",grid="all"]
246
|=======================
247
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
248 65 zero_gravi
.21+<| `0xffffffd0` .21+<| `NEORV32_UART1.CTRL` <|`11:0` _UART_CTRL_BAUDxx_ ^| r/w <| 12-bit BAUD value configuration value
249
                                                <|`12` _UART_CTRL_SIM_MODE_ ^| r/w <| enable **simulation mode**
250
                                                <|`13` _UART_CTRL_RX_EMPTY_ ^| r/- <| RX FIFO is empty
251
                                                <|`14` _UART_CTRL_RX_HALF_  ^| r/- <| RX FIFO is at least half-full
252
                                                <|`15` _UART_CTRL_RX_FULL_  ^| r/- <| RX FIFO is full
253
                                                <|`16` _UART_CTRL_TX_EMPTY_ ^| r/- <| TX FIFO is empty
254
                                                <|`17` _UART_CTRL_TX_HALF_  ^| r/- <| TX FIFO is at least half-full
255
                                                <|`18` _UART_CTRL_TX_FULL_  ^| r/- <| TX FIFO is full
256
                                                <|`19` -                    ^| r/- <| _reserved_, read as zero
257
                                                <|`20` _UART_CTRL_RTS_EN_   ^| r/w <| enable RTS hardware flow control
258
                                                <|`21` _UART_CTRL_CTS_EN_   ^| r/w <| enable CTS hardware flow control
259
                                                <|`22` _UART_CTRL_PMODE0_   ^| r/w .2+<| parity bit enable and configuration (`00`/`01`= no parity; `10`=even parity; `11`=odd parity)
260
                                                <|`23` _UART_CTRL_PMODE1_   ^| r/w
261
                                                <|`24` _UART_CTRL_PRSC0_    ^| r/w .3+<| 3-bit baudrate clock prescaler select
262
                                                <|`25` _UART_CTRL_PRSC1_    ^| r/w
263
                                                <|`26` _UART_CTRL_PRSC2_    ^| r/w
264
                                                <|`27` _UART_CTRL_CTS_      ^| r/- <| current state of UART's CTS input signal
265
                                                <|`28` _UART_CTRL_EN_       ^| r/w <| UART enable
266
                                                <|`29` _UART_CTRL_RX_IRQ_   ^| r/w <| RX IRQ mode: `1`=FIFO at least half-full; `0`=FIFO not empty; hardwired to zero if _UART0_RX_FIFO_ = 1
267
                                                <|`30` _UART_CTRL_TX_IRQ_   ^| r/w <| TX IRQ mode: `1`=FIFO less than half-full; `0`=FIFO not full; hardwired to zero if _UART0_TX_FIFO_ = 1
268
                                                <|`31` _UART_CTRL_TX_BUSY_  ^| r/- <| transmitter busy flag
269 64 zero_gravi
.6+<| `0xffffffd4` .6+<| `NEORV32_UART1.DATA` <|`7:0` _UART_DATA_MSB_ : _UART_DATA_LSB_ ^| r/w <| receive/transmit data (8-bit)
270
                                              <|`31:0` -                ^| -/w <| **simulation data output**
271
                                              <|`28` _UART_DATA_PERR_   ^| r/- <| RX parity error
272
                                              <|`29` _UART_DATA_FERR_   ^| r/- <| RX data frame error (stop bit nt set)
273
                                              <|`30` _UART_DATA_OVERR_  ^| r/- <| RX data overrun
274
                                              <|`31` _UART_DATA_AVAIL_  ^| r/- <| RX data available when set
275 60 zero_gravi
|=======================

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.