How to enable UART on the pin header

You can use a general-purpose UART interface on the onboard pin header.

Please see the pin expansion descriptions to know how UART pins are exposed on the board before reading this guide.

As you can see, there're several sets of UART pins on the onboard pin header. Those locations differ from each other but in common, pin #8 and #10 will always be used for the first exposed UART pin set. Additionally, each board has the other UART pins available.

In this guide, you will know how you can enable the UART pins on the board.

Overview

  • If you enable UART functionality of the pins, you cannot use them as GPIO or the other alternative function.

Basically, the necessary nodes for UART functionality are already defined in the device source tree. If you enable the nodes by editing the device tree, you can use the function without any other bothers.

It seems easy but the real work doesn't. But thanks to the Device Tree Overlay, you can enable them just edit the /media/boot/config.ini file.

Enable the first UART pins

Open /media/boot/config.ini file with your favorite text editor.

Then edit the DTBO parts of the file as shown below. See the overlays variable having “uart0” value.

  • If you set nothing, then all pins will work as a general-purpose I/O mode.
; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32"
 
[overlay_hktft35]
overlays="hktft35

Reboot to apply the new DTBO settings. After reboot, you can find the extra /dev/ttyS1 device files in the device list.

$ ls -al /dev/ttyS?
crw--w---- 1 root tty     238, 0 May 28 18:36 /dev/ttyS0
crw-rw---- 1 root dialout 238, 1 Jan 29  2018 /dev/ttyS1

Enable all of the available UART pins

Each board has a different number of UART pin sets. Here's how DTBO settings in config.ini look like if all available UART pins enabled.

Odroid-XU4

UART DTBO Pin header Phy Pin # (RX) Phy Pin # (TX) GPIO Pin # (RX) GPIO Pin # (TX) Device File
UART_0 uart0.dtbo CON10 (2*15 pins) 6 8 171 (GPA0.0) 172 (GPA0.1) /dev/ttySAC0
Shifter Shield 10 8
; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="uart0"

Odroid-N2/N2+

UART DTBO Pin header Phy Pin # (RX) Phy Pin # (TX) GPIO Pin # (RX) GPIO Pin # (TX) Device File
UART_EE_A uart0.dtbo J2 (2*20 pins) 10 8 489 (GPIOX.13) 488 (GPIOX.12) /dev/ttyS1
UART_EE_B uart1.dtbo J2 (2*20 pins) 15 35 483 (GPIOX.7) 482 (GPIOX.6) /dev/ttyS2
; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="uart0 uart1"

Odroid-C4

UART DTBO Pin header Phy Pin # (RX) Phy Pin # (TX) GPIO Pin # (RX) GPIO Pin # (TX) Device File
UART_EE_A uart0.dtbo J2 (2*20 pins) 10 8 489 (GPIOX.13) 488 (GPIOX.12) /dev/ttyS1
UART_EE_B uart1.dtbo J2 (2*20 pins) 15 33 483 (GPIOX.7) 482 (GPIOX.6) /dev/ttyS2
UART_EE_C uart2.dtbo J2 (2*20 pins) 26 32 23 (GPIOH.6) 24 (GPIOH.7) /dev/ttyS3
UART_AO_B uart3.dtbo J7 (1*7 pins) 4 6 505 (GPIOAO.9) 504 (GPIOAO.8) /dev/ttyS4
; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="uart0 uart1 uart2 uart3"

In Odroid-C4, all the serial device files will be listed like,

$ ls -al /dev/ttyS?
crw--w---- 1 root tty     239, 0 Apr 26 05:45 /dev/ttyS0
crw-rw---- 1 root dialout 239, 1 Mar 17 21:36 /dev/ttyS1
crw-rw---- 1 root dialout 239, 2 Mar 17 21:36 /dev/ttyS2
crw-rw---- 1 root dialout 239, 3 Mar 17 21:36 /dev/ttyS3
crw-rw---- 1 root dialout 239, 4 Mar 17 21:36 /dev/ttyS4
  • /dev/ttyS0 in Odroid-N2 and Odroid-C4 is the default debugging UART interface.
  • This guide is for Odroid-N2 and C4 but you can use /dev/ttyS1 (/dev/ttySAC0 in Odroid-XU4) on the other board as well since that first UART pin locates with the same pin numbers.

Connect wires

The pin map of onboard 4-pin CON5 header for our debugging UART (Shown as /dev/ttyS0) is,

_____UART____
|           |
|Pin 4 - GND|
|Pin 3 - RXD|
|Pin 2 - TXD|
|Pin 1 - VCC|
|_          |
  |_________|

3.3V LVTTL

You can connect the UART pins on the pin header to your host PC.

See the pin maps.

UART_EE_A (/dev/ttyS1)

J2 Header Pin # UART Module Pin # Role
9 4 GND
10 3 RxD
8 2 TxD
38 1 VCC

UART_EE_B (/dev/ttyS2)

J2 Header Pin # UART Module Pin # Role
9 4 GND
15 3 RxD
35 (N2)/33(C4) 2 TxD
38 1 VCC

Connect the cables like the following picture, which shows when using UART_EE_A.

The RxD and TxD pins must be twisted together.

ODROID-N2

ODROID-C4

Connect the opposite side of the UART module to your host PC.

Test drive

  • Assume that your host PC is Debian/Ubuntu system.

Enter the following commands to set /dev/ttyS1 up.

$ sudo stty -F /dev/ttyS1 115200

On your host PC, install minicom to serial communication.

$ sudo apt install minicom

Check the UART module installed as /dev/ttyUSB*.

$ ls /dev/ttyUSB?
/dev/ttyUSB0

Then open minicom with the following options.

$ minicom -b 115200 -D /dev/ttyUSB0

At your target board, put something to /dev/ttyS1 device.

$ echo "something" | sudo tee /dev/ttyS1

Then you can see the message on the minicom screen on your host PC.

2021/04/26 15:01 · joshua