Torizon GPIO and libgpiod

I’m using Colibri IMX8x with Torizon image and evaluation container. I created with VSCODE extesion a C++ make program, all works fine until I decided to use libgpiod.

After 2 days I could compile and entry in debug mode, but the output (SODIMM 102) is not energized (I’ve already tried it with Embedded Linux Multimedia image by gpioset etc…on my carrier board) and it works fine.

this my LDFLAGS in the make file

LDFLAGS :=-lpthread -lrt -lgpiod

this is torizonpackages.json project file

{
    "deps": [
        "libgpiod2" 
    ],
    "devDeps": [
        "libgpiod-dev"
    ]
}

this is my program, i know from my test with Linux Embedded that SODIMM_102 is gpiochip4 and line 22, and anyway gpiod_ctxless_find_line call returns always with error (I tried “SODIMM_102” “102” “SODIMM102”)

#include <gpiod.h>
int main(int argc, char* argv[])
{
	int line_value = 0;
	char bank[32];
	unsigned int line;

	/*if (gpiod_ctxless_find_line("SODIMM_102", bank, sizeof(bank), &line) <= 0)
	{
			printf("Error finding GPIO\n");
			return EXIT_FAILURE;
	}*/
	snprintf(bank, sizeof(bank), "gpiochip4");
	line = 22;
	while (1) {
		/* GPIO pin toggle */
		line_value = !line_value;
		gpiod_ctxless_set_value(bank, line,line_value, false,"gpio-toggle",NULL,NULL);
		sleep(1);
		printf("Setting pin to %d\n", line_value);
	}

	return EXIT_SUCCESS;


}

the program run and debug but I have no output, I think there is something wrong with the library.

this my tdx-info

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.129-6.5.0+git.6f8fd49366db #1-TorizonCore SMP PREEMPT Fri Dec 22 11:15:52 UTC 2023
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/7e7d5c182b8db9a981d1f942cee2a808b3535fa86862471d67f718c4959f44df/0
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.5.0-build.8
Distro variant:           VARIANT="Docker"
Hostname:                 colibri-imx8x-06846833
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Colibri iMX8QXP on Colibri Evaluation Board V3
Toradex version:          0051 V1.0D
Serial number:            06846833
Processor arch:           aarch64
------------------------------------------------------------

Greetings @fabrizio.camagna,

Did you remember to include the respective GPIO device into the container so it has access? Once I did this, the application ran as expected. Here’s my docker-compose.yml from my project:

version: "3.9"
services:
  test-debug:
    build:
      context: .
      dockerfile: Dockerfile.debug
    image: ${LOCAL_REGISTRY}:5002/test-debug:${TAG}
    ports:
      - 2230:2230
    devices:
      - "/dev/gpiochip4:/dev/gpiochip4"

  test:
    build:
      context: .
      dockerfile: Dockerfile
    image: ${DOCKER_LOGIN}/test:${TAG}
    devices:
      - "/dev/gpiochip4:/dev/gpiochip4"

Whenever you use some kind of hardware peripheral in your containerized application you must always give your container access to that peripheral in some way. Otherwise your container won’t be able to find or access that peripheral.

Best Regards,
Jeremias

Thank you very much Jeremias, now it works!!

Glad I was able to help!