UART Serial Communication
1 UART Subsystem
UART is a serial, asynchronous, full-duplex communication interface with a little-bit-first (LSB First) bit order. After the two devices agree on the baud rate, data frame length, whether to use a parity bit, and the stop-bit length, they send and receive data through the TX (transmit) and RX (receive) signal lines. TX and RX are each relative to the device itself. In Linux, UARTs are usually managed by the kernel serial driver. User space accesses them via devices such as /dev/ttyS*, /dev/ttyAMA*, and /dev/ttyUSB*. Applications typically use open/read/write/ioctl or termios to configure the UART.
The UART wiring diagram is as follows:

The UART subsystem is mainly composed of the following parts:
1. TTY subsystem interface
The Linux UART subsystem is implemented on top of the TTY (Teletypewriter) framework for serial device management, providing a unified abstraction interface for character terminals, consoles, and serial communication. The TTY subsystem handles serial driver registration, device management, data buffering, and user-space access control. The /sys/class/tty directory exposes the registered serial devices in the system, including device names, driver binding relationships, and running status. Users can read related sysfs nodes to view UART device attributes, device numbers, and driver information, enabling serial device management and debugging.
2. UART character device node
The Linux kernel usually creates device nodes under /dev, such as /dev/ttyS0, /dev/ttyS1, and /dev/ttyAMA0, corresponding to different UART controllers or serial devices. These character device nodes provide a standard access interface for user-space programs. Applications can communicate with a specific serial device through system calls such as open(), read(), write(), and ioctl() to send and receive data, configure the baud rate, set the parity bit, and manage flow control. For example, users can use serial terminal tools (such as minicom or picocom) or custom applications to access a UART device for debug log output, command interaction, and peripheral communication.
3. Console and serial driver binding
The UART subsystem also serves as the Linux console output. During system boot, the kernel can specify the console device through the bootargs parameter, for example:
console=ttyS0,115200
This redirects the kernel boot log and shell output to the ttyS0 serial port, with the baud rate set to 115200.
After the UART driver completes hardware initialization, it registers the underlying UART controller as a TTY device and maps it to the corresponding character device node, enabling data exchange between user space and the hardware serial port.

Tip
Before operating the UART, confirm that the corresponding pins are configured for UART function in the DTS, not for GPIO or other muxed functions. 🔧 [TODO manual-fill: serial-port to pin mapping]
2 Shell Operations
2.1 List Available Serial Devices
# List all tty serial devices
ls /dev/tty*Expected output:
/dev/tty /dev/ttyAMA1 /dev/ttyS000 /dev/ttyp1
/dev/ttyAMA0 /dev/ttyAMA2 /dev/ttyp0Note
tty
This is the control device name of the current terminal, usually meaning the "current console".
ttyAMA0 / ttyAMA1 / ttyAMA2:
These are usually hardware UART serial ports, representing the 0th, 1st, and 2nd hardware serial ports. These devices are commonly used for: debug output, connecting to an MCU, attaching serial modules, production-line testing communication, etc.
ttyS000:
This is also a serial device name, usually registered by a different UART/serial driver. Some platforms name a serial port ttyS*, others ttyAMA*, depending on the driver and platform.
ttyp0 / ttyp1
These are pseudo-terminals, not hardware serial ports. Usually used for: shell sessions, terminal emulators, and local pseudo-terminal connections.
2.2 View Serial Device Details
cat /proc/tty/driver/<serial-driver-name>Expected output:
serinfo:1.0 driver revision:
0: uart:PL011 rev2 mmio:0x12040000 irq:27 tx:12924 rx:454 RTS|CTS|DTR|DSR|CD|RI
1: uart:PL011 rev2 mmio:0x12041000 irq:28 tx:0 rx:0 RI
2: uart:PL011 rev2 mmio:0x12042000 irq:29 tx:0 rx:0 RILog notes
serinfo:1.0 driver revision: The current version of the ttyAMA serial driver is 1.0.
0: uart:PL011 rev2 mmio:0x12040000 irq:27 tx:12924 rx:454 RTS|CTS|DTR|DSR|CD|RI Means the following:
0:Indicates the 0th serial port, usually corresponding to /dev/ttyAMA0.uart:PL011 rev2Indicates a PL011 type serial controller, version rev2.mmio:0x12040000The memory-mapped address of this serial controller.irq:27This serial port uses interrupt number 27.tx:1292412924 characters/bytes have been transmitted.rx:454454 characters/bytes have been received.RTS|CTS|DTR|DSR|CD|RIThese are modem control/status signal line flags, indicating that this serial driver supports these hardware handshake signals.
2.3 View Serial Parameters with stty
Using ttyAMA0 as an example
# View the current configuration of ttyAMA0
stty -F /dev/ttyAMA0Expected output:
/proc/tty/driver # stty -F /dev/ttyAMA0
speed 115200 baud; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol =
; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-brkint ixoff -imaxbel
-iextenLog notes
speed 115200 baud: The current serial baud rate is 115200, meaning the UART communication speed is 115200 bps.
line = 0: Indicates line discipline 0 is in use.
min = 1; time = 0; These are read-related parameters, often governing read() behavior. min = 1 means: return only after at least 1 byte is received. time = 0 means: no timeout set; read() blocks until the min condition is met. This is a common blocking-read pattern.
2.4 Configure Serial Parameters with stty
# Set baud rate 115200, 8N1 (8 data bits, no parity, 1 stop bit)
stty -F /dev/ttyAMA0 115200 cs8 -cstopb -parenb raw -echoExpected output:
# Command executed successfully, no output# Confirm the configuration took effect
stty -F /dev/ttyAMA0
Expected output:
```text
speed 115200 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon -echo2.5 Send and Receive Data with cat and echo
# Terminal 1: receive data (blocking wait)
cat /dev/ttyAMA0# Terminal 2: send data
echo "Hello UART" > /dev/ttyAMA0Expected output (terminal):
Hello UART2.6 Common stty Configuration Commands
# Set baud rate to 9600
stty -F /dev/ttyAMA0 9600
# Set 7 data bits + even parity
stty -F /dev/ttyAMA0 cs7 parenb -parodd
# Set 2 stop bits
stty -F /dev/ttyAMA0 cstopb
# Restore 115200 8N1
stty -F /dev/ttyAMA0 115200 cs8 -cstopb -parenb raw -echo