MX8 UART

From Variscite Wiki
Revision as of 17:54, 12 July 2021 by Nate (talk | contribs)
VAR-SOM-MX8 UART

VAR-SOM-MX8 UART Overview

On VAR-SOM-MX8 up to 5 UARTS can be used.
By default, UART0, UART1, UART2 and UART4 are enabled, UART3 is disabled as it shares pins with the second Ethernet controller. UART5 is not defined.
UART0 is used for debug console, UART1, UART2 and UART4 are connected to J18 header on Symphony-Board. UART3 is connected to J30 header on Symphony-Board (not assembled by default).
UART1 is connected to Bluetooth module on SOM, it can be used on J18 only when BT is disabled.
Only UART0, UART1 and UART3 have RTS and CTS lines.
Inspect the carrier board datasheet or schematics for the exact pinout.

On SPEAR-MX8 up to 5 UARTS can be used.
By default, UART0, UART1 and UART2 are enabled, and UART3 and UART4 are not defined (UART3 shares pins with the second Ethernet controller).
UART0 is used for debug console, UART0 and UART2 are connected to J26 header on SPEAR-CustomBoard. UART3 and UART4 are connected to J20 header on the SPEAR-CustomBoard.
UART1 is connected to the Bluetooth module on the SOM. it can be used only when BT is disabled (not exported on SPEAR-CustomBoard).
Only UART0, UART1 and UART3 have RTS and CTS lines.
Inspect the carrier board datasheet or schematics for the exact pinout.

UART naming under Linux

The Linux devices corresponding to UART0 - UART4 are /dev/ttyLP0 - /dev/ttyLP4 respectively.

Testing UART2 on VAR-SOM-MX8

Short J18.3 and J18.5 pins and run the following commands:

# stty -F /dev/ttyLP2 -echo -onlcr 115200
# cat /dev/ttyLP2 &
# echo hello > /dev/ttyLP2

For each invocation of echo command the "hello" string should appear on the terminal.

Testing UART4 on VAR-SOM-MX8

Short J18.7 and J18.9 pins and run the following commands:

# stty -F /dev/ttyLP4 -echo -onlcr 115200
# cat /dev/ttyLP4 &
# echo hello > /dev/ttyLP4

Testing UART2 on SPEAR-MX8

Short J26.17 and J26.19 pins and run the following commands:

# stty -F /dev/ttyLP2 -echo -onlcr 115200
# cat /dev/ttyLP2 &
# echo hello > /dev/ttyLP2

For each invocation of echo command the "hello" string should appear on the terminal.

Disabling UART2

To disable UART2 on VAR-SOM-MX8 edit arch/arm64/boot/dts/freescale/fsl-imx8qxp-var-som-common.dtsi under kernel source directory and modify

&lpuart2 {
        ...
        status = "okay";
};

to

&lpuart2 {
        ...
        status = "disabled";
};


On SPEAR-MX8 modify arch/arm64/boot/dts/freescale/fsl-imx8qxp-var-spear-common.dtsi in the same manner.


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/ttyLPN -echo -onlcr 115200
# echo hello > /dev/ttyLPN

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.