GPIOlib on Torizon OS 6.7.0

Hello Toradex Community,

Probably a basic question, but I want to create a Torizon OS image based on 6.7.0 that includes GPIO functionality.
I have followed the tutorials on creating a custom image using Torizon-core builder but I am having a hard time finding documentation on how to create a custom .dts file that calls out using the GPIOLIB library.
Essentially I want to merge Torizon OS 6.7.0 and Embedded Toradex Image with the proper pin mapping.
I have the following setup:
Colibri Eval Board with iMXDX8
Im using a linux desktop for dev/image compilation
Thank you

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


To create a custom Torizon OS image with GPIO functionality and proper pin mapping, you need to follow these steps:

  1. Set Up Your Development Environment:

  2. Create a Custom Device Tree:

    • You need to modify the device tree to configure the GPIO pins as required. The device tree source files (.dts) define the hardware configuration, including GPIO pin mappings.
  3. Modify the Device Tree:

    • Locate the device tree source file for your specific module (Colibri iMX8X). You can find the base device tree files in the Toradex GitHub repository or in the TorizonCore Builder workspace.

    • Create a device tree overlay to modify the GPIO configuration. Here is an example of how to create a device tree overlay:

      /dts-v1/;
      /plugin/;
      
      / {
          compatible = "toradex,colibri-imx8x-eval-v3";
      };
      
      &iomuxc {
          pinctrl_gpio: pinctrl_gpio {
              fsl,pins = <
                  MX8QXP_I2C0_SCL_LSIO_GPIO0_IO12 0x06000020
                  MX8QXP_I2C0_SDA_LSIO_GPIO0_IO13 0x06000020
              >;
          };
      };
      
      &gpio0 {
          status = "okay";
      };
      

      This example configures two GPIO pins (GPIO0_IO12 and GPIO0_IO13) on the Colibri iMX8X. Adjust the pin numbers and configurations as needed for your application.

  4. Build the Custom TorizonCore Image:

    • Use TorizonCore Builder to integrate your custom device tree overlay into the TorizonCore image. Here is a basic example of how to do this:

      # Initialize the TorizonCore Builder workspace
      torizoncore-builder init --device colibri-imx8x
      
      # Add your custom device tree overlay
      torizoncore-builder dt checkout
      cp path/to/your/custom-overlay.dts device-trees/overlays/
      torizoncore-builder dt compile
      
      # Bundle the custom device tree into the TorizonCore image
      torizoncore-builder bundle --output-dir custom-torizon-image
      
  5. Deploy the Custom Image:

    • Flash the custom TorizonCore image to your Colibri iMX8X module using Toradex Easy Installer or other suitable methods.
  6. Verify GPIO Functionality:

    • Once the custom image is running on your module, you can use the libgpiod tools to verify the GPIO functionality. For example, you can use gpioset and gpioget to control and read the GPIO pins.

      # List available GPIO chips
      gpiodetect
      
      # Get information about GPIO lines
      gpioinfo gpiochip0
      
      # Set a GPIO line to high
      gpioset gpiochip0 12=1
      
      # Read the value of a GPIO line
      gpioget gpiochip0 12
      

By following these steps, you should be able to create a custom Torizon OS image with the required GPIO functionality and pin mapping for your Colibri iMX8X module. If you encounter any issues or need further assistance, feel free to ask the Toradex Community or refer to the Toradex Developer Center.

Please, also check if these links can help you solve your problem:

Custom device tree apalis imx8.

Where can I find the pin map to define the rest of the pins? Do I use Pinout Designer? Is so, what do I do with the xml output with respect to the .dts?

Greetings @vlad1us,

I’m not sure if I fully follow what you are asking. Let me see if I can try and clarify what you are looking for.

Probably a basic question, but I want to create a Torizon OS image based on 6.7.0 that includes GPIO functionality.

We have a whole article about using GPIO on Torizon OS here: How to Use GPIO on Torizon OS | Toradex Developer Center

Does this not suffice for your needs?

how to create a custom .dts file that calls out using the GPIOLIB library.

What do you mean exactly here “using the GPIOLIB library”? Are you talking about using sysfs for GPIO access, or are you talking about something else?

If you are talking about sysfs, you should know this method of GPIO access has been deprecated in recent kernel versions. It can still work but it’s not recommended anymore.

Essentially I want to merge Torizon OS 6.7.0 and Embedded Toradex Image with the proper pin mapping.

I’m not quite sure what you mean by this either. What do you mean merge these two images with proper pin mapping?

Where can I find the pin map to define the rest of the pins? Do I use Pinout Designer? Is so, what do I do with the xml output with respect to the .dts?

All pin mappings and definitions can be found in the respective datasheet on our website. Unless you are referring to something else.

Best Regards,
Jeremias