<?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>I need help getting a GPIO to work from the DTS to the code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/124960/i-need-help-getting-a-gpio-to-work-from-the-dts-to-the-code</link><description>Hi all, 
 this is a bit embarrassing, I updated from nrf SDK 2.5.0 to 3.1.1 and I&amp;#39;m a bit lost with the simplest things. 
 I need to toggle an LED on a custom board. I&amp;#39;m using an NRF52840 on a UBLOX module. The JLINK debugger recognises the microcontroller</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 Oct 2025 06:45:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/124960/i-need-help-getting-a-gpio-to-work-from-the-dts-to-the-code" /><item><title>RE: I need help getting a GPIO to work from the DTS to the code</title><link>https://devzone.nordicsemi.com/thread/551524?ContentTypeID=1</link><pubDate>Wed, 15 Oct 2025 06:45:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:878943d5-622b-4641-b216-0d794fc6584d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;This looks about correct.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think you need to specify&amp;nbsp;CONFIG_PINCTRL=y in prj.conf, as I believe it is set by default.&lt;/p&gt;
&lt;p&gt;Other than that, to set GPIO outputs that you want to control manually from your application, it is normal to define them as leds in your overlay/dts files, and use the API that you are using here.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;An alternative is to use the buttons and leds module that is used in the nrf samples, such as the peripheral_uart sample.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can add the&amp;nbsp;CONFIG_DK_LIBRARY=y, and include:&lt;/p&gt;
&lt;p&gt;#include &amp;lt;dk_buttons_and_leds.h&amp;gt;&lt;/p&gt;
&lt;p&gt;and use&amp;nbsp;dk_buttons_init() and dk_leds_init(), which will configure all the buttons and leds defined in your board files. Look at the sample for reference. If you dig into the dk_buttons_and_leds.c, you will see that it is set up pretty much like you already did in your application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I need help getting a GPIO to work from the DTS to the code</title><link>https://devzone.nordicsemi.com/thread/551501?ContentTypeID=1</link><pubDate>Wed, 15 Oct 2025 01:34:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78cd4633-8194-4969-b8a4-1d234edb6cb2</guid><dc:creator>albert_1977</dc:creator><description>&lt;p&gt;I got it working.&lt;/p&gt;
&lt;p&gt;On the prj.conf file I have the two lines:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_PINCTRL=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;On the .dts file in the &amp;quot;boards&amp;quot; folder I had to add:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;amp;gpiote {
	status = &amp;quot;okay&amp;quot;;
};

&amp;amp;gpio0 {
	status = &amp;quot;okay&amp;quot;;
};

&amp;amp;gpio1 {
	status = &amp;quot;okay&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The overlay file has the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	leds {
		compatible = &amp;quot;gpio-leds&amp;quot;;

		led0: led_0{
			gpios = &amp;lt; &amp;amp;gpio0 24 GPIO_ACTIVE_HIGH&amp;gt;;
			label = &amp;quot;LED0&amp;quot;;
		};

		led1: led_1{
			gpios = &amp;lt; &amp;amp;gpio0 16 GPIO_ACTIVE_HIGH&amp;gt;;
			label = &amp;quot;LED1&amp;quot;;
		};
	};

    aliases{
        led0 = &amp;amp;led0;
    }; &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And finally on the C code I have:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   250
static void pin_ios_task(void);

K_THREAD_DEFINE(pio_ios_tid, PIN_IOS_STACKSIZE, pin_ios_task, NULL, NULL, NULL, PIN_IOS_PRIORITY, 0, 0);

/* Identifier for GPIOs */
#define LED0_NODE           DT_ALIAS(led0)
static struct gpio_dt_spec gpio_led_0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

LOG_MODULE_REGISTER(pin_ios);

void pin_ios_init(void)
{
	
	gpio_pin_configure_dt(&amp;amp;gpio_led_0, GPIO_OUTPUT_ACTIVE);

	if (!gpio_is_ready_dt(&amp;amp;gpio_led_0))
	{
		LOG_ERR(&amp;quot;Error LED 0 init&amp;quot;);
	}

	return;
}

static void pin_ios_task(void)
{
    while(1)
    {
        k_sleep(K_MSEC(SLEEP_TIME_MS));
        gpio_pin_toggle_dt(&amp;amp;gpio_led_0);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am still not sure what is actually the correct way of doing this of if I added too much information, but it was the only way to get it to compile and run.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I need help getting a GPIO to work from the DTS to the code</title><link>https://devzone.nordicsemi.com/thread/551500?ContentTypeID=1</link><pubDate>Tue, 14 Oct 2025 23:39:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:259e11a2-ef98-49d9-b677-e35e0144bf28</guid><dc:creator>albert_1977</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t get it working yet. It was just a mistake on the original question. I&amp;#39;ll zip up the project later today, I&amp;#39;ll still try to get it working.&lt;/p&gt;
&lt;p&gt;This is a custom board, but like I mentioned before, the programmer works and the microcontroller is detected. I have an LED on P0.24 that I&amp;#39;d like to toggle and it&amp;#39;s something I&amp;#39;m struggling with the DTS currently.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I need help getting a GPIO to work from the DTS to the code</title><link>https://devzone.nordicsemi.com/thread/551447?ContentTypeID=1</link><pubDate>Tue, 14 Oct 2025 13:37:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0a5e13d-20a0-4394-b894-b755ff096e40</guid><dc:creator>Edvin</dc:creator><description>[quote user="albert_1977"]&lt;p&gt;I&amp;#39;m sorry,&lt;/p&gt;
&lt;p&gt;the overlay file is in the project folder, and set as overlay file in the build configuration:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Does that mean that you got it working? Or not?&lt;/p&gt;
&lt;p&gt;If not, can you please zip and upload the application here, so that I can have a look? Also specify what board you are building for, please.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I need help getting a GPIO to work from the DTS to the code</title><link>https://devzone.nordicsemi.com/thread/551374?ContentTypeID=1</link><pubDate>Tue, 14 Oct 2025 08:51:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e515617-5dbd-40d1-9453-5e5090035e4e</guid><dc:creator>albert_1977</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry,&lt;/p&gt;
&lt;p&gt;the overlay file is in the project folder, and set as overlay file in the build configuration:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1760431894936v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>