Drive IO during boot process on colibri imx8x

Hi,

i have basically the same problem as the Thread Starter in this one: Drive IO during boot process
As i’m on an imx8 and don’t want to take over the discussion I decided to start this new Thread.

Background: We are replacing Colibri T20 Modules with the imx8 modules and don’t have the option to redesign our carrier board. And the gpio that I need to setup as early as possible is connected to a (very loud) beeper. And in the default state, the imx8 drives the beeper. So, setting the port to output low in my application is not an option, as it takes too long to get to this point.

I tried the gpio-hog (mentioned in the other Thread) and it works, but, as I want to use the gpio in my application and, as far as I know, with using the gpio-hog this is not possible.

My other Idea was to configure the pin in the Device-Tree, which also did not work. I expected the internal pull-down configured via the pad settings to hold SODIMM 79 low. Measuring the level, it still was not low.

&iomuxc {
	pinctrl_hog0: hog0grp {
		fsl,pins = .....
			   <IMX8QXP_SAI0_TXC_LSIO_GPIO0_IO26			0x06000020>,		/* SODIMM  79 */

		.....
	};
};

SODIMM 79 is the Port in question, and I used many different values instead of 0x06000020. To calculate these values, I read the “i.MX 8DualX/8DualXPlus/8QuadXPlus Applications Processor Reference Manual, Rev. 0, 05/2020” from NXP (Section “pad/mux control for SAI0_TXC”).

So, I think I need another approach. From my perspective, setting the port in uboot would be the best in my use case.

My Questions are:

  • Did I miss something/did something wrong in my first two tries (gpio-hog and pinctrl)
  • Do I have any alternatives to the uboot approach? If so, what are they?
  • Where can I find a general documentation about modifying uboot for my imx8 board
  • Where can I find detailed information about setting the gpio-ports in uboot.

Best regards,

Stefan

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


I can help with GPIO configuration during boot on your Colibri iMX8X. However, to provide the most accurate guidance, could you specify which OS and version you are running? Common platforms include:

Hardware: Colibri iMX8X with various carrier boards
OS Options: Torizon OS (6.x, 7.x), Yocto BSP (6.x, 7.x)

You can get this information using the tdx-info command - more details at Getting Device Information with Tdx-Info | Toradex Developer Center

Initial Analysis

Your approach with device tree configuration should work. For GPIO control during early boot, you have several options:

1. GPIO Hog with Application Access

Regarding your concern about using gpio-hog preventing application access - this isn’t necessarily true(1). You can configure a GPIO hog for initial state and still access it from userspace applications using libgpiod(1).

2. Device Tree Overlay Approach

For device tree configuration, you’ll want to create a proper overlay that both configures the pin and assigns it to the GPIO controller(2). The pad configuration alone may not be sufficient.

3. U-Boot GPIO Configuration

U-Boot does provide GPIO control capabilities(1). The GPIO driver has a command-line interface that can set and get GPIO values, though the pin must be muxed to GPIO functionality in U-Boot code(1).

To calculate the U-Boot pin number, use this formula(1):

pin = 32 * GPIO_BANK + GPIO_LINE

For example, GPIO3_10 would be: pin = 32 * 3 + 10 = 106(1)

Next Steps

Once you provide your OS version, I can give you specific implementation details for:

  • Proper device tree overlay syntax for your platform
  • GPIO hog configuration that allows application access
  • U-Boot modification procedures if needed

The solution will depend on whether you’re using Torizon OS or Yocto BSP, as the implementation methods differ between platforms.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

@ToradexAI
I use TorizonOS 7.5.0+build.30.
Yes, please give me implementation details.

After your answer, I tried the gpio-hog again. With this DeviceTree Overlay:

&iomuxc {
pinctrl_hog0: hog0grp {
fsl,pins = <IMX8QXP_CSI_D07_CI_PI_D09				0x61>,		/* SODIMM  65 /
<IMX8QXP_QSPI0A_DATA2_LSIO_GPIO3_IO11		0x20>,		/ SODIMM  69 /
<IMX8QXP_SAI0_TXC_LSIO_GPIO0_IO26			0x40>,	/ SODIMM  79 /
<IMX8QXP_ENET0_RGMII_RXC_LSIO_GPIO5_IO03		0x06000020>,	/ SODIMM  85 /
<IMX8QXP_CSI_D06_CI_PI_D08				0x61>,		/ SODIMM  85 /
<IMX8QXP_QSPI0B_SCLK_LSIO_GPIO3_IO17			0x20>,		/ SODIMM  95 /
<IMX8QXP_SAI0_RXD_LSIO_GPIO0_IO27			0x20>,		/ SODIMM  97 /
<IMX8QXP_CSI_D03_CI_PI_D05				0x61>,		/ SODIMM  97 /
<IMX8QXP_QSPI0B_DATA0_LSIO_GPIO3_IO18		0x20>,		/ SODIMM  99 /
<IMX8QXP_SAI0_TXFS_LSIO_GPIO0_IO28			0x20>,		/ SODIMM 101 /
<IMX8QXP_CSI_D00_CI_PI_D02				0x61>,		/ SODIMM 101 /
<IMX8QXP_SAI0_TXD_LSIO_GPIO0_IO25			0x20>,		/ SODIMM 103 /
<IMX8QXP_CSI_D01_CI_PI_D03				0x61>,		/ SODIMM 103 /
<IMX8QXP_QSPI0B_DATA1_LSIO_GPIO3_IO19		0x20>,		/ SODIMM 105 /
<IMX8QXP_USB_SS3_TC2_LSIO_GPIO4_IO05			0x20>,		/ SODIMM 127 /
<IMX8QXP_USB_SS3_TC3_LSIO_GPIO4_IO06			0x20>,		/ SODIMM 131 /
<IMX8QXP_USB_SS3_TC1_LSIO_GPIO4_IO04			0x20>,		/ SODIMM 133 /
<IMX8QXP_CSI_PCLK_LSIO_GPIO3_IO00			0x20>,		/ SODIMM  96 /
<IMX8QXP_QSPI0B_DATA3_LSIO_GPIO3_IO21		0x20>,		/ SODIMM  98 /
<IMX8QXP_SAI1_RXFS_LSIO_GPIO0_IO31			0x20>,		/ SODIMM 100 /
<IMX8QXP_QSPI0B_DQS_LSIO_GPIO3_IO22			0x20>,		/ SODIMM 102 /
<IMX8QXP_QSPI0B_SS0_B_LSIO_GPIO3_IO23		0x20>;		/ SODIMM 104 */
};
};

&lsio_gpio0 {
gpio-line-names = “”,
“SODIMM_70”,
“SODIMM_60”,
“SODIMM_58”,
“SODIMM_78”,
“SODIMM_72”,
“SODIMM_80”,
“SODIMM_46”,
“SODIMM_62”,
“SODIMM_48”,
“SODIMM_74”,
“SODIMM_50”,
“SODIMM_52”,
“SODIMM_54”,
“SODIMM_66”,
“SODIMM_64”,
“SODIMM_68”,
“”,
“”,
“SODIMM_82”,
“SODIMM_56”,
“SODIMM_28”,
“SODIMM_30”,
“”,
“SODIMM_61”,
“SODIMM_103”,
“SODIMM_79”,
“”,
“SODIMM_101”,
“SODIMM_25”,
“SODIMM_27”,
“SODIMM_100”;

sodimm79-hog {
    gpio-hog;
    gpios = <26 GPIO_ACTIVE_HIGH>;
    output-low;
    line-name = "SODIMM_79";
};		  

};

I get this Exception in my C# Code:

System.IO.IOException: Error setting pin mode, for pin: 26, error: 16 (Device or resource busy)
at System.Device.Gpio.Drivers.LibGpiodDriver.SetPinMode(Int32 pinNumber, PinMode mode)
at System.Device.Gpio.GpioController.SetPinMode(Int32 pinNumber, PinMode mode)
at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber, PinMode mode)
at Mft.Core.Hardware.MftHardwareActuators.Summer(SummerState state) in /home/torizon/STS/repos/MFT/src/Mft.Core/Hardware/MftHardwareActuators.cs:line 70
at Mft.App.Controllers.HardwareController.Summer(SummerRequest request) in /home/torizon/STS/repos/MFT/src/Mft.App/Controllers/HardwareController.cs:line 71
at lambda_method849(Closure, Object, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
— End of stack trace from previous location —
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
— End of stack trace from previous location —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
— End of stack trace from previous location —
2
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)

Perfect! Now I can provide specific implementation details for Torizon OS 7.5.0.

The Issue: GPIO Hog vs Application Access

The error you’re seeing is exactly what you suspected - when a GPIO is hogged, it becomes “busy” and cannot be opened by your application(1). The “Device or resource busy” error (errno 16) confirms this.

Solution 1: Device Tree Overlay for Early GPIO Configuration (Recommended)

For Torizon OS, the best approach is to create a proper device tree overlay that configures the GPIO without hogging it. Here’s how to implement this:

Create the Device Tree Overlay

Create a file called colibri-imx8x-gpio79-overlay.dts:

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>

/ {
    compatible = "toradex,colibri-imx8x";
};

&iomuxc {
    pinctrl_sodimm_79_gpio: sodimm_79_gpio_grp {
        fsl,pins = <
            IMX8QXP_SAI0_TXC_LSIO_GPIO0_IO26 0x06000020  /* SODIMM 79 */
        >;
    };
};

&lsio_gpio0 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_sodimm_79_gpio>;
    
    gpio-line-names = "",
        "SODIMM_70",
        "SODIMM_60", 
        "SODIMM_58",
        "SODIMM_78",
        "SODIMM_72",
        "SODIMM_80",
        "SODIMM_46",
        "SODIMM_62",
        "SODIMM_48",
        "SODIMM_74",
        "SODIMM_50",
        "SODIMM_52",
        "SODIMM_54",
        "SODIMM_66",
        "SODIMM_64",
        "SODIMM_68",
        "",
        "",
        "SODIMM_82",
        "SODIMM_56",
        "SODIMM_28",
        "SODIMM_30",
        "",
        "SODIMM_61",
        "SODIMM_103",
        "SODIMM_79",
        "",
        "SODIMM_101",
        "SODIMM_25",
        "SODIMM_27",
        "SODIMM_100";
};

Deploy with TorizonCore Builder

  1. Create a tcbuild.yaml configuration file(2):
input:
  easy-installer:
    local: torizon-os-colibri-imx8x-Tezi_7.5.0+build.30

customization:
  device-tree:
    include-dirs:
      - linux/include
      - linux/arch/arm64/boot/dts/freescale
    custom: linux/arch/arm64/boot/dts/freescale/imx8qxp-colibri-eval-v3.dts
    add:
      - /overlays/colibri-imx8x-gpio79-overlay.dts

output:
  easy-installer:
    local: custom-torizon-os-colibri-imx8x
    name: Torizon OS - GPIO79 Early Config
  1. Build and deploy the custom image(2).

Solution 2: Application-Level Early Initialization

If you need the GPIO to be low immediately when your application starts, configure it in your C# application’s startup code:

// Early in your application startup
using var controller = new GpioController();
controller.OpenPin(26, PinMode.Output);
controller.Write(26, PinValue.Low);

Solution 3: U-Boot Approach (Advanced)

For the earliest possible control, you can modify U-Boot. For Colibri iMX8X, you would need to(1):

  1. Calculate the U-Boot GPIO number: For GPIO0_26, this would be 32 * 0 + 26 = 26(1)
  2. Modify the board file to set the GPIO during board_init(1)
  3. Use U-Boot GPIO commands: gpio set 26 or gpio clear 26(1)

However, this requires custom U-Boot compilation and is more complex than the device tree approach.

Testing Your GPIO

Once you’ve deployed the overlay, test the GPIO using libgpiod tools(3):

# Find your GPIO
gpiofind SODIMM_79

# Set it low
gpioset 0 26=0

# Set it high  
gpioset 0 26=1

Key Points

  1. Remove the gpio-hog from your overlay - this prevents application access(1)
  2. Use proper pinctrl configuration to ensure the pin is muxed to GPIO function early in boot(2)
  3. Configure pull-down in pad settings (0x06000020) to ensure the pin defaults low(2)
  4. Your application can then control the GPIO normally using the .NET GPIO APIs(3)

The pad configuration value 0x06000020 you’re using should provide a pull-down, which combined with the early pinctrl configuration should keep your beeper quiet during boot.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Hello @StefanStolz,

My suggestion here would be to setup the pin with an internal pull-down.
I understand that you tried this, but it is worth revisiting this so we can understand why that did not work.

My main suspect is that the pinctrl node was defined but not used in any other node.
In such case, the configuration would not have applied.
Could you confirm what was the configuration you had on your device tree?

Another possible cause is the carrier board, does it have a pull-up resistor for SODIMM_79?

Best Regards,
Bruno

Hello @bruno.tx ,

you were right. Thank you :slight_smile:

My Configuration was not applied and therefore not used.

Maybe this helps others:

I used this lines in my Overlay-File:

&iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_lvds_converter>, <&pinctrl_gpio_iris>, <&pinctrl_my_hog0>;

	pinctrl_my_hog0: my_hog0grp {
		fsl,pins = <IMX8QXP_SAI0_TXC_LSIO_GPIO0_IO26  0x20000040>;
	};
};

The Value (0x20000040) is calculated by the Documentation from NXP - “i.MX 8DualX/8DualXPlus/8QuadXPlus Applications Processor Reference Manual, Rev. 0, 05/2020”

Best Regards,

Stefan

Thanks for the update and for sharing your configuration.

Best Regards,

Bruno