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

Subversion Repositories neorv32

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

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
| Configuration generics:  | _IO_UART0_EN_ | implement UART0 when _true_
16
| CPU interrupts:          | fast IRQ channel 2 | RX done interrupt
17
|                          | fast IRQ channel 3 | TX done interrupt (see <<_processor_interrupts>>)
18
|=======================
19
 
20
[IMPORTANT]
21
Please note that ALL default example programs and software libraries of the NEORV32 software
22
framework (including the bootloader and the runtime environment) use the primary UART
23
(_UART0_) as default user console interface. For compatibility, all C-language function calls to
24
`neorv32_uart_*` are mapped to the according primary UART (_UART0_) `neorv32_uart0_*`
25
functions.
26
 
27
**Theory of Operation**
28
 
29
In most cases, the UART is a standard interface used to establish a communication channel between the
30
computer/user and an application running on the processor platform. The NEORV32 UARTs features a
31
standard configuration frame configuration: 8 data bits, an optional parity bit (even or odd) and 1 stop bit.
32
The parity and the actual Baudrate are configurable by software.
33
 
34 64 zero_gravi
The UART0 is enabled by setting the _UART_CTRL_EN_ bit in the UART control register `CTRL`. The actual
35
transmission Baudrate (like 19200) is configured via the 12-bit _UART_CTRL_BAUDxx_ baud prescaler (`baud_rate`) and the
36
3-bit _UART_CTRL_PRSCx_ clock prescaler.
37 60 zero_gravi
 
38
.UART prescaler configuration
39
[cols="<4,^1,^1,^1,^1,^1,^1,^1,^1"]
40
[options="header",grid="rows"]
41
|=======================
42 64 zero_gravi
| **`UART_CTRL_PRSCx`**       | `0b000` | `0b001` | `0b010` | `0b011` | `0b100` | `0b101` | `0b110` | `0b111`
43 60 zero_gravi
| Resulting `clock_prescaler` |       2 |       4 |       8 |      64 |     128 |    1024 |    2048 |    4096
44
|=======================
45
 
46
_**Baudrate**_ = (_f~main~[Hz]_ / `clock_prescaler`) / (`baud_rate` + 1)
47
 
48 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
49
transfer is completed when the _UART_CTRL_TX_BUSY_ control register flag returns to zero. A new received byte
50 60 zero_gravi
is available when the _UART_DATA_AVAIL_ flag of the UART0_DATA register is set. A "frame error" in a received byte
51
(broken stop bit) is indicated via the _UART_DATA_FERR_ flag in the UART0_DATA register.
52
 
53
**RX Double-Buffering**
54
 
55
The UART receive engine provides a simple data buffer with two entries. These two entries are transparent
56
for the user. The transmitting device can send up to 2 chars to the UART without risking data loss. If another
57
char is sent before at least one char has been read from the buffer data loss occurs. This situation can be
58 64 zero_gravi
detected via the receiver overrun flag _UART_DATA_OVERR_ in the `DATA` register. The flag is
59
automatically cleared after reading `DATA`.
60 60 zero_gravi
 
61
**Parity Modes**
62
 
63 64 zero_gravi
The parity flag is added if the _UART_CTRL_PMODE1_ flag is set. When _UART_CTRL_PMODE0_ is zero the UART
64 60 zero_gravi
operates in "even parity" mode. If this flag is set, the UART operates in "odd parity" mode. Parity errors in
65
received data are indicated via the _UART_DATA_PERR_ flag in the _UART_DATA_ registers. This flag is updated with each new
66
received character. A frame error in the received data (i.e. stop bit is not set) is indicated via the
67 64 zero_gravi
_UART_DATA_FERR_ flag in the `DATA`. This flag is also updated with each new received character
68 60 zero_gravi
 
69
**Hardware Flow Control – RTS/CTS**
70
 
71
The UART supports hardware flow control using the standard CTS (clear to send) and/or RTS (ready to send
72
/ ready to receive "RTR") signals. Both hardware control flow mechanisms can be individually enabled.
73
 
74 64 zero_gravi
If **RTS hardware flow control** is enabled by setting the _UART_CTRL_RTS_EN_ control register flag, the UART
75 60 zero_gravi
will pull the `uart0_rts_o` signal low if the UART's receiver is idle and no received data is waiting to get read by
76
application software. 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.
77
 
78
The RTS line is de-asserted (going high) as soon as the start bit of a new incoming char has been
79
detected. The transmitting device continues sending the current char and can also send another char
80
(due to the RX double-buffering), which is done by most terminal programs. Any additional data send
81
when RTS is still asserted will override the RX input buffer causing data loss. This will set the _UART_DATA_OVERR_ flag in the
82 64 zero_gravi
`DATA` register. Any read access to this register clears the flag again.
83 60 zero_gravi
 
84 64 zero_gravi
If **CTS hardware flow control** is enabled by setting the _UART_CTRL_CTS_EN_ control register flag, the UART's
85 60 zero_gravi
transmitter will not start sending a new char until the `uart0_cts_i` signal goes low. If a new data to be
86
send is written to the UART data register while `uart0_cts_i` is not asserted (=low), the UART will wait for
87
`uart0_cts_i` to become asserted (=high) before sending starts. During this time, the UART busy flag
88 64 zero_gravi
_UART_CTRL_TX_BUSY_ remains set.
89 60 zero_gravi
 
90
If `uart0_cts_i` is asserted, no new data transmission will be started by the UART. The state of the `uart0_cts_i`
91
signals has no effect on a transmission being already in progress.
92
 
93
Signal changes on `uart0_cts_i` during an active transmission are ignored. Application software can check
94 64 zero_gravi
the current state of the `uart0_cts_o` input signal via the _UART_CTRL_CTS_ control register flag.
95 60 zero_gravi
 
96
[TIP]
97
Please note that – just like the RXD and TXD signals – the RTS and CTS signals have to be **cross**-coupled
98
between devices.
99
 
100
**Interrupts**
101
 
102
The UART features two interrupts: the "TX done interrupt" is triggered when a transmit operation (sending) has finished. The "RX
103
done interrupt" is triggered when a data byte has been received. If the UART0 is not implemented, the UART0 interrupts are permanently tied to zero.
104
 
105
[NOTE]
106
The UART's RX interrupt is always triggered when a new data word has arrived – regardless of the
107
state of the RX double-buffer.
108
 
109
**Simulation Mode**
110
 
111 64 zero_gravi
The default UART0 operation will transmit any data written to the `DATA` register via the serial TX line at
112 60 zero_gravi
the defined baud rate. Even though the default testbench provides a simulated UART0 receiver, which
113
outputs any received char to the simulator console, such a transmission takes a lot of time. To accelerate
114
UART0 output during simulation (and also to dump large amounts of data for further processing like
115
verification) the UART0 features a **simulation mode**.
116
 
117 64 zero_gravi
The simulation mode is enabled by setting the _UART_CTRL_SIM_MODE_ bit in the UART0's control register
118
`CTRL`. Any other UART0 configuration bits are irrelevant, but the UART0 has to be enabled via the
119
_UART_CTRL_EN_ bit. When the simulation mode is enabled, any written char to `DATA` (bits 7:0) is
120 60 zero_gravi
directly output as ASCII char to the simulator console. Additionally, all text is also stored to a text file
121
`neorv32.uart0.sim_mode.text.out` in the simulation home folder. Furthermore, the whole 32-bit word
122 64 zero_gravi
written to `DATA` is stored as plain 8-char hexadecimal value to a second text file
123 60 zero_gravi
`neorv32.uart0.sim_mode.data.out` also located in the simulation home folder.
124
 
125
If the UART is configured for simulation mode there will be **NO physical UART0 transmissions via
126
`uart0_txd_o`** at all. Furthermore, no interrupts (RX done or TX done) will be triggered in any situation.
127
 
128
[TIP]
129 62 zero_gravi
More information regarding the simulation-mode of the UART0 can be found in the Uer Guide
130
section https://stnolting.github.io/neorv32/ug/#_simulating_the_processor[Simulating the Processor].
131 60 zero_gravi
 
132 64 zero_gravi
.UART0 register map (`struct NEORV32_UART0`)
133 60 zero_gravi
[cols="<6,<7,<10,^2,<18"]
134
[options="header",grid="all"]
135
|=======================
136
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
137 64 zero_gravi
.12+<| `0xffffffa0` .12+<| `NEORV32_UART0.CTRL` <|`11:0` _UART_CT_BAUDxx_ ^| r/w <| 12-bit BAUD value configuration value
138
                                                <|`12` _UART_CT_SIM_MODE_ ^| r/w <| enable **simulation mode**
139
                                                <|`20` _UART_CT_RTS_EN_   ^| r/w <| enable RTS hardware flow control
140
                                                <|`21` _UART_CT_CTS_EN_   ^| r/w <| enable CTS hardware flow control
141
                                                <|`22` _UART_CT_PMODE0_   ^| r/w .2+<| parity bit enable and configuration (`00`/`01`= no parity; `10`=even parity; `11`=odd parity)
142
                                                <|`23` _UART_CT_PMODE1_   ^| r/w
143
                                                <|`24` _UART_CT_PRSC0_    ^| r/w .3+<| 3-bit baudrate clock prescaler select
144
                                                <|`25` _UART_CT_PRSC1_    ^| r/w
145
                                                <|`26` _UART_CT_PRSC2_    ^| r/w
146
                                                <|`27` _UART_CT_CTS_      ^| r/- <| current state of UART's CTS input signal
147
                                                <|`28` _UART_CT_EN_       ^| r/w <| UART enable
148
                                                <|`31` _UART_CT_TX_BUSY_  ^| r/- <| trasmitter busy flag
149
.6+<| `0xffffffa4` .6+<| `NEORV32_UART0.DATA` <|`7:0` _UART_DATA_MSB_ : _UART_DATA_LSB_ ^| r/w <| receive/transmit data (8-bit)
150
                                              <|`31:0` -                ^| -/w <| **simulation data output**
151
                                              <|`28` _UART_DATA_PERR_   ^| r/- <| RX parity error
152
                                              <|`29` _UART_DATA_FERR_   ^| r/- <| RX data frame error (stop bit nt set)
153
                                              <|`30` _UART_DATA_OVERR_  ^| r/- <| RX data overrun
154
                                              <|`31` _UART_DATA_AVAIL_  ^| r/- <| RX data available when set
155 60 zero_gravi
|=======================
156
 
157
 
158
 
159
<<<
160
// ####################################################################################################################
161
:sectnums:
162
==== Secondary Universal Asynchronous Receiver and Transmitter (UART1)
163
 
164
[cols="<3,<3,<4"]
165
[frame="topbot",grid="none"]
166
|=======================
167
| Hardware source file(s): | neorv32_uart.vhd |
168
| Software driver file(s): | neorv32_uart.c |
169
|                          | neorv32_uart.h |
170
| Top entity port:         | `uart1_txd_o` | serial transmitter output UART1
171
|                          | `uart1_rxd_i` | serial receiver input UART1
172
|                          | `uart1_rts_o` | flow control: RX ready to receive
173
|                          | `uart1_cts_i` | flow control: TX allowed to send
174
| Configuration generics:  | _IO_UART1_EN_ | implement UART1 when _true_
175
| CPU interrupts:          | fast IRQ channel 4 | RX done interrupt
176
|                          | fast IRQ channel 5 | TX done interrupt (see <<_processor_interrupts>>)
177
|=======================
178
 
179
**Theory of Operation**
180
 
181
The secondary UART (UART1) is functional identical to the primary UART (<<_primary_universal_asynchronous_receiver_and_transmitter_uart0>>).
182
Obviously, UART1 has different addresses for
183 64 zero_gravi
the control register (`CTRL`) and the data register (`DATA`) – see the register map below. However, the
184 60 zero_gravi
register bits/flags use the same bit positions and naming. Furthermore, the "RX done" and "TX done" interrupts are
185
mapped to different CPU fast interrupt channels.
186
 
187
**Simulation Mode**
188
 
189
The secondary UART (UART1) provides the same simulation options as the primary UART. However,
190
output data is written to UART1-specific files: `neorv32.uart1.sim_mode.text.out` is used to store
191
plain ASCII text and `neorv32.uart1.sim_mode.data.out` is used to store full 32-bit hexadecimal
192
encoded data words.
193
 
194 64 zero_gravi
.UART1 register map (`struct NEORV32_UART1`)
195 60 zero_gravi
[cols="<6,<7,<10,^2,<18"]
196
[options="header",grid="all"]
197
|=======================
198
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
199 64 zero_gravi
.12+<| `0xffffffd0` .12+<| `NEORV32_UART1.CTRL` <|`11:0` _UART_CT_BAUDxx_ ^| r/w <| 12-bit BAUD value configuration value
200
                                                <|`12` _UART_CT_SIM_MODE_ ^| r/w <| enable **simulation mode**
201
                                                <|`20` _UART_CT_RTS_EN_   ^| r/w <| enable RTS hardware flow control
202
                                                <|`21` _UART_CT_CTS_EN_   ^| r/w <| enable CTS hardware flow control
203
                                                <|`22` _UART_CT_PMODE0_   ^| r/w .2+<| parity bit enable and configuration (`00`/`01`= no parity; `10`=even parity; `11`=odd parity)
204
                                                <|`23` _UART_CT_PMODE1_   ^| r/w
205
                                                <|`24` _UART_CT_PRSC0_    ^| r/w .3+<| 3-bit baudrate clock prescaler select
206
                                                <|`25` _UART_CT_PRSC1_    ^| r/w
207
                                                <|`26` _UART_CT_PRSC2_    ^| r/w
208
                                                <|`27` _UART_CT_CTS_      ^| r/- <| current state of UART's CTS input signal
209
                                                <|`28` _UART_CT_EN_       ^| r/w <| UART enable
210
                                                <|`31` _UART_CT_TX_BUSY_  ^| r/- <| trasmitter busy flag
211
.6+<| `0xffffffd4` .6+<| `NEORV32_UART1.DATA` <|`7:0` _UART_DATA_MSB_ : _UART_DATA_LSB_ ^| r/w <| receive/transmit data (8-bit)
212
                                              <|`31:0` -                ^| -/w <| **simulation data output**
213
                                              <|`28` _UART_DATA_PERR_   ^| r/- <| RX parity error
214
                                              <|`29` _UART_DATA_FERR_   ^| r/- <| RX data frame error (stop bit nt set)
215
                                              <|`30` _UART_DATA_OVERR_  ^| r/- <| RX data overrun
216
                                              <|`31` _UART_DATA_AVAIL_  ^| r/- <| RX data available when set
217 60 zero_gravi
|=======================

powered by: WebSVN 2.1.0

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