This is a kernel module, with DT Overlay, to illustrate usage of GPIO subsystem in Linux kernel.
- Raspberry Pi 3 Model B Rev 1.2
- Arduino UNO
Raspberry Pi OS (32-bit) Lite (2020-08-20 release)
Connect GPIO17 on Raspberry Pi Model B, through proper logic level shifter, to pin 7 on Arduino UNO.
First compile device tree:
dtc -@ -I dts -O dtb -o arduino-gpio.dtbo arduino-gpio.dts
Then move it to /boot/overlays/ folder:
sudo cp arduino-gpio.dtbo /boot/overlays/
After that, add the following lines to /boot/config.txt
dtoverlay=arduino-gpio
Reboot your Raspberry Pi. You may check current device tree after reboot with:
dtc -I fs /proc/device-tree | less
If everything goes well, you should be able to find somethings like this
under gpio@7e200000
nodes:
...
gpio@7e200000 {
...
arduino_gpio_conf {
brcm,pins = < 0x11 >;
phandle = < 0x86 >;
brcm,pull = < 0x01 >;
brcm,function = < 0x01 >;
};
...
...
Also, below root node:
/{
...
arduino_gpio {
gpios = < 0x10 0x11 0x00 >;
compatible = "arduino";
status = "ok";
phandle = < 0x87 >;
pinctrl-0 = < 0x86 >;
pinctrl-names = "default";
};
...
To build the module, simply use make:
make
To check if the module works, connect Arduino UNO with USB, then upload gpio_read.ino to Arduino UNO. Open serial console before install module.
sudo insmod arduino_gpio_module.ko
You will see Raspberry Pi alter GPIO level for 5 times (once per second).
You made my day. Thank you.