Gpiochip and libpiod not working

Hi friends,

I'm new using OpenWrt, and I have encountered some problems trying to manipulate the Gpins.
Notice: I'm a new user of OpenWrt and also Linux embedded system. Coming from microcontrollers programming, all this nonsense to access GPIO is quite odd to me.

I have had access to GPIO pins before using the sysfs system, but because this way have been deprecated, I want to include the my gpio controller using the libgpiod.
I believe I installed all packages and libs needed before building my custom system, but things are not working as expected.

  • First, I don't have any gpio chip on dev/
  • On sys/class/gpio , I can see a gpiochip0 which have info corresponding to my chip, like number of pins, pins description, etc.
    -On usr/bin I can see: gpiodetect, gpiofind, gpioinfo, etc. But using the commands doesn't return anything.
    -Also my custom package who is using gpiod.h, I tried functions like
    gpiod_chip_open("sys/class/gpio/")
    gpiod_chip_open_by_name("gpiochip0")
    etc,
    NO WORKING NEITHER; it's not detecting any gpiochip.

Maybe there is somewhere a manual "Enable" that I am missing, in order of getting visible a gpiochip inside dev/

This is part of my "config.buildinfo"
Screenshot (1627)

My board is atsam5d2, but I also tried with a raspberry pi. No idea what I am doing wrong.

Thanks

https://openwrt.org/docs/techref/hardware/port.gpio

But you also need to have the pin controller initialized in the dts file.

Personally I also think PIC microcontrollers have easier IO handling than OS based hardware.

Hi Imi,

have you solved your issue? I have it too.
I'm building Openwrt 22.03.5 for LinkIt Smart 7688. Using gpiodetect I have no result, there aren't chips on dev/ and old approach (sys/class/gpio etc.) doesn't work.

I have just to configure a custom reset button and this is driving me crazy.
Last but not least, I've changed gpio pin to default reset button, it is configured well but doesn't work.

I suspect that gpis-controller is not configured in dts file

@freespirit
I was lucky that we changed board and on the new one, I didn't have this problem; libgpiod was ok.
But, as "flygarn12" mentioned, it's probably something off with the DTS file or drivers. I've found that sometimes Openwrt Linux kernel doesn't have the lattes board files from certain vendors. For example , for Microchip MPUs, some dts, dtsi and some drivers doesn't match the one you find on the Microchip repo. Therefore, you will need to make changes by yourself. Try to get a .dts files from your vendor and compare it to the one inside your build_dir.

Thanks for your feedback. I made several tests and my suspicions are more and more confirmed, I think the gpio-controllers are not well configured

Hi all, any updates on this? I'm completely new to openWRT and just want to see if I can toggle some GPIOs on the HLK-7628N which has support on 22.03.5. The old approach using /sys/class/gpio lists 3 different GPIO chips, but none of them actually work to toggle GPIOs when I try to, but I guess that's expected. gpiod-tools installs fine, but I see no chips available on /dev/

I'm using the firmware that is mentioned on the page for my router [OpenWrt Wiki] Techdata: Hi-Link HLK-7628N, but don't really know where to go from there. Do I have to get the source code for the commit mentioned on that page and edit something and then build the firmware myself?

i2c works. Add packages: kmod-i2c-mt7628, i2c-tools
Then, using an expander (e.g. cjmcu 2317) you can control the GPIO.
Once connected, look here: https://openwrt.org/docs/guide-user/hardware/usb.i2c-tiny-usb