This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF1960 and Out-of-tree Zephyr new driver development?

Hello Devzone Community,

I'm a couple weeks into learning, working with Nordic ncs, Zephyr RTOS and west and friends.  I'm working on an out-of-tree driver, and am stuck at an early during build error relating to the flag which enables the new sensor driver I'm writing.  I'm working up code to configure and read data from Kionix KX132 accelerometer.  The error I get is:

~/ncs/zephyr/samples/sandbox-de-ted/kionix-work/app/prj.conf:16: warning: attempt to assign the value 'y' to the undefined symbol KX132_1211

I have high confidence that I have installed Nordic's ncs v1.6.1 SDK, and a toolchain correctly.  I can build and run multiple sample apps from 'ncs/zephyr/samples', where 'ncs' is the root directory of the SDK, the location in which I run 'west init', 'west export-zephyr' and 'west update'.  I started my driver work by copying sample/basic/blinky and adding to that.  I successfully combined blinky with 'hello world' so I have a one-way UART for messages and very limited debugging. 

I've made two forays into device driver in-tree work.  First I followed the directory and file layout of a good tutorial posted at Memfault site:  https://interrupt.memfault.com/blog/building-drivers-on-zephyr.  From this tutorial I created a dir structure like:


    app-for-new-driver
    |
  +-+--------+----------+------------+
  |        |          |            |
drivers   src    app.overlay     zephyr
  |                                |
kionix                         module.yml
  |
kx132-1211

There are CMakeLists.txt and Kconfig files in most of these directories, and specifically all the dirs under the 'drivers' directory.  Somehow though it appears that the build process is not finding the Kconfig in directory 'kx132-1211', a file which contains:

# SPDX-License-Identifier: Apache-2.0

config KX132_1211
    bool "KX132-1211 accelerometer"
    depends on I2C
    help
       Enable Kionix KX132-1211 accelerometer

The line 'config KX132_1211' is supposed to generate a symbol early enough in the build process, such that cmake and related tools know to compile my in-tree driver.  I've also tried to follow the information at https://docs.zephyrproject.org/latest/application/index.html.  This document links to an example "out of tree driver" app at github:  https://github.com/zephyrproject-rtos/example-application.

I cloned this example application, which entails a driver named 'EXAMPLESENSOR', into the same location where I've successfully built ncs sample apps.  Building this example app, however, results in the same error:

ncs/zephyr/samples/sandbox-de-ted/example-application/app/prj.conf:7: warning: attempt to assign the value 'y' to the undefined symbol EXAMPLESENSOR

Before building this unchanged sample project I had earlier in the day restructured my Kionix driver app to have a directory tree like 'example application':


app-for-new-driver
     |
   +-+---------------+-------------+
   |                 |             |
drivers             app          zephyr
   |                 |             |
kionix           +---+---+     module.yml
   |             |       |
kx132-1211      src    board
                         |
                    app.overlay

Again I have placed CMakeLists.txt files and Kconfig files in all the dirs where the two tutorials + examples show them present.

Can anyone share with me a open source, publicly available "out of tree driver" Zephyr example app?  Can anyone share a document which more clearly explains the config file requirements to successfully create, and have parsed at the right build time, a new sensor driver flag of the form "CONFIG_<NEW_DRIVER_NAME>"?

- Ted

Parents
  • Correction:  where I write "in-tree work" I intended to say "out-of-tree work".  Second, in my request for an out of tree driver example, I specifically need one which compiles correctly.  I have yet to locate a build-able example "out of Zephyr tree" driver with app to demonstrate the driver.

  • Hi guys I've been trying to build the drive that Ted mentioned, I assume it's already patched/changed, well the problem is I can't build it...
    I get :

    nrfConnectSDK/v1.8.0/nRF9160-work/nRF9160-work-main/kionix-work/app/src/main.c:17:10: fatal error: kx132-1211.h: No such file or directory
       17 | #include "kx132-1211.h"
          |          ^~~~~~~~~~~~~~

    The main reason I came here is that I get similar problems (to the original problem Ted had with the:

    attempt to assign the value 'y' to the undefined symbol

    I'm trying to build pinetime hypnos with ncs, and it doesn't work apart form other problems I have/had I cannot move over this one. So I guessed I will try to find something that actually works (I've already established that for some reason Kconfig is part of the problem) under ncs.
    As I've researched over the Internet it seems its some kind of generic problem people have with out of tree or local drivers  directory, all methods, guidelines are mostly it seems for pure Zephyr, not for creations like ncs.

    So to build this repo from Ted's github I'm using Windows with ncs  (1.8.0) installed with toolchain manager.
    I put Ted's repo into main 1.8.0 and then under bash (opened from toolchain manager)
    I call :
    west build -b nrf9160dk_nrf9160_ns kionix-work/app

    and it ends up with the error like pasted above.

    I have some experience with ncs, but all I've been doing was fairly simple, not touching custom drivers presented in this very fashion (as out of tree driver), nor had to touch Zephyr's build system that much.

    Now I guess that since the error is about not finding the include file (and I assume that if everything is setup correctly it should be just picked up like that) there is still some kind "wrongness" there (or change in ncs/Zephyr).

    I would be grateful if someone could tell me how to exactly build it under ncs (it should help me move forward with hypnos I believe)

    Best Regards,
    Pawel

Reply
  • Hi guys I've been trying to build the drive that Ted mentioned, I assume it's already patched/changed, well the problem is I can't build it...
    I get :

    nrfConnectSDK/v1.8.0/nRF9160-work/nRF9160-work-main/kionix-work/app/src/main.c:17:10: fatal error: kx132-1211.h: No such file or directory
       17 | #include "kx132-1211.h"
          |          ^~~~~~~~~~~~~~

    The main reason I came here is that I get similar problems (to the original problem Ted had with the:

    attempt to assign the value 'y' to the undefined symbol

    I'm trying to build pinetime hypnos with ncs, and it doesn't work apart form other problems I have/had I cannot move over this one. So I guessed I will try to find something that actually works (I've already established that for some reason Kconfig is part of the problem) under ncs.
    As I've researched over the Internet it seems its some kind of generic problem people have with out of tree or local drivers  directory, all methods, guidelines are mostly it seems for pure Zephyr, not for creations like ncs.

    So to build this repo from Ted's github I'm using Windows with ncs  (1.8.0) installed with toolchain manager.
    I put Ted's repo into main 1.8.0 and then under bash (opened from toolchain manager)
    I call :
    west build -b nrf9160dk_nrf9160_ns kionix-work/app

    and it ends up with the error like pasted above.

    I have some experience with ncs, but all I've been doing was fairly simple, not touching custom drivers presented in this very fashion (as out of tree driver), nor had to touch Zephyr's build system that much.

    Now I guess that since the error is about not finding the include file (and I assume that if everything is setup correctly it should be just picked up like that) there is still some kind "wrongness" there (or change in ncs/Zephyr).

    I would be grateful if someone could tell me how to exactly build it under ncs (it should help me move forward with hypnos I believe)

    Best Regards,
    Pawel

Children
  • Hello again Pawel,

    I amend my statement just after the west.yml code excerpt, near end of my reply this hour:  if and when in your project you are able to invoke `west update` and confirm that you are now downloading, or having `west` at minimum check that your copy of `zephyr-driver-work-v2` is up to date, you should be poised to add a line to your app's `prj.conf` file, to enable this sensor.  In my driver demo's prj.conf, the one line which "turns on" and includes all the out-of-tree driver details is:

       CONFIG_KX132_1211=y

    The symbol which I actually wrote in the driver code is `KX132_1211`, but somewhere the actions of, I am guessing, Kconfig language and parser converts my symbol and prepends `CONFIG_` to the beginning of that symbol.

    I think you already have this symbol in a prj.conf or other project config file, otherwise you would not have that "undefined symbol" error.

    On a few occasions this year 2021, I encountered the error "attempting to assign 'y' to undefined symbol" when I had failed to reference needed third party repositories in my project manifest file.  I am also still trying to wrap my head about the way in which the `west` utility reaches up into the parent directory above my local cloned app repository, and populates the other project dependencies (code repos) there.  The top location(s) and hierarchy of `west` workspaces is a little different than I am used to seeing in my prior C based, embedded and other project experiences.

    This reminds me, while you may not need write your own out-of-tree Zephyr device drivers, the following blog post by engineer Jared Wolff has been an excellent resource to me:

       *  https://interrupt.memfault.com/blog/building-drivers-on-zephyr

    I also highly recommend to visit Jared's technical help forum at https://community.jaredwolff.com/.  Mr. Wolff is knowledgeable, responsive, patient and enthusiastic.  All great qualities for an engineer working in these fields and collaborating with other developers and teams.  I've posted my technical, Zephyr and nRF9160 related questions there on several occasions and always received prompt, useful help.  Definitely another technical forum worth visiting!

    - Ted

Related