Using i.MX RT1050 UART Ports in Linux Print


Unless you have reconfigured Linux to run the console on some interface other than the serial UART (LPUART1), the serial device driver is already enabled in your kernel configuration and Linux makes use of i.MX RT1050 LPUART1 for the serial console and the high-level shell. This application note explains how to enable additional UART ports in Linux.

Do not enable any UART interfaces except for those that you plan to use in your application. For one thing, unless an UART interface is actually required, you want to keep it in reset in order to save some power. Another consideration is that UART signals may conflict with other I/O interfaces on the i.MX RT1050 pins. More on that right below.

Allocation of the i.MX RT1050 pins to specific I/O interfaces is defined in the projects/rootfs/rootfs.dts.IMXRT105X_NXPEVK file.

For example, let's add LPUART8 to the system. Edit projects/rootfs/rootfs.dts.IMXRT105X_NXPEVK as follows:

  • Add a node for LPUART8:
  • soc { aips0: aips-bus@40000000 { ... uart7: serial@401a0000 { compatible = "fsl,imxrt1050-lpuart"; reg = <0x401a0000 0x1000>; interrupts = <27>; clocks = <&uart_clk>; clock-names = "ipg"; dmas = <&edma 0 73>, <&edma 0 72>; dma-names = "rx","tx"; status = "disabled"; }; ... }; };

  • Enable LPUART8 interface, and configure the LPUART8 signals on the i.MX RT1050 pins B1.10 and B1.11:
  • &uart7 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart7>; status = "okay"; }; &iomuxc { ... pinctrl_uart7: uart7grp { fsl,pins = < MXRT105X_PAD_AD_B1_10_LPUART8_TX MXRT105X_PAD_CFG_UART MXRT105X_PAD_AD_B1_11_LPUART8_RX MXRT105X_PAD_CFG_UART >; }; ... }

    There must be a device node in the target root file system for each UART port to allow accessing it using standard Linux interfaces. In the rootfs project, this device node is created by Linux automatically during the system bootup. Note that /dev/ttyLP0 corresponds to LPUART1, /dev/ttyLP1 to LPUART2 and so on. Add the appropriate info:

    aliases { ... serial7 = &uart7; ... };

Having updated your project configuration as described above, build the bootable Linux image (<project>.uImage) by running make in the project directory. There are several ways to deploy the resulted binary to the system, see Loading Linux images via Ethernet and TFTP and Installing Linux images to SD Card for example.

Stop At U-Boot prompt and enable UART7 clocks:

>= md 400fc080 1 400fc080: 00fc0f0f >= mw 400fc080 00fccf0f >= md 400fc080 1 400dc080: 00fccf0f

After that, when you boot the newly installed Linux image on the target with run bootcmd, there will be a message in the kernel bootstrap print-out indicating that additional UARTs interfaces are available:

... 401a0000.serial: ttyLP7 at MMIO 0x401a0000 (irq = 45, base_baud = 375000) is a FSL_LPUART ... / # ls -l /dev/ttyLP* crw------- 1 root root 251, 0 Jan 1 00:00 /dev/ttyLP0 crw------- 1 root root 251, 7 Jan 1 00:00 /dev/ttyLP7

Typically, UART ports are used to connect various equipment such as modems, sensors, additional computers and so on. In Linux, serial ports are accessed from C-level user space code using the stadard POSIX APIs. These APIs are extensively defined in various materials available in the Internet. For instance, try googling for something like this "How to access serial ports in C".

The LPUART8 port is available at J23 connector of the NXP i.MX RT1050 EVK board, so you may connect your USB-UART converter as follows:

i.MX RT1050 PinA i.MX RT1050 Function NXP i.MX RT1050 EVK Boad Connection WaveShare FT232 USB UART Board Connection
GPIO_AD_B1_11 lpuart8.RX J23.2 CON6.3 (TXD)
GPIO_AD_B1_10 lpuart8.TX J23.1 CON6.4 (RXD)
GND GND J21.6 CON6.2 (GND)

As a very simple test you may just loopback the RX and TX lines of LPUART8 on the NXP i.MX RT1050 EVK board (short J23.1 and J23.2), and use the following commands to send/receive text to/from LPUART8:

  • Configure port and start the reader process:
  • / # stty -echo raw speed 115200 < /dev/ttyLP7 / # cat /dev/ttyLP7 &

  • Write a string to LPUART8 and observe the echo coming from reader:
  • / # echo "Hello from IMXRT1050 over UART" > /dev/ttyLP7 Hello from IMXRT1050 over UART / #