Libgpiod on toradex imx7d

Dear All,

I followed OpenEmbedded Core and generated a console-tdx-image.

Then I tried doing the GPIO on Colibri Aster Board (Basic GPIO usage - Iris Carrier Board - Colibri iMX7) where I was able write on gpio pins but not able to read using the sysfs interface. I used the following pins for in out.

Connector       SODIMM      ImxBallName     Linux Pin No 32*(Cnt-1) + GPIO NUM
X17.3 GPIO      45          GPIO1_IO01      1
X17.4 GPIO      67          GPIO1_IO11      11
LED4                104         GPIO2_IO27      59

X20.12          59          GPIO1_IO02           8
X20.12          135        GPIO1_IO02           2 

But none of the pins I was able to read correctly.

  • What has to be done in to successfully read gpios, please provide detailed steps as no clear information i could find on the community posts.

Then I read that sysfs was deprecated. Now I wish to using libgpiod on the build image. I can see /dev/gpiochip interfaces but libgpiod commands are not available.

  • I want to know how can libgpiod be used/integrated in the linux image so i can use it to read write gpios.

Regards
Kashyap

Dear @gada.kashyap,

As you have already noticed, sysfs have been deprecated and from BSP 3.0 onwards, we support libgpiod in order to be aligned with the Linux kernel community.

As stated in this link, BSP 3.0 supports libgpiod. But the user space tools and libraries are not already included in the Demo image available in the Toradex Easy Installer, so one might have to do a custom Yocto build to add them. This could be why you don’t see libgpiod commands being available.

For further information, please kindly refer to the following developer articles:
https://developer.toradex.com/knowledge-base/libgpiod#1---apalis-imx6--colibri-imx6imx7
https://developer.toradex.com/knowledge-base/gpio-(linux)#Embedded_Linux_BSP_30_Onwards

Hope this answer helps.

Best Regards,
Janani.

Dear Janani,

As per your reply -

But the user space tools and libraries
are not already included in the Demo
image available in the Toradex Easy
Installer, so one might have to do a
custom Yocto build to add them.

I wish to know, how the user space tools and libraries can be added to the yocto build.
I found out the libgpiod package is located in meta-oe layer (https://layers.openembedded.org/layerindex/recipe/66918/)
I want to know what modifications I need to make in yocto build directory so that this library becomes available in the image I build using bitbake.

Regards

Dear @gada.kashyap ,

I have just done the following and it works for me. I just bit baked the available libgpiod package and installed the .ipk onto my image. And I was readily able to use the libgpiod commands.

Could you tell me what exact image and version you use? And also can you please tell me if you had made any changes to the device tree?

Regards,
Janani

Embedded Linux 3.0 on Aster + Colibri iMX7

No changes made to Device Tree.

Dear @saijanani.tx ,

i have kind of a similar problem.

I started experimenting with my iMX7 two days ago and thanks to the great tutorials on the wibside i already bitbaked my own OpenEmbedded console-tdx-image image.

My setup:

Colibri iMX7D512MB with Colibri Evaluation Board V3.2B

Linux colibri-imx7 4.14.170-3.0.4+gbaa6c24240a4 #1 SMP Wed Jun 3 12:37:49 UTC 2020 armv7l GNU/Linux

I added the libgpiod and libgpiod-tools packages to the build.

I connected the following Pins on the Eval Board:

LED1 to X22Pin08 (GPIO4.17; SODIMMPin103)
LED2 to X22Pin10 (GPIO4.19; SODIMMPin097)
LED3 to X22Pin12 (GPIO4.21; SODIMMPin059)
LED4 to X22Pin14 (GPIO4.23; SODIMMPin065)
SW1 to X22Pin07 (GPIO4.16; SODIMMPin101)
SW2 to X22Pin09 (GPIO4.18; SODIMMPin079)
SW3 to X22Pin11 (GPIO4.20; SODIMMPin067)
SW4 to X22Pin13 (GPIO4.22; SODIMMPin085)

To keep it simple i want to read the input from SW1 and i want to set the output to LED1.
I can now use the command line tools (gpioinfo, gpioset, gpioget).

gpioget 4 16 always returns 0 independent of the state of the Switch.

gpioset 4 17=0 or gpioset 4 17=1 cant light the LED.

gpioinfo shows:

gpiochip4 - 32 lines:
    line  16:      unnamed       unused   input  active-high
    line  17:      unnamed       unused  output  active-high
    line  18:      unnamed       unused   input  active-high
    line  19:      unnamed       unused  output  active-high
    line  20:      unnamed       unused   input  active-high
    line  21:      unnamed       unused  output  active-high
    line  22:      unnamed       unused   input  active-high
    line  23:      unnamed       unused  output  active-high

Which simple step did i missed?

Best Regards,
Florian

Dear @marcel.tx

thanks for this fast answer.

I will try to create a custom device tree for my gpio test.

Best Regards,
Florian

Dear @gada.kashyap ,

The openembedded packages libgpiod and libgpiod-tools packages are deployed starting with the 3.0b3 image. Could you therefore also tell the exact version you use? Probably the output of uname -a?

And can you specify what exact Device tree are you using?

Best Regards,
Janani

https://developer.toradex.com/device-tree-customization#pinmux-imx7

You are welcome. Please let us know if you have any other question.

Best regards,
Jaski

It took me some time but i finally managed to set my LED1 and read SW1.

There is an alias in the device tree that maps all GPIO4.XX to GPIO3.

Because of that, you have to set GPIO4.17 with gpioset 3 17=1.

Best regards,
Florian

Perfect that the issue is solved.

Thanks for the feedback.

Best regards,
Jaski

Happy New Year,

Same topic, new problem.

I switched to BSP 5.0 for my colibri imx7 and now i am using a slightly modified tdx-reference-minimal-image. I added some packages to “conf/local.conf”:

IMAGE_INSTALL_append = " python3 python3-dev libgpiod"

I also compiled my own device tree with a different pinconfig.

I can now read and write GPIO Pins over the userspace tools provided by libgpiod.

I can’t use the libgpiod API in Python because it is not provided by default.

Like mentioned here i have to add the PACKAGECONFIG option “python3” to the libgpiod package. I tried to follow the steps on the yoctoproject mega-manual and tried the following:

I created the file “/layers/meta-openembedded/meta-oe/recipes-support/libgpiod/libgpiod_1.4.3.bbappend”:

PACKAGECONFIG_append = " python3"

I also tried to add the following line to “conf/local.conf”:

PACKAGECONFIG_append_libgpiod = " python3"

Both of those did not work.

Can you please help me to get the libgpiod API working with python.

Best regards, Florian

Dear @Florian ,

Happy New Year to you too as well.

Have you perhaps checked all the dependencies associated? https://packages.debian.org/unstable/python3-libgpiod

Dear @saijanani.tx,

Thanks for the answer.

I managed to get the libgpiod-python-API working.

The problem was that i am still new to the yocto project. I assumed that bitbake would automatically add the missing package “libgpiod-python” to the image, if the PACKAGECONFIG option “python3” was set for the libgpiod package. Of course you have to add the package manually after setting the PACKAGECONFIG variable.

To add the libgpiod-python-API you have to add the following variables to the “conf/local.conf” file:

PACKAGECONFIG_append_pn-libgpiod = " python3"
IMAGE_INSTALL_append = " python3 libgpiod libgpiod-python"

That took me way too long to figure out, but at least i learned a lot.

Best regards, Florian

Dear @Florian ,

Thank you for the feedback and I am glad it is working now

Best Regards,
Janani