<?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>Custom SPI Device Driver exception when running</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/120343/custom-spi-device-driver-exception-when-running</link><description>I am using VSCode with nRF Connect extension with the 2.9.1 SDK. 
 I am trying to write my own device driver for the Zephyr OS and the TI CC1101 chip. Since the tutorial isn&amp;#39;t up to date yet I am trying to cobble together a lot of different things to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Apr 2025 18:25:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/120343/custom-spi-device-driver-exception-when-running" /><item><title>RE: Custom SPI Device Driver exception when running</title><link>https://devzone.nordicsemi.com/thread/530067?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 18:25:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58cfcc68-2f39-4feb-94e8-c4be009bccf5</guid><dc:creator>Tony</dc:creator><description>&lt;p&gt;I figured this all out. I had to modify some of the yaml for the dts device. There was a mix of comma and dash and they had to all be dashes.&lt;/p&gt;
&lt;p&gt;I also found that the code was referencing the cs-gpios of the SPI definition, so I had to move that from the spi part to the cc1101 part.&lt;/p&gt;
&lt;p&gt;Now it builds and the structure has what it needs.&lt;/p&gt;
&lt;p&gt;Files:&lt;/p&gt;
&lt;p&gt;Overlay&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;amp;spi21 {
    compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	  status = &amp;quot;okay&amp;quot;;
	  pinctrl-0 = &amp;lt;&amp;amp;spi21_default&amp;gt;;
	  pinctrl-1 = &amp;lt;&amp;amp;spi21_sleep&amp;gt;;
	  pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
	  cc1101: cc1101@0 {
		reg = &amp;lt;0&amp;gt;;
		compatible = &amp;quot;ti-cc1101&amp;quot;;
		spi-max-frequency = &amp;lt;2500000&amp;gt;;
		cs-gpios = &amp;lt;&amp;amp;gpio1 8 GPIO_ACTIVE_LOW&amp;gt;;
		int_gpios = &amp;lt;&amp;amp;gpio1 7 (GPIO_ACTIVE_LOW)&amp;gt;, &amp;lt;&amp;amp;gpio0 34 (GPIO_ACTIVE_LOW)&amp;gt;;
		frequency = &amp;lt;868300&amp;gt;;
		bitrate = &amp;lt;38368&amp;gt;;
		status = &amp;quot;okay&amp;quot;;
	};
};
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;ti-cc1101.yaml&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Copyright (c) 2018, Linaro Limited
# SPDX-License-Identifier: Apache-2.0

description: Texas Instruments CC1101 wireless transceiver

compatible: &amp;quot;ti-cc1101&amp;quot;

include: spi-device.yaml

properties:
  int_gpios:
    type: phandle-array
    required: true
    description: GPIOs connected to the GDO0 and GDO2 pins of the transceiver.
  cs-gpios:
     type: phandle-array
     description: GPIO connected nCS
 
  frequency:
    type: int
    description: The carrier frequency, in kHz.
  bitrate:
    type: int
    description: The bitrate in bit per second.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;.c file declaration&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const struct device *cs = DEVICE_DT_GET_ANY(ti_cc1101);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It all compiles and the ncs member is filled out.&lt;/p&gt;
&lt;p&gt;I figured out a lot of this when I noticed this macro define:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define CC1101_DEFINE(inst)                                             \
    static struct cc1101_data cc1101_data_##inst = {                    \
        .frequency = DT_INST_PROP(inst, frequency),                     \
        .bitrate = DT_INST_PROP(inst, bitrate),                         \
    };                                                                  \
    static struct cc1101_config cc1101_config_##inst = {                \
        .spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8), 150),        \
        .gdo0 = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, int_gpios, 0),       \
        .gdo2 = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, int_gpios, 1),       \
        .ncs = GPIO_DT_SPEC_INST_GET(inst, cs_gpios),                   \
    };                                                                  \
    DEVICE_DT_INST_DEFINE(inst, cc1101_init, NULL,                      \
                  &amp;amp;cc1101_data_##inst, &amp;amp;cc1101_config_##inst, POST_KERNEL,  \
                  99, NULL);


DT_INST_FOREACH_STATUS_OKAY(CC1101_DEFINE)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;At that point I put the error about cs_gpios together with the fact that the spi part of the overlay had something like that, but the cc1101 didn&amp;#39;t. I was assuming a child had access to its parents in the macro when really you have to move it from the parent to the child in the overlay.&lt;/p&gt;
&lt;p&gt;Makes me wonder if you talk about that in the tutorials anywhere because I have been through the beginner and intermediate tutorials and didn&amp;#39;t see anything about that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom SPI Device Driver exception when running</title><link>https://devzone.nordicsemi.com/thread/530044?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 14:51:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22762e77-bb29-4733-a797-697b6cb2f895</guid><dc:creator>Tony</dc:creator><description>&lt;p&gt;I am new to the device driver model and am starting to think this issue is because I am getting the spispec pointer using the regular method of getting a pointer to a device tree item instead of using the one that is specific to my device driver.&lt;/p&gt;
&lt;p&gt;The problem is probably related to the fact that I can&amp;#39;t us the right one because I get a compiler error. The details of that are in this ticket:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/119838/adding-spi-to-a-project"&gt;Adding SPI to a project&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is it true that if I can resolve the issue of getting my device driver the right way, the ncs field will probably be filled in for me?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom SPI Device Driver exception when running</title><link>https://devzone.nordicsemi.com/thread/530043?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 14:46:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49c36791-8a49-4ebb-9d06-d6f285fb922c</guid><dc:creator>Tony</dc:creator><description>&lt;p&gt;Sorry I didn&amp;#39;t see the Insert Code. I will remember that in the future. Thanks for the tip.&lt;/p&gt;
&lt;p&gt;This is where config comes from:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int cc1101_txrx(const struct device *dev, uint8_t reg, uint8_t *txb, uint8_t txlen, uint8_t *rxb, uint8_t rxlen)
{
    const struct cc1101_config *config = dev-&amp;gt;config;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;so it is the spispec that is passed in and created by the device tree stuff.&lt;/p&gt;
&lt;p&gt;Thank you for asking the question because as I look at this further it might be something in the cc1101 driver code that I got from github.&lt;/p&gt;
&lt;p&gt;If you are willing to look and maybe help figure it out, that code is here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/studiofuga/cc1101"&gt;github.com/.../cc1101&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom SPI Device Driver exception when running</title><link>https://devzone.nordicsemi.com/thread/530019?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 13:20:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fea82bd5-d619-489e-8f8b-cbe69e0d8cc1</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is a lot easier to read the code if you use insert -&amp;gt; code.&lt;/p&gt;
[quote user=""]&lt;div&gt;&lt;span&gt;It gets past the check for bus being null and device_is_ready, so I would expect everything is ready to start using SPI on this device.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Inside the cc1101_find_chip function I eventually get to this line:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;config&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;ncs&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;port&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;!=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gpio_pin_set_dt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;config&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;ncs&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; }&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;Is config a non-null variable? How is this declared etc?&lt;/p&gt;
&lt;p&gt;Is this the cs-gpios that you are trying to handle?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>