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

  • 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.

  • Thank you Sigurd,

    The links you have sent regarding Zephyr UART driver example and related materials, plus the diff.patch file are turning out helpful.  I've applied the patch you sent, and achieved an error-free compilation on my local workstation's experimental kionix code repo.  I pushed those diffs to Github, then cloned the same project to a distinct place on my workstation.

    In this `git push; git clone` test, the build in the newly cloned kionix project failed at a much later stage.  I don't have the exact message on hand, but that message appears to regard a device symbol that's missing an element.  Somewhere in the Zephyr build toolchain, a _CONCAT_ macro receives a NULL parameter, so a comlete device symbol cannot be properly generated.  I'm looking into this now.  I'd seen this before when I'd gotten an 'include file' line incorrect in a CMakeLists.txt file.

    The original project instance where I first patched is still building.  I'm now making a file by file comparison between this and the newly cloned project.  The difference must be something in a git controlled file, as you corrected my code based on what you found on github.

    Also I observe that your patch amends two or three Kconfig files.  I'm reviewing your corrections closely to understand the modified syntax.

    Thank you again, Sigurd.  I am looking forward to grasping cmake and Kconfig better soon.  I will keep yourself and DevZone community posted as to my progress.

    - Ted

  • tedhavelka said:
    I've applied the patch you sent, and achieved an error-free compilation on my local workstation's experimental kionix code repo.

     Great Slight smile

    tedhavelka said:
    Somewhere in the Zephyr build toolchain, a _CONCAT_ macro receives a NULL parameter, so a comlete device symbol cannot be properly generated.

    Could be that the board overlay you had is not being applied (correctly) for the board you are building for.

    /*
     *  https://community.jaredwolff.com/d/73-accelerometer-example-failing-to-compile-on-feather-v2/2
     *  https://www.youtube.com/watch?v=sWaxQyIgEBY  --- Device Tree Deep Dive
     */
    
    &i2c1 {
            compatible = "nordic,nrf-twim";
            status = "okay";
            sda-pin = <26>;
            scl-pin = <27>;
            kionix_sensor: kx132-1211@1f {
                    compatible = "kionix,kx132-1211"; 
                    reg = <0x1F>;
                    label = "KX132-1211";
            };  
    };

     

  • 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

Related