<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zephyr GPIO trouble</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103677/zephyr-gpio-trouble</link><description>As always the simplest thing in Zephyr is also the most complicated. I have a Laird module (the BL652) that originally used GPIO 0.19 as an LED driver in their device tree. I overlay that use in my device tree to produce an (active low) enable like so</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Sep 2023 23:10:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103677/zephyr-gpio-trouble" /><item><title>RE: Zephyr GPIO trouble</title><link>https://devzone.nordicsemi.com/thread/445711?ContentTypeID=1</link><pubDate>Tue, 12 Sep 2023 23:10:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51d2332a-2d74-47f2-b278-35228750f635</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Bret,&lt;/p&gt;
&lt;p&gt;I found two issues in your code, but neither of which should lead to the result you observe.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In your overlay, you are deleting node &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;led2&lt;/span&gt;, but deleting the alias for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;led1&lt;/span&gt;.
&lt;ol&gt;
&lt;li&gt;This should lead to a build failure, not a run time issue.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;In your function, you are configuring the pin again every time you want to set it.
&lt;ol&gt;
&lt;li&gt;This is unnecessary but should not impact the behavior. I checked.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Other than that, I tried your code, and it just works for me.&lt;/p&gt;
&lt;p&gt;I use the nRF52840 DK, so I changed the pin number to 14. Otherwise, it&amp;#39;s pretty much exactly your code. I deleted node &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;led1&lt;/span&gt; in my test. I am not sure which board you are using. But if you use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;nrf52dk_nrf52832&lt;/span&gt;&amp;nbsp;and want to use P0.19. If so, you will need to delete node &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;led2&lt;/span&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;overlay:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; /delete-node/ &amp;amp;led1; // GPIO 14 repurposed to be vout enable
 /{
	lm5176_control {
		compatible = &amp;quot;gpio-leds&amp;quot;;
		enable1: enable_1 {
			gpios = &amp;lt;&amp;amp;gpio0 14 GPIO_ACTIVE_HIGH&amp;gt;;
			label = &amp;quot;VOUT Enable Low&amp;quot;;
		};
	};
	aliases {
		cmvoutenable = &amp;amp;enable1;
		/delete-property/ led1; // This was GPIO 14
	};
 };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;main.c modified from hello_world:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

#define VOUT_ENABLE DT_ALIAS(cmvoutenable)
static const struct gpio_dt_spec vout_enable = GPIO_DT_SPEC_GET(VOUT_ENABLE, gpios);

typedef uint32_t message_error_t;
#define GPIO_ERROR 1
#define MESSAGE_OK 0

uint32_t init(void)
{
    if (!device_is_ready(vout_enable.port)) {
        printk(&amp;quot;VOUT GPIO enable not ready\n&amp;quot;);
        return GPIO_ERROR;
    } else {
        if( gpio_pin_configure_dt(&amp;amp;vout_enable, GPIO_OUTPUT_ACTIVE) &amp;lt; 0 ) {
            printk(&amp;quot;VOUT GPIO enable cannot be activated\n&amp;quot;);
            return GPIO_ERROR;
        }
    }
	return 0;
}

message_error_t lm5176_vout_set_enable_no_init( bool on )
{
    if ( on ) {
        printk(&amp;quot;Enabling Vout\n&amp;quot;);
    }
    else {
        printk(&amp;quot;Disabling Vout\n&amp;quot;);
    }
    // GPIO logic is reversed from pin function
    if( gpio_pin_set_dt(&amp;amp;vout_enable, on ? 0 : 1 ) &amp;lt; 0 ) {
        printk(&amp;quot;Unable to set Vout enable&amp;quot;);
        return GPIO_ERROR;
    }
    return MESSAGE_OK;
}

message_error_t lm5176_vout_set_enable_with_init( bool on )
{
    if (!device_is_ready(vout_enable.port)) {
        printk(&amp;quot;VOUT GPIO enable not ready\n&amp;quot;);
        return GPIO_ERROR;
    } else {
        if( gpio_pin_configure_dt(&amp;amp;vout_enable, GPIO_OUTPUT_ACTIVE) &amp;lt; 0 ) {
            printk(&amp;quot;VOUT GPIO enable cannot be activated\n&amp;quot;);
            return GPIO_ERROR;
        }
    }
    if ( on ) {
        printk(&amp;quot;Enabling Vout\n&amp;quot;);
    }
    else {
        printk(&amp;quot;Disabling Vout\n&amp;quot;);
    }
    // GPIO logic is reversed from pin function
    if( gpio_pin_set_dt(&amp;amp;vout_enable, on ? 0 : 1 ) &amp;lt; 0 ) {
        printk(&amp;quot;Unable to set Vout enable&amp;quot;);
        return GPIO_ERROR;
    }
    return MESSAGE_OK;
}

#define lm5176_vout_set_enable lm5176_vout_set_enable_with_init

int main(void)
{
	printk(&amp;quot;Hello World! %s\n&amp;quot;, CONFIG_BOARD);
	init();
	while(1)
	{
		lm5176_vout_set_enable(true);
		k_sleep(K_SECONDS(1));
		lm5176_vout_set_enable(false);
		k_sleep(K_SECONDS(1));
	}
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Could you please review your setup, including the hardware, to see if you missed anything?&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>