<?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>Device Tree - How to find structure and definitions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105061/device-tree---how-to-find-structure-and-definitions</link><description>There is piles of documentation about DT but little of that documentation appears very useful. 
 What I believe DT is: 
 A language/syntax like xml or json. ie DT defines some structure but not the meaning. 
 Data in the DT is used by a underlying custom</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 Oct 2023 08:43:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105061/device-tree---how-to-find-structure-and-definitions" /><item><title>RE: Device Tree - How to find structure and definitions</title><link>https://devzone.nordicsemi.com/thread/453190?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2023 08:43:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c60d778-adbf-46b2-8d0e-3ced65467f1f</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Your feedback and experience with using Zephyr has been forwarded.&lt;/p&gt;
[quote user="sfjklsdvmwoir"]Things are scattered across the project folder structure so you need to know or you are just in the dark.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;In my workspace under ...\external\zephyr\drivers\CMakeLists.txt includes drivers with add_subdirectory_ifdef&lt;/li&gt;
&lt;li&gt;Under each driver folder is another CMakeLists.txt with the same structure for individual drivers of that class.&lt;/li&gt;
&lt;li&gt;At this point the Kconfig of each driver appears to take over and define if it is enabled or not. How the system chooses a driver (hopefully the one you want) after that is unclear as alot of defines and dependencies are scattered across the build.&lt;/li&gt;&lt;/ul&gt;[/quote]
&lt;p&gt;As you have found, the drivers are located under for example &amp;lt;NCS_installation_dir&amp;gt;/nrf/drivers and &amp;lt;NCS_installation_dir&amp;gt;/zephyr/drivers. The CMakeLists.txt files add the relevant driver files to your project depending on what is enabled.&lt;br /&gt;The Kconfig files defines the configurations for a specific device, both ones that are user-configurable and some that are not. Often they have a default value that you can override by setting it to something else in your project configuration (prj.conf) if they are user-configurable.&lt;/p&gt;
&lt;p&gt;How the system chooses a driver is decided by the &amp;quot;compatible&amp;quot; field of the enabled devicetree node and the Kconfig options of the driver. Take for example SPI. Setting CONFIG_SPI=y in prj.conf will enable SPI. For the nRF5340 DK you might have SPI4 enabled in devicetree (status = &amp;quot;okay&amp;quot;) as it is in nrf5340_cpuapp_common.dtsi:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arduino_spi: &amp;amp;spi4 {
	compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
	cs-gpios = &amp;lt;&amp;amp;arduino_header 16 GPIO_ACTIVE_LOW&amp;gt;; /* D10 */
	pinctrl-0 = &amp;lt;&amp;amp;spi4_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi4_sleep&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here the compatible field is nordic,nrf-spim, which means it is the nRF SPIM driver that will be used. You can see this in the drivers Kconfig file, zephyr/drivers/spi/Kconfig.nrfx:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;config SPI_NRFX_SPIM
	def_bool y
	depends on DT_HAS_NORDIC_NRF_SPIM_ENABLED&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The config option DT_HAS_NORDIC_NRF_SPIM_ENABLED is generated from the devicetree node when &amp;#39;compatible = &amp;quot;nordic,nrf-spim&amp;#39; and &amp;#39;status = &amp;quot;okay&amp;quot;&amp;#39;. SPI_NRFX_SPIM is set to &amp;#39;y&amp;#39; by default, but it depends on DT_HAS_NORDIC_NRF_SPIM_ENABLED, so it is only set to &amp;#39;y&amp;#39; if DT_HAS_NORDIC_NRF_SPIM_ENABLED is enabled, that is, if a node with nrf-spim is enabled in devicetree.&lt;/p&gt;
[quote user="sfjklsdvmwoir"]...\external\zephyr\dts\arm\nordic contains the base nodes for all of the peripherals on the Nordic board.[/quote]
&lt;p&gt;Correct. These are the base devicetree files describing the chips themselves. The ones under boards/arm are for the DKs.&lt;/p&gt;
[quote user="sfjklsdvmwoir"]...\external\zephyr\dts\bindings\ Holds yaml files that will explain some of the settings for a peripheral. That said its layered and does not seem well documented so only use if you cant find the definitions externally.
[/quote]
&lt;p&gt;These are the bindings I wrote about in my first reply:&lt;/p&gt;
[quote user="Marte.M"]If you want to find the required properties of a specific devicetree node you can look at the bindings for that node, for example, &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/build/dts/api/bindings/spi/nordic,nrf-spi.html"&gt;nordic,nrf-spi&lt;/a&gt;. This shows which base and node specific properties the node has, the data types of the properties, and a description for each property. [/quote]
&lt;p&gt;And these pages: &amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/zephyr/build/dts/bindings-syntax.html"&gt;Devicetree bindings syntax&lt;/a&gt; and &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/zephyr/build/dts/bindings.html"&gt;Devicetree bindings&lt;/a&gt;.&lt;/p&gt;
[quote user="sfjklsdvmwoir"]From what I can tell drivers like LED driver do not have an official definition (In the devicetree spec) so maybe this is were you can find that kind of information (here or under the link provided in the official answer above).[/quote]
&lt;p&gt;The most common LEDs are &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/zephyr/build/dts/api/bindings/led/gpio-leds.html"&gt;gpio-leds&lt;/a&gt; and &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/zephyr/build/dts/api/bindings/led/pwm-leds.html"&gt;pwm-leds&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As you can see in most of our samples, we use the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/nrf/libraries/others/dk_buttons_and_leds.html"&gt;DK Buttons and LEDs&lt;/a&gt; library.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree - How to find structure and definitions</title><link>https://devzone.nordicsemi.com/thread/453095?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 14:55:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb1a61d7-eedb-4c92-b434-a0eb4ee6b241</guid><dc:creator>sfjklsdvmwoir</dc:creator><description>&lt;p&gt;For those who are also lost here is a few things I have discovered lately:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Things are scattered across the project folder structure so you need to know or you are just in the dark.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;In my workspace under ...\external\zephyr\drivers\CMakeLists.txt includes drivers with add_subdirectory_ifdef&lt;/li&gt;
&lt;li&gt;Under each driver folder is another CMakeLists.txt with the same structure for individual drivers of that class.&lt;/li&gt;
&lt;li&gt;At this point the Kconfig of each driver appears to take over and define if it is enabled or not. How the system chooses a driver (hopefully the one you want) after that is unclear as alot of defines and dependencies are scattered across the build.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;...\external\zephyr\dts\arm\nordic contains the base nodes for all of the peripherals on the Nordic board.&lt;/li&gt;
&lt;li&gt;Ever wonder about the definitions of the macros in devicetree files: ...\external\zephyr\include\zephyr\dt-bindings\ holds those, or at least all of the ones I have looked up so far. nrf-pinctrl.h holds all those functional definitions for GPIOs.&lt;/li&gt;
&lt;li&gt;...\external\zephyr\dts\bindings\ Holds yaml files that will explain some of the settings for a peripheral. That said its layered and does not seem well documented so only use if you cant find the definitions externally.
&lt;ul&gt;
&lt;li&gt;From what I can tell drivers like LED driver do not have an official definition (In the devicetree spec) so maybe this is were you can find that kind of information (here or under the link provided in the official answer above).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;devicetree.org has a specification that I am assuming is the official base.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It some one knows better please correct my statements. Clearly I am not in the know.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree - How to find structure and definitions</title><link>https://devzone.nordicsemi.com/thread/453069?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 14:07:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6eeeff88-d1e4-4072-9e56-7a4f0b2bd916</guid><dc:creator>sfjklsdvmwoir</dc:creator><description>&lt;p&gt;Thank you. We will keep reading or just blindly coping and pasting. I know that Zephyr is not run by the Nordic team but it is a contributor so maybe you can take a little partition. I(out team) think devicetree violates the KISS principle. Adding more syntax, layers, files, and complexity to the problem (especially when the core solution does not change) is not a good solution. When we started the project all we wanted to do was set a GPIO and that took hours vs the few mins it has taken in the STM or NXP environments. On a personal note I find it detracts from understanding the hardware and confidence that the system is setup and running the way you configured it. Confidence is further detracted when often a SDK update appears to break something in the devicetree macros... Its a pain to track those problems down. Why not just implement the solution in C (that is were it ends up anyways after all the layers unravel).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree - How to find structure and definitions</title><link>https://devzone.nordicsemi.com/thread/452448?ContentTypeID=1</link><pubDate>Thu, 26 Oct 2023 08:21:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c31da1f-3599-45b7-a99b-8780171acb45</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Devicetree has a steep learning curve and can be difficult when getting started.&lt;/p&gt;
&lt;p&gt;I know you said that little of the documentation is useful, but I still want to mention some pages which I have found to be helpful: &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/build/dts/intro-syntax-structure.html"&gt;Devicetree - Syntax and structure&lt;/a&gt;,&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/build/dts/bindings-syntax.html"&gt;Devicetree bindings syntax&lt;/a&gt;,&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.3.0/zephyr/build/dts/bindings.html"&gt;Devicetree bindings&lt;/a&gt; and &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/build/dts/howtos.html"&gt;Devicetree HOWTOs&lt;/a&gt;.&lt;/p&gt;
[quote user=""]The question is were do you find the definitions and structure to properly setup nodes in a device tree? [/quote]
&lt;p&gt;This is where the syntax pages are really helpful. The first one explains devicetree nodes and properties, and shows some important properties. The second explains the same for bindings. &lt;/p&gt;
[quote user=""]Each hardware type will have its own structure and flags/data. [/quote]
&lt;p&gt;If you want to find the required properties of a specific devicetree node you can look at the bindings for that node, for example, &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.2/zephyr/build/dts/api/bindings/spi/nordic,nrf-spi.html"&gt;nordic,nrf-spi&lt;/a&gt;. This shows which base and node specific properties the node has, the data types of the properties, and a description for each property. Another option is to look at how it is used in other devicetree files, for example the nrf-spi node here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi1 {
	compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;spi1_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi1_sleep&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;
[quote user=""]Or if I wanted to setup a driver that has no example in DT ( examples are how I currently guess what should be done) where would I find the structure and definitions?[/quote]
&lt;p&gt;This is described in the links above, but I have also made a simple example specifically for creating your own custom device with devicetree bindings and devicetree nodes. You can find it here: &lt;a href="https://github.com/martelmy/NCS_examples/tree/main/devicetree/devicetree_custom_device"&gt;https://github.com/martelmy/NCS_examples/tree/main/devicetree/devicetree_custom_device&lt;/a&gt;. Please note that this is not an official example, so it has not been tested extensively and is provided as-is.&lt;/p&gt;
[quote user=""]Even better is it feasible to not use DT?[/quote]
&lt;p&gt;No, devicetree is necessary to describe hardware in Zephyr.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>