zephyr-rtos

ZephyrOS: how to add driver module to out of tree project


I haven't found a definitive info on how to add a driver module to out-of-tree Zephyr project, so I will provide the answer by my own.


Solution

  • Changes:

    CMakeLists.txt

    +set(ZEPHYR_EXTRA_MODULES drivers/ololo)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    

    prj.conf

    +CONFIG_OLOLO=y
    

    Kconfig

    No changes

    New files:

    drivers/ololo/CMakeLists.txt

    zephyr_library()
    zephyr_library_sources_ifdef(CONFIG_OLOLO ololo.c)
    

    drivers/ololo/Kconfig

    menuconfig OLOLO
            bool "Ololo driver"
            default y
            select BLAH
            depends on MEH
            help
              Enable support for ololo driver
    
    if OLOLO
    
    module = OLOLO
    module-str = ololo
    source "subsys/logging/Kconfig.template.log_config"
    
    endif
    

    drivers/ololo/ololo.c

    /* Code goes here */
    

    drivers/ololo/zephyr/module.yml

    build:
      cmake: .
      kconfig: Kconfig