Out-of-tree driver - Zephyr (freestanding app)

out-of-tree-driver-test.zip

Hi,

We have a custom board that includes an ST LIS2DE12 sensor.  I followed what looks like the normal procedure to create an out-of-tree driver for it by refactoring the Zephyr driver for a similar ST part.  I've included the driver in my source tree, and it compiles normally, but won't link with the typical "undefined reference to `__device_dts_ord_xxx'" link error.

Note that this is a freestanding application.

I've cloned the hello_world application, and added my driver (and an overlay that includes the part).  Obviously - it can't run, since the DK board doesn't have the part - but what I'm trying to do is to get it to build without the linker error.  I've attached the code to this ticket.

What magic do I need to include in my source tree to get my out-of-tree driver to build and link as part of the zephyr tree?

Thanks in advance,

Cammie

Parents
  • I have found a working solution to this now, thanks to this dicord answer:

    The problem is indeed, that Zephyr does not seem to clearly document freestanding+out-of-tree applications:
    You have to include your out-of-tree driver inside your freestanding app root folder like this:

    ├── drivers
    │   ├── CMakeLists.txt
    │   ├── Kconfig
    │   ├── rtc
    │   │   ├── CMakeLists.txt
    │   │   ├── Kconfig
    │   │   ├── pcf85063a_util.h
    │   │   └── pcf85063a.c
    │   └── zephyr
    │       └── module.yml
    ├── dts
    │   └── bindings
    │       └── rtc
    │           └── nxp,pcf85063a.yaml
    ├── include
    │     └── app
    │       └── drivers
    │           └── rtc.h
    ├── src
    └── proj.conf

    and your driver is actually a so-called "module" which needs the drivers/zephyr/module.yml file with the following content:

    build:
      cmake: .
      kconfig: Kconfig

    Next, you need to include this in your app's root CMakeLists.txt before you find the zephyr package (I don't know why, but I got it running this way):

    list(APPEND ZEPHYR_EXTRA_MODULES
      ${CMAKE_CURRENT_SOURCE_DIR}/drivers
    )

    This is needed instead of the previously (likely, as in my case) used

    add_subdirectory(drivers)

    so I removed the latter line in my repo and replaced it with the list command above.

    Hope, you will find that this solution also works in your case!

    Kind regards.

  • Hey Hi!

    I tried the above and with some references , i could able to build out of tree driver for my application.

    But, i cannot able to access the rtc.h (in your case) from pcf85063a.c ,if rtc.h is placed in include/app/drivers/rtc.h.

    i moved it to the pcf85063a.c folder and accessed it by "#include "rtc.h"" directly,

    but i cant access if it is in the include directory, how to include the rtc.h if placed there?

    should i need to add some line in cmakelists to include them??

    or anyother way to include them??

Reply
  • Hey Hi!

    I tried the above and with some references , i could able to build out of tree driver for my application.

    But, i cannot able to access the rtc.h (in your case) from pcf85063a.c ,if rtc.h is placed in include/app/drivers/rtc.h.

    i moved it to the pcf85063a.c folder and accessed it by "#include "rtc.h"" directly,

    but i cant access if it is in the include directory, how to include the rtc.h if placed there?

    should i need to add some line in cmakelists to include them??

    or anyother way to include them??

Children
No Data
Related