Enabling SPI and TWI drivers on Zephyr

Hi

First the fundamentals, I am using:

  • nRF52840-DK
  • nRF Connect for VS Code: v2024.7.13

I am trying to create a demonstration project, where I need both SPI and TXI/I2C.

Here is a copy of the essentials:

prj.conf:

CONFIG_EVENTS=y
CONFIG_SETTINGS=y
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_DK_LIBRARY=y
CONFIG_LOG=y

CONFIG_SPI=y
CONFIG_I2C=y

#CONFIG_NRFX_SPIM1=y
#CONFIG_NRFX_TWI0=y

nrf52840dk_nrf52840.overlay:

&spi1 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = <&spi1_default>;    
};
&i2c0 {
    status = "okay";
    compatible = "nordic,nrf-twim";
    pinctrl-0 = <&i2c0_default>;    
};

twi code:

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h>
#include <nrfx_twim.h>

#define TWIM_INST_IDX 0

static nrfx_twim_t twim_inst = NRFX_TWIM_INSTANCE(TWIM_INST_IDX);
// Comile error: 'NRFX_TWIM0_INST_IDX' undeclared here (not in a function)

spi code:

#include <zephyr/kernel.h>
#include <zephyr/drivers/spi.h>
#include <nrfx_spim.h>

#define SPIM_INST_IDX 1

static nrfx_spim_t spim_inst = NRFX_SPIM_INSTANCE(SPIM_INST_IDX);
// compile error: 'NRFX_SPIM1_INST_IDX' undeclared here (not in a function)

In my first attempts with only SPI interface enabled, I got it working by using the CONFIG_NRFX_SPIM1=y line in the prj.conf file. But I do not thick that it was the right way.

What do I miss? Do I need more includes? Or some other changes to the project?

I have tried to look at the examples, e.g. "nrfx_spim basic non-blocking example.", here only the CONFIG_NRFX_SPI1=y is used, but the error detector in the editor expects an error (just As in my application), but it does compile:

CONFIG_NRFX_SPIM1 was assigned the value y, but got the value n. Missing dependencies: n
SPIM1 driver instance
Type: bool
Value: n

Thanks in advance.

Kasper

Parents
  • Hi

    I am using NCS 2.6.1, and I am not getting any issue: can build and flash

    Just attaching the whole project (with the build folder as well).

    hello_world_2.rar

  • Thanks for the example. It did not compile out of the box, because the path to the devicetree file contains folder names on your local drive. But after changing that, i did build. And I was focusing on the build lines regarding the devicetree: (I shortened the project paths for simplicity)

    -- Found BOARD.dts: C:/ncs/v2.5.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: C:/.../hello_world_2/nrf52840dk_nrf52840.overlay
    -- Found devicetree overlay: nrf52840dk_nrf52840.overlay
    -- Generated zephyr.dts: C:/.../hello_world_2/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: C:/.../hello_world_2/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: C:/.../hello_world_2/build/zephyr/dts.cmake
    

    And the I compared it with the build output from my project. 

    -- Found BOARD.dts: C:/ncs/v2.5.1/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts
    -- Generated zephyr.dts: C:/.../display-demo/build_1/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: C:/.../display-demo/build_1/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: C:/.../display-demo/build_1/zephyr/dts.cmake
    

    Therefore I verified the build configuration, where devicetree overlays can be added. It was missing. I believed that I just forgot it (or did not know anything about it). I added it, and hit the "Build Configuration" Button. BUT: No change. I looked at the build configuration once again, and the reference to the devicetree overlay was empty again.

    Byt why . . .  ? ? ?

  • Is this happening to only this project, or any other project with the overlay that you create?

    Can you exit and restart the VS code and see if it configures correctly?

    Once I also had a weird (but kind of same issue) that the configurations of a specific project were applied to new projects, but I got rid of that by reinstalling. That might also help.

Reply Children
No Data
Related