Using i.MX 8M UART Ports in Linux |
The i.MX 8M SoC implements 4 UART controllers (UART1-4), which can be used either by the Cortex-A53 or Cortex-M4 cores. The default Linux kernel configuration for the Emcraft i.MX 8M SOM reserves UART3 for use by FreeRTOS running on the Cortex-M4 core, while other UART ports are accessible from 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/arm64/boot/dts/freescale/fsl-imx8mq.dtsi file, located in the Linux kernel tree:
Note that all UART ports are disabled by default in the above file, which is generic for the entire i.MX 8M family and the i.MX 8M processor in particular. For this reason arch/arm64/boot/dts/freescale/fsl-imx8mq.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 8M SOM configuration of the UART ports is performed in the The UART configuration for the Emcraft i.MX 8M SOM enables UART1, UART2 and UART4 ports. The UART1 is used as the Linux console, while UART2 and UART4 provide communication channel with the built-in BT module and PCIe extension cards on the PCIe1 bus. In the below .dts example, UART3 is enabled and configured for using by Linux on the Emcraft i.MX 8M 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 8M 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 UART3.
Note that the default Emcraft software distribution runs a FreeRTOS demo application that makes use of UART3 on the Cortex-M4 core. To disable the application enter the following commands in the U-Boot prompt:
The UART3 port can be accessed on the J5 connector (first serial port) on the Emcraft IMX8M-SOM-BSB board. |