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

  • Hello Pawel,

    Regarding your questions, I was eventually able to solve these problems of header files not found, and a Kconfig symbol I'd created for the KX132-1211 not being defined.  I may be able to help.

    First, apologies that I did not return and post my solution, so that Nordic team could close this ticket.  The summary solution I can share is that I needed to write a correct `west` manifest file for my Zephyr based app.

    Second, a couple of comments:  I'm working in a Linux environment at the command line, and relying regularly on the Python based `west` utility, and cmake and friends.  Second comment, forgive me if I state things that are basic or obvious.  I don't mean to underestimate your project. experience.

    So I created this tiny app to exercise Kionix driver which I am developing.  The `west` manifest file pulls together three git repositories, to form a complete, build-able project.  These repositories are Nordic's nrfconnect/sdk-nrf/releases/tag/v1.6.1, zephyr-driver-work-v2, and kionix-driver-demo.

    The third of these repositories is my app.  This is the code in which you'll find `int main()`.  I'd seen somewhere this past year among Zephyr RTOS tutorials and how-tos, a recurring theme:  "Zephyr projects are app centric".  It has taken me a while to understand this statement.  But I'm finding it accurate and true.  The simple driver demo above pulls in the much larger coding projects of ncs, and the out-of-tree driver, each of these as code dependencies much like libraries.  In this sense my app is my starting point, and the west.yml manifest file is really what makes this so.

    Your starting point naturally is different.  I can see this from the path you name, `nrfConnectSDK/v1.8.0/...`.  Without knowing more detail about your project, I am curious to know whether your west.yml manifest file references the Kionix driver code at kionix-driver-demo?  If not, this may be part of the reason you're getting the "no such [header] file or directory" and "attempting to assign 'y' to undefined symbol" errors.

    Here is the brief `west` manifest file which I use to build my driver testing app:

    manifest:
      remotes:
        - name: nrfconnect
          url-base: https://github.com/nrfconnect
      projects:
        - name: nrf 
          repo-path: sdk-nrf
          remote: nrfconnect
          revision: v1.6.1
          import: true
        # Drivers repository
        - name: zephyr-driver-work-v2
          path: kionix-drivers
          revision: main
          url: https://github.com/tedhavelka/zephyr-driver-work-v2
    #      import: true   ...2021-08-26 for some reason this should be commented out - TMH
      self:
        # This repository should be cloned to 
        path: kionix-driver-demo
    

    I'm wondering what happens if you add the lines 11..15 to your app's west.yml manifest file, and then invoke `west update`.  If this works as I expect, you should get a copy of the Kionix out-of-tree driver project, in a directory that's located at the top dir of your west workspace.

    One other caveat:  I have not finished the KX132-1211 driver.  I've only developed that driver minimally so far, enough to obtain x, y, z axis acceleration readings, and I believe to set output data rate.  Does Pinetime Hypnos or another part of your work depend on a complete Kionix KX132-1211 driver?

    I am curious to hear whether any of this helps you resolve your build errors.  Keep safe,

     - Ted

  • 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