Skip to content

UART

UART Overview

Serial Port Device Node Device Tree VAR-SOM-MX7 / VAR-MX7CustomBoard
UART1 /dev/ttymxc0 uart1 A7 serial debug console
UART2 /dev/ttymxc1 uart2 Used as debug UART by Cortex-M4 FreeRTOS demos, ortherwise free for use. Connected to header J5: RX (J5.5), TX (J5.7), RTS (J5.6), CTS (J5.8).
UART3 /dev/ttymxc2 uart3 Used for the Bluetooth HCI interface on the SoM, free for use in certain cases. Connected to header J13: RX (J13.5), TX (J13.7), RTS (J13.1), CTS (J13.2). [1]
  1. ↑ See Testing UART3 on VAR-SOM-MX7 and Testing UART3 on VAR-SOM-MX7-5G

Testing UART2 on VAR-SOM-MX7

Short J5.5 with J5.7 and J5.6 with J5.8, then run the following commands:

stty -F /dev/ttymxc1 -echo -onlcr 115200 crtscts
cat /dev/ttymxc1 &
echo hello > /dev/ttymxc1

Each time you run this echo command the "hello" string should appear on the terminal.

Testing UART3 on VAR-SOM-MX7

Note: UART3 is used by the Bluetooth module on the SoM. For SoM configurations without the WiFi/BT module installed, UART3 can be used by the carrier board.

Short J13.1 with J13.3 and J13.5 with J13.7, then run the following commands:

stty -F /dev/ttymxc2 -echo -onlcr 115200 crtscts
cat /dev/ttymxc2 &
echo hello > /dev/ttymxc2

Each time you run this echo command the "hello" string should appear on the terminal.

Testing UART3 on VAR-SOM-MX7-5G

Note: UART3 is used by the Bluetooth module on the SoM. It can be used by the carrier board by disabling the Variscite Bluetooth service and the UART buffer on the SoM (controlled by BT_BUF_GPIO [GPIO1_IO6]).

Disable the Bluetooth device-tree node (only VAR-SOM-MX7-5G_V2):

&bluetooth_iw61x {
    status = "disabled";
};

Disable the Variscite Bluetooth service:

systemctl disable --now variscite-bt

Disable the Bluetooth UART buffer on the SoM (not required for Scarthgap 6.6.y_2.2.2 and above):

gpioset -t 0 --chip gpiochip0 6=1

Short J13.1 with J13.3 and J13.5 with J13.7, then run the following commands:

stty -F /dev/ttymxc2 -echo -onlcr 115200 crtscts
cat /dev/ttymxc2 &
echo hello > /dev/ttymxc2

Each time you run this echo command the "hello" string should appear on the terminal.

Configuring RS485 Half-Duplex

Each UART can be configured for RS485 Half-Duplex mode by using a GPIO pin to drive the receive and transmit enable inputs. This can be configured in the device tree by making the following changes to the uart node and replacing X, Y & Z with the proper values:

&uartX {                                                          /* Add RS485 properties to uartX */
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_uartX>, <&pinctrl_uartX_rs485>;     /* Add RS485 GPIO pinctrl */
    rts-gpios = <&gpioY Z GPIO_ACTIVE_LOW>;                   /* Add rts-gpios property */
    linux,rs485-enabled-at-boot-time;                         /* Enable RS485 at boot time to skip using TIOCSRS485 ioctl */
    status = "okay";
};

Next, configure the RS485 GPIO pin by adding pinctrl_uartX_rs485 to iomuxc. Replace X, GPIO_PIN_FUNCTION, and GPIO_PIN_SETTINGS with the proper values:

&iomuxc {
    pinctrl_uartX_rs485: uartXrs485 {
        fsl,pins = <
            GPIO_PIN_FUNCTION  GPIO_PIN_SETTINGS
        >;
    };
};

Note: For more information about configuring pins, please see i.MX Device Tree Pinmux Settings Guide

After making these changes, RS485 mode will be enabled by default and can be verified from the console by running the commands below. Replace N with the proper value, which is typically X-1 relative to the device tree node uartX:

stty -F /dev/ttymxcN -echo -onlcr 115200
echo hello > /dev/ttymxcN

The below logic analyzer capture shows the RS485 RX/TX enable line toggling when writing to the UART:

Rs485.png

Please refer to the Linux device tree bindings for more RS485 configuration options.