SPI on nRF52840 and Zephyr

I’m just starting out writing code for the nRF52840 using the u-blox evaluation kit (nina-b302) which, apparently, is effectively compatible with the nordic nrf52840dk. I have a GPIO pin up and running but can’t say the same for SPI. Specifically I’m doing this…

#define SPI DT_NODELABEL(spi1)
const struct device *spi_dev = device_get_binding(DT_LABEL(SPI));

But the device is coming back NULL. The node label is listed in zephyr.dts and has a property of status = "okay";. I have a suspicion the zephyr configuration itself is borken (and is not building the spi driver) but don’t know how to check this, or where the configuration options are.

Anyone seen this before? Any ideas?

What does your zephyr/prj.conf look like in full? Do you do a CONFIG_SPI=y, CONFIG_SPI_1=y in there and all the related things as seen in the KConfig? Configuring Zephyr is also documented in the PlatformIO docs.

Hi Max, thanks for replying.

There is no zephyr/prj.conf. There’s a CMakeLists.txt.

Ummmm, I’m new to this…

You’ve started your GPIO blink example from the official example project at platform-nordicnrf52/examples/zephyr-blink at develop · platformio/platform-nordicnrf52 · GitHub, which has the zephyr folder, right? In its prj.conf, there’s also the CONFIG_GPIO=y option, without which your GPIO project shouldn’t even work o_o.

Can you clone the above blink project, modify the platformio.ini by removing all environments but the one’s correct for your board (while adapting board = ofc), verifying that the firmware works, then expand it with the configuration options above in the zephyr/prj.conf to activate SPI, and then retest SPI functionality again?

Ah, got it. There is no zephyr/prj.conf (I started from “New Project” on PIO home) but you can always create one. Adding “CONFIG_SPI=y” appears to have done the job. I got some reading to do.

Thanks!