Including custom zephyr module

Hello,

We are developing a custom Zephyr module that we would like to include into multiple projects.

After a lot of testing and debugging we ran into a very weird issue that we cannot explain.  

The module looks like this:

C:/path-to-my-module/test-module/
  library/
    include/
        test_module.h
    src/
        test_module.c
    Kconfig
  zephyr/
    module.yml
  CMakeLists.txt


Where the CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.20.0)

# Define the project as library
zephyr_library_named()

# Include the library headers
zephyr_include_directories(library/include)

# Add the source files to the library
file(GLOB_RECURSE SRC "library/src/*.c")
zephyr_library_sources(${SRC})

And the zephyr/module.yml like this:

name: test-module

build:
  cmake: .
  kconfig: ./library/Kconfig

The project's CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.20.0)

set(EXTRA_ZEPHYR_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/../modules/test-module)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(test-app VERSION 0.0.1)

zephyr_include_directories(include)
target_include_directories(app PRIVATE
    include
)

file(GLOB_RECURSE SRC "src/*.c")
target_sources(app PRIVATE ${SRC})

The module is added to the project using west, like this:

manifest:
  remotes:
    - <remotes>

  projects:
    - name: test-module
        path: modules/test-module
        remote: <remote>
        revision: 0.0.1
    - name: sdk-nrf
      path: nrf
      remote: ncs
      revision: v2.5.0
      import:
        name-whitelist:
          - cmsis
          - hal_nordic
          - mcuboot
          - mcumgr
          - segger
          - tinycrypt
          - zephyr
          - nrfxlib
          - mbedtls
          - zcbor
          - hostap
          - trusted-firmware-m
          - open-amp
          - libmetal
          - nanopb

This all works fine and all the modules are correctly loaded after using 'west update'. However, when building the project I get a lot of errors that the module cannot find certain configs and files (just a small part of the error):

error: 'CONFIG_LWM2M_ENGINE_MAX_PENDING' undeclared here (not in a function)
  147 |         struct coap_pending pendings[CONFIG_LWM2M_ENGINE_MAX_PENDING + 1];
error: 'CONFIG_LWM2M_ENGINE_MAX_REPLIES' undeclared here (not in a function)
  148 |         struct coap_reply replies[CONFIG_LWM2M_ENGINE_MAX_REPLIES + 1];
error: 'DT_N_ALIAS_isp_P_gpios_IDX_0_VAL_pin' undeclared here (not in a function); did you mean 'DT_N_S_leds_S_led_0_P_gpios_IDX_0_VAL_pin'?
  237 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
error: '__device_dts_ord_DT_N_ALIAS_isp_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
   85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)

However, now the weird part which took me a lot of time and mainly luck to figure out. When I only remove the module lines from the west.yml file (not the module files themselves) and execute the 'west update' command again the build succeeds. As soon as I configure the module again in the west.yml file and use 'west update', (so the exact same files are checked out) the build fails again with the same errors.

How does the west.yml influence the build process and how can I solve this problem?

Thank you.

Parents Reply Children
  • Hi Dejan,

    I just tried your suggestion and removing the EXTRA_ZEPHYR_MODULES does not seem to be the trick unfortunately. When I remove this line and add the submodule again in the west manifest, it fails with the same errors as in my original question.

    It does indeed try to build the module without needing the EXTRA_ZEPHYR_MODULES. Can it be possible that the build order is different when using it through the west manifest compared to the EXTRA_ZEPHYR_MODULES? 

    Best regards,

    Henrico

  • It does indeed try to build the module without needing the EXTRA_ZEPHYR_MODULES. Can it be possible that the build order is different when using it through the west manifest compared to the EXTRA_ZEPHYR_MODULES? 

    yes, the build order is different.
    Zephyr modules provided with `EXTRA_ZEPHYR_MODULES` are processed after `ZEPHYR_MODULES`.
    In general `ZEPHYR_MODULES` are obtained by `west list` but can also be provided as build argument.

    Therefore, when `test-module` is in the manifest at the location you present, then I assume that it comes first in the list (second in case your manifest project is also a Zephyr module)

    In general it is wise to have Zephyr modules self-contained, however this is not always possible, and in situations where a Zephyr module depends on other modules, then one should add `depends:` to the module.yml file.

    For example the following will add a dependency between your module `and hal_nordic`:

    name: test-module

    build:
      depends:
      - hal_nordic
      cmake: .
      kconfig: ./library/Kconfig

    docs.zephyrproject.org/.../modules.html

Related