Here described step of development imx6 gpio configuration and control web interface using OpenWrt driven IMX6ULL SoM.
As a result following web interface will be implemented:
MR that implements this functionaly may be found here.
If you don’t have time to read article and just want to get such UI control interface – just clone or download that repository and compile it using single command:
First step to add support for new hardware is DTS modification. As GPIO is probably the easiest hardware to add support for each pad you want to use as GPIO require just one single line to be added in DTS:
Pads naming is following:
as each PAD of CPU might be configured for usage with different functionality. Resulted file might be found here.
That’s it. The rest of development process to be done on application layer.
Manual GPIO configuration and control.
Let’s compile image with modified DTS:
copy it to the device:
and update firmware:
GPIO configuration at user space is pretty simple. First you have to export GPIO. For example:
The number of each GPIO might be gotten by simple calculation. First you have to look at schematic. Each pin of IMX6 SoM marked with set of available interfaces current pad might be configured for. GPIO as well.
Let’s suppose we want to use NAND_CE1 as general purpoce input/output routed to header P7 of development board. That PAD number 14 is part of controller number 4.
So to get PAD number you can use at user space you have to subtract 1 from PAD controller number ( 4-1 = 3, numbering starts from zero), multiple resulted value to 32 (3 * 32 = 96) as each PAD controller contains up to 32 pins (some pads from this 32 pin might be missed). And finally to get resulted value you have to add pad number from it’s name (96 + 14 = 110). E.g. formula is following:
So now we know PAD number to export it:
then you have to set GPIO direction. To use pad as output to drive for example LEDs, relays, to generate output signals:
or as input to control value of buttons, catch input signals:
To set value of output GPIO:
To read value of input GPIO:
List of already used pins might be found at:
Except bash commands there are other gpio configuration/control methods exists. One of them – writing C application explained in this chapter. Another one – using web interface will be explained in next chapter. We will pack that application as package. Source code might be found here. Package contains: Makefile and source code files (files folder better to be placed in luci-gpio package so ignore it for now). Usage of gpio_conf.json will be explained later.
C application itself is pretty simple:
No need to recompile whole image to test it on hardware. Compile package only:
resulted binary might be found here:
copy executable file gpio via scp and run it.
Next method to control GPIO is using web interface. Gives highest flexibility.
Similar to C application it will be packed in package. We will use existing OpenWrt web interface called LuCi. You probably seen it in your home router. IMX6 will act as backend for users accessing web interface from browser. Makefile is pretty simple. Source code will have just two files: gpio.lua – lua script that might be considered as Backend part of solution. It is responsible for handling queries from Frontend.
Each luci module must have function called index that responsible for registration new module of web interface with its API – list of supported URLs that current module to be handle:
Two endpoints gpio_configuration_get and gpio_configuration_set to configure GPIOs.
You can recompile whole image and update firmware of target machine but to speed up development process (delivery of code changes) you better to develop SW right on target machine.
- create gpio.lua in /usr/lib/lua/luci/controller folder. It will be Backend part of solution:
- create gpio.htm in /usr/lib/lua/luci/view folder. It will be Frontend part of solution:
- create switch.css in /www/luci-static/resources folder for styling of UI:
You allowed to give any names to this files but make sure that .lua file name is same as module name provided in the body of that file and it is similar to .htm file name.
Then each time you made changes .htm or .css files you have to update web page in your browse to see them.
For changes in .lua file you have to clear cashe files:
Don’t forget to use developer tools of browser:
Here how result looks like:
Join our telegram channel to see more photos and videos.