Set GPIO pin as low by default

Hi everyone,

I’m trying to set pin #49 (GPIO 119) by default as low. From what I understand, this needs to be done through dts. I wrote the following dts:

/dts-v1/;
/plugin/;

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

/ {
    metadata {
        title = "Set GPIO0_C5 to Low";
        compatible = "radxa,cm3-io", "radxa,cm3-rpi-cm4-io";
        category = "misc";
        exclusive = "GPIO0_C5";
        description = "Set GPIO0_C5 to Low.\nOn Radxa CM3 IO this is pin 5.\nOn Radxa CM3 RPI CM4 IO this is pin 5.";
    };

    fragment@0 {
        target-path = "/";

        __overlay__ {
            gpio0_c5_low: gpio0_c5_low {
                compatible = "gpio-leds";
                gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_LOW>; // Note: GPIO_ACTIVE_LOW to set it to low
                default-state = "off"; // Setting default-state to "off" ensures it starts as low
            };
        };
    };
};

I compiled it and activated it with rsetup. However, when I check the state of the pin with:

sudo cat /sys/kernel/debug/gpio

I always get that the pin is high. Can someone please help me troubleshoot this? I checked dmesg, but there weren’t any error messages. I’m not sure what else to try.

1 Like

For those who are interested, after further investigation, I discovered that it’s not possible to set the default value using the device tree source (DTS). Instead, I was able to achieve this by recompiling U-Boot and setting the values in the U-Boot prompt console.

Hi adm99

I have the same problem. How did you solve it? Please explain it more in detail.

Thx

I’m sorry I haven’t been notified. I managed to do it but I don’t think it’s the best way. As long as I know you should set an ENV_OFFSET and I didn’t.

This is how i did it:
You need to add the following at the end of this file -> https://github.com/radxa-repo/bsp/blob/main/u-boot/.common/kconfig.conf

# Environment commands
#
# CONFIG_CMD_ASKENV is not set
CONFIG_CMD_EXPORTENV=y
CONFIG_CMD_IMPORTENV=y
CONFIG_CMD_EDITENV=y
# CONFIG_CMD_GREPENV is not set
CONFIG_CMD_SAVEENV=y
CONFIG_CMD_ENV_EXISTS=y
# CONFIG_CMD_ENV_CALLBACK is not set

Radxa Debian Image 8

# CONFIG_CMD_ENV_FLAGS is not set
#CONFIG_ENV_IS_IN_FLASH=y
CONFIG_ENV_IS_IN_MMC=y
CONFIG_ENV_IS_NOWHERE=n

Then run bsp, build the image with rbuild and specify the uboot that you just generated.
Once done it you just have to set the values on u-boot prompt, for example like this:

gpio set A21
gpio clear A21
gpio status -a A21

=> setenv set-ioA21 ‘gpio set A21;gpio clear A21’
=> saveenv