# Debug UART in kernel

Source: [https://docs.qualcomm.com/doc/80-88500-1/topic/20_Debug_UART_in_kernel.html](https://docs.qualcomm.com/doc/80-88500-1/topic/20_Debug_UART_in_kernel.html)

## About this task

## Procedure

1. Run the following commands and ensure that the UART is registered with the Linux TTY stack: 
        
adb shellCopy to clipboard

        ls /dev/ttyHS*Copy to clipboard

If the device is not listed in the output, verify the code modifications and ensure that the information is correctly defined.
2. To enable loopback, run the following commands:
        
adb shellCopy to clipboard

        mount -t debugfs none /sys/kernel/debugCopy to clipboard

        cd /sys/devices/platform/soc/898000.qcom,qup_uart/Copy to clipboard

        echo 3 > loopbackCopy to clipboard

        cat loopbackCopy to clipboard

Note: Ensure that the `cat loopback` command returns 1.
3. To dump the UART Rx data, open another shell and run the following command:
        
cat /dev/ttyHS#Copy to clipboard
4. Transmit test data through a separate shell.
        
echo "Hello World" > /dev/ttyHS#Copy to clipboard

- If loopback works:
        - The test message loop appears continuously in the command shell until you exit the `cat` command. This issue occurs because of the internal loopback and the method that the `cat` command uses to open the UART.
        - It indicates that the UART is properly configured and only the GPIO settings must be confirmed.
    - If loopback does not work:
        1. Ensure that the UART is still in the Active state.
        2. Open the UART from the shell and dump any data that UART receives:

                cat /dev/ttyHS#Copy to clipboard
5. Run the following commands in the adb shell and verify the IPC logs:
        
cat /sys/kernel/debug/ipc_logging/898000.qcom,qup_uart_misc/log_cont > c:\temp\qup_uart_misc.txtCopy to clipboard

        cat /sys/kernel/debug/ipc_logging/898000.qcom,qup_uart_pwr/log_cont > c:\temp\qup_uart_pwr.txtCopy to clipboard

        cat /sys/kernel/debug/ipc_logging/898000.qcom,qup_uart_rx/log_cont > c:\temp\qup_uart_rx.txtCopy to clipboard

        cat /sys/kernel/debug/ipc_logging/898000.qcom,qup_uart_tx/log_cont > c:\temp\qup_uart_tx.txtCopy to clipboard
6. Verify the IOCTL function. 
        
This function can be used to control the UART power resource by using the
          `TIOCPMGET` or `TIOCPMPUT` parameter. This parameter calls the
            `vote_clock_on()` or `vote_clock_off()` functions to
          manage the UART power. The IOCTL can be called from the user space application, which uses
          this UART port. 
**Example:**

        ioctl(fd_uart, TIOCPMGET, 0); //fd is file description which is getting from open UART port with '/dev/ttyHS#'. 
        ioctl(fd_uart, TIOCPMPUT, 0);
        [kernel/msm-4.14/drivers/tty/serial/msm_geni_serial.c]
        static int msm_geni_serial_ioctl(struct uart_port *uport, unsigned int cmd, unsigned long arg) 
        { 
            int ret = -ENOIOCTLCMD; 
            switch (cmd) { 
                case TIOCPMGET: { 
                    ret = vote_clock_on(uport); 
                    break; 
                    } 
                    case TIOCPMPUT: { 
                    ret = vote_clock_off(uport); 
                    break; 
                    }Copy to clipboard
7. Verify the TrustZone access control.
        
The TrustZone access control is required to get the bus access QUP. Based on the access entry, the firmware of the bus is loaded.

The QUP supports both the 4-wire UART with flow control and the 2-wire UART without flow control. Following is the TrustZone access control entry for both the flow controls, providing access to the QUPV3\_0\_SE6 from the AC\_HLOS, application processor side, in the FIFO mode:

        const QUPv3_se_security_permissions_type qupv3_perms_default[] 
        {
        <snip>
        { QUPV3_0_SE2, QUPV3_PROTOCOL_UART_2W, QUPV3_MODE_FIFO,AC_HLOS, TRUE, TRUE,FALSE },
        { QUPV3_0_SE6, QUPV3_PROTOCOL_UART_4W, QUPV3_MODE_FIFO,AC_HLOS, TRUE, TRUE,FALSE }<snip>
        }Copy to clipboard

**Parent Topic:** [UART in QUP](https://docs.qualcomm.com/doc/80-88500-1/topic/29_UART_in_QUP_v3.html)

Last Published: Aug 18, 2023

[Previous Topic
Methods to control UART clocks](https://docs.qualcomm.com/bundle/publicresource/80-88500-1/topics/21_Code_walkthrough___UART_driver.md#Methods_to_control_UART_clocks_27) [Next Topic
Configure UART in sensor low-power island (SLPI) processor](https://docs.qualcomm.com/bundle/publicresource/80-88500-1/topics/28_Configure_UART_in_sensor_low_power_island__SLPI__processor.md)