This guide will show you how to control the mikroBUS GPIOs, SPI, I2C, and UART from the RZ/G2LC HummingBoard Linux userspace.
Here is a microBUS connector pinout:
Choosing the pin function
According to the SOC specification, most of the pins can be used as GPIO or as alternative function pins.
The pin P45_2 can be used as GPIO.
The pins P44_3, P44_0, P44_2, and P44_1 can be used as GPIOs by default. Enable the
spi1
node in the devise tree to use them as SPI.The pins P41_0, P41_1, P40_0, and P40_0 are used as uart ttySC1 by default. Disable the
scif1
node in the devise tree to use them as GPIOs.I2C0_SCL and I2C0_SDA can’t be used as GPIOs, only as I2C pins.
GPIO
To use GPIO in Linux, either gpiod or sysfs can be used.
Both methods need the GPIO number that Linux assigned during the enumeration. This number is dynamically assigned to the GPIO based on the number of pins, GPIO controllers, etc. Usually, this number is stable, but it might change during the BSP updates and sometimes even during reboots. The gpioinfo utility gives us information about the number of the GPIO we need to use according to its label:
$ gpioinfo | grep P45_2 line 362: "P45_2" unused input active-high
In this example, the GPIO P45_2 has the number 362.
Setting GPIO using gpiod:
gpioset -m wait gpiochip0 362=1
Note: after exit, the gpioset utility will reset GPIO to its default state (input hi-z); for more info, read about gpioset modes.
Setting GPIO using sysfs:
The export number of the GPIO can be calculated as the GPIO controller base plus the GPIO number.
$ ls /sys/class/gpio/ export gpiochip120 unexport
The GPIO controller base is 120, and the GPIO number is 362.
The export number is 120 + 362 = 482
echo 482 > /sys/class/gpio/export echo out > /sys/class/gpio/P45_2/direction echo 1 > /sys/class/gpio/P45_2/value
UART
UART is available in Linux as a standard serial device /dev/ttySC1.
To use it, you can use the default utilities:
stty -F /dev/ttySC1 9600 echo "test string" > /dev/ttySC1
You also can use picocom, minicom, screen, etc.
I2C
The I2C0_SCL and I2C0_SDA pins can be utilized as an I2C0 connection and are available via /dev/i2c-0.
New devices can be detected via the i2cdetect utility:
$ i2cdetect -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- UU -- -- -- UU UU -- UU 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: UU -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Note: The I2C0 bus is used for many devices on the board. Be careful connecting to this pin something that can fault the I2C bus.
Options to control the device:
i2c-tools utilities
Add device to i2c0 node in the dts
Also possible that the kernel will bind the driver automatically during the i2c bus scan
SPI
SPI pins of the mikroBUS connector connected to the SPI1 interface of the SOC. To use them, configure the spi1
node in the dts first.
The spi1
node can be configured as a specific or dummy SPI device, depending on the task.
Here is an example of the dummy device configuration:
&spi1 { status = "okay"; spidev@0 { compatible = "spidev"; reg = <0>; spi-max-frequency = <500000>; }; };
After this configuration, the SPI would be accessible via the /dev/spidev0.0 device and can be used with the spidev_test utility.
To fully use SPI, replace the spidev node with a specific device node and use a particular driver.