Skip to content

UART / TTY Subsystem Notes

1. TTY Architecture

TX Path

write()
  → tty core
  → line discipline
  → serial driver
  → UART hardware

RX Path

UART RX
  → interrupt
  → flip buffer
  → line discipline
  → tty core
  → read()

2. Key Components

TTY Core

  • manages /dev/ttyXXX
  • buffering
  • process interaction

Line Discipline (N_TTY)

  • canonical mode
  • echo
  • signal handling

Serial Driver (PL011)

  • hardware TX/RX
  • interrupt handling

3. Canonical vs Raw Mode

Mode Behavior
canonical line-based input
raw byte stream

UART communication uses raw mode.


4. termios / stty Important Fields

Check current config:

stty -F /dev/ttyAMA2 -a

Speed

  • speed 115200 baud → UART baudrate

Control Flags (c_cflag)

  • cs8 → 8 data bits

  • -parenb → no parity

  • -cstopb → 1 stop bit

  • cread → enable receiver

  • clocal → ignore modem control signals

  • -crtscts → disable hardware flow control


Input Flags (c_iflag)

  • -ixon -ixoff → disable software flow control

  • -icrnl → do not translate CR to NL


Output Flags (c_oflag)

  • -opost → disable output processing

Local Flags (c_lflag)

  • -icanon → raw mode (no line buffering)

  • -echo → disable echo

  • -isig → disable signal handling (Ctrl+C)


Control Characters

  • VMIN
  • VTIME

Example:

  • min = 0
  • time = 10

Meaning:

  • non-blocking read
  • 1 second timeout

5. Why Python Test Works Better

Python test:

  • single process
  • explicit termios config
  • controlled timing
  • uses flush

Shell test:

  • multiple processes
  • implicit config
  • race conditions

6. Key Insight

TTY is not a simple char device.

driver → flip buffer → tty core → user

Instead of:

driver → copy_to_user

7. Summary

  • UART is hardware
  • TTY is abstraction
  • termios is control plane
  • line discipline processes data
  • serial driver handles hardware