# Configure pin as simple GPIO

**URL:** <https://community.solid-run.com/t/configure-pin-as-simple-gpio/482>\
**Category:** NXP i.MX8M Plus\
**Tags:** iMX8M-plus\
**Created:** [October 12, 2022, 6:12pm UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482 "2022-10-12T18:12:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvd](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mvd](https://community.solid-run.com/u/mvd)\
**Post date:** [October 12, 2022, 6:12pm UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/1 "2022-10-12T18:12:46Z")

</div>

Hello,  
I am using Solidrun Pulse with iMX8M Plus on it. I have built OS based on instructions from this [repository](https://github.com/SolidRun/meta-solidrun-arm-imx8). But I can not get any of the GPIO pins working as simple GPIO pin.

As additional explanation - below as attachment you can find two of many patches which I applied just for the testing purposes but they simply not working. After the building I can find that file `imx8mp-solidrun.dts` in the build directory have been affected by the patches, so there is no doubt that patching gone well but I am still unable toggle the pin, nor to get logical 0 or 1 from it by following [these instructions](https://solidrun.atlassian.net/wiki/spaces/developer/pages/396197889/GPIO+Pins+Control+-+HummingBoard+Pulse+Mate+i.MX8M+Plus+SOM).

So can I get just simple example of the patch which makes any of the mikroBUS pins (preferably UART ones) functional as GPIO input pin?

Thanks.

0011-gpio-example1.patch

```auto
diff --git a/arch/arm/dts/imx8mp-solidrun.dts b/arch/arm/dts/imx8mp-solidrun.dts
index 1725cae6..921dabd2 100644
--- a/arch/arm/dts/imx8mp-solidrun.dts
+++ b/arch/arm/dts/imx8mp-solidrun.dts
@@ -586,4 +586,10 @@
 			MX8MP_IOMUXC_GPIO1_IO02__WDOG1_WDOG_B	0xc6
 		>;
 	};
+
+ pinctrl_button: buttongrp {
+ fsl,pins =
+ <MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26	0x00>,
+ <MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26	0x00>;
+ };
 };

```

0011-gpio-example2.patch

```auto
diff --git a/arch/arm/dts/imx8mp-solidrun.dts b/arch/arm/dts/imx8mp-solidrun.dts
index 1725cae6..c1a7aa9d 100644
--- a/arch/arm/dts/imx8mp-solidrun.dts
+++ b/arch/arm/dts/imx8mp-solidrun.dts
@@ -409,6 +409,8 @@
 			MX8MP_IOMUXC_SAI2_RXD0__GPIO4_IO23	0x19
 			MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24	0x19
 			MX8MP_IOMUXC_UART4_RXD__GPIO5_IO28	0x19
+ MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26 0x146
+ MX8MP_IOMUXC_UART3_TXD__GPIO5_IO27 0x106
 		>;
 	};

```

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [October 13, 2022, 3:56am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/2 "2022-10-13T03:56:35Z")

</div>

The issue is that you have defined those pins in 2 locations. The pin mux driver will then only assign them to one function. If the group that the pins are assigned to is then owned by another driver the kernel will not allow userspace to control them as they are allocated to a driver.

---

<div class="post-metadata">

**Author:** ![mvd](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mvd](https://community.solid-run.com/u/mvd)\
**Post date:** [October 13, 2022, 6:03am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/3 "2022-10-13T06:03:42Z")

</div>

Hi jnettlet,  
thanks for fast response. I haven’t applied both patches in the same time, but beside that - can you send me an example of proper patch how to set `MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26` as GPIO controllable from user space.

Thanks.

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [October 13, 2022, 6:13am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/4 "2022-10-13T06:13:42Z")

</div>

It would be something like this.

```auto
diff --git a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
index 32e43400de96..a928e50c9fc2 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
+++ b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts 
@@ -514,6 +550,7 @@ MX8MP_IOMUXC_HDMI_DDC_SCL__HDMIMIX_HDMI_SCL 0x400001c3
                        MX8MP_IOMUXC_HDMI_DDC_SDA__HDMIMIX_HDMI_SDA 0x400001c3
                        MX8MP_IOMUXC_HDMI_HPD__HDMIMIX_HDMI_HPD 0x40000019
                        MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC 0x40000019
+ MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26 0x19
                >;
        };
 
diff --git a/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi b/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi
index 02aa6e6c3101..882d6ccee931 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi
@@ -516,7 +516,6 @@ pinctrl_uart1: uart1grp {
                fsl,pins = <
                        MX8MP_IOMUXC_UART1_RXD__UART1_DCE_RX 0x140
                        MX8MP_IOMUXC_UART1_TXD__UART1_DCE_TX 0x140
- MX8MP_IOMUXC_UART3_RXD__UART1_DCE_CTS 0x140
                        MX8MP_IOMUXC_UART3_TXD__UART1_DCE_RTS 0x140
                >;
        };

```

And then to expose the pin to sysfs you need to export it with `echo 154 > /sys/class/gpio/export` as per the instructions on [developer.solid-run.com](http://developer.solid-run.com). The gpio can then be controlled in /sys/class/gpio/gpio154

---

<div class="post-metadata">

**Author:** ![mvd](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mvd](https://community.solid-run.com/u/mvd)\
**Post date:** [October 13, 2022, 6:59am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/5 "2022-10-13T06:59:37Z")

</div>

Hmmm, both files are not existing at all.

```auto
RROR: u-boot-imx-2021.04-r0 do_patch: Applying '0011-proposal.patch' failed:
stdout: can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
|index 32e43400de96..a928e50c9fc2 100644
|--- a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
|+++ b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts

```

I was patching totally different file `imx8mp-solidrun.dts.`- the one created [here](https://github.com/SolidRun/meta-solidrun-arm-imx8/blob/hardknott-imx8mp/recipes-bsp/u-boot/u-boot-imx/0002-Add-imx8mp-solidrun-device-tree-to-u-boot.patch). Then later I patch that file.

I can not even find `imx8mp-hummingboard-pulse.dts`. So where that file coming from - I can not find it the `linux-imx` repository. Where I can find it ?

P.S.  
The most similar one which I can see is `linux-imx/arch/arm64/boot/dts/freescale/imx8mq-hummingboard-pulse.dts` - but that is imx8m **q**

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [October 13, 2022, 8:17am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/6 "2022-10-13T08:17:48Z")

</div>

those patches are for the linux kernel. The patched kernel should be in your build/tmp/work directory, which should include the device-tree files for the iMX8MP som and hummingboard.

---

<div class="post-metadata">

**Author:** ![mvd](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mvd](https://community.solid-run.com/u/mvd)\
**Post date:** [October 13, 2022, 8:28am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/7 "2022-10-13T08:28:54Z")

</div>

I don’t get where is the `imx8mp-hummingboard-pulse.dts`. In general - if I want to patch some file it must exist somewhere - in this particular case I want to patch `imx8mp-hummingboard-pulse.dts` but I can not find it - it is not in the build directory. Or can you tell me where I should put the patch which you proposed?

For example the file which I was patching `imx8mp-solidrun.dts` is in `build/tmp/work/imx8mpsolidrun-poky-linux/u-boot-imx/2021.04-r0/git/arch/arm/dts`.

Thanks.

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [October 13, 2022, 8:33am UTC](https://community.solid-run.com/t/configure-pin-as-simple-gpio/482/8 "2022-10-13T08:33:52Z")

</div>

The file does not exist in the meta repository for yocto. We provide a patch series for NXP’s BSP that adds our board support. The device-tree files are created when yocto does the bitbake build for the kernel package. Therefore your will only find the file in your yocto build directory.

I would recommend that you familiarize yourself with the Yocto kernel development process regarding adding your own customization patches. [Yocto Project Linux Kernel Development Manual — The Yocto Project ® 4.0.999 documentation](https://docs.yoctoproject.org/kernel-dev/index.html)
