common:application_note:gpio:enable_spi_i2c_uart_with_dtbo

How to Enable SPI/I2C/UART/PWM Using DTBO

  • DTBO feature requires a specific kernel version or up. Please see the following for the boards.
    • ODROID-XU4: 5.4
    • ODROID-N2/N2+: 4.9.230
    • ODROID-C4: 4.9.230
    • ODROID-M1: 4.19.219
    • Android
      • ODROID-N2/N2+: 4.9.113
      • ODROID-C4: 4.9.113
  • And also need the latest boot.ini, config.ini and including overlays directory structure in BOOT partition.
  • The other boards including C2 are not supported and there's no plan to support them for now.
  • To know Device Tree Overlay further, please refer to the document linked below.

By default, SPI, I2C, UART are enabled when you flash a new Odroid Linux image. But to control them, we can use config.ini file.

In your Odroid board, move to the /media/boot directory or /boot directory.

target
cd /media/boot

Then you can see the below files. Those files may be different from yours because it depends on the boards.

/media/boot
├── Image.gz
├── amlogic
│   ├── meson64_odroidc4.dtb
│   └── overlays
│       └── odroidc4
│           ├── ads7846.dtbo
│           ├── can0.dtbo
│           ├── esp8089.dtbo
│           ├── fanspeed-full.dtbo
│           ├── gpio-joystick0.dtbo
│           ├── gpio-joystick1.dtbo
│           ├── hifishield.dtbo
│           ├── hifishield2.dtbo
│           ├── hktft32.dtbo
│           ├── hktft35.dtbo
│           ├── i2c0.dtbo
│           ├── i2c1.dtbo
│           ├── lineout.dtbo
│           ├── onewire.dtbo
│           ├── pcf8563.dtbo
│           ├── pwm_a-pwmfan.dtbo
│           ├── pwm_ab.dtbo
│           ├── pwm_b-backlight.dtbo
│           ├── pwm_cd.dtbo
│           ├── pwm_ef.dtbo
│           ├── sdio.dtbo
│           ├── spi0.dtbo
│           ├── sx865x-i2c1.dtbo
│           ├── uart0.dtbo
│           ├── uart1.dtbo
│           ├── uart2.dtbo
│           └── uart3.dtbo
├── boot.ini
├── boot.ini.default
├── config.ini
├── display.bin
├── edid.bin
└── uInitrd
/media/boot
├── Image.gz
├── amlogic
│   ├── meson64_odroidn2.dtb
│   ├── meson64_odroidn2_plus.dtb
│   └── overlays
│       └── odroidn2
│           ├── ads7846.dtbo
│           ├── can0.dtbo
│           ├── fanspeed-full.dtbo
│           ├── gpio-joystick0.dtbo
│           ├── gpio-joystick1.dtbo
│           ├── gpio_spdif.dtbo
│           ├── hktft32.dtbo
│           ├── hktft35.dtbo
│           ├── i2c0.dtbo
│           ├── i2c1.dtbo
│           ├── irblaster.dtbo
│           ├── onewire.dtbo
│           ├── pwm_c-pwmfan.dtbo
│           ├── pwm_cd.dtbo
│           ├── pwm_d-backlight.dtbo
│           ├── pwm_ef.dtbo
│           ├── saradc.dtbo
│           ├── spi0.dtbo
│           ├── sx865x-i2c1.dtbo
│           ├── uart0.dtbo
│           └── uart1.dtbo
├── boot.ini
├── boot.ini.old
├── config.ini
├── config.ini.old
├── display.bin
├── edid.bin
└── uInitrd
/boot
├── System.map-4.19.219-odroid-arm64
├── boot-logo.bmp.gz
├── boot.scr
├── boot.scr.bak
├── config-4.19.219-odroid-arm64
├── config.ini
├── dtb -> dtbs/4.19.219-odroid-arm64/rockchip/rk3568-odroid-m1.dtb
├── dtb-4.19.219-odroid-arm64 -> dtbs/4.19.219-odroid-arm64/rockchip/rk3568-odroid-m1.dtb
├── dtbs
│   └── 4.19.219-odroid-arm64
│       ├── rk3568-odroid-m1.dtb -> rockchip/rk3568-odroid-m1.dtb
│       └── rockchip
│           ├── overlays
│           │   └── odroidm1
│           │       ├── display_vu8m.dtbo
│           │       ├── hktft32.dtbo
│           │       ├── i2c0.dtbo
│           │       ├── i2c1.dtbo
│           │       ├── imx219.dtbo
│           │       ├── imx477.dtbo
│           │       ├── ov5647.dtbo
│           │       ├── pwm1.dtbo
│           │       ├── pwm2.dtbo
│           │       ├── pwm9.dtbo
│           │       ├── rknpu.dtbo
│           │       ├── spi0.dtbo
│           │       ├── uart0-with-ctsrts.dtbo
│           │       ├── uart0.dtbo
│           │       └── uart1.dtbo
│           ├── px30-ad-d6-anx6345.dtb
│           ├── px30-ad-r35-mb-rk618-dual-lvds.dtb
│           ├── px30-ad-r35-mb-rk618-hdmi-lvds.dtb
│           ├── px30-ad-r35-mb-rk618-hdmi.dtb
│           ├── px30-ad-r35-mb-rk618-lvds.dtb
│           ├── px30-evb-ddr3-lvds-v10.dtb
│           ├── px30-evb-ddr3-v10-avb.dtb
...
│           ├── rk3568-evb1-ddr4-v10-linux-spi-nor.dtb
│           ├── rk3568-evb1-ddr4-v10-linux.dtb
│           ├── rk3568-evb1-ddr4-v10.dtb
│           ├── rk3568-evb2-lp4x-v10-bt1120-to-hdmi.dtb
│           ├── rk3568-evb2-lp4x-v10.dtb
│           ├── rk3568-evb4-lp3-v10.dtb
│           ├── rk3568-evb5-ddr4-v10.dtb
│           ├── rk3568-evb6-ddr3-v10-linux.dtb
│           ├── rk3568-evb6-ddr3-v10-rk628-bt1120-to-hdmi.dtb
│           ├── rk3568-evb6-ddr3-v10-rk628-rgb2hdmi.dtb
│           ├── rk3568-evb6-ddr3-v10-rk630-bt656-to-cvbs.dtb
│           ├── rk3568-evb6-ddr3-v10.dtb
│           ├── rk3568-evb7-ddr4-v10.dtb
│           ├── rk3568-iotest-ddr3-v10-linux.dtb
│           ├── rk3568-iotest-ddr3-v10.dtb
│           ├── rk3568-nvr-demo-v10-linux-spi-nand.dtb
│           ├── rk3568-nvr-demo-v10-linux.dtb
│           ├── rk3568-nvr-demo-v10.dtb
│           ├── rk3568-nvr-demo-v12-linux-spi-nand.dtb
│           ├── rk3568-nvr-demo-v12-linux.dtb
│           └── rk3568-odroid-m1.dtb
├── initrd.img -> initrd.img-4.19.219-odroid-arm64
├── initrd.img-4.19.219-odroid-arm64
├── initrd.img.old -> initrd.img-4.19.219-odroid-arm64
├── lost+found [error opening dir]
├── vmlinuz -> vmlinuz-4.19.219-odroid-arm64
├── vmlinuz-4.19.219-odroid-arm64
└── vmlinuz.old -> vmlinuz-4.19.219-odroid-arm64

Check that /media/boot/amlogic/overlays/odroid(c4/n2) directory and SPI, I2C, UART, PWM .dtbo files.

Or Check that /boot/dtbs/4.19.219-odroid-arm64/rockchip/overlays/odroidm1/ directory in ODROID-M1.

All the Odroid ARM boards have exportable 1 SPI, 2 I2C, 1 UART, 4 PWM bus on their 40 pin header. But some boards may have the other rest buses. We're providing all the possible bus as a DTBO file, so that you can enable them just by referring the Expansion connectors page of each board.

Here's the Device Tree Overlay part of the config.ini file.

; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32 ads7846"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"

To enable a communication protocol that you want to use, just change the section profile or the overlays key.

Check the overlay_profile key and that corresponded section profile that added to the bottom of the codes.

SPI

; Device Tree Overlay
overlay_resize=16384
overlay_profile=spi
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32 ads7846"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"
 
[overlay_spi]
overlays="spi0"

I2C

; Device Tree Overlay
overlay_resize=16384
overlay_profile=i2c
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32 ads7846"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"
 
[overlay_i2c]
overlays="i2c0 i2c1"

UART

; Device Tree Overlay
overlay_resize=16384
overlay_profile=uart
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32 ads7846"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"
 
[overlay_uart]
overlays="uart0"

PWM

; Device Tree Overlay
overlay_resize=16384
overlay_profile=pwm
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32 ads7846"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"
 
[overlay_pwm]
overlays="pwm_cd pwm_ef"

All the possible components

In Odroid-C4 and ODROID-N2, there're two more UART channels exposed on the 40 pin header.

Here's an example that shows the codes when if all of the protocols to be enabled.

; Device Tree Overlay
overlay_resize=16384
overlay_profile=all
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32 ads7846"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"
 
[overlay_all]
overlays="spi0 i2c0 i2c1 uart0 uart1 uart2"

In this case, we can check if that enabled by using WiringPi.

target
sudo gpio readall
ODROID-C4
 +-----+-----+---------+------+---+--- C4 ---+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3V |      |   |  1 || 2  |   |      | 5V      |     |     |
 | 493 |   8 |   SDA.2 | ALT1 | 1 |  3 || 4  |   |      | 5V      |     |     |
 | 494 |   9 |   SCL.2 | ALT1 | 1 |  5 || 6  |   |      | 0V      |     |     |
 | 481 |   7 |  IO.481 |   IN | 1 |  7 || 8  | 1 | ALT1 | TxD1    | 15  | 488 |
 |     |     |      0V |      |   |  9 || 10 | 1 | ALT1 | RxD1    | 16  | 489 |
 | 479 |   0 |  IO.479 |   IN | 1 | 11 || 12 | 1 | IN   | IO.492  | 1   | 492 |
 | 480 |   2 |  IO.480 |   IN | 1 | 13 || 14 |   |      | 0V      |     |     |
 | 483 |   3 |  IO.483 | ALT2 | 1 | 15 || 16 | 1 | IN   | IO.476  | 4   | 476 |
 |     |     |    3.3V |      |   | 17 || 18 | 1 | IN   | IO.477  | 5   | 477 |
 | 484 |  12 |    MOSI | ALT4 | 1 | 19 || 20 |   |      | 0V      |     |     |
 | 485 |  13 |    MISO | ALT4 | 1 | 21 || 22 | 1 | IN   | IO.478  | 6   | 478 |
 | 487 |  14 |    SLCK | ALT4 | 1 | 23 || 24 | 1 | OUT  | SS      | 10  | 486 |
 |     |     |      0V |      |   | 25 || 26 | 0 | ALT2 | IO. 23  | 11  | 23  |
 | 474 |  30 |   SDA.3 | ALT2 | 1 | 27 || 28 | 1 | ALT2 | SCL.3   | 31  | 475 |
 | 490 |  21 |  IO.490 |   IN | 1 | 29 || 30 |   |      | 0V      |     |     |
 | 491 |  22 |  IO.491 |   IN | 1 | 31 || 32 | 1 | ALT2 | IO. 24  | 26  | 24  |
 | 482 |  23 |  IO.482 | ALT2 | 1 | 33 || 34 |   |      | 0V      |     |     |
 | 495 |  24 |  IO.495 |   IN | 0 | 35 || 36 | 1 | OUT  | IO. 22  | 27  | 22  |
 |     |  25 |   AIN.2 |      |   | 37 || 38 |   |      | 1V8     | 28  |     |
 |     |     |      0V |      |   | 39 || 40 |   |      | AIN.0   | 29  |     |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+--- C4 ---+---+------+---------+-----+-----+
ODROID-N2
 +-----+-----+---------+------+---+--- N2 ---+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3V |      |   |  1 || 2  |   |      | 5V      |     |     |
 | 493 |   8 |   SDA.2 | ALT1 | 1 |  3 || 4  |   |      | 5V      |     |     |
 | 494 |   9 |   SCL.2 | ALT1 | 1 |  5 || 6  |   |      | 0V      |     |     |
 | 473 |   7 |  IO.473 |   IN | 0 |  7 || 8  | 1 | ALT1 | TxD1    | 15  | 488 |
 |     |     |      0V |      |   |  9 || 10 | 1 | ALT1 | RxD1    | 16  | 489 |
 | 479 |   0 |  IO.479 |   IN | 1 | 11 || 12 | 1 | IN   | IO.492  | 1   | 492 |
 | 480 |   2 |  IO.480 |   IN | 1 | 13 || 14 |   |      | 0V      |     |     |
 | 483 |   3 |  IO.483 | ALT2 | 1 | 15 || 16 | 1 | IN   | IO.476  | 4   | 476 |
 |     |     |    3.3V |      |   | 17 || 18 | 1 | IN   | IO.477  | 5   | 477 |
 | 484 |  12 |    MOSI | ALT4 | 1 | 19 || 20 |   |      | 0V      |     |     |
 | 485 |  13 |    MISO | ALT4 | 1 | 21 || 22 | 1 | IN   | IO.478  | 6   | 478 |
 | 487 |  14 |    SCLK | ALT4 | 1 | 23 || 24 | 1 | OUT  | CE0     | 10  | 486 |
 |     |     |      0V |      |   | 25 || 26 | 0 | IN   | IO.464  | 11  | 464 |
 | 474 |  30 |   SDA.3 | ALT2 | 1 | 27 || 28 | 1 | ALT2 | SCL.3   | 31  | 475 |
 | 490 |  21 |  IO.490 | ALT1 | 0 | 29 || 30 |   |      | 0V      |     |     |
 | 491 |  22 |  IO.491 |   IN | 1 | 31 || 32 | 0 | IN   | IO.472  | 26  | 472 |
 | 481 |  23 |  IO.481 |   IN | 1 | 33 || 34 |   |      | 0V      |     |     |
 | 482 |  24 |  IO.482 | ALT2 | 1 | 35 || 36 | 0 | IN   | IO.495  | 27  | 495 |
 |     |  25 |   AIN.3 |      |   | 37 || 38 |   |      | 1V8     | 28  |     |
 |     |     |      0V |      |   | 39 || 40 |   |      | AIN.2   | 29  |     |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+--- N2 ---+---+------+---------+-----+-----+
ODROID-M1
 +-----+-----+---------+------+---+--- M1 ---+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3V |      |   |  1 || 2  |   |      | 5V      |     |     |
 | 110 |   8 |    SDA0 | ALT5 | 1 |  3 || 4  |   |      | 5V      |     |     |
 | 109 |   9 |    SCL0 | ALT5 | 1 |  5 || 6  |   |      | 0V      |     |     |
 |  14 |   7 |  IO0_B6 |   IN | 1 |  7 || 8  | 1 | ALT5 | UART.TX | 15  | 126 |
 |     |     |      0V |      |   |  9 || 10 | 1 | ALT5 | UART.RX | 16  | 127 |
 |  16 |   0 |  IO0_C0 |   IN | 0 | 11 || 12 | 0 | IN   | IO3_D0  | 1   | 120 |
 |  17 |   2 |  IO0_C1 |   IN | 0 | 13 || 14 |   |      | 0V      |     |     |
 | 106 |   3 |  IO3_B2 |   IN | 0 | 15 || 16 | 0 | IN   | IO3_C6  | 4   | 118 |
 |     |     |    3.3V |      |   | 17 || 18 | 0 | IN   | IO3_C7  | 5   | 119 |
 |  89 |  12 | SPI.TXD | ALT4 | 1 | 19 || 20 |   |      | 0V      |     |     |
 |  88 |  13 | SPI.RXD | ALT4 | 1 | 21 || 22 | 0 | IN   | IO3_D1  | 6   | 121 |
 |  91 |  14 | SPI.CLK | ALT4 | 0 | 23 || 24 | 1 | ALT4 | SPI.CS0 | 10  | 90  |
 |     |     |      0V |      |   | 25 || 26 | 0 | IN   | IO3_D2  | 11  | 122 |
 |  12 |  30 |    SDA1 |   IN | 1 | 27 || 28 | 1 | IN   | SCL1    | 31  | 11  |
 | 145 |  21 |  IO4_C1 |   IN | 0 | 29 || 30 |   |      | 0V      |     |     |
 | 142 |  22 |  IO4_B6 |   IN | 0 | 31 || 32 | 0 | IN   | IO3_D3  | 26  | 123 |
 |  13 |  23 |  IO0_B5 |   IN | 1 | 33 || 34 |   |      | 0V      |     |     |
 | 125 |  24 |  IO3_D5 |  OUT | 0 | 35 || 36 | 0 | IN   | IO3_D4  | 27  | 124 |
 |     |  25 |    AIN1 |      |   | 37 || 38 |   |      | 1V8     | 28  |     |
 |     |     |      0V |      |   | 39 || 40 |   |      | AIN0    | 29  |     |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+--- M1 ---+---+------+---------+-----+-----+

Also, we can check them with on /dev directory.

target
ls -al /dev/i2c* /dev/spi* /dev/ttyS*
crw------- 1 root root     89, 0 Jun 18 08:48 /dev/i2c-0
crw------- 1 root root     89, 1 Jun 18 08:48 /dev/i2c-1
crw------- 1 root root    153, 0 Jun 18 08:48 /dev/spidev0.0
crw--w---- 1 root tty     239, 0 Jun 18 08:48 /dev/ttyS0
crw-rw---- 1 root dialout 239, 1 Jun 18 08:47 /dev/ttyS1
crw-rw---- 1 root dialout 239, 2 Jun 18 08:47 /dev/ttyS2
crw-rw---- 1 root dialout 239, 3 Jun 18 08:47 /dev/ttyS3
  • common/application_note/gpio/enable_spi_i2c_uart_with_dtbo.txt
  • Last modified: 2022/09/14 08:53
  • by steve.jeong