<?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>GPIO overlays</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101817/gpio-overlays</link><description>I&amp;#39;ve been looking through this forum for advice on GPIO overlays and there seems to be a lot of confusion. 
 So I looked at the button and blinky examples and put together the following overlay for my board: 
 
 This repurposes GPIO 15 to be an LED instead</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 17 Jul 2023 16:21:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101817/gpio-overlays" /><item><title>RE: GPIO overlays</title><link>https://devzone.nordicsemi.com/thread/436831?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 16:21:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39cb343d-eb3e-42f4-ae97-2f1a9e16620c</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;It&amp;#39;s working!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO overlays</title><link>https://devzone.nordicsemi.com/thread/436636?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 06:46:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:837efdd3-d314-453d-a854-dd8df1b0eee1</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks for sharing your project. Yes, it is necessary to remove the alias as well if you delete the button node, just as I did in the overlay I posted earlier.&lt;/p&gt;
&lt;p&gt;While building your project, I&amp;nbsp;got an &amp;quot;implicit declaration&amp;quot; warning for the GPIO_DT_SPEC_GET() macro and an &amp;quot;incomplete type&amp;quot; error for the gpio_dt_spec struct. This was because you were missing the &amp;lt;zephyr/drivers/gpio.h&amp;gt; include.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Build log&lt;/strong&gt;&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/pastedimage1689575872503v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code with required &amp;quot;include&amp;quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

#define LED0_NODE DT_ALIAS(mycustomled)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO overlays</title><link>https://devzone.nordicsemi.com/thread/436565?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2023 21:13:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b070807f-daf9-4378-bac7-d8f7d77aac1c</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;Adding only&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/delete-node/ &amp;amp;button2;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In my overlay file causes this line in the dts file to fail:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;		sw1 = &amp;amp;button2;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The message is &amp;quot;Unknown reference to &amp;amp;button2&amp;quot; as you might expect.&lt;/p&gt;
&lt;p&gt;Adding this line to my overlay:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;		/delete-property/ sw1;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Does not fix it.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve zipped up and attached the entire project so you can see the build failure first hand.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/cm_5F00_fw_5F00_core.zip"&gt;devzone.nordicsemi.com/.../cm_5F00_fw_5F00_core.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO overlays</title><link>https://devzone.nordicsemi.com/thread/436456?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2023 11:24:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbc56bac-d034-4371-8409-13178e831e42</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;It looks like you only deleted the alias, but not the button node. I had this line at the beginning of my overlay:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/delete-node/ &amp;amp;button2;&lt;/pre&gt;&lt;/p&gt;
[quote user="bretforeman_personal"]I pasted in the runtime code as you suggested and the build still fails[/quote]
&lt;p&gt;Can you please post the build log? You should be able to compile despite the warning about overlapping pin assignments.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO overlays</title><link>https://devzone.nordicsemi.com/thread/436337?ContentTypeID=1</link><pubDate>Thu, 13 Jul 2023 17:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9358916-95c2-4192-95d0-bbd7a54080ce</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;I added the delete-property as you suggested. In my case, GPIO 15 was connected to button2 and aliased to sw1 in my boards dts file. Here&amp;#39;s fragment from the board&amp;#39;s dts:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	buttons {
		compatible = &amp;quot;gpio-keys&amp;quot;;
		button1: button_1 {
			gpios = &amp;lt;&amp;amp;gpio0 11 GPIO_PULL_UP&amp;gt;;
			label = &amp;quot;Push button switch 1&amp;quot;;
		};
		button2: button_2 {
			gpios = &amp;lt;&amp;amp;gpio0 15 GPIO_PULL_UP&amp;gt;;
			label = &amp;quot;Push button switch 2&amp;quot;;
		};
	};

	/* These aliases are provided for compatibility with samples */
	aliases {
		led0 = &amp;amp;led1;
		led1 = &amp;amp;led2;
		sw0 = &amp;amp;button1;
		sw1 = &amp;amp;button2;
		mcuboot-button0 = &amp;amp;button1;
		mcuboot-led0 = &amp;amp;led1;
		watchdog0 = &amp;amp;wdt0;
	};
	&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So my overlay deletes sw1 and looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/{
	custom_leds {
 	   compatible = &amp;quot;gpio-leds&amp;quot;;
	   led0: led_0 {
		  gpios = &amp;lt;&amp;amp;gpio0 15 GPIO_ACTIVE_HIGH&amp;gt;;
		  label = &amp;quot;My custom LED&amp;quot;;
	   };
	};
	aliases {
		mycustomled = &amp;amp;led0;
		/delete-property/ sw1;
	};
 };
 &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still getting the same warning:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Pin 15 of &amp;amp;gpio0 already assigned to &amp;amp;button2
bl652_dvk.dts(44, 12): Overlapping assignment
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I pasted in the runtime code as you suggested and the build still fails, probably because I&amp;#39;m still not correctly deleting the button and replacing with the led.&lt;/p&gt;
&lt;p&gt;Can you see what I still have wrong?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO overlays</title><link>https://devzone.nordicsemi.com/thread/436169?ContentTypeID=1</link><pubDate>Thu, 13 Jul 2023 08:20:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d565175-4eee-46b3-a46d-d70823e94d3b</guid><dc:creator>Vidar Berg</dc:creator><description>[quote user=""]The first problem with this approach is that I get the following warning:[/quote]
&lt;p&gt;As indicated by the warning, you currently have the GPIO assigned as both a button and an LED. To get rid of the warning, you can delete the button node and its alias in your overlay, as shown below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/delete-node/ &amp;amp;button2;


/{
    custom_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;My custom LED&amp;quot;;
        };
    };
    aliases {
        mycustomled = &amp;amp;ledx;
        /delete-property/ sw2;
    };

};&lt;/pre&gt;&lt;/p&gt;
[quote user=""]The next thing I do is to try and get a device in the runtime code with the following line:[/quote]
&lt;p&gt;If you want to use the Zephyr GPIO API to control the pin, then you need to initialize the gpio_dt_spec struct for the child node (led0). You can see how it is done in the Blinky example here: &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/b37ce40878ec52295afe6350d17712d60eb6639a/samples/basic/blinky/src/main.c#L20C75-L20C75"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/b37ce40878ec52295afe6350d17712d60eb6639a/samples/basic/blinky/src/main.c#L20C75-L20C75&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;E.g.,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LED0_NODE DT_ALIAS(mycustomled)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>