Guidance Required for Contributing a New Sensor Driver to Zephyr/NCS

Hi everyone,

I have created a new sensor driver using the Zephyr Sensor API, including support for:

  • sample_fetch()

  • channel_get()

  • attr_set()

  • attr_get()

  • trigger handling

I developed the driver completely using Zephyr APIs and infrastructure, including:

  • <zephyr/device.h>

  • <zephyr/drivers/i2c.h>

  • <zephyr/drivers/gpio.h>

  • <zephyr/drivers/sensor.h>

  • <zephyr/sys/util.h>

Now I would like to contribute this sensor driver to Zephyr/NCS.

I checked the Zephyr contribution guide:
https://docs.nordicsemi.com/bundle/ncs-1.0.0/page/zephyr/contribute/index.html

However, I could not clearly understand the complete workflow for contributing a new sensor driver.

Could someone please provide a detailed explanation or step-by-step guide for:

  1. Where the driver should be added in Zephyr

  2. Required files (Kconfig, CMakeLists, DTS bindings, documentation, sample, tests, etc.)

  3. Coding style and checkpatch requirements

  4. How to create the GitHub pull request properly

  5. Whether contribution should go directly to Zephyr upstream or first into NCS

  6. Any mandatory CI/tests before submission

It would be very helpful for me to understand the proper contribution process.

Best regards,
Milan

Parents
  • Hi!

    Whether contribution should go directly to Zephyr upstream or first into NCS

    I suggest contributing it directly to Zephyr upstream. https://github.com/zephyrproject-rtos/zephyr

    It will then make it's way into our NCS Zephyr fork after that.

    For your other questions, I suggest asking in the Zephyr Discord: https://docs.zephyrproject.org/latest/develop/getting_started/index.html#asking-for-help

  • Hello Zephyr Community,

    First of all please private this thread because i am sharing critical info about my contribution and here

    I am trying to contribute a new sensor driver for the AMS AS7341 Spectral Sensor to Zephyr (using NCS v3.2.2 / Zephyr), and I would appreciate some guidance regarding CI/Twister failures during the contribution process.

    Environment

    • NCS Version: v3.2.2

    • Target Hardware: nRF9151

    • Driver: AMS AS7341 Spectral Sensor

    • Driver implemented using Zephyr Sensor API:

      • sample_fetch()

      • channel_get()

      • attr_set()

      • attr_get()

      • Trigger support APIs

    Driver Integration

    I added the driver under:

    zephyr/drivers/sensor/ams/ams_as7341/
    

    Files:

    ams_as7341.c
    ams_as7341.h
    Kconfig
    CMakeLists.txt
    

    I also updated:

    zephyr/drivers/sensor/ams/Kconfig
    zephyr/drivers/sensor/ams/CMakeLists.txt
    

    to include the new driver.

    Devicetree Binding

    Added:

    zephyr/dts/bindings/sensor/ams,as7341.yaml
    

    Content:

    # Copyright (c) 2026 Dotcom IoT LLP
    # SPDX-License-Identifier: Apache-2.0
    
    description: AMS AS7341 spectral sensor
    
    compatible: "ams,as7341"
    
    include:
      - sensor-device.yaml
      - i2c-device.yaml
    

    Twister Test

    Created:

    zephyr/tests/drivers/sensor/ams_as7341/
    

    Files:

    src/main.c

    #include <zephyr/ztest.h>
    #include <zephyr/drivers/sensor.h>
    
    ZTEST_SUITE(ams_as7341_tests, NULL, NULL, NULL, NULL, NULL);
    
    ZTEST(ams_as7341_tests, test_basic_assertions)
    {
    	zassert_true(1, "basic assertion failed");
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(ams_as7341_test)
    
    FILE(GLOB app_sources src/*.c)
    target_sources(app PRIVATE ${app_sources})
    

    prj.conf

    CONFIG_ZTEST=y
    CONFIG_SENSOR=y
    CONFIG_I2C=y
    CONFIG_AMS_AS7341=y
    

    testcase.yaml

    tests:
      drivers.sensor.ams_as7341:
        tags:
          - drivers
          - sensor
        platform_allow:
          - native_sim
        integration_platforms:
          - native_sim
        harness: ztest
    

    Local Validation

    Twister

    Executed:

    export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
    export ZEPHYR_SDK_INSTALL_DIR=/home/dnk133/ncs/toolchains/927563c840/opt/zephyr-sdk
    
    ~/ncs/v3.2.2/zephyr/scripts/twister \
        -T tests/drivers/sensor/ams_as7341 \
        -p native_sim \
        -v
    

    Result:

    PASS
    

    Checkpatch

    Executed:

    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/ams_as7341.c
    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/ams_as7341.h
    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/Kconfig
    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/CMakeLists.txt
    ./scripts/checkpatch.pl --file dts/bindings/sensor/ams,as7341.yaml
    

    Result:

    No checkpatch errors reported
    

    CI Failure

    However, after creating the pull request, CI fails during the Twister build stage.

    From the CI log, I see errors similar to:

    error: as7341_init defined but not used [-Werror=unused-function]
    

    and multiple failures such as:

    drivers.sensor.generic_test
    drivers.sensor.no_default
    drivers.sensor.pm
    drivers.sensor.trigger.own
    

    The failure seems to occur on the native_sim/native build configurations.

    Screenshot attached below for reference.

    My Questions

    1. Why does the driver pass local Twister testing but fail in Zephyr CI?

    2. Is as7341_init() expected to be conditionally compiled using a DT_INST macro?

    3. Could the failure be caused by:

      • Missing DT_INST_FOREACH_STATUS_OKAY() usage?

      • Missing device instantiation macros?

      • Missing Kconfig dependencies?

      • Driver being compiled even when no AS7341 instance exists in the build?

    4. Are there additional sensor-driver tests that must be added beyond a simple ZTest application?

    5. Is there any recommended checklist for contributing a new sensor driver to Zephyr/NCS?

    Any suggestions on what I should inspect next would be greatly appreciated.

    Thank you for your time and guidance.

    Best Regards,
    Milan Pipaliya

Reply
  • Hello Zephyr Community,

    First of all please private this thread because i am sharing critical info about my contribution and here

    I am trying to contribute a new sensor driver for the AMS AS7341 Spectral Sensor to Zephyr (using NCS v3.2.2 / Zephyr), and I would appreciate some guidance regarding CI/Twister failures during the contribution process.

    Environment

    • NCS Version: v3.2.2

    • Target Hardware: nRF9151

    • Driver: AMS AS7341 Spectral Sensor

    • Driver implemented using Zephyr Sensor API:

      • sample_fetch()

      • channel_get()

      • attr_set()

      • attr_get()

      • Trigger support APIs

    Driver Integration

    I added the driver under:

    zephyr/drivers/sensor/ams/ams_as7341/
    

    Files:

    ams_as7341.c
    ams_as7341.h
    Kconfig
    CMakeLists.txt
    

    I also updated:

    zephyr/drivers/sensor/ams/Kconfig
    zephyr/drivers/sensor/ams/CMakeLists.txt
    

    to include the new driver.

    Devicetree Binding

    Added:

    zephyr/dts/bindings/sensor/ams,as7341.yaml
    

    Content:

    # Copyright (c) 2026 Dotcom IoT LLP
    # SPDX-License-Identifier: Apache-2.0
    
    description: AMS AS7341 spectral sensor
    
    compatible: "ams,as7341"
    
    include:
      - sensor-device.yaml
      - i2c-device.yaml
    

    Twister Test

    Created:

    zephyr/tests/drivers/sensor/ams_as7341/
    

    Files:

    src/main.c

    #include <zephyr/ztest.h>
    #include <zephyr/drivers/sensor.h>
    
    ZTEST_SUITE(ams_as7341_tests, NULL, NULL, NULL, NULL, NULL);
    
    ZTEST(ams_as7341_tests, test_basic_assertions)
    {
    	zassert_true(1, "basic assertion failed");
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(ams_as7341_test)
    
    FILE(GLOB app_sources src/*.c)
    target_sources(app PRIVATE ${app_sources})
    

    prj.conf

    CONFIG_ZTEST=y
    CONFIG_SENSOR=y
    CONFIG_I2C=y
    CONFIG_AMS_AS7341=y
    

    testcase.yaml

    tests:
      drivers.sensor.ams_as7341:
        tags:
          - drivers
          - sensor
        platform_allow:
          - native_sim
        integration_platforms:
          - native_sim
        harness: ztest
    

    Local Validation

    Twister

    Executed:

    export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
    export ZEPHYR_SDK_INSTALL_DIR=/home/dnk133/ncs/toolchains/927563c840/opt/zephyr-sdk
    
    ~/ncs/v3.2.2/zephyr/scripts/twister \
        -T tests/drivers/sensor/ams_as7341 \
        -p native_sim \
        -v
    

    Result:

    PASS
    

    Checkpatch

    Executed:

    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/ams_as7341.c
    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/ams_as7341.h
    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/Kconfig
    ./scripts/checkpatch.pl --file drivers/sensor/ams/ams_as7341/CMakeLists.txt
    ./scripts/checkpatch.pl --file dts/bindings/sensor/ams,as7341.yaml
    

    Result:

    No checkpatch errors reported
    

    CI Failure

    However, after creating the pull request, CI fails during the Twister build stage.

    From the CI log, I see errors similar to:

    error: as7341_init defined but not used [-Werror=unused-function]
    

    and multiple failures such as:

    drivers.sensor.generic_test
    drivers.sensor.no_default
    drivers.sensor.pm
    drivers.sensor.trigger.own
    

    The failure seems to occur on the native_sim/native build configurations.

    Screenshot attached below for reference.

    My Questions

    1. Why does the driver pass local Twister testing but fail in Zephyr CI?

    2. Is as7341_init() expected to be conditionally compiled using a DT_INST macro?

    3. Could the failure be caused by:

      • Missing DT_INST_FOREACH_STATUS_OKAY() usage?

      • Missing device instantiation macros?

      • Missing Kconfig dependencies?

      • Driver being compiled even when no AS7341 instance exists in the build?

    4. Are there additional sensor-driver tests that must be added beyond a simple ZTest application?

    5. Is there any recommended checklist for contributing a new sensor driver to Zephyr/NCS?

    Any suggestions on what I should inspect next would be greatly appreciated.

    Thank you for your time and guidance.

    Best Regards,
    Milan Pipaliya

Children
No Data
Related