<?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: &amp;#39;reg&amp;#39; node property</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67205/device-tree-reg-node-property</link><description>Hello, 
 I need someone to shed some light on how to use the &amp;#39;reg&amp;#39; node property because I am confused.com . 
 On this page https://docs.zephyrproject.org/latest/guides/dts/intro.html &amp;#39;reg&amp;#39; is described as follows, 
 reg 
 Information used to address</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Oct 2020 17:31:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67205/device-tree-reg-node-property" /><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/276017?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2020 17:31:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c50649ff-fbf6-4cee-8c69-b38bb7cb0a00</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Thank you Simon for providing answering my questions.&amp;nbsp;&lt;/p&gt;
[quote userid="72692" url="~/f/nordic-q-a/67205/device-tree-reg-node-property/275888#275888"]&lt;div class="quote-user"&gt;Learner said:&lt;/div&gt;&lt;div class="quote-content"&gt;I favour option 1b. Can you please help me with the steps I need to take to implement this?&lt;/div&gt;[/quote]
&lt;p&gt;&lt;/p&gt;
[quote userid="72692" url="~/f/nordic-q-a/67205/device-tree-reg-node-property/275888#275888"]However, this question is out-of-scope for this ticket, which was about the reg node property. Could you open a new ticket and ask about this? In this way we keep DevZone more organized and it easier for future users to navigate. Thanks for your understanding &lt;span class="emoticon ui-tip" title="Slight smile"&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/1f642.svg" alt="Slight smile" /&gt;&lt;/span&gt;[/quote]
&lt;p&gt;I fully understand your point. I have opened another ticket dedicated to the SPI&amp;nbsp;device driver implementation.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/275888?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2020 11:50:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93b5da51-dc26-43dc-aec9-ea52caf8730a</guid><dc:creator>Simon</dc:creator><description>[quote user="Learner"]Can both methods of accessing devices over SPI (memory-mapped and SPI devices) be used with zephyr RTOS?[/quote]
&lt;p&gt;I am not sure what you mean by &amp;quot;accesing devices&amp;quot;. But both methods can be used in Zephyr. Read &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.3.0/zephyr/guides/dts/intro.html#important-properties"&gt;this&lt;/a&gt; for more information. You should just set the reg field appropriately, and then you don&amp;#39;t have to worry about it more in your main code. The underlying&amp;nbsp;drivers&amp;nbsp;will use the reg fields and handle everything for you.&lt;/p&gt;
&lt;p&gt;The sensor (e.g. the &lt;span&gt;apds sensor&lt;/span&gt;) can be accessed from the code by using device_get_binding(&amp;lt;label&amp;gt;), where &amp;lt;label&amp;gt; is what you have set label equal to in the overlay/dts-file. E.g. &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L136"&gt;this sensor&lt;/a&gt;&amp;nbsp;is accessed by using device_get_binding(&lt;span&gt;&amp;quot;ADXL362&amp;quot;&lt;/span&gt;).&lt;/p&gt;
[quote user="Learner"]I favour option 1b. Can you please help me with the steps I need to take to implement this?[/quote]
&lt;p&gt;This question was about how to implement the sensor into your application and if you should create your own driver or not, and you decide to go for option b: &lt;em&gt;&amp;quot;b. Easier way: Setup the SPI instance in your application, then add the communication protocol on-top.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;However, this question is out-of-scope for this ticket, which was about the reg node property. Could you open a new ticket and ask about this? In this way we keep DevZone more organized and it easier for future users to navigate. Thanks for your understanding &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
[quote user="Learner"]So, sub-node &lt;strong&gt;adxl362@0&lt;/strong&gt;&amp;nbsp;is an SPI device that is connected to spi3 and uses the pins defined&amp;nbsp;below. Pin 8 is the CS for spi device&amp;nbsp;&lt;strong&gt;adxl362@0&lt;/strong&gt;&amp;nbsp;and pin 7 is the CS for spi device &lt;strong&gt;adxl372@1&lt;/strong&gt;. &lt;strong&gt;Is this right?&amp;nbsp;&lt;/strong&gt;[/quote]
&lt;p&gt;&amp;nbsp;Yes, you have understood it correctly.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/275297?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2020 09:23:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbb9b456-9f9b-4981-b311-903a05b768e9</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Thank you Simon.&lt;/p&gt;
&lt;p&gt;I am clear about the chip select question. However, I asked 3 more questions&amp;nbsp;further up in this trail. You will find them if you search for the character &amp;#39;?&amp;#39;.&lt;/p&gt;
&lt;p&gt;Please provide answers. Thank you.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/275289?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2020 08:53:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3e25896-aa61-4e26-a9cf-fd86c2958096</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I think the zeros below are&amp;nbsp;&lt;span&gt;SPI device&amp;#39;s chip select GPIO flags. See &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.3.0-rc1-ncs2/include/devicetree/spi.h#L191-L212"&gt;this&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;cs-gpios = &amp;lt;&amp;amp;gpio0 8&amp;nbsp;&lt;span style="background-color:rgba(255, 255, 0, 1);color:rgba(255, 0, 0, 1);"&gt;0&lt;/span&gt;&amp;gt;, &amp;lt;&amp;amp;gpio0 7&amp;nbsp;&lt;span style="background-color:rgba(255, 255, 0, 1);color:rgba(255, 0, 0, 1);"&gt;0&lt;/span&gt;&amp;gt;;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I believe the value assigned to &lt;code&gt;reg &lt;/code&gt;shows whether&amp;nbsp;&lt;span&gt;an SPI device have a chip select line configured or not, 1 if yes and 0 if no. See &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.3.0-rc1-ncs2/include/devicetree/spi.h#L83-L116"&gt;this&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/275254?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2020 07:25:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d03ecbb-74bc-4182-8b1c-f716b676f92f</guid><dc:creator>Learner</dc:creator><description>[quote userid="72692" url="~/f/nordic-q-a/67205/device-tree-reg-node-property/275063#275063"]&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L136"&gt;This&lt;/a&gt; is an example of&amp;nbsp;&lt;strong&gt;SPI device.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In this case the reg property will be on the from&amp;nbsp;&lt;code&gt;reg = &amp;lt;address&amp;gt;,&amp;nbsp;&lt;/code&gt;which is the chip select line number&lt;/li&gt;&lt;/ul&gt;[/quote]
&lt;p&gt;You are saying the value assigned to reg property is the chip select line (cs). What is meant by line in this context? is it the pin number on a particular port? I thought the chip select line is specified by the line below.&lt;/p&gt;
[quote userid="92434" url="~/f/nordic-q-a/67205/device-tree-reg-node-property/275211#275211"]cs-gpios = &amp;lt;&amp;amp;gpio0 8 &lt;span style="background-color:#ffff00;color:#ff0000;"&gt;0&lt;/span&gt;&amp;gt;, &amp;lt;&amp;amp;gpio0 7 &lt;span style="background-color:#ffff00;color:#ff0000;"&gt;0&lt;/span&gt;&amp;gt;;[/quote]
&lt;p&gt;Please clarify. Thank you.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/275211?ContentTypeID=1</link><pubDate>Thu, 15 Oct 2020 20:46:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c6b2400-da3a-4aff-a8c3-ea9267818df0</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Thank you for&amp;nbsp;your answer.&lt;/p&gt;
&lt;p&gt;Can both methods of accessing devices over SPI (memory-mapped and SPI devices) be used with zephyr RTOS?&lt;/p&gt;
[quote userid="72692" url="~/f/nordic-q-a/67205/device-tree-reg-node-property/275063#275063"]&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L136"&gt;This&lt;/a&gt; is an example of&amp;nbsp;&lt;strong&gt;SPI device.&lt;/strong&gt;[/quote]
&lt;p&gt;So, sub-node &lt;strong&gt;adxl362@0&lt;/strong&gt;&amp;nbsp;is an SPI device that is connected to spi3 and uses the pins defined&amp;nbsp;below. Pin 8 is the CS for spi device&amp;nbsp;&lt;strong&gt;adxl362@0&lt;/strong&gt;&amp;nbsp;and pin 7 is the CS for spi device &lt;strong&gt;adxl372@1&lt;/strong&gt;. &lt;strong&gt;Is this right?&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is the &lt;span style="background-color:#ffff00;color:#ff0000;"&gt;0&lt;/span&gt;&amp;nbsp;in the chip select line below (cs-gpios) for?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt; status = &amp;quot;okay&amp;quot;;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt; sck-pin = &amp;lt;3&amp;gt;;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt; mosi-pin = &amp;lt;4&amp;gt;;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt; miso-pin = &amp;lt;5&amp;gt;;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt; cs-gpios = &amp;lt;&amp;amp;gpio0 8 &lt;span style="background-color:#ffff00;color:#ff0000;"&gt;0&lt;/span&gt;&amp;gt;, &amp;lt;&amp;amp;gpio0 7 &lt;span style="background-color:#ffff00;color:#ff0000;"&gt;0&lt;/span&gt;&amp;gt;;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Let me put&amp;nbsp;it to you what I think I understood from your answer and relate to what I am trying to implement on our own proprietary board.&lt;/p&gt;
&lt;p&gt;I need to communicate with a&amp;nbsp;device over SPI using nRF5340 and zephyr RTOS. I have the source code for the driver.&lt;/p&gt;
&lt;p&gt;For example if I&amp;nbsp;wanted to communicate with&amp;nbsp;&amp;nbsp;the device over spi1 I need to implement the following in an overlay file.&lt;/p&gt;
&lt;p&gt;&amp;amp;spi1 {&lt;br /&gt;&amp;nbsp; &amp;nbsp;compatible = &amp;quot;nordic,nrf-spim&amp;quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;status = &amp;quot;okay&amp;quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;sck-pin = &amp;lt;13&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;mosi-pin = &amp;lt;09&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;miso-pin = &amp;lt;40&amp;gt;;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;cs-gpios = &amp;lt;&amp;amp;gpio0 19&lt;span style="background-color:#ffff00;color:#ff0000;"&gt;&lt;strong&gt; 0&lt;/strong&gt;&lt;/span&gt;&amp;gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;};&lt;/p&gt;
&lt;p&gt;I am not sure about&amp;nbsp;what to do with the source code for the device driver. I do not want to create a full blown zephyr based driver for this device. I have read on DevZone this&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;Drivers-wise, you essentially have two options (zephyr choice is divided into two options):&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;1. Use the generic Zephyr driver API&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; a. Hard way: Create a full-blown zephyr based driver - this is normally not done unless you plan to do a pull-request to the zephyr-rtos project.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; b. Easier way: Setup the SPI instance in your application, then add the communication protocol on-top.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;2. Use the nordic specific nrfx driver directly&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;You can use the Zephyr API to create your own driver. This includes creating Kconfig menu, device tree, and developing the sensor src and porting to use the spi.h API. This would then be a portable driver, which can theoretically run on any of the supported SPI &amp;quot;backends&amp;quot; (ie: x86, arm, xtensa, etc), but its not a straight forward process.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;You also have the option to use the nrfx_spim driver directly in your application, by adding CONFIG_NRFX_SPIM=y, then adding for instance CONFIG_NRFX_SPIM1=y.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I favour option 1b. Can you please help me with the steps I need to take to implement this?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Device Tree: 'reg' node property</title><link>https://devzone.nordicsemi.com/thread/275063?ContentTypeID=1</link><pubDate>Thu, 15 Oct 2020 11:56:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dedead70-1f04-4cc9-83a8-bd4e6d86c4c4</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I looked into this, and I think I understand how this works&lt;/p&gt;
&lt;p&gt;There is a difference between&amp;nbsp;&lt;strong&gt;Devices accessed via memory-mapped&amp;nbsp;&lt;/strong&gt;and&amp;nbsp;&lt;strong&gt;SPI devices&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L128"&gt;This&lt;/a&gt; is an example of&amp;nbsp;&lt;strong&gt;Devices accessed via memory-mapped&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;There is not defined any reg property &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L129-L134"&gt;here&lt;/a&gt;, so it will get the default value from &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.3.0-rc1-ncs1/dts/arm/nordic/nrf9160_common.dtsi#L261"&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;In this case the reg property will be on the form&amp;nbsp;&lt;code&gt;&lt;span&gt;reg = &amp;lt;address length&amp;gt;, &lt;/span&gt;&lt;/code&gt;&lt;span&gt;which gives information on where this peripheral is placed in memory and how much memory it occupies. It should coincide with the values defined &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fspim.html&amp;amp;cp=2_0_0_5_12"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L136"&gt;This&lt;/a&gt; is an example of&amp;nbsp;&lt;strong&gt;SPI device.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In this case the reg property will be on the from&amp;nbsp;&lt;code&gt;reg = &amp;lt;address&amp;gt;,&amp;nbsp;&lt;/code&gt;which is the chip select line number&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The values you see in zephyr.dts comes from &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.3.0-rc1-ncs1/dts/arm/nordic/nrf5340_cpuapp_common.dtsi#L231"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>