<?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>Which macro to get sck, mosi and miso pin on spi master</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89246/which-macro-to-get-sck-mosi-and-miso-pin-on-spi-master</link><description>Hello, 
 I works with Zephyr, VCS, SDK 2.0.0 
 I don&amp;#39;t find how to get pin number from the DTS pinctrl . 
 In this folowing code, I want to replace magic number (uplighted in yellow) by macro to acces data of the DTS 
 Thank&amp;#39;s by advance for your help</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 Jun 2022 14:21:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89246/which-macro-to-get-sck-mosi-and-miso-pin-on-spi-master" /><item><title>RE: Which macro to get sck, mosi and miso pin on spi master</title><link>https://devzone.nordicsemi.com/thread/374943?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 14:21:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a17a4fc1-5f5d-4afa-83ee-cd22ab939cfc</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;Stéphane,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It seems like I was wrong in my first reply. The spi_nrfx_spim.c will not use the DT_PROP macros to get the sck, mosi and miso pins when pinctrl is enabled due to &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L507"&gt;this check&lt;/a&gt;. Instead it will configure it through &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L534"&gt;pin_ctrl_apply_state()&lt;/a&gt;--&amp;gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/include/zephyr/drivers/pinctrl.h#L350"&gt;pin_ctrl_apply_state_direct()&lt;/a&gt;--&amp;gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/pinctrl/pinctrl_nrf.c#L101"&gt;pin_ctrl_configure_pins()&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Please use the approach by Tristen&amp;nbsp;instead:&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/89246/which-macro-to-get-sck-mosi-and-miso-pin-on-spi-master/374615"&gt;RE: Which macro to get sck, mosi and miso pin on spi master&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I will get back to you if I find a better approach&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which macro to get sck, mosi and miso pin on spi master</title><link>https://devzone.nordicsemi.com/thread/374685?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 08:22:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81214c89-3b82-491f-ab45-21167bede844</guid><dc:creator>ngbe</dc:creator><description>&lt;p&gt;Hello Tristen,&lt;/p&gt;
&lt;p&gt;Interesting, thank you for you experience sharing.&lt;/p&gt;
&lt;p&gt;St&amp;eacute;phane&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which macro to get sck, mosi and miso pin on spi master</title><link>https://devzone.nordicsemi.com/thread/374615?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 17:52:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3785a44-6788-4591-9482-f44a40116352</guid><dc:creator>Tristen</dc:creator><description>&lt;p&gt;To answer your original question (for cases like mine where I use PINCTRL but also had to use the&amp;nbsp;NRFX SPI driver for one of my SPI peripherals in order to utilize PPI), I did not find any DT macros that would just do this. Understanding the Device Tree, you can use a combination of other macros to access pin info. Here&amp;#39;s an example:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;dtsi file:&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;...&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; spi1_default: spi1_default {&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; group1 {&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; psels = &amp;lt;&lt;/span&gt;&lt;span&gt;NRF_PSEL&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPIM_SCK&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;9&lt;/span&gt;&lt;span&gt;)&amp;gt;,&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;NRF_PSEL&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPIM_MOSI&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;8&lt;/span&gt;&lt;span&gt;)&amp;gt;,&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;NRF_PSEL&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPIM_MISO&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt;)&amp;gt;;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;dts file:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;...&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;amp;spi1 {&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; compatible = &lt;/span&gt;&lt;span&gt;&amp;quot;nordic,nrf-spim&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; status = &lt;/span&gt;&lt;span&gt;&amp;quot;okay&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; pinctrl-0 = &amp;lt;&amp;amp;spi1_default&amp;gt;;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; pinctrl-1 = &amp;lt;&amp;amp;spi1_sleep&amp;gt;;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; pinctrl-names = &lt;/span&gt;&lt;span&gt;&amp;quot;default&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;sleep&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; cs-gpios = &amp;lt;&amp;amp;gpio0 &lt;/span&gt;&lt;span&gt;31&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;GPIO_ACTIVE_LOW&lt;/span&gt;&lt;span&gt;&amp;gt;;&lt;br /&gt;&lt;/span&gt;};&lt;/code&gt;&lt;br /&gt;&lt;code&gt;...&lt;/code&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;strong&gt;application:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;#define &lt;/span&gt;&lt;span&gt;SPI_NODE&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;DT_NODELABEL&lt;/span&gt;&lt;span&gt;(spi1)&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;#define &lt;/span&gt;&lt;span&gt;SPI_PINCTRL_NODE&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;DT_CHILD&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;DT_PINCTRL_0&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPI_NODE&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;), group1)&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;Then in your SPI Configuration structure, you can grab the property like this:&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;nrfx_spim_config_t xSpiConfig = {&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;.sck_pin &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;DT_PROP_BY_IDX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPI_PINCTRL_NODE&lt;/span&gt;&lt;span&gt;, psels, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) &amp;amp; 0x3F,&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;.mosi_pin &amp;nbsp; &amp;nbsp; &amp;nbsp; = (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;DT_PROP_BY_IDX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPI_PINCTRL_NODE&lt;/span&gt;&lt;span&gt;, psels, &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;)&amp;nbsp;&amp;amp; 0x3F,&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;.miso_pin &amp;nbsp; &amp;nbsp; &amp;nbsp; = (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;DT_PROP_BY_IDX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPI_PINCTRL_NODE&lt;/span&gt;&lt;span&gt;, psels, &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;)&amp;nbsp;&amp;amp; 0x3F,&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;.ss_pin &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = &lt;/span&gt;&lt;span&gt;DT_GPIO_PIN_BY_IDX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SPI_NODE&lt;/span&gt;&lt;span&gt;, cs_gpios, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;/code&gt;&lt;span&gt;&lt;code&gt;),&lt;/code&gt;&lt;br /&gt;&lt;code&gt;...&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The psel property will return a 32-bit configuration (defined in nrf-pinctrl.h), but you just need the first 6 bits.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;If anyone knows an easier way, please share.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which macro to get sck, mosi and miso pin on spi master</title><link>https://devzone.nordicsemi.com/thread/374066?ContentTypeID=1</link><pubDate>Fri, 24 Jun 2022 08:10:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c82b56-16e0-43cd-96e8-7a713a8afd33</guid><dc:creator>ngbe</dc:creator><description>&lt;p&gt;Hello Simon,&lt;/p&gt;
&lt;p&gt;Thank you for your reply,&lt;br /&gt;I took your advice and it is all right with Zephyr API.&lt;/p&gt;
&lt;p&gt;Note that I have to add following properties in &amp;quot;zephyr/dts/bindings/spi/nordic,nrf-spim.yaml&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;   spi-max-frequency:
      type: int
      required: false
      default: 4000000
      description: Maximum clock frequency of device&amp;#39;s SPI interface in Hz

    duplex:
      type: int
      default: 0
      required: false
      description: |
        Duplex mode, full or half. By default it&amp;#39;s always full duplex thus 0
        as this is, by far, the most common mode.
        Use the macros not the actual enum value, here is the concordance
        list (see dt-bindings/spi/spi.h)
          0    SPI_FULL_DUPLEX
          2048 SPI_HALF_DUPLEX
      enum:
        - 0
        - 2048

    frame-format:
      type: int
      default: 0
      required: false
      description: |
        Motorola or TI frame format. By default it&amp;#39;s always Motorola&amp;#39;s,
        thus 0 as this is, by far, the most common format.
        Use the macros not the actual enum value, here is the concordance
        list (see dt-bindings/spi/spi.h)
          0     SPI_FRAME_FORMAT_MOTOROLA
          32768 SPI_FRAME_FORMAT_TI
      enum:
        - 0
        - 32768
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;WIthout that , SPI_CONFIG_DT fail .&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct spi_dt_spec	spi_rfid={ 
	.bus=DEVICE_DT_GET(SPI_RFID_NODE), 
	.config=SPI_CONFIG_DT(SPI_RFID_NODE,SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_MODE_CPHA | SPI_MODE_CPOL,0),
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;St&amp;eacute;phane&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which macro to get sck, mosi and miso pin on spi master</title><link>https://devzone.nordicsemi.com/thread/373766?ContentTypeID=1</link><pubDate>Wed, 22 Jun 2022 16:53:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6eaf1fe-1ebe-4a4b-a41b-ac66a50a8dcc</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;&lt;strong&gt;Update 30.06.2022: Added strikethrough to an incorrect statement.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I would recommend you to use the Zephyr API. Then the information specified in DTS will automatically get picked up by the&amp;nbsp;SPI drivers without you needing to do anything. It is also much less complicated to use.&lt;/p&gt;
&lt;p&gt;However, you might have chosen to use the nrfx drivers for a specific reason, but I thought it would be nice to inform you in case you weren&amp;#39;t aware.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through;"&gt;To answer your question, you could&amp;nbsp;take a look at the file&amp;nbsp;spi_nrfx_spim.c to see how to get the&amp;nbsp;pin number from the DTS pinctrl (use DT_PROP_OR or DT_PROP macros)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through;"&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L487-L488"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L487-L488&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through;"&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L511-L515"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L511-L515&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through;"&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L510"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/drivers/spi/spi_nrfx_spim.c#L510&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;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>