> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# UART

UART 设备以异步方式传输数据。因此，发送端 UART 输出位与接收端 UART 采样位之间没有时钟信号进行同步。发送端 UART 不使用时钟信号，而是在被传输的数据包中添加起始位和停止位。这些位定义了数据包的开始和结束。这样，接收端 UART 就知道何时开始读取这些位。当接收端 UART 检测到起始位时，它会以称为波特率的特定频率开始读取传入的位。

![两个 UART 设备之间的数据传输](https://mintcdn.com/qualcomm-prod/rpHTx_a6zriKQll9/System/Interfaces/images/Data_transfer_uart.png?fit=max\&auto=format\&n=rpHTx_a6zriKQll9\&q=85\&s=eec251edb3d467cd9741f67e96734d8f)

**图：两个 UART 设备之间的数据传输**

决定传输成功的参数如下：

* **波特率**
* **起始位**
* **停止位**
* **奇偶校验位**
* **数据位**
* **流控**

下图显示了一个 UART 数据包示例。

![UART 数据包](https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/System/Interfaces/images/uart_data_packet.png)

**图：UART 数据包**

## **UART 特性**

下表描述了应用程序的 UART 传输模式。

**表：UART 传输模式**

<table>
  <thead>
    <tr>
      <th>子系统</th>
      <th>传输模式</th>
      <th>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Linux</td>

      <td>
        <ul>
          <li>FIFO（低速）</li>
          <li>CPU DMA（高速）</li>
        </ul>
      </td>

      <td>
        <ul>
          <li>支持从 300 bps 到 4 Mbps 的波特率。</li>
          <li>FIFO 模式在其 Rx/Tx 缓冲区和系统内存之间传输数据。</li>
          <li>DMA 模式在其 Rx/Tx 缓冲区和系统内存之间传输数据。使用支持更高波特率和更大数据包的高速 UART 驱动可获得更好的性能。例如，Bluetooth 无线技术连接模块。</li>
        </ul>
      </td>
    </tr>

    <tr>
      <td>Boot</td>
      <td>FIFO</td>

      <td>
        <ul>
          <li>Rx/Tx 每字符 5 位到 8 位。</li>
          <li>支持的最大波特率为 115200。</li>
        </ul>
      </td>
    </tr>

    <tr>
      <td>ADSP</td>
      <td>FIFO</td>

      <td>
        <ul>
          <li>Rx/Tx 每字符 5 位到 8 位。</li>
          <li>支持的波特率：115200、230400、460800、921600、1000000、3000000 和 6000000。</li>
        </ul>
      </td>
    </tr>
  </tbody>
</table>

## **UART 接口组件**

下表提供了不同子系统的 UART 驱动配置的路径。

> [!NOTE]
>
> **注意**
>
> 使用本页中的路径之前，请下载并解压适用于您所用版本的 Qualcomm Linux 平台软件包。`ADSP.HT.5.5.c8` 目录表示软件包中的 ADSP 源代码树；其版本可能因发布版本而异。请将 \<chipset> 替换为您平台的固件目录：sc7280（QCS6490 和 QCS5430）、sa8775p（Dragonwing IQ-9075）或 qcs615（Dragonwing IQ-615）。

**表：UART 接口：Linux**

<table>
  <thead>
    <tr>
      <th>文件类型</th>
      <th>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>设备树源</td>

      <td>
        <ul>
          <li>QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi)</li>
          <li>Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)</li>
          <li>Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)</li>
        </ul>
      </td>
    </tr>

    <tr>
      <td>Pinctrl 设置</td>

      <td>
        <ul>
          <li>相应 QUP v3 串行引擎的引脚控制表位于 `<workspace_path_of_LINUX_kernel_image>/sources/kernel/kernel_platform/kernel/arch/arm64/boot/dts/qcom/<chipset>.dts`。</li>

          <li>
            有关覆盖芯片产品的 DTSI 配置示例，请参阅以下 DTSI 文件。

            <ul>
              <li>QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi)</li>
              <li>Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)</li>
              <li>Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)</li>
            </ul>
          </li>
        </ul>
      </td>
    </tr>

    <tr>
      <td>Qualcomm TEE 设置</td>

      <td>
        <ul>
          <li>`/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/qup_accesscontrol/qupv3/config/<chipset>/QUPAC_Access.c`</li>
        </ul>
      </td>
    </tr>
  </tbody>
</table>

**表：UART 接口：Boot（仅 UEFI）**

<table>
  <thead>
    <tr>
      <th>文件类型</th>
      <th>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>QUP v3 串行引擎配置</td>

      <td>
        <ul>
          <li>
            `/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/BOOT.MXF.1.0.c1/boot_images/boot/QcomPkg/SocPkg/<chipset>/Settings/UART/UartSettings.c`
          </li>
        </ul>
      </td>
    </tr>

    <tr>
      <td>Qualcomm TEE 设置</td>

      <td>
        <ul>
          <li>
            `/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/qup_accesscontrol/qupv3/config/<chipset>/QUPAC_Access.c`
          </li>
        </ul>
      </td>
    </tr>
  </tbody>
</table>

**表：UART 接口：ADSP/SLPI**

<table>
  <thead>
    <tr>
      <th>文件类型</th>
      <th>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>QUP v3 串行引擎配置</td>

      <td>
        <ul>
          <li>`/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_common/config/<chipset>/adsp/ssc/qup_devcfg.c`</li>
          <li>`/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/<chipset>/fw_devcfg.c`</li>
        </ul>
      </td>
    </tr>

    <tr>
      <td>固件配置设置</td>

      <td>
        <ul>
          <li>`/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/<chipset>/fw_devcfg.c`</li>
          <li>`/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/<chipset>/fw_devcfg.xml`</li>
        </ul>
      </td>
    </tr>
  </tbody>
</table>

### **UART API**

本节列出了以下子系统的 UART API。

* Linux：[https://github.com/torvalds/linux/blob/master/include/linux/tty.h](https://github.com/torvalds/linux/blob/master/include/linux/tty.h)
* Boot：QcomPkg/Include/HSUart.h
* ADSP：adsp\_proc/core/api/buses/uart.h

## **UART 软件设备树配置**

本节提供有关 UART 设备树配置以及设备节点文档的信息。

### **Linux**

有关内核设备实例的信息，请参阅 [https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/serial/qcom%2Cserial-geni-qcom.yaml](https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/serial/qcom%2Cserial-geni-qcom.yaml)。

有关 UART 驱动文件的信息，请参阅 [https://github.com/torvalds/linux/blob/master/drivers/tty/serial/qcom\_geni\_serial.c](https://github.com/torvalds/linux/blob/master/drivers/tty/serial/qcom_geni_serial.c)

```dts theme={null}
uart7: serial@99c000 {
	/* Manufacturer's serial driver */
	compatible = "qcom,geni-uart";
	/* Serial-engine address and size */
	reg = <0 0x0099c000 0 0x4000>;
	/* Serial-engine clock */
	clocks = <&gcc GCC_QUPV3_WRAP0_S7_CLK>;
	clock-names = "se";
	/* Pin control settings */
	pinctrl-names = "default";
	pinctrl-0 = <&qup_uart7_cts>, <&qup_uart7_rts>,
		    <&qup_uart7_tx>, <&qup_uart7_rx>;
	interrupts = <GIC_SPI 608 IRQ_TYPE_LEVEL_HIGH>;
	power-domains = <&rpmhpd SC7280_CX>;
	operating-points-v2 = <&qup_opp_table>;
	interconnects = <&clk_virt MASTER_QUP_CORE_0 0
			 &clk_virt SLAVE_QUP_CORE_0 0>,
			<&gem_noc MASTER_APPSS_PROC 0
			 &cnoc2 SLAVE_QUP_0 0>;
	interconnect-names = "qup-core", "qup-config";
	/* Change to "okay" to enable the QUPv3 serial engine for UART. */
	status = "disabled";
};
```

有关串行引擎 GPIO 的配置设置，请参阅以下 DTSI 文件。

* QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi)
* Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)
* Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)

```text theme={null}
qup_uart7_cts: qup-uart7-cts-state {
				pins = "gpio28";
				function = "qup07";
			};

			qup_uart7_rts: qup-uart7-rts-state {
				pins = "gpio29";
				function = "qup07";
			};

			qup_uart7_tx: qup-uart7-tx-state {
				pins = "gpio30";
				function = "qup07";
			};

			qup_uart7_rx: qup-uart7-rx-state {
				pins = "gpio31";
				function = "qup07";
			};
```

> [!NOTE]
>
> **注意**
>
> 必须在 `QUPAC_Access.c` 文件中对齐 Qualcomm TEE 配置，以确保 GPIO/QUP v3 可以使用。您可以在 `/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/qup_accesscontrol/qupv3/config/<chipset>/QUPAC_Access.c` 访问 Qualcomm TEE 镜像。修改所需的设置，或查看为 QUP v3 串行引擎特定实例分配的默认设置。

QUP v3 同时支持启用流控的 4 线 UART 和未启用流控的 2 线 UART。以下 Qualcomm TEE 访问示例控制着两者的条目。启用 UART 协议的 QUP v3 串行引擎配置如下：

* 为 SE7 启用的默认配置为 HS UART
  ```text theme={null}
  { QUPV3_0_SE7, QUPV3_PROTOCOL_UART_4W, QUPV3_MODE_FIFO, AC_HLOS, TRUE, TRUE, FALSE }, 
  ```
* SE5 的 2 线 UART 配置
  ```text theme={null}
  uart5: serial@994000 {
  compatible = "qcom,geni-uart";
  reg = <0 0x00994000 0 0x4000>;
  clocks = <&gcc GCC_QUPV3_WRAP0_S5_CLK>;
  clock-names = "se";
  pinctrl-names = "default";
  pinctrl-0 =  <&qup_uart5_tx>, <&qup_uart5_rx>;
  interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
  power-domains = <&rpmhpd SC7280_CX>;
  operating-points-v2 = <&qup_opp_table>;
  interconnects = <&clk_virt MASTER_QUP_CORE_0 0 &clk_virt SLAVE_QUP_CORE_0 0>,
      <&gem_noc MASTER_APPSS_PROC 0 &cnoc2 SLAVE_QUP_0 0>;
  interconnect-names = "qup-core", "qup-config";
  status = "disabled";
  };
  ```
  ```text theme={null}
  { QUPV3_0_SE5, QUPV3_PROTOCOL_UART_2W, QUPV3_MODE_FIFO,
  AC_HLOS, TRUE, FALSE, FALSE },
  ```

### **Boot**

可以使用 `/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/BOOT.MXF.1.0.c1/boot_images/boot/QcomPkg/SocPkg/<chipset>/Settings/UART/UartSettings.c` 文件在启动阶段将 QUP v3 串行引擎配置为 UART。

```text theme={null}
UART_PROPERTIES devices =
{
   // MAIN_PORT
   0x00994000,    // Serial Engine Base address
   0x009C0000,// qup_common base address
   0x2001c161,  // GPIO TX pin Config
   0x2000c171,  // GPIO RX Pin Config
   0,           // gpio_cts_config
   0,           // gpio_rfr_config
   0,           // clock_id_index
   (void*)0,        // bus_clock_id
   (void*)CLK_QUPV3_WRAP0_S5,     // core_clock_id
   0,          // irq number not used
   0,  //TCSR base
   0,  // TCSR offset
   0   // TCSR value

};
```

**GPIO 配置**

GPIO 配置列于下表中。

**表：UART GPIO 配置**

<table>
  <thead>
    <tr>
      <th>位</th>
      <th>参数</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>\[0:3]</td>
      <td>GPIO 功能</td>
    </tr>

    <tr>
      <td>\[4:13]</td>
      <td>GPIO 编号</td>
    </tr>

    <tr>
      <td>\[14]</td>
      <td>方向</td>
    </tr>

    <tr>
      <td>\[15:17]</td>
      <td>上下拉类型</td>
    </tr>

    <tr>
      <td>\[18:21]</td>
      <td>驱动强度</td>
    </tr>
  </tbody>
</table>

您必须根据以下位域配置每个 GPIO。

```text theme={null}
<!--
GPIO configuration calculation

GPIO DIR values
GPIO_INPUT = 0x0
GPIO_OUTPUT = 0x1

GPIO_PULL values
GPIO_NO_PULL = 0, /**< -- Do not specify a pull. */
GPIO_PULL_DOWN = 0x1, /**< -- Pull the GPIO down. */
GPIO_KEEPER_ENABLE = 0x2, /**< -- Keeper Enable. */
GPIO_PULL_UP = 0x3, /**< -- Pull the GPIO up. */

GPIO_DRV_STRENGTH values
GPIO_2P0MA = 0, /**< -- Specify a 2 mA drive. */
GPIO_4P0MA = 0x1, /**< -- Specify a 4 mA drive. */
GPIO_6P0MA = 0x2, /**< -- Specify a 6 mA drive. */
GPIO_8P0MA = 0x3, /**< -- Specify a 8 mA drive. */

GPIO_FUNC_SELECT_Value
GPIO_FS_VAL =0, //Specifies GPIO function

GPIO_FS_VAL =0X1, //Specify NON GPIO function( UART/SPI/I2C)
	
GPIO configuration = (GPIO_NUM & 0xFF) << 0x10 |
(GPIO_FS_VAL & 0xF) << 0xC |
(GPIO_DRV_STRENGTH & 0xF) << 0x8 |
(GPIO_PULL & 0xF) << 0x4 |
(GPIO_DIR & 0xF)

-->
/*
| RESERVED | GPIO NUM | DRIVE | FUNC | PULL | DIR |
-------------------------------------------------------------------------
| 0000 | 0000 | 0001 | 1110 | 0001 | 0001 | 0010 | 0001 |
-------------------------------------------------------------------------
*/
```

### **ADSP**

固件在 ADSP 子系统的启动序列期间加载 SSC QUP。因此，配置文件位于 ADSP 构建中的 `/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/<chipset>/fw_devcfg.c`。

以下配置是在 FIFO 模式下加载了 UART 固件的 SSC QUP SE5/6 的示例。

```text theme={null}
                   offset,        protocol,   mode,  load_fw, dfs_mode
se_cfg se0_cfg = { 0x80000, SE_PROTOCOL_I3C,    GSI,     TRUE, TRUE  };
se_cfg se1_cfg = { 0x84000, SE_PROTOCOL_I2C,    GSI,     TRUE, TRUE  };
se_cfg se2_cfg = { 0x88000, SE_PROTOCOL_I2C,    GSI,     TRUE, TRUE  };
se_cfg se3_cfg = { 0x8C000, SE_PROTOCOL_I2C,    GSI,     FALSE, TRUE  };
se_cfg se4_cfg = { 0x90000, SE_PROTOCOL_SPI,    GSI,     TRUE, TRUE };
se_cfg se5_cfg = { 0x94000, SE_PROTOCOL_UART,   FIFO,    TRUE,FALSE };
se_cfg se6_cfg = { 0x98000, SE_PROTOCOL_UART,   FIFO,    TRUE,FALSE  };
```

GPIO 配置：QUP 通用驱动程序中的每个串行引擎都按协议使用默认 GPIO 配置进行配置。QUP v3 通用驱动程序会根据串行引擎中加载的协议，从 `/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_common/config/<chipset>/adsp/ssc/qup_instance_mapping.c` 中获取 GPIO 配置。

可以按如下方式覆盖默认 GPIO 配置。

```text theme={null}
{      .instance_id          =  6 ,         //Instance ID
        .qup              =  QUP_SSC,    //QUP Type
        .se_index         =  5,          //SE ID
        .se_data          =  NULL,       //devcfg_map
        .protocol_io_cfg  =  {
                                TLMM_MAP(TLMM_GPIO_KEEPER ,TLMM_GPIO_2MA,TLMM_GPIO_KEEPER ),              //SLEEP CFG
                                TLMM_MAP(TLMM_GPIO_NO_PULL,TLMM_GPIO_6MA,TLMM_GPIO_KEEPER ),              //SPI CFG
                                TLMM_MAP(TLMM_GPIO_NO_PULL,TLMM_GPIO_2MA,TLMM_GPIO_NO_PULL),              //UART CFG
                                TLMM_MAP(TLMM_GPIO_PULL_UP,TLMM_GPIO_2MA,TLMM_GPIO_NO_PULL),              //I2C CFG
                                TLMM_MAP(TLMM_GPIO_PULL_UP,TLMM_GPIO_2MA,TLMM_GPIO_KEEPER )               //I3C CFG
                             },
        .se_exclusive     =  TRUE,
}
```

TLMM\_MAP 是用于初始化活动状态和睡眠状态 GPIO 配置的宏。例如，TLMM\_MAP 宏的示例用法。

```text theme={null}
TLMM_MAP (active state pull type, drive strength, sleep state pull type)
```

## **UART 工具**

本节提供有关 UART 串行接口驱动的各种测试工具和方法的信息，以确认 UART 数据传输。

### **Linux**

有关更多详细信息，请参阅 [https://docs.kernel.org/admin-guide/serial-console.html](https://docs.kernel.org/admin-guide/serial-console.html)。

## **在内核中启用 UART**

本节提供有关如何在内核中启用 UART 的信息。

### **Linux**

支持 UART 接口需要以下驱动内核配置。

* UART 驱动：[https://github.com/torvalds/linux/blob/master/drivers/tty/serial/qcom\_geni\_serial.c](https://github.com/torvalds/linux/blob/master/drivers/tty/serial/qcom_geni_serial.c)
* 内核 `defconfig` 文件路径：`<workspace_path_of_LINUX_kernel_image>/sources/kernel/kernel_platform/kernel/arch/arm64/configs/qcom_defconfig`

启用以下内核配置。

* `CONFIG_QCOM_GENI_SE=y`
* `CONFIG_SERIAL_QCOM_GENI=y`

要为回环验证启用串行节点，请按如下方式更新 `/arch/arm64/boot/dts/qcom/<chipset>.dtsi` 文件：

```dts theme={null}
/* Add this entry to the existing aliases node. */
serial1 = &uart7;

/* Add this node outside the aliases node. */
&uart7 {
	status = "okay";
};
```

> [!NOTE]
>
> **注意**
>
> 您应当编译内核配置和设备树更改。编译完成后，可以将镜像加载到设备上以验证接口。有关接口验证的信息，请参阅 [Verify UART interface](https://dragonwingdocs.qualcomm.com/System/Interfaces/uart.md#verify-uart-interface) 部分。

### **Boot/ADSP**

有关自定义，请参阅 [UART software device tree configuration](https://dragonwingdocs.qualcomm.com/System/Interfaces/uart.md#uart-software-device-tree-configuration) 部分。

## **UART 自定义**

有关自定义 UART 软件的信息，请参阅 [QUP v3 access control customization](https://dragonwingdocs.qualcomm.com/System/Interfaces/references.md#qup-v3-access-control-customization)。

## **验证 UART 接口**

本节介绍 UART 驱动的验证过程以及 Qualcomm 驱动的测试结果。

### **Linux**

要启用 UART 节点，请执行以下操作并编译内核配置。

1. 要将 UART 状态更改为 **OK** 并为特定 UART 节点添加别名，请编辑以下 DTSI 文件。

   * QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi)
   * Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)
   * Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)

   > [!NOTE]
   >
   > **注意**
   >
   > 启用 SSH shell 或使用 ADB shell 运行命令并在 SSH shell（控制台）窗口中显示输出。有关如何运行 SSH 的更多信息，请参阅 [Use SSH](https://dragonwingdocs.qualcomm.com/Key-Documents/Flash-Guide/how-to-sign-in-with-ssh) 部分。

   ```dts theme={null}
   aliases {
           i2c0 = &i2c0;
           spi15 = &spi15;
           serial1 = &uart7;
   };

   &uart7 {
           status = "okay";
   };
   ```
2. 为进行回环测试，请在 [https://github.com/torvalds/linux/blob/master/drivers/tty/serial/qcom\_geni\_serial.c](https://github.com/torvalds/linux/blob/master/drivers/tty/serial/qcom_geni_serial.c) 文件的 `qcom_geni_serial.c` 中禁用 `if` 条件。
   ```text theme={null}
   //if (mctrl & TIOCM_LOOP) // Disabling the if condition for loopback test
   port->loopback = RX_TX_CTS_RTS_SORTED;
   ```

要在 Linux 内核中验证 QUP v3 UART 注册功能，请确保 UART 已正确注册到 TTY 栈。

1. 在以下 DTSI 文件中禁用 UART 默认用例。
   * QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi)
   * Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)
   * Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)
   ```text theme={null}
   bluetooth: bluetooth {
          status = "disabled";
   };
   ```
   重新构建并启动设备后，运行以下命令。
   ```text theme={null}
   ls /dev/ttyHS1
   dmesg | grep ttyH
   ```
   将显示以下输出。
   ```text theme={null}
   /dev/ttyHS1
   [    3.355487] 99c000.serial: ttyHS1 at MMIO 0x99c000 (irq = 137, base_baud = 0) is a MSM
   ```
2. 要验证 UART 驱动，请执行以下操作：
   1. 打开 SSH shell 或使用 ADB shell。如果 SELinux 阻止了某项操作，请运行 `setenforce 0` 将其临时设置为宽容（permissive）模式。
   2. 注册 UART。
      ```text theme={null}
      ls /dev/ttyHS*
      ```
      以下是示例输出。
      ```text theme={null}
      ls /dev/ttyHS*
      /dev/ttyHS1
      ```
      根据为 `serial1 = &uart7` 添加的别名映射 `ttyHS1` 端口并启用串行引擎。

内核中注册的 UART 设备会被列出。UART 驱动遵循测试序列以启用回环。在 DUT 中启用 UART 节点后，运行以下命令以验证在 DTSI 文件中已启用 UART 实例。

> [!NOTE]
>
> **注意**
>
> 打开两个 SSH shell 或使用 ADB shell 来写入和读取 UART 回环的数据。有关如何运行 SSH 的更多信息，请参阅 [Use SSH](https://dragonwingdocs.qualcomm.com/Key-Documents/Flash-Guide/how-to-sign-in-with-ssh) 部分。

1. 打开 SSH shell 或使用 ADB shell。如果 SELinux 阻止了某项操作，请运行 `setenforce 0` 将其临时设置为宽容（permissive）模式。
2. 使用 `echo` 命令传输数据。
   ```text theme={null}
   echo "This Document Is Very Much Helpful" > /dev/ttyHS1
   ```
3. 在 UART 设备节点中读取数据。
   ```text theme={null}
   cat /dev/ttyHS1
   ```

## **调试 UART 问题**

本节提供有关在 UART 软件驱动中启用调试日志的信息。

### **Linux**

UART 驱动日志记录通过动态调试方法启用。在 `<workspace_path_of_LINUX_kernel_image>/sources/kernel/kernel_platform/kernel/arch/arm64/configs/qcom_defconfig` 中启用 `CONFIG_DYNAMIC_DEBUG` 以支持内核驱动的动态调试。

要在内核日志（`dmesg`）中启用并查看 UART 驱动日志，请运行以下命令。

```text theme={null}
mount -t debugfs none /sys/kernel/debug
echo -n "file qcom_geni_serial.c +p" > /sys/kernel/debug/dynamic_debug/control
echo -n "file qcom-geni-se.c +p" > /sys/kernel/debug/dynamic_debug/control
echo -n "file serial_core.c +p" > /sys/kernel/debug/dynamic_debug/control
echo -n "file gpi.c +p" > /sys/kernel/debug/dynamic_debug/control
```

## **UART 示例**

有关上游设备树参考的信息，请参阅以下 DTSI 文件。

* QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/kodiak.dtsi)
* Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)
* Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)

有关 Qualcomm Linux 硬件 SoC 的设备树节点信息，请参阅以下 DTSI 文件。

* QCS6490 和 QCS5430：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts)
* Dragonwing IQ-9075：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/lemans.dtsi)
* Dragonwing IQ-615：[https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/talos.dtsi)
