Peripheral


This chapter describes the common information and instructions of Peripheral on IoT Yocto, such as listing peripheral hardware, operating devices, and so on. Peripheral on different platforms may have some platform-specific instructions or test results. For example, you will use different peripheral interfaces on different platforms. Please refer to the platform-specific section for more details.


Note

All cmd operations presented in this chapter are based on the IoT Yocto v22.1, Genio 350-EVK. You might get different operation result depends on what platform you currently use.

I2C

There are some I2C tools to operate I2C adapters and devices.

i2cdetect will list all available I2C adapters and the I2C devices on a specific I2C bus. You can see the connected I2C device address, e.g. 0x53, and 0x57.

i2cdetect -l
i2c-3   i2c             i2c-mt65xx                              I2C adapter
i2c-1   i2c             i2c-mt65xx                              I2C adapter
i2c-2   i2c             i2c-mt65xx                              I2C adapter
i2c-0   i2c             i2c-mt65xx                              I2C adapter
i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- 53 -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Note

Make sure you don’t have more than one device with the same address connected to the same I2C bus. Otherwise, the address will conflict.

i2cdump will list all registers of a specific I2C device.

i2cdump -y 0 0x57
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: a5 a5 92 00 00 81 63 02 00 0f 00 00 00 00 00 00    ???..?c?.?......
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
...

i2cset and i2cget will write and read the register value.

i2cget -f -y 0 0x57 0x2
0x92
i2cset -f -y 0 0x57 0x2 0x93
i2cget -f -y 0 0x57 0x2
0x93

Please refer to the platform-specific section for more details on each platform.

SPI

First, you need to probe the SPI device manually by the command:

modprobe spidev

After probing, you can find an SPI device under /dev.

ls -l /dev/spidev0.0
crw------- 1 root root 153, 0 Sep 20 12:22 /dev/spidev0.0

To test the SPI device, you can use a pre-installed tool, spidev_test. It verifies that the data sent by Tx should be the same as the data received by Rx.

Note

Before using spidev_test to test, SPI_MOSI and SPI_MISO should be shorted.

dd if=/dev/random of=test.bin bs=96 count=1
1+0 records in
1+0 records out
96 bytes copied, 0.000968692 s, 99.1 kB/s
spidev_test -D /dev/spidev0.0 -s 400000 -i test.bin -v
spi mode: 0x0
bits per word: 8
max speed: 400000 Hz (400 kHz)
TX | A3 62 7A EB CA 8E 69 98 1C A9 A8 E4 2C 9A 6A 0E 94 DA EC 34 84 28 FC AE 7F 27 91 E7 B9 7E D6 32  |.bz...i.....,.j....4.(...'...~.2|
TX | 21 4A 08 0A B5 65 B3 3D D7 63 CC 6B 4C 77 A4 D4 C8 FB 57 93 B7 91 4A 34 F6 16 76 FB 72 9C C9 66  |!J...e.=.c.kLw....W...J4..v.r..f|
TX | 43 FE E0 90 54 62 E4 BC CF BF 36 81 D4 95 BF FB EF 84 66 E1 30 E0 D2 24 E5 DD 98 24 C0 F8 A1 E3  |C...Tb....6.......f.0..$...$....|
RX | A3 62 7A EB CA 8E 69 98 1C A9 A8 E4 2C 9A 6A 0E 94 DA EC 34 84 28 FC AE 7F 27 91 E7 B9 7E D6 32  |.bz...i.....,.j....4.(...'...~.2|
RX | 21 4A 08 0A B5 65 B3 3D D7 63 CC 6B 4C 77 A4 D4 C8 FB 57 93 B7 91 4A 34 F6 16 76 FB 72 9C C9 66  |!J...e.=.c.kLw....W...J4..v.r..f|
RX | 43 FE E0 90 54 62 E4 BC CF BF 36 81 D4 95 BF FB EF 84 66 E1 30 E0 D2 24 E5 DD 98 24 C0 F8 A1 E3  |C...Tb....6.......f.0..$...$....|

You can refer to the source of spidev_test here for how to use the SPI device.

Please refer to the platform-specific section for more details on each platform.

USB

The USB ports on the board may have different usages, such as USB master/slave, image flush port, and the console port. Please refer to the platform-specific section for more details on each platform.

PWM

Please refer to the platform-specific section for more details on each platform.

UART

You can use sysfs to find out the UART devices.

ls -l /sys/class/tty/ttyS*
lrwxrwxrwx 1 root root 0 Sep 20 10:43 /sys/class/tty/ttyS0 -> ../../devices/platform/soc/11002000.uart0/tty/ttyS0
lrwxrwxrwx 1 root root 0 Sep 20 10:43 /sys/class/tty/ttyS1 -> ../../devices/platform/soc/11003000.uart1/tty/ttyS1
lrwxrwxrwx 1 root root 0 Sep 20 10:43 /sys/class/tty/ttyS2 -> ../../devices/platform/soc/11004000.uart2/tty/ttyS2

By default, the console log is transferred to the host through ttyS0.

Please refer to the platform-specific section for more details on each platform.

Note

In the current release, DMA mode (CONFIG_MTK_UART_APDMA) is disabled by default due to known issues in UART kernel driver. The support for UART DMA mode is a work in progress.

GPIO

You can use GPIO tools to operate the GPIO pin.

gpiodetect will list all available GPIO chips.

gpiodetect
gpiochip0 [1000b000.pinctrl] (156 lines)

gpioinfo will list all states of GPIO pins.

gpioinfo | head
gpiochip0 - 156 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed       unused   input  active-high
        line   3:      unnamed       unused   input  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused   input  active-high
        line   6:      unnamed       unused   input  active-high
        line   7:      unnamed       unused   input  active-high
        line   8:      unnamed       unused   input  active-high
        ...

gpioset and gpioget will write and read the specific GPIO pin. If you short GPIO pin 32 and GPIO pin 34, you can set one pin and get the value back from another pin.

gpioset gpiochip0 32=0
gpioget gpiochip0 34
0
gpioset gpiochip0 32=1
gpioget gpiochip0 34
1

Please refer to the platform-specific section for more details on each platform.

Pin Header

The boards have the pin header. Some follow Raspberry Pi HAT configuration and some don’t. Please refer to the platform-specific section for more details.