Use of EXTRA_ZEPHYR_MODULES and custom board within a project with several freestanding apps


Some guidance on this query,please.
I have a project with several freestanding application (please check topology below). I would like all the apps to acccess a custom board definition. I use the same zephyr west workspace for several projects so I would not like to follow the example-application T2: Star topology.

For that purpose I have added a zephyr/moudles.yml with the following parameters:

# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

build:
settings:
# Additional roots for boards and DTS files. Zephyr will use the
# `<board_root>/boards` for additional boards. The `.` is the root of this
# repository.
board_root: .



and also added below line to CMakeList.txt file of each app:

set(EXTRA_ZEPHYR_MODULES ../)


File Structure

<opt/zephyr>/
└──── zephyrproject/
├─── .west/
│ └─── config
├── zephyr/
├── bootloader/
├── modules/
└── ...


<home/user>/
└─── project/
|───app1/
| ├── CMakeLists.txt
| ├── prj.conf
| └── src/
| └── main.c
|───app2/
| ├── CMakeLists.txt
| ├── prj.conf
| └── src/
| └── main.c
|───app3/
| ├── CMakeLists.txt
| ├── prj.conf
| └── src/
| └── main.c
|
|───boards/arm/custom_board
| └── ...
|
└── zephyr/
└── module.yml



Am I missing sth? Is this structure possible at all?

Thanks

  • Hello,

    I beleive you need to specify the absolute path to your zephyr module when setting it from your CMakelists.txt file before find_package().

    e.g.,

    cmake_minimum_required(VERSION ...
    set(EXTRA_ZEPHYR_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../")
    
    find_package(..
     

    Also, 'boards' should be a subdirectory of your module directory. 

    e.g.,

    my_module/
    ├── boards
    │   └── arm
    └── zephyr
    └── module.yml

    module.yml

    build:
      settings:
        board_root: .

    Another way to use an out-of-tree board without creating a new Zephyr module is to append the path to your board root to the BOARD_ROOT variable by adding the following line to your CMakeLists.txt file: 

    list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../)

    Regardless of the approach you use, you may need to specify the board root path in the VS code extension for it to detect your custom board:

    https://docs.nordicsemi.com/bundle/nrf-connect-vscode/page/guides/bd_boards_devices.html#finding-new-boards 

    Best regards,

    Vidar

  • Thanks for the prompt reply Vidar. If I try to set the module directly on the proect folder, I get the below error. Is there a way to overcome this? Is it a requirement to place the modules files on a separate directory?

    CMake Error at /opt/ncs/v2.6.0/zephyr/CMakeLists.txt:591 (add_subdirectory):
    The binary directory
    
    /home/x/git/zephyr_project_sample/source/build
    
    is already used to build a source directory. It cannot be used to build
    source directory
    
    /home/x/git/zephyr_project_sample
    
    Specify a unique binary directory name.

  • Hi,

    I tried testing this on my end but did not encounter any build errors. I've attached the test sample I created. Could you please review it to see what we are doing differently?

    external_module_test.zip

    Folder structure:

    external_module_test/
    ├── hello_world
    │   ├── build
    │   ├── CMakeLists.txt
    │   ├── prj.conf
    │   ├── README.rst
    │   ├── sample.yaml
    │   └── src
    ├── hello_world_1
    │   ├── build
    │   ├── CMakeLists.txt
    │   ├── prj.conf
    │   ├── README.rst
    │   ├── sample.yaml
    │   └── src
    └── my_module
    ├── boards
    └── zephyr

Related