“Serial TTY overview”的版本间的差异

来自百问网嵌入式Linux wiki
 
(未显示同一用户的11个中间版本)
第103行: 第103行:
 
==Configuration==
 
==Configuration==
  
This section describes how to configure a device on a serial port.
+
本节介绍如何在串行端口上配置设备。
  
 
===Kernel Configuration===
 
===Kernel Configuration===
The serial driver, serial framework, and TTY framework are activated by default in ST deliveries. Nevertheless, if a specific configuration is needed, this section indicates how IIO can be activated/deactivated in the kernel.
+
默认情况下,ST交付中会激活串行驱动程序,串行框架和TTY框架。 但是,如果需要特定的配置,则本节说明如何在内核中激活/停用IIO。
  
Activate the device TTY in kernel configuration with Linux [[Menuconfig or how to configure kernel | Menuconfig ]] tool.
+
使用Linux[[Menuconfig or how to configure kernel | Menuconfig ]] 工具。
  
For TTY, select:
+
对于TTY,选择:
 
<pre>
 
<pre>
 
Device Drivers  --->
 
Device Drivers  --->
第116行: 第116行:
 
     [*]  Enable TTY                           
 
     [*]  Enable TTY                           
  
Allows to remove the TTY support which can save space, and blocks features that require TTY from inclusion in the kernel.
+
允许删除可节省空间的TTY支持,并阻止需要TTY的功能包含在内核中。
The TTY is required for any text terminals or serial port communication. Most users should leave this enabled.
+
任何文本终端或串行端口通信都需要TTY。 大多数用户应启用此功能。
 
</pre>
 
</pre>
  
For the STM32 serial driver, select:
+
对于STM32串行驱动程序,选择:
 
<pre>
 
<pre>
 
Device Drivers  --->
 
Device Drivers  --->
第128行: 第128行:
 
     [*]  Support for console on STM32
 
     [*]  Support for console on STM32
  
This driver is for the on-chip serial controller on STMicroelectronics STM32 MCUs.
+
该驱动程序用于STMicroelectronics STM32 MCU上的片上串行控制器。
The USART supports Rx and Tx functionality. It supports all industry standard baud rates.</pre>
+
USART支持Rx和Tx功能。它支持所有行业标准的波特率。</pre>
  
 
===Device tree configuration ===
 
===Device tree configuration ===
The UART configuration thanks to the device tree is described in the dedicated article [[Serial TTY device tree configuration|Serial TTY device tree configuration]].
+
专用文章[[Serial TTY device tree configuration|Serial TTY device tree configuration]]中描述了由于设备树而导致的UART配置。
  
 
==How to use TTY==
 
==How to use TTY==
This section describes how to use TTY from the user land (from a terminal or an application) and from the kernel space, based on the two following use cases:
+
本节基于以下两个用例,描述如何从用户区域(从终端或应用程序)以及内核空间使用TTY:
* How to configure the serial port by using the termios structure
+
* 如何使用termios结构配置串行端口
* How to send/receive data
+
* 如何发送/接收数据
  
The termios structure allows to configure communication ports with many settings, such as :
+
termios结构允许使用许多设置来配置通信端口,例如:
 
* Baud rate
 
* Baud rate
 
* Character size mask
 
* Character size mask
第148行: 第148行:
 
* ...
 
* ...
  
As the [[USART internal peripheral]] supports 7, 8 and 9 word length data, the following termios character size and parity bit configurations are supported:
+
由于[[USART internal peripheral]] 支持7、8和9个字长的数据,因此支持以下termios字符大小和奇偶校验位配置:
 
<span id{{=}}"CSIZE_configurations"></span>
 
<span id{{=}}"CSIZE_configurations"></span>
 
* CS6 with parity bit
 
* CS6 with parity bit
第154行: 第154行:
 
* CS8 with or without parity bit
 
* CS8 with or without parity bit
  
Tips to use TTY:
+
使用TTY的提示:
* '''How to use TTY from user terminal''': TTY usage from a user terminal is described in a dedicated article, [[How to use TTY with User Terminal|How to use TTY from a user terminal]]
+
* '''如何从用户终端使用TTY''':专用文章中介绍了用户终端的TTY使用情况, [[How to use TTY with User Terminal|How to use TTY from a user terminal]]
* '''How to use TTY from an application''': TTY usage from an application is described in a dedicated article, [[How_to_use_TTY_from_an_application|How to use TTY from an application]]
+
* '''如何在应用程序中使用TTY''':专用文章[[How_to_use_TTY_from_an_application|How to use TTY from an application]]中描述了应用程序的TTY使用情况
* '''TTY line discipline''': TTY line discipline is described in a dedicated article,  [[Serial TTY line discipline|Serial TTY line discipline]]
+
* '''TTY线路规程''':TTY线路规程在专门的文章中描述,[[Serial TTY line discipline|Serial TTY line discipline]]
  
 
==How to trace and debug the framework==
 
==How to trace and debug the framework==
  
 
=== How to monitor ===
 
=== How to monitor ===
As Debugfs does not propose any information about serial or TTY frameworks, the way to monitor Serial and TTY  frameworks is to use the linux kernel log method (based on printk) described in [[Dmesg_and_Linux_kernel_log]] article.
+
由于Debugfs不提供有关串行或TTY框架的任何信息,因此监视串行和TTY框架的方法是使用 [[Dmesg_and_Linux_kernel_log]] 文章中所述的linux内核日志方法(基于printk)。
  
 
=== How to trace ===
 
=== How to trace ===
 
==== Kernel boot log ====
 
==== Kernel boot log ====
The following extract of '''kernel boot log''' shows a serial driver properly probed:
+
以下'''内核启动日志'''摘录显示了已正确探测的串行驱动程序:
  
 
<pre>
 
<pre>
第183行: 第183行:
  
 
==== dmesg output information ====
 
==== dmesg output information ====
The system log shows the UART devices and associated TTY terminals registered during the probe.
+
系统日志显示在探测期间注册的UART设备和相关的TTY端子。
 
  {{Board$}} dmesg | grep ttySTM*
 
  {{Board$}} dmesg | grep ttySTM*
 
  [    0.000000] Kernel command line: root=/dev/mmcblk0p5 rootwait rw earlyprintk console=ttySTM1,115200
 
  [    0.000000] Kernel command line: root=/dev/mmcblk0p5 rootwait rw earlyprintk console=ttySTM1,115200
第194行: 第194行:
  
 
==== Dynamic trace ====
 
==== Dynamic trace ====
A detailed dynamic trace is available in [[How to use the kernel dynamic debug]]<br/>
+
详细的动态跟踪可在[[How to use the kernel dynamic debug]]中找到。<br/>
 
   {{Board$}} echo  "file drivers/tty/* +p" > /sys/kernel/debug/dynamic_debug/control
 
   {{Board$}} echo  "file drivers/tty/* +p" > /sys/kernel/debug/dynamic_debug/control
This command enables all the traces related to the TTY core and drivers at runtime.<br/>
+
此命令在运行时启用与TTY内核和驱动程序相关的所有跟踪。<br/>
A finer selection can be made by choosing only the files to trace.<br/>
+
通过仅选择要跟踪的文件,可以进行更好的选择。<br/>
  
{{Info|Reminder: ''loglevel'' needs to be increased to 8 by using either boot arguments or the ''dmesg -n 8'' command through the console}}
+
{{Info|提醒:需要通过控制台使用引导参数或“ dmesg -n 8”命令将“ loglevel”增加到8}}
  
 
=== How to debug ===
 
=== How to debug ===
While a TTY serial port is instantiated, the TTY core exports different files through devfs, sysfs and procfs.
+
在实例化TTY串行端口时,TTY内核通过devfs,sysfs和procfs导出不同的文件。
  
 
====devfs====
 
====devfs====
* The repository '''/dev''' contains all the probed TTY serial devices.
+
* 存储库'''/ dev'''包含所有探查的TTY串行设备。
  
 
  {{Board$}} ls /dev/ttySTM*
 
  {{Board$}} ls /dev/ttySTM*
第212行: 第212行:
  
 
====sysfs====
 
====sysfs====
* '''/sys/class/tty/''' lists all TTY devices which ttySx correspond to serial port devices.
+
* '''/ sys / class / tty /'''列出了ttySx对应于串行端口设备的所有TTY设备。
 
  {{Board$}} ls /sys/class/tty/*/device/driver
 
  {{Board$}} ls /sys/class/tty/*/device/driver
 
  /sys/class/tty/{{Green|'''ttySTM1'''}}/device/driver -> ../../../../bus/platform/drivers/{{Green|'''stm32-usart'''}}
 
  /sys/class/tty/{{Green|'''ttySTM1'''}}/device/driver -> ../../../../bus/platform/drivers/{{Green|'''stm32-usart'''}}
 
  /sys/class/tty/{{Green|'''ttySTM0'''}}/device/driver -> ../../../../bus/platform/drivers/{{Green|'''stm32-usart'''}}
 
  /sys/class/tty/{{Green|'''ttySTM0'''}}/device/driver -> ../../../../bus/platform/drivers/{{Green|'''stm32-usart'''}}
  
* '''/sys/devices/platform/soc/''' lists all the usart devices probed
+
* '''/ sys / devices / platform / soc /'''列出所有探测到的usart设备
 
   
 
   
 
  {{Board$}} ls -d /sys/devices/platform/soc/*.serial
 
  {{Board$}} ls -d /sys/devices/platform/soc/*.serial
第223行: 第223行:
 
  /sys/devices/platform/soc/{{Green|'''4000f000.serial'''}}  /sys/devices/platform/soc/{{Green|'''40010000.serial'''}}
 
  /sys/devices/platform/soc/{{Green|'''4000f000.serial'''}}  /sys/devices/platform/soc/{{Green|'''40010000.serial'''}}
  
* '''/sys/devices/platform/soc/''device''.serial/tty''' lists the TTY terminal associated to a serial device
+
* '''/sys/devices/platform/soc/''device''.serial/tty'''列出与串行设备关联的TTY终端
  
 
  {{Board$}} ls /sys/devices/platform/soc/{{Green|'''4000f000.serial'''}}/tty/       
 
  {{Board$}} ls /sys/devices/platform/soc/{{Green|'''4000f000.serial'''}}/tty/       
第230行: 第230行:
  
 
====procfs====
 
====procfs====
* The repository '''/proc/device-tree''' lists all the usart devices declared in the device-tree, including the disabled ones.
+
* 仓库'''/ proc / device-tree'''列出了在设备树中声明的所有usart设备,包括禁用的设备。
 
  {{Board$}} ls -d /proc/device-tree/soc/serial@*
 
  {{Board$}} ls -d /proc/device-tree/soc/serial@*
 
  /proc/device-tree/soc/serial@4000e000  /proc/device-tree/soc/serial@40010000  /proc/device-
 
  /proc/device-tree/soc/serial@4000e000  /proc/device-tree/soc/serial@40010000  /proc/device-
第237行: 第237行:
 
  tree/soc/serial@40019000  /proc/device-tree/soc/serial@5c000000
 
  tree/soc/serial@40019000  /proc/device-tree/soc/serial@5c000000
  
Then for each device listed, device-tree properties are available.
+
然后,对于列出的每个设备,设备树属性均可用。
 
  {{Board$}} ls /proc/device-tree/soc/serial@40010000/
 
  {{Board$}} ls /proc/device-tree/soc/serial@40010000/
 
  clock-names  compatible      interrupts-extended  name    pinctrl-0  pinctrl-names  reg    wakeup-source
 
  clock-names  compatible      interrupts-extended  name    pinctrl-0  pinctrl-names  reg    wakeup-source
 
  clocks      interrupt-names  linux,phandle        phandle  pinctrl-1  power-domains  status
 
  clocks      interrupt-names  linux,phandle        phandle  pinctrl-1  power-domains  status
  
:As an example, the status entry provides the status of the device in the device tree node.
+
:例如,状态条目提供设备树节点中设备的状态。
 
   
 
   
 
  {{Board$}} cat /proc/device-tree/soc/{{Green|'''serial@40010000'''}}/status
 
  {{Board$}} cat /proc/device-tree/soc/{{Green|'''serial@40010000'''}}/status
第249行: 第249行:
  
  
* The file '''/proc/interrupts''' lists the interrupts for active serial ports.
+
* 文件'''/ proc / interrupts'''列出了活动串行端口的中断。
 
  {{Board$}} cat /proc/interrupts | grep serial
 
  {{Board$}} cat /proc/interrupts | grep serial
 
  26:          0          0    GIC-0  71 Level    4000f000.serial
 
  26:          0          0    GIC-0  71 Level    4000f000.serial
第258行: 第258行:
  
 
<span id{{=}}"procfs_serialcounters"></span>
 
<span id{{=}}"procfs_serialcounters"></span>
* The file '''/proc/tty/driver/stm32-usart''' lists serial core counters and modem information for each serial instance.
+
* 文件'''/ proc / tty / driver / stm32-usart'''列出了每个串行实例的串行核心计数器和调制解调器信息。
  
:Driver information:
+
:驱动程序信息:
 
:* serial driver name
 
:* serial driver name
 
:* serial device start address
 
:* serial device start address
 
:* irq number
 
:* irq number
  
:Counters:
+
:计数器:
 
:* tx: Number of bytes sent
 
:* tx: Number of bytes sent
 
:* rx: Number of bytes received
 
:* rx: Number of bytes received
第274行: 第274行:
 
:* bo: Number of framework buffer overrun errors received
 
:* bo: Number of framework buffer overrun errors received
  
:Modem information:
+
:调制解调器信息:
 
:* RTS: Request To Send
 
:* RTS: Request To Send
 
:* CTS: Clear To Send
 
:* CTS: Clear To Send
第289行: 第289行:
  
 
==How to go further==
 
==How to go further==
The Linux community provides many detailed documentation about Linux serial/TTY. Please find below a selection of the most relevant ones:
+
Linux社区提供了许多有关Linux串行/ TTY的详细文档。 请在下面找到最相关的选项:
* Linux Serial-HOWTO <ref>[http://tldp.org/HOWTO/Serial-HOWTO.html Linux Serial-HOWTO], tdlp.org training document, describes how to set up serial ports from both hardware and software perspectives</ref> describes how to set up serial ports from both hardware and software perspectives.
+
* Linux Serial-HOWTO <ref>[http://tldp.org/HOWTO/Serial-HOWTO.html Linux Serial-HOWTO], tdlp.org training document, describes how to set up serial ports from both hardware and software perspectives</ref> 从硬件和软件角度描述了如何设置串行端口。
* Serial Programming Guide for POSIX Compliant Operating Systems <ref>[https://www.cmrr.umn.edu/~strupp/serial.html Serial Programming Guide for POSIX Compliant Operating Systems], by Michael Sweet, training document</ref> , by Michael Sweet.
 
  
 +
* POSIX兼容操作系统的串行编程指南<ref>[https://www.cmrr.umn.edu/~strupp/serial.html Serial Programming Guide for POSIX Compliant Operating Systems], by Michael Sweet, training document</ref> , 作者:Michael Sweet。
  
More information can be found in the following web articles in order to get a good understanding of the Linux TTY framework:
+
 
* TTY Subsystem <ref> [https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.genprogc/ttysys.htm TTY Subsystem], by IBM </ref>, by IBM
+
可以在以下Web文章中找到更多信息,以更好地了解Linux TTY框架:
* The TTY demystified <ref>[http://www.linusakesson.net/programming/tty/ The TTY demystified] TTY subsystem presentation article, by Linus Akesson </ref>, by Linus Akesson
+
* TTY子系统 <ref> [https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.genprogc/ttysys.htm TTY Subsystem], by IBM </ref>,由IBM
* Serial drivers training <ref>[http://bootlin.com/doc/legacy/serial-drivers/linux-serial-drivers.pdf Linux serial drivers training] Linux Serial Drivers training, by Bootlin </ref>, by Bootlin
+
* TTY揭密 <ref>[http://www.linusakesson.net/programming/tty/ The TTY demystified] TTY subsystem presentation article, by Linus Akesson </ref>, 作者Linus Akesson
* Linux Serial drivers <ref>[http://www.linux.it/~rubini/docs/serial/serial.html Linux Serial Drivers] Serial drivers article describing data flows, by Alessandro Rubini</ref>, by Alessandro Rubini
+
* 串行驱动程序培训 <ref>[http://bootlin.com/doc/legacy/serial-drivers/linux-serial-drivers.pdf Linux serial drivers training] Linux Serial Drivers training, by Bootlin </ref>, 作者 Bootlin
* Serial Device Bus <ref>[https://elinux.org/images/0/0e/Serdev-elce-2017-2.pdf The Serial Device Bus] Serdev framework presentation, by Johan Hovold</ref>, by Johan Hovold
+
* Linux串行驱动程序 <ref>[http://www.linux.it/~rubini/docs/serial/serial.html Linux Serial Drivers] Serial drivers article describing data flows, by Alessandro Rubini</ref>, 作者 Alessandro Rubini
 +
* 串行设备总线<ref>[https://elinux.org/images/0/0e/Serdev-elce-2017-2.pdf The Serial Device Bus] Serdev framework presentation, by Johan Hovold</ref>,作者 Johan Hovold
  
 
==References==
 
==References==
 
<references />
 
<references />
 
<noinclude>
 
[[Category:Serial TTY|1]]
 
{{PublicationRequestId | 15053 | 2020-02-21 | 8368 (BrunoB - 2018-08-31)}}
 
{{ArticleBasedOnModel | Framework overview article model}}
 
</noinclude>
 

2020年11月11日 (三) 12:37的最新版本

本文提供有关 Linux® TTY框架的信息。 它解释了如何激活“”UART“”接口,以及如何从用户和内核空间访问它。

Framework purpose

TTY子系统控制UART设备与使用这些设备的程序之间的通信。
TTY子系统负责:

  • 控制异步线路上的物理数据流(包括传输速度,字符大小和线路可用性)。
  • 通过识别特殊字符并适应本国语言来解释数据。
  • 通过控制终端的概念来控制作业和终端访问。


TTY子系统不支持STM32 USART外设的同步模式。
控制终端管理一组进程的输入和输出操作。 TTY特殊文件(ttyX文件系统条目)支持控制终端接口。
为了执行其任务,TTY子系统由模块(也称为学科)组成。 模块是一组处理规则,它们控制计算机与异步设备之间的通信接口。 可以为每个TTY动态添加和删除模块。

TTY子系统支持三种主要类型的模块:

  • TTY驱动程序:TTY驱动程序或硬件规则直接控制硬件(TTY设备)或伪硬件(PTY设备)。 它们通过为适配器上面的模块提供服务来执行对适配器的实际输入和输出。 打开端口时,这些服务是流控制和特殊语义。
  • 线学科:线学科提供编辑,作业控制和特殊字符解释。 它们执行入站和出站数据流上发生的所有转换。 生产线规程还为TTY驱动程序执行大多数错误处理和状态监视。
  • 转换器模块:转换器模块或映射学科,翻译或映射输入和输出字符。


从内核4.12版本开始,串行设备总线(也称为Serdev)已在TTY框架中引入,以改善为连接到串行端口的设备(例如:蓝牙,NFC,FM无线电和GPS设备)提供的接口 学科“驾驶员”有一些已知的局限性:

  • 设备是在用户空间而不是固件中编码的(ACPI的设备树)
  • “驱动程序”不是内核驱动程序,而是用户空间守护程序
  • 内核空间中没有描述相关的资源(GPIO和中断,调节器,时钟,音频接口),这会影响电源管理
  • 打开端口时会注册“驱动程序”

Serdev允许将设备连接到UART,而无需了解线路规则限制:

  • 新总线类型:串行
  • Serdev控制器
  • Serdev设备(客户端或从设备)
  • Serdev TTY-端口控制器
    • 仅内核内控制器实现
    • 定义客户端时,由TTY驱动程序注册
    • 客户端由固件(设备树或ACPI)描述


STMicroelectronics提供的USART低级驱动程序(“drivers/tty/serial/stm32 USART.c”)支持 RS-232 standard (for serial communication transmission of data), and RS-485 standard (for modbus协议应用程序为例)。

Linux®低级驱动程序不支持USART同步模式。


在以下用例中,TTY框架用于访问串行设备:

  • Linux启动过程中的“'tty虚拟控制台”'
  • pts pseudo-terminal通过终端访问
  • 用户空间应用程序

System overview

How to use TTY from an application How to use TTY from a user terminal Example: Bluetooth_overview termios drivers/tty/tty_io.c | |}} tty char driver Line discipline drivers/tty/serdev | |}} serdev framework drivers/tty | |}} tty framework drivers/tty/serial/serial_core.c | |}} serial_core framework drivers/tty/serial/stm32-usart.c | |}} stm32-usart driver USART internal peripheral
Serial TTY architecture overview


注意: 在引导过程中,当探测串行设备时,串行框架会将关联的tty终端实例化为虚拟设备。 然后,系统将该tty虚拟设备视为关联的串行设备的子级。

Components description

从客户端应用程序到硬件

  • 应用程序:客户应用程序,用于从串行端口上连接的外围设备读取/写入数据。
  • TTY tools: Linux社区提供的工具,例如sttyldattachinputattachtty ttys agety mingettykermit minicom
  • Termios: API,提供使用串行驱动程序开发应用程序的接口。
  • 客户端子系统:serdev内核的内核子系统客户端(示例:蓝牙概述).
  • STM32 USART: STM32前端IP通过串行端口连接到外部设备。

APIs description

TTY仅向用户空间提供字符设备接口(命名为/ dev / ttyX)。 用户空间TTY客户端应用程序的主要API由便携式POSIX终端接口termios提供,该终端依赖于/ dev / ttyX接口进行TTY链接配置。

[1] 是一个用户区域API,它的功能描述了用于控制异步通信端口的通用终端接口。

POSIX termios API抽象化了硬件的低级细节,并提供了一个简单而完整的编程接口,可用于高级项目。 它是character device API[2] ioctl操作。

注意: 如果在内核级别需要串行接口(例如,通过内核驱动程序通过U(S)ART控制外部设备),则客户可以使用 line discipline 或“ Serdev”客户端。

  • 学科将负责:
    • 创建这个新的内核API
    • 在串行内核和新内核API之间路由数据流
  • Serdev提供了内核驱动程序的接口。
    • 此界面类似于线路规则操作:打开和关闭,终端设置,写入,调制解调器控制,读取(回调)和写入唤醒(回调)

Configuration

本节介绍如何在串行端口上配置设备。

Kernel Configuration

默认情况下,ST交付中会激活串行驱动程序,串行框架和TTY框架。 但是,如果需要特定的配置,则本节说明如何在内核中激活/停用IIO。

使用Linux Menuconfig 工具。

对于TTY,选择:

Device Drivers  --->
   Character devices  --->
     [*]   Enable TTY                           

允许删除可节省空间的TTY支持,并阻止需要TTY的功能包含在内核中。
任何文本终端或串行端口通信都需要TTY。 大多数用户应启用此功能。

对于STM32串行驱动程序,选择:

Device Drivers  --->
   Character devices  --->
      Serial drivers  --->
     <*> STMicroelectronics STM32 serial port support
     [*]   Support for console on STM32

该驱动程序用于STMicroelectronics STM32 MCU上的片上串行控制器。 
USART支持Rx和Tx功能。它支持所有行业标准的波特率。

Device tree configuration

专用文章Serial TTY device tree configuration中描述了由于设备树而导致的UART配置。

How to use TTY

本节基于以下两个用例,描述如何从用户区域(从终端或应用程序)以及内核空间使用TTY:

  • 如何使用termios结构配置串行端口
  • 如何发送/接收数据

termios结构允许使用许多设置来配置通信端口,例如:

  • Baud rate
  • Character size mask
  • Parity bit enabling
  • Parity and framing errors detection settings
  • Start/stop input and output control
  • RTS/CTS (hardware) flow control
  • ...

由于USART internal peripheral 支持7、8和9个字长的数据,因此支持以下termios字符大小和奇偶校验位配置:

  • CS6 with parity bit
  • CS7 with or without parity bit
  • CS8 with or without parity bit

使用TTY的提示:

How to trace and debug the framework

How to monitor

由于Debugfs不提供有关串行或TTY框架的任何信息,因此监视串行和TTY框架的方法是使用 Dmesg和Linux内核日志 文章中所述的linux内核日志方法(基于printk)。

How to trace

Kernel boot log

以下内核启动日志摘录显示了已正确探测的串行驱动程序:

[    0.793340] STM32 USART driver initialized
[    0.798779] 4000f000.serial: ttySTM1 at MMIO 0x4000f000 (irq = 25, base_baud = 4000000) is a stm32-usart
[    0.808875] stm32-usart 4000f000.serial: interrupt mode used for rx (no dma)
[    0.816106] stm32-usart 4000f000.serial: interrupt mode used for tx (no dma)
[    0.824253] 40010000.serial: ttySTM0 at MMIO 0x40010000 (irq = 27, base_baud = 4000000) is a stm32-usart
[    0.833796] console [ttySTM0] enabled
[    0.833796] console [ttySTM0] enabled
[    0.840862] bootconsole [earlycon0] disabled
[    0.840862] bootconsole [earlycon0] disabled
[    0.850132] stm32-usart 40010000.serial: interrupt mode used for rx (no dma)
[    0.855755] stm32-usart 40010000.serial: interrupt mode used for tx (no dma)

dmesg output information

系统日志显示在探测期间注册的UART设备和相关的TTY端子。

Board $> dmesg | grep ttySTM*
[    0.000000] Kernel command line: root=/dev/mmcblk0p5 rootwait rw earlyprintk console=ttySTM1,115200
# ttySTM1 terminal is associated with usart3 (4000f000.serial) # 
[    0.798779] 4000f000.serial: ttySTM1 at MMIO 0x4000f000 (irq = 25, base_baud = 4000000) is a stm32-usart
# ttySTM0 terminal is associated with uart4 (40010000.serial) for console#
[    0.824253] 40010000.serial: ttySTM0 at MMIO 0x40010000 (irq = 27, base_baud = 4000000) is a stm32-usart      
# ttySTM0 terminal is activated by default for console #
[    0.833796] console [ttySTM0] enabled

Dynamic trace

详细的动态跟踪可在How to use the kernel dynamic debug中找到。

 Board $> echo  "file drivers/tty/* +p" > /sys/kernel/debug/dynamic_debug/control

此命令在运行时启用与TTY内核和驱动程序相关的所有跟踪。
通过仅选择要跟踪的文件,可以进行更好的选择。

Info.png 提醒:需要通过控制台使用引导参数或“ dmesg -n 8”命令将“ loglevel”增加到8

How to debug

在实例化TTY串行端口时,TTY内核通过devfs,sysfs和procfs导出不同的文件。

devfs

  • 存储库/ dev包含所有探查的TTY串行设备。
Board $> ls /dev/ttySTM*
# ttySTM1 and ttySTM0 terminals are probed #
/dev/ttySTM1  /dev/ttySTM0

sysfs

  • / sys / class / tty /列出了ttySx对应于串行端口设备的所有TTY设备。
Board $> ls /sys/class/tty/*/device/driver
/sys/class/tty/ttySTM1/device/driver -> ../../../../bus/platform/drivers/stm32-usart
/sys/class/tty/ttySTM0/device/driver -> ../../../../bus/platform/drivers/stm32-usart
  • / sys / devices / platform / soc /列出所有探测到的usart设备
Board $> ls -d /sys/devices/platform/soc/*.serial
# Serial devices 4000f000.serial (usart3) and 40010000.serial (uart4) are probed #
/sys/devices/platform/soc/4000f000.serial  /sys/devices/platform/soc/40010000.serial
  • /sys/devices/platform/soc/device.serial/tty列出与串行设备关联的TTY终端
Board $> ls /sys/devices/platform/soc/4000f000.serial/tty/      
# ttySTM1 is associated to serial device 4000f000.serial (usart3)  #
ttySTM1

procfs

  • 仓库/ proc / device-tree列出了在设备树中声明的所有usart设备,包括禁用的设备。
Board $> ls -d /proc/device-tree/soc/serial@*
/proc/device-tree/soc/serial@4000e000  /proc/device-tree/soc/serial@40010000  /proc/device-
tree/soc/serial@40018000  /proc/device-tree/soc/serial@44003000
/proc/device-tree/soc/serial@4000f000  /proc/device-tree/soc/serial@40011000  /proc/device-
tree/soc/serial@40019000  /proc/device-tree/soc/serial@5c000000

然后,对于列出的每个设备,设备树属性均可用。

Board $> ls /proc/device-tree/soc/serial@40010000/
clock-names  compatible       interrupts-extended  name     pinctrl-0  pinctrl-names  reg     wakeup-source
clocks       interrupt-names  linux,phandle        phandle  pinctrl-1  power-domains  status
例如,状态条目提供设备树节点中设备的状态。
Board $> cat /proc/device-tree/soc/serial@40010000/status
# status of device serial@40010000 (uart4) is set to "okay" in the device tree #
okay


  • 文件/ proc / interrupts列出了活动串行端口的中断。
Board $> cat /proc/interrupts | grep serial
26:          0          0     GIC-0  71 Level     4000f000.serial
27:          0          0  stm32-exti-h  28 Edge      4000f000.serial
28:      13509          0     GIC-0  84 Level     40010000.serial
29:          0          0  stm32-exti-h  30 Edge      40010000.serial


  • 文件/ proc / tty / driver / stm32-usart列出了每个串行实例的串行核心计数器和调制解调器信息。
驱动程序信息:
  • serial driver name
  • serial device start address
  • irq number
计数器:
  • tx: Number of bytes sent
  • rx: Number of bytes received
  • fe: Number of framing errors received
  • pe: Number of parity errors received
  • brk: Number of break signals received
  • oe: Number of overrun errors received
  • bo: Number of framework buffer overrun errors received
调制解调器信息:
  • RTS: Request To Send
  • CTS: Clear To Send
  • DTR: Data Terminal Ready
  • DSR: Data Set Ready
  • CD: Carrier Detect
  • RI: Ring Indicator
Board $> cat /proc/tty/driver/stm32-usart 
serinfo:1.0 driver revision:
0: uart:stm32-usart mmio:0x40010000 irq:29 tx:22722 rx:2276 RTS|CTS|DTR|DSR|CD
1: uart:stm32-usart mmio:0x4000F000 irq:27 tx:0 rx:1149 fe:121 oe:2 pe:296 brk:3 RTS|CTS|DTR|DSR|CD
3: uart:stm32-usart mmio:0x4000E000 irq:25 tx:0 rx:0 CTS|DSR|CD

How to go further

Linux社区提供了许多有关Linux串行/ TTY的详细文档。 请在下面找到最相关的选项:

  • Linux Serial-HOWTO [3] 从硬件和软件角度描述了如何设置串行端口。
  • POSIX兼容操作系统的串行编程指南[4] , 作者:Michael Sweet。


可以在以下Web文章中找到更多信息,以更好地了解Linux TTY框架:

  • TTY子系统 [5],由IBM
  • TTY揭密 [6], 作者Linus Akesson
  • 串行驱动程序培训 [7], 作者 Bootlin
  • Linux串行驱动程序 [8], 作者 Alessandro Rubini
  • 串行设备总线[9],作者 Johan Hovold

References

  1. termios API, Linux Programmer's Manual termios API Documentation (user land API with serial devices)
  2. Character device API overview, Accessing hardware from userspace training, Bootlin documentation
  3. Linux Serial-HOWTO, tdlp.org training document, describes how to set up serial ports from both hardware and software perspectives
  4. Serial Programming Guide for POSIX Compliant Operating Systems, by Michael Sweet, training document
  5. TTY Subsystem, by IBM
  6. The TTY demystified TTY subsystem presentation article, by Linus Akesson
  7. Linux serial drivers training Linux Serial Drivers training, by Bootlin
  8. Linux Serial Drivers Serial drivers article describing data flows, by Alessandro Rubini
  9. The Serial Device Bus Serdev framework presentation, by Johan Hovold