Configure iMX6 pads for serial communication (UART) - FrankBau/meta-marsboard-bsp GitHub Wiki
In the MarS Board schematics, you will find UART pins which are available on the extension headers. In this example we will use the following pins on header J11:
Function | Pin |
---|---|
UART4_TXD | 4 |
UART4_RXD | 6 |
UART5_TXD | 8 |
UART5_RXD | 10 |
UART4_RTS | 12 |
UART4_CTS | 14 |
UART5_RTS | 16 |
UART5_CTS | 18 |
UART4 and UART5 are already configured in the device tree file. Pin multiplexing is done in the blocks:
pinctrl_uart4: uart4grp {
fsl,pins = <
MX6QDL_PAD_CSI0_DAT12__UART4_TX_DATA 0x1b0b1
MX6QDL_PAD_CSI0_DAT13__UART4_RX_DATA 0x1b0b1
MX6QDL_PAD_CSI0_DAT16__UART4_RTS_B 0x1b0b1
MX6QDL_PAD_CSI0_DAT17__UART4_CTS_B 0x1b0b1
>;
};
pinctrl_uart5: uart5grp {
fsl,pins = <
MX6QDL_PAD_CSI0_DAT14__UART5_TX_DATA 0x1b0b1
MX6QDL_PAD_CSI0_DAT15__UART5_RX_DATA 0x1b0b1
MX6QDL_PAD_CSI0_DAT18__UART5_RTS_B 0x1b0b1
MX6QDL_PAD_CSI0_DAT19__UART5_CTS_B 0x1b0b1
>;
};
and enabled at global level:
&uart4 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart4>;
status = "okay";
};
&uart5 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart5>;
status = "okay";
};
All serial ports described in the .dts are already mapped by the linux kernel to serial devices. On the target enter:
root@marsboard:~# ls -l /dev/ttymx*
crw------- 1 root tty 207, 17 Dec 9 05:03 /dev/ttymxc1
crw------- 1 root root 207, 18 Dec 9 04:46 /dev/ttymxc2
crw------- 1 root root 207, 19 Dec 9 04:52 /dev/ttymxc3
crw------- 1 root root 207, 20 Dec 9 04:53 /dev/ttymxc4
Their order corresponds to the .dts file: uart2, uart3, uart4, and uart5 (uart1 is not enabled).
uart2 is used by the linux terminal for stdin and stdout. This is defined in the Linux kernel command line (which is passed from the U-Boot boot loader). To print the kernel command line, enter:
root@marsboard:~# cat /proc/cmdline
console=ttymxc1,115200 root=/dev/mmcblk0p2 rootwait ...
Testing
To check uart function, you may cross-connect UART4_TXD --> UART5_RXD (pin 4 and 10 of header J11) with a wire. Redirect the output of UART5 (/dev/ttymxc4) to your terminal by entering:
cat /dev/ttymxc4 &
and send some data to UART4 (/dev/ttymxc3):
echo 1234567890 > /dev/ttymxc3
When the cable is connected, you will see the same data arriving on UART5:
root@marsboard:~# echo 0123456789 > /dev/ttymxc3
0123456789
When the wire is connected, you will see the echo in the terminal. If you remove the wire, nothing will be transmitted. In a similar way, you may test the reverse connection UART5_TXD --> UART4_RXD.
Note: the flow control signals RTS and CTS have not been used so far. Todo: add more tests with flow control.
Further reading
You may also use the sysfs entry /sys/class/tty/ttymxc0/
or the program stty
to configure the serial port.
You may use the program microcom
on the MarS Board to open a serial terminal.
For **programming **a serial port, see https://www.cmrr.umn.edu/~strupp/serial.html.