<?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>Questions regarding inconsistencies in retrieving device structures</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118169/questions-regarding-inconsistencies-in-retrieving-device-structures</link><description>I&amp;#39;m following the nordic academic courses, which are very nice by the way! 
 
 I&amp;#39;ve now followed three topics and I find three different variants which confuse me a lot: 
 1. const struct device * uart = DEVICE_DT_GET ( DT_NODELABEL (uart0)); 
 2. const</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Jan 2025 14:15:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118169/questions-regarding-inconsistencies-in-retrieving-device-structures" /><item><title>RE: Questions regarding inconsistencies in retrieving device structures</title><link>https://devzone.nordicsemi.com/thread/519332?ContentTypeID=1</link><pubDate>Tue, 21 Jan 2025 14:15:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f690bedc-ad70-4656-922b-3f586f557294</guid><dc:creator>AHaug</dc:creator><description>[quote user="Mart"]Would you say these commands are interchangable with eachother? If so, can you provide an example?&amp;nbsp;[/quote]
&lt;p&gt;Some are, but it depends on how they are defined in the devicetree.&lt;/p&gt;
&lt;p&gt;You could for instance use&amp;nbsp;GPIO_DT_SPEC_GET(DT_NODELABEL(led_0); instead of&amp;nbsp;GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios); and get the same device&amp;nbsp;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;given&lt;/em&gt;&lt;/span&gt;&lt;em&gt;&lt;/em&gt; that the device has both an alias and a nodelabel specified when the device has been defined, which they has for the case of the leds.&lt;/p&gt;
&lt;p&gt;I was about to see if I could write down an explanation which broke down the abstraction layers even further, but I believe lesson 2 in the fundamentals academy course breaks it down far better than what I could without spending far too long time on the explanation. See&amp;nbsp;&lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-2-reading-buttons-and-controlling-leds/topic/devicetree/"&gt;https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-2-reading-buttons-and-controlling-leds/topic/devicetree/&lt;/a&gt;&amp;nbsp;with specific focus on the section regarding &amp;quot;DK devicetree file&amp;quot; roughly around the middle.&lt;/p&gt;
&lt;p&gt;In short, the two ways are interchangeable due to&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;There exists a device in the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/3758bcbfa5cd749d977e2600b6687104b8948243/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts#L30"&gt;dts that has a nodelabel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;There exists an &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/3758bcbfa5cd749d977e2600b6687104b8948243/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts#L120"&gt;alias for this device&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let me know if this answers your questions&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions regarding inconsistencies in retrieving device structures</title><link>https://devzone.nordicsemi.com/thread/519111?ContentTypeID=1</link><pubDate>Mon, 20 Jan 2025 14:27:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f98556ba-3ae7-441a-a2cb-2b25f081d40b</guid><dc:creator>Mart</dc:creator><description>&lt;p&gt;Thanks for your answer. This helps a bit.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Though I think the following would help see the differences for me:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Would you say these commands are interchangable with eachother? If so, can you provide an example?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions regarding inconsistencies in retrieving device structures</title><link>https://devzone.nordicsemi.com/thread/519074?ContentTypeID=1</link><pubDate>Mon, 20 Jan 2025 13:19:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63e18a76-0d61-420a-a4b8-05e8b136685e</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]I&amp;#39;m following the nordic academic courses, which are very nice by the way![/quote]
&lt;p&gt;We&amp;#39;re glad to hear that!&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;p&gt;&lt;span&gt;The static part, that ofcourse I get but what I do not understand is why there are (already) three different variants of getting my device structure?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sure, I do understand that the three lines are meant for different applications but to me they do kind of the same, right?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can somebody explain the reason for that and their differences in a bit more detail because it is confusing me.&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I see where the confusion comes from. Yes, they mean basically the same, and it is as you say different ways to get your device&amp;#39;s structure which often has their own sets of equivalent options. Which you choose depends on how you&amp;#39;ve defined the device or what type of device it is.&lt;/p&gt;
&lt;p&gt;1: This is fetching the device using a &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/build/dts/intro-syntax-structure.html#dt-node-labels"&gt;nodelabel&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2: This is fetching the device using&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/zephyr-apis-latest/page/structgpio_dt_spec.html"&gt;GPIO_DT_SPEC_GET( node_id, prop )&lt;/a&gt;, which is from the Zephyr API for gpios, using the device&amp;#39;s &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/build/dts/intro-syntax-structure.html#dt-node-labels"&gt;alias&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;3:&amp;nbsp;&lt;/em&gt;This is fetching a subdevice, in this case the sensor is a subsensor attached to the I2C bus. You can see a similar api for PWM here:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/zephyr-apis-latest/page/group_pwm_interface.htm"&gt;https://docs.nordicsemi.com/bundle/zephyr-apis-latest/page/group_pwm_interface.htm&lt;/a&gt;l&lt;/p&gt;
&lt;p&gt;Devicetree has a more expanded (and very helpful) documentation which you can see here:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/build/dts/index.html"&gt;https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/build/dts/index.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>