Skip to content

UART: Serial programming

Userspace

Referring to:

for detail intructions when programing with serial port.

A serial port configuration is stored in a structure struct termios, which defined in <asm/termbits.h>. Userspace program interfaces with serial port via device file (/dev/ttyS0 for example).

When a new session with a serial port is created, current configuration will be saved in struct termios oldtio, oldtio is get from device by API:

int tcgetattr(int fd, struct termios *termios_p);

A new configuration struct termios newtio is created and applied to device by API:

int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);

After applying compatible configuration, userspace application can communicate with serial port by calling read and write system call with file description fd.

Kernelspace

Referring to:

To be properly intergrated in a Linux system, serial ports like UART must be visible as TTY devices from user space application. Therefore, the serial driver must be part of the kernle TTY subsystem.

uart_driver

Back to top