GPIO Kernel Driver on Yocto - cu-ecen-aeld/yocto-assignments-base GitHub Wiki
Description
This page helps you integrate a GPIO Device Driver using syscalls into your Yocto build and test it out by controlling an LED.
Links to Implementation
- GPIO open source repository
- Forked local repository
- Load script for driver
- Unload script for driver
- Recipe for GPIO driver
Finding the GPIO to Use
The following steps rely on knowing which GPIO you want to use and how the kernel refers to the GPIO. To do this, it may be helpful to probe /sys/kernel/debug/gpio
on target:
The GPIO number used in the following steps is found in the leftmost column; for example, gpio-514
corresponds to GPIO number 514 in the kernel. Once a pin is in use in the kernel, it is assigned a name that is visible here (like RGB_R
on gpio-514
or ID_SDA
on gpio-512
). Pins that already have a name that isn't GPIOx
may have reserved usage or be inaccessible for external connections.
It may be helpful to build a test driver that simply toggles the pin to perform some trial-and-error to determine which pin you want to use. It may be helpful to parameterize a test kernel module to test multiple pins quickly; this can be done with module parameters. Alternatively, depending on the version of the kernel, the sysfs
interface may be supported to manipulate pins:
The above image shows toggling GPIO 517 using the sysfs
interface, which may provide faster testing iteration than writing a test kernel module.
Steps to setup the driver repository
-
Fork from the driver repository from here.
-
See reference commit at https://github.com/Embetronicx/Tutorials/commit/e225a9ef8ba02afbcf4790d57f78fefba5fd86c7 for changes including:
- Adding a load and unload script to load and unload at startup. This could alternatively be placed in your rootfs overlay
- Modifying the build script to align with the makefile.
- Create a recipe linked to the forked repository and build your Yocto image with this recipe.
- See example recipe at here.
Testing GPIO driver on the target
- Load the driver using modprobe.
modprobe aesdgpio.ko
- Check if driver is loaded using lsmod
- Turn the GPIO on/off to control the LED.
echo 1 > /dev/ext_device
echo 0 > /dev/ext_device
A small demonstration of GPIO driver
References
https://embetronicx.com/tutorials/linux/device-drivers/gpio-driver-basic-using-raspberry-pi/