Using i.MX 6ULL UART Ports in Linux |
In Linux, parameters of each UART controller (interrupt request numbers, DMA configuration, etc.) are specified in uartX child nodes of the soc node in the arch/arm/boot/dts/imx6ull.dtsi file located in the Linux kernel tree:
Note that all UART ports are disabled by default in the above file, so arch/arm/boot/dts/imx6ull.dtsi rarely needs to be modified, and all detailed UART port configuration is performed by board specific device tree files (.dts). For the Emcraft i.MX 6ULL SOM, configuration of the UART ports is performed in the projects/rootfs/rootfs.dts file. In particular, this file enables required ports as well as sets other UART related configuration parameters, such as presence of the flow control logic. Additionally, the projects/rootfs/rootfs.dts file defines which I/O pins are used by a specific UART port on the Emcraft i.MX 6ULL SOM. Since a single i.MX 6ULL I/O pin can be shared between several peripherals, a care must be taken while changing these parameters. The UART configuration for the Emcraft i.MX 6ULL SOM enables UART1 and UART3 ports. The UART1 is used as the Linux console, while UART3 provides communication channel over the Raspberry Pi (P10) connector. In the below .dts example, UART3 is enabled and configured for using by Linux on the Emcraft i.MX 6ULL SOM:
Whenever the Linux kernel finds an enabled UART port, it automatically creates a corresponding device node file, which can be used for accessing this port using standard Linux interfaces. For the i.MX 6ULL UART device node files have the following format: /dev/ttymxcX, where X starts from 0. Thus, for UART1 the kernel will create the /dev/ttymxc0 file, and so on. 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 standard 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". As a simple test, the following commands can be used to send/receive text to/from UART.
~ # stty -echo raw 115200 < /dev/ttymxc2 Hello from the host over UART ^C |