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't up to date yet I am trying to cobble together a lot of different things to make this work.
I have another ticket regarding that setup.
This ticket is about a work around that I found to get past some of those issues and just try to use my driver as a generic SPI device.
I have this in my overlay file:
&spi21 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi21_default>;
pinctrl-1 = <&spi21_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
cc1101: cc1101@0 {
reg = <0>;
compatible = "vnd,spi-device";
spi-max-frequency = <2500000>;
//int_gpios = <&gpio1 7 (GPIO_ACTIVE_LOW)>, <&gpio0 34 (GPIO_ACTIVE_LOW)>;
//frequency = <868300>;
//bitrate = <38368>;
status = "okay";
};
};
&pinctrl {
spi21_default: spi21_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 11)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
};
};
spi21_sleep: spi21_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 11)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
low-power-enable;
};
};
};
In my .c file I have this to define the device object:
#define SPIOP SPI_WORD_SET(8) | SPI_TRANSFER_MSB
struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(cc1101), SPIOP, 0);
In the same file when I initialize the spispec object I use this:
if(!spispec.bus) {
printk("cc1101 not in devicetree\n");
return -1;
}
if (!device_is_ready(spispec.bus)) {
printk("cc1101 device is not ready\n");
return -1;
}
uint8_t chipVer = cc1101_find_chip(spispec.bus);
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.
Inside the cc1101_find_chip function I eventually get to this line:
if (config->ncs.port != 0) {
gpio_pin_set_dt(&config->ncs, 0);
}
At this point here is the debug output values of config->ncs (which is a struct):

Notice that port is 0xffffffff
port is defined as a pointer in the gpio_dt_spec struct which is what ncs is defined as:
struct gpio_dt_spec {
/** GPIO device controlling the pin */
const struct device *port;
/** The pin's number on the device */
gpio_pin_t pin;
/** The pin's configuration flags as specified in devicetree */
gpio_dt_flags_t dt_flags;
};
When the internal nordic method gpio_pin_set function gets called with that point and that function tries to use port I get an exception (of course we would).
So what is going on here? I am following the code that should work to set up this device and yet the port is 0xffffffff.
Why?