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.

Reply Children
No Data
Related