Difficulty creating a Zephyr-based nRFConnect project within VSCode that contains a custom sensor driver

I have been trying to create an nRFConnect based project using toolchain 2.5.0 and SDK 2.5.0 (also 2.5.99-dev1) that enables me to create an example application that uses a custom external driver.  As a simple example, let's say I want to take the "Blinky" project, add SPI, and then add a custom sensor driver. Let's call that custom sensor driver "my_accel_chip."  While the rules for creating drivers that work with the Zephyr API are straightforward, there's no easy way that I have been able to find that works seamlessly with nrfConnect and VSCode.  For example:

https://iwasz.pl/electronics/2021-06-18-out-of-tree-zephyr-module.md/

https://jdelaney.me/posts/zephyr-oot-modules/

https://blog.golioth.io/adding-an-out-of-tree-sensor-driver-to-zephyr/

Apparently you can't just clone git clone github.com/.../example-application my-app and open up a folder  and build an app either, you need "west" and the venv setup.

../src/main.c: In function 'main':
/opt/nordic/ncs/v2.5.99-dev1/zephyr/include/zephyr/device.h:85:41: error: '__device_dts_ord_DT_N_NODELABEL_examplesensor0_ORD' undeclared (first use in this function)
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)

Reading through the documentation, it appears there is a "workspace" method that requires WEST to initialize the project that is not supported with nrfConnect/vscode. Trouble is, I don't have the ability to manually open up the .venv and run west  and initialize the project.

So I have two questions:

(1) How do you activate the venv/west workspace so you can run west commands manually within VSCode and nrfConnect

(2) Is there a *WORKING TEMPLATE* for an APP + OUT OF TREE Sensor Driver that I can use within nrfConnect Examples such as Blinky + SPI for an equivalent "my_external_tree_sensor_driver"?  I've tried creating a workspace, then importing an app like Blinky, updating the device tree to support SPI, then copying "my_out_of_tree_driver" as per the structures described in the above links, including CMakeLists.txt, yaml files, Kconfig, etc, then tried to add the driver, both to the workspace, and as an alternative, copying my driver right in "myapp."  

I have had zero success.  This is on MacOS. Toolchains and APIs are stored in /opt/nordic/ncs , while my workspace where my app is stored is in /home/myusername/nordic_apps/

So I'm really not sure how to create a driver structure, as shown in Mike Delaney's Blog as an example, like where to put this file structure, or how to integrate with nRFConnect tools / VSCode.  For example, do I structure my code like this?

  my_app
  |-- src/main.c
|-- prj.conf ...
|-- CMakeLists.txt
  my_out_of_tree_driver
  |-- drivers
        |-- sensor
              |-- bh1750
                    |-- bh1750.c
                    |-- bh1750.h
                    |-- CMakeLists.txt
                    |-- KConfig
              |-- CMakeLists.txt
              |-- Kconfig
        |-- CMakeLists.txt
        |-- Kconfig
  |-- dts
        |-- bindings
              |-- sensor
                    |-- rohm,bh1750-i2c.yaml
  |-- include
        |-- drivers
  |-- Kconfig
  |-- CMakeLists.txt
  |-- zephyr
        |-- module.yml

Or like this?

my_app (driver contained within my_app)

|-- src/main.c
|-- prj.conf ...
|-- CMakeLists.txt

|-- my_out_of_tree_driver
  |-- drivers
        |-- sensor
              |-- bh1750
                    |-- bh1750.c
                    |-- bh1750.h
                    |-- CMakeLists.txt
                    |-- KConfig
              |-- CMakeLists.txt
              |-- Kconfig
        |-- CMakeLists.txt
        |-- Kconfig
  |-- dts
        |-- bindings
              |-- sensor
                    |-- rohm,bh1750-i2c.yaml
  |-- include
        |-- drivers
  |-- Kconfig
  |-- CMakeLists.txt
  |-- zephyr
        |-- module.yml

OR... Can Nordic provide a fully working nRFConnect / VSCode solution with a sample app and sample external sensor driver included in the package, because right now that does not exist!

Thanks, Josh
  • Hello Josh,

    Sorry for the delayed response.

    Is there any update at your end?

    I started with the Example Application provided by Nordic. This is same/similar version as of the zephyr example application.

    I followed the steps that are described in the readme. Particularly, I ran the following commands in the command line (west must have been installed already):

    west init -m https://github.com/nrfconnect/ncs-example-application --mr main my-workspace
    cd my-workspace
    west update
    cd ncs-example-application
    west build -b custom_plank app

    this would initiate a west repo, download the files from github, do an update, and then build the APP (the application folder containing the source code) for the custom_plank board.

    Next, I opened the APP folder with the VSCode, and built for the NRF5840 board after adding a suitable overlay, and it compiled well.

Related