Remap pin from uart1 to general purpose GPIO

Hi Toradex team,

Hope you can help me with this, I have created a overlay with the main objective to repurpose the pin 19 of the Mallow board to be used as GPIO. This pin is used by the RTS of UART1. My main goal was to still use the RX/TX of UART1 but disable the RTS and CTS.

My overlay is as follow:

/dts-v1/;
/plugin/;

#include "imx8mp-verdin.dtsi"
#include "imx8mp-verdin-mallow.dtsi"

/ {
    compatible = "toradex,verdin-imx8mp";
};

&uart1 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_uart1_nortscts>;  /* Only TX/RX, no RTS/CTS */
};

&iomuxc {    
    pinctrl_uart1_nortscts: uart1_nortscts {
        fsl,pins =
            <MX8MP_IOMUXC_UART1_RXD__UART1_DCE_RX		0x1c4>,	/* SODIMM 129 */
			<MX8MP_IOMUXC_UART1_TXD__UART1_DCE_TX		0x1c4>;	/* SODIMM 131 */
    };

    /* 0x1c4: Commonly used for GPIO pins with pull-up enabled, medium drive strength, and hysteresis enabled. */
    /* 0x106: Commonly used for GPIO pins with no pull, low drive strength, and hysteresis enabled. */
    /* 0x146: output */
    pinctrl_pinpad: pinpad_ctrl_grp {
        fsl,pins =
            <MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24		0x146>;  /* SODIMM 133 */
    };
};

&gpio4 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_pinpad>; 
    status = "okay";
};

The overlay is being loaded to the board but when using the lib gpiod to set the pin and check its status nothing happen…

Do you have any suggestion, i’m on the correct path?
Appreciate any help you can provide. Thanks in advance

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.148-6.8.0+git.8c5c2dcbf6ba #1-TorizonCore SMP PREEMPT Tue Aug 6 10:01:59 UTC 2024
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.0/torizon/4ba8fb87dbcbe4eef169c350696ae1ce34e2585cf534963f9395709a06466082/0
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.8.0-build.22
Distro variant:           VARIANT="Docker"
Hostname:                 verdin-imx8mp-15459446
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Verdin iMX8M Plus on Verdin Development Board
Toradex version:          0063 V1.1B
Serial number:            15459446
Processor arch:           aarch64
------------------------------------------------------------

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

Did you like my answer?

:+1: :-1:


Hello!

To remap the UART1 pins to GPIO on your Verdin iMX8M Plus, please follow these steps:

  1. Disable the Existing UART1 Node:

    First, you need to disable the current UART1 node in your device tree:

    &uart1 {
        status = "disabled";
    };
    
  2. Create a New UART1 Node Without RTS/CTS:

    Next, define a new UART1 node that excludes the RTS/CTS functionality:

    &aips3 {
        uart1-custom: serial@30860000 {
            compatible = "fsl,imx8mp-uart", "fsl,imx6q-uart";
            reg = <0x30860000 0x10000>;
            interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
            clocks = <&clk IMX8MP_CLK_UART1_ROOT>,
                     <&clk IMX8MP_CLK_UART1_ROOT>;
            clock-names = "ipg", "per";
            dmas = <&sdma1 22 4 0>, <&sdma1 23 4 0>;
            dma-names = "rx", "tx";
            pinctrl-names = "default";
            pinctrl-0 = <&pinctrl_uart1>;
            status = "okay";
        };
    };
    
  3. Configure the UART Pins You Want to Keep:

    Specify the UART pins you wish to retain:

    &pinctrl_uart1 {
        fsl,pins =
            <MX8MP_IOMUXC_UART1_RXD__UART1_DCE_RX     0x1c4>,
            <MX8MP_IOMUXC_UART1_TXD__UART1_DCE_TX     0x1c4>;
    };
    
  4. Add GPIO Configuration for Former RTS/CTS Pins:

    Finally, configure the former RTS/CTS pins as GPIOs:

    &iomuxc {
        pinctrl_my_gpio: mygpiogrp {
            fsl,pins = <
                MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24 0x1c4
            >;
        };
    };
    
    &gpio4 {
        gpio4_io24: gpio4_io24_output {
            gpio-hog;
            gpios = <24 GPIO_ACTIVE_HIGH>;
            output-high;
            line-name = "gpio4_io24_output";
            status = "okay";
        };
    };
    

These steps will help you successfully remap the UART1 pins to GPIO. Remember to ensure that the original UART1 node is completely disabled and that your overlay does not include full DTSI files.

If you have any further questions, feel free to ask!

Best regards,
Toradex AI Assistant

Ok, Thanks for the help.

Final working dts with control handled on the user space:

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/clock/imx8mp-clock.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include "imx8mp-pinfunc.h"

/ {
    compatible = "toradex,verdin-imx8mp";
};

&uart1 {
    status = "disabled";
};

&aips3 {
    uart1_custom: serial@30860000 {
        compatible = "fsl,imx8mp-uart", "fsl,imx6q-uart";
        reg = <0x30860000 0x10000>;
        interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
        clocks = <&clk IMX8MP_CLK_UART1_ROOT>,
                 <&clk IMX8MP_CLK_UART1_ROOT>;
        clock-names = "ipg", "per";
        dmas = <&sdma1 22 4 0>, <&sdma1 23 4 0>;
        dma-names = "rx", "tx";
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_uart1>;
        status = "okay";
    };
};

&iomuxc {

    pinctrl_uart1: uart1grp  {
        fsl,pins =
            <MX8MP_IOMUXC_UART1_RXD__UART1_DCE_RX     0x1c4>,
            <MX8MP_IOMUXC_UART1_TXD__UART1_DCE_TX     0x1c4>;
    };

    pinctrl_pinpad_gpio: pinpadgpiogrp {
        fsl,pins = <
            MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24 0x1c4
        >;
    };
};

Dear @af-silva,

Thank you for sharing your solution and I am glad you got it working.

Best regards,
Collin