<?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>Problem using nRF Connect SDK devicetree GPIO definitions in code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85362/problem-using-nrf-connect-sdk-devicetree-gpio-definitions-in-code</link><description>Hi, 
 
 I am just starting out creating a project to run on an nRF9160 on custom hardware. I have set up a development environment (v1.9.0) through nRF Connect for Desktop app. I have created a custom board configuration based on the thingy91_nrf9160</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 29 Mar 2022 12:44:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85362/problem-using-nrf-connect-sdk-devicetree-gpio-definitions-in-code" /><item><title>RE: Problem using nRF Connect SDK devicetree GPIO definitions in code</title><link>https://devzone.nordicsemi.com/thread/360543?ContentTypeID=1</link><pubDate>Tue, 29 Mar 2022 12:44:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32ef8b64-c79b-4c0a-9317-63b2d1615d9b</guid><dc:creator>luc_eac</dc:creator><description>&lt;p&gt;For future visitors, I have figured out what I was missing.&lt;/p&gt;
&lt;p&gt;I was unaware that the device tree file is only half of the story and that the system also needs a binding to link the dts configuration to a template which specifies the possible fields of a dts node. This binding is what you put in the &amp;quot;compatible&amp;quot; field.&lt;/p&gt;
&lt;p&gt;In my case I defined a file in my board folder under dts/bindings/eac,testpin.yaml, which contains:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;description: GPIO used as testpin

compatible: &amp;quot;eac,testpin&amp;quot;

include: base.yaml

properties:
  status:
    required: true

  gpios:
    type: phandle-array
    required: true
    description: |
      GPIO to use as testpin.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And added to my dts node:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;tp: testpin {
	compatible = &amp;quot;eac,testpin&amp;quot;;
	gpios = &amp;lt;&amp;amp;gpio0 22 0&amp;gt;;
	status = &amp;quot;okay&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using nRF Connect SDK devicetree GPIO definitions in code</title><link>https://devzone.nordicsemi.com/thread/356081?ContentTypeID=1</link><pubDate>Thu, 03 Mar 2022 14:06:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41b2bd89-856b-4466-8dd5-70ac5a7a639c</guid><dc:creator>luc_eac</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br /&gt;Thank you for your answer. I have seen the button examples, but the trouble is I am not trying to implement a button here. I am implementing a GPIO pin.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br /&gt;Looking at the Zephyr device tree documentation they make it seem like you can just create a node (which I named tp) and include a &amp;quot;gpios&amp;quot; parameter to it to define a gpio. All of the examples look like this, roughly..&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;gpio1: gpio@... { };

gpio2: gpio@... { };

n: node {
        gpios = &amp;lt;&amp;amp;gpio1 10 GPIO_ACTIVE_LOW&amp;gt;,
                &amp;lt;&amp;amp;gpio2 30 GPIO_ACTIVE_HIGH&amp;gt;;
};&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Looking at the nRF Connect view in Visual Studio Code under the devicetree tab the pin is also recognised as a GPIO node with the name tp, so s&amp;oacute;mething is happening..&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Naamloos.png" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have tried adding my own source file to the dts configuration, but that made no difference.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;testpins {
	compatible = &amp;quot;testpin&amp;quot;;

	tp: tspn {
		gpios = &amp;lt;&amp;amp;gpio0 22 0&amp;gt;;
		label = &amp;quot;TP42&amp;quot;;
	};
};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How do I configure just a regular old GPIO in the devicetree (not tied button or led drivers) to use in my own code?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem using nRF Connect SDK devicetree GPIO definitions in code</title><link>https://devzone.nordicsemi.com/thread/356067?ContentTypeID=1</link><pubDate>Thu, 03 Mar 2022 13:36:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08ab5fa8-518e-4155-996a-ef4690db90f0</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Looks like the DTS configuration you have attached is missing the whole configuration, and you have only part of the configuration. E.g. look at&amp;nbsp;nrf\boards\arm\thingy91_nrf9160\thingy91_nrf9160_common.dts&lt;/p&gt;
&lt;p&gt;From here you can see how they have configured the button connected to the nRF9160:&lt;br /&gt;&lt;pre class="ui-code" data-mode="json"&gt;buttons {
	compatible = &amp;quot;gpio-keys&amp;quot;;

	button0: button_0 {
		gpios = &amp;lt;&amp;amp;gpio0 26 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
		label = &amp;quot;Button 1&amp;quot;;
	};
};

&amp;amp;gpio0 {
	status = &amp;quot;okay&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Edit: You should also have a look at the basic button sample in Zephyr (zephyr\samples\basic\button\src\main.c)&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>