xref: /freebsd/share/man/man4/uart.4 (revision d7d962ead0b6e5e8a39202d0590022082bf5bfb6)
1.\"
2.\" Copyright (c) 2003 Marcel Moolenaar
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\"
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd July 11, 2020
29.Dt UART 4
30.Os
31.Sh NAME
32.Nm uart
33.Nd driver for Universal Asynchronous Receiver/Transmitter (UART) devices
34.Sh SYNOPSIS
35.Cd "device uart"
36.Pp
37.Cd "device puc"
38.Cd "device uart"
39.Pp
40.Cd "device scc"
41.Cd "device uart"
42.Pp
43In
44.Pa /boot/device.hints :
45.Cd hint.uart.0.disabled="1"
46.Cd hint.uart.0.baud="38400"
47.Cd hint.uart.0.port="0x3f8"
48.Cd hint.uart.0.flags="0x10"
49.Pp
50With
51.Ar flags
52encoded as:
53.Bl -tag -compact -width 0x000000
54.It 0x00010
55device is potential system console
56.It 0x00080
57use this port for remote kernel debugging
58.It 0x00100
59set RX FIFO trigger level to ``low'' (NS8250 only)
60.It 0x00200
61set RX FIFO trigger level to ``medium low'' (NS8250 only)
62.It 0x00400
63set RX FIFO trigger level to ``medium high'' (default, NS8250 only)
64.It 0x00800
65set RX FIFO trigger level to ``high'' (NS8250 only)
66.El
67.\"
68.Sh DESCRIPTION
69The
70.Nm
71device driver provides support for various classes of UARTs implementing the
72EIA RS-232C (CCITT V.24) serial communications interface.
73Each such interface is controlled by a separate and independent instance of
74the
75.Nm
76driver.
77The primary support for devices that contain multiple serial interfaces or
78that contain other functionality besides one or more serial interfaces is
79provided by the
80.Xr puc 4 ,
81or
82.Xr scc 4
83device drivers.
84However, the serial interfaces of those devices that are managed by the
85.Xr puc 4 ,
86or
87.Xr scc 4
88driver are each independently controlled by the
89.Nm
90driver.
91As such, the
92.Xr puc 4 ,
93or
94.Xr scc 4
95driver provides umbrella functionality for the
96.Nm
97driver and hides the complexities that are inherent when elementary components
98are packaged together.
99.Pp
100The
101.Nm
102driver has a modular design to allow it to be used on differing hardware and
103for various purposes.
104In the following sections the components are discussed in detail.
105Options are described in the section that covers the component to which each
106option applies.
107.\"
108.Ss CORE COMPONENT
109At the heart of the
110.Nm
111driver is the core component.
112It contains the bus attachments and the low-level interrupt handler.
113.\"
114.Ss HARDWARE DRIVERS
115The core component and the kernel interfaces talk to the hardware through the
116hardware interface.
117This interface serves as an abstraction of the hardware and allows varying
118UARTs to be used for serial communications.
119.\"
120.Ss SYSTEM DEVICES
121System devices are UARTs that have a special purpose by way of hardware
122design or software setup.
123For example, Sun UltraSparc machines use UARTs as their keyboard interface.
124Such an UART cannot be used for general purpose communications.
125Likewise, when the kernel is configured for a serial console, the
126corresponding UART will in turn be a system device so that the kernel can
127output boot messages early on in the boot process.
128.\"
129.Ss KERNEL INTERFACES
130The last but not least of the components is the kernel interface.
131This component ultimately determines how the UART is made visible to the
132kernel in particular and to users in general.
133The default kernel interface is the TTY interface.
134This allows the UART to be used for terminals, modems and serial line IP
135applications.
136System devices, with the notable exception of serial consoles, generally
137have specialized kernel interfaces.
138.\"
139.Sh HARDWARE
140The
141.Nm
142driver supports the following classes of UARTs:
143.Pp
144.Bl -bullet -compact
145.It
146NS8250: standard hardware based on the 8250, 16450, 16550, 16650, 16750 or
147the 16950 UARTs.
148.It
149SCC: serial communications controllers supported by the
150.Xr scc 4
151device driver.
152.El
153.\"
154.Sh Pulse Per Second (PPS) Timing Interface
155The
156.Nm
157driver can capture PPS timing information as defined in RFC 2783.
158The API, accessed via
159.Xr ioctl 2 ,
160is available on the tty device.
161To use the PPS capture feature with
162.Xr ntpd 8 ,
163symlink the tty callout device
164.Va /dev/cuau?
165to
166.Va /dev/pps0.
167.Pp
168The
169.Va hw.uart.pps_mode
170tunable configures the PPS capture mode for all uart devices;
171it can be set in
172.Xr loader.conf 5 .
173The
174.Va dev.uart.0.pps_mode
175sysctl configures the PPS capture mode for a specific uart device;
176it can be set in
177.Xr loader.conf 5
178or
179.Xr sysctl.conf 5 .
180.Pp
181The following capture modes are available:
182.Bl -tag -compact -offset "mmmm" -width "mmmm"
183.It 0x00
184Capture disabled.
185.It 0x01
186Capture pulses on the CTS line.
187.It 0x02
188Capture pulses on the DCD line.
189.El
190.Pp
191The following values may be ORed with the capture mode to configure
192capture processing options:
193.Bl -tag -compact -offset "mmmm" -width "mmmm"
194.It 0x10
195Invert the pulse (RS-232 logic low = ASSERT, high = CLEAR).
196.It 0x20
197Attempt to capture narrow pulses.
198.El
199.Pp
200Add the narrow pulse option when the incoming PPS pulse width is small
201enough to prevent reliable capture in normal mode.
202In narrow mode the driver uses the hardware's ability to latch a line
203state change; not all hardware has this capability.
204The hardware latch provides a reliable indication that a pulse occurred,
205but prevents distinguishing between the CLEAR and ASSERT edges of the pulse.
206For each detected pulse, the driver synthesizes both an ASSERT and a CLEAR
207event, using the same timestamp for each.
208To prevent spurious events when the hardware is intermittently able to
209see both edges of a pulse, the driver will not generate a new pair of
210events within a half second of the prior pair.
211Both normal and narrow pulse modes work with
212.Xr ntpd 8 .
213.Pp
214Add the invert option when the connection to the uart device uses TTL
215level signals, or when the PPS source emits inverted pulses.
216RFC 2783 defines an ASSERT event as a higher-voltage line level, and a CLEAR
217event as a lower-voltage line level, in the context of the RS-232 protocol.
218The modem control signals on a TTL-level connection are typically
219inverted from the RS-232 levels.
220For example, carrier presence is indicated by a high signal on an RS-232
221DCD line, and by a low signal on a TTL DCD line.
222This is due to the use of inverting line driver buffers to convert between
223TTL and RS-232 line levels in most hardware designs.
224Generally speaking, a connection to a DB-9 style connector is an RS-232
225level signal at up to 12 volts.
226A connection to header pins or an edge-connector on an embedded board
227is typically a TTL signal at 3.3 or 5 volts.
228.Sh Special Devices
229The
230.Nm
231driver also supports an initial-state and a lock-state control
232device for each of the callin and the callout "data" devices.
233The termios settings of a data device are copied
234from those of the corresponding initial-state device
235on first opens and are not inherited from previous opens.
236Use
237.Xr stty 1
238in the normal way on the initial-state devices to program
239initial termios states suitable for your setup.
240.Pp
241The lock termios state acts as flags to disable changing
242the termios state.
243E.g., to lock a flag variable such as CRTSCTS, use
244.Em stty crtscts
245on the lock-state device.
246Speeds and special characters
247may be locked by setting the corresponding value in the lock-state
248device to any nonzero value.
249E.g., to lock a speed to 115200, use
250.Dq Li stty 115200
251on the initial-state device and
252.Dq Li stty 1
253on the lock-state device.
254.Pp
255Correct programs talking to correctly wired external devices
256work with almost arbitrary initial states and almost no locking,
257but other setups may benefit from changing some of the default
258initial state and locking the state.
259In particular, the initial states for non (POSIX) standard flags
260should be set to suit the devices attached and may need to be
261locked to prevent buggy programs from changing them.
262E.g., CRTSCTS should be locked on for devices that support
263RTS/CTS handshaking at all times and off for devices that do not
264support it at all.
265CLOCAL should be locked on for devices that do not support carrier.
266HUPCL may be locked off if you do not
267want to hang up for some reason.
268In general, very bad things happen
269if something is locked to the wrong state, and things should not
270be locked for devices that support more than one setting.
271The CLOCAL flag on callin ports should be locked off for logins
272to avoid certain security holes, but this needs to be done by
273getty if the callin port is used for anything else.
274.Sh FILES
275.Bl -tag -width "/dev/ttyu?.init" -compact
276.It Pa /dev/ttyu?
277for callin ports
278.It Pa /dev/ttyu?.init
279.It Pa /dev/ttyu?.lock
280corresponding callin initial-state and lock-state devices
281.Pp
282.It Pa /dev/cuau?
283for callout ports
284.It Pa /dev/cuau?.init
285.It Pa /dev/cuau?.lock
286corresponding callout initial-state and lock-state devices
287.El
288.Sh SEE ALSO
289.Xr cu 1 ,
290.Xr puc 4 ,
291.Xr scc 4 ,
292.Xr ttys 5
293.\"
294.Sh HISTORY
295The
296.Nm
297device driver first appeared in
298.Fx 5.2 .
299.Sh AUTHORS
300The
301.Nm
302device driver and this manual page were written by
303.An Marcel Moolenaar Aq Mt marcel@xcllnt.net .
304