Problem with Out of Tree Driver Build

I have been banging my head against this wall for a long time now. I am trying to add support for the NAU7802 sensor based on this repository: https://github.com/TinNotTim/nau7802_loadcell_zephyr_driver/blob/main/Kconfig

I am using the latest 2.7.0 nRF Connect release building for the xiao_ble_sense board. I cannot roll back to 2.6.1 as there is a bug with the LSM6DSL sensor implementation. 

I CANNOT get it to build for the life of me. I am getting a multitude of errors:

1. On a pristine build I always get an error with trying to include the `offsets.h` file. The error is documented in this ticket, but it is not my main focus right now as it goes away after a rebuild. 

In file included from /opt/nordic/ncs/v2.6.1/zephyr/include/zephyr/app_memory/app_memdomain.h:9,
                 from /opt/nordic/ncs/v2.6.1/zephyr/include/zephyr/rtio/rtio.h:31,
                 from /opt/nordic/ncs/v2.6.1/zephyr/include/zephyr/drivers/sensor.h:28,
                 from /Users/ericpietrowicz/firmware/nau7802-test-delete-me/drivers/sensor/nau7802/nau7802.h:13,
                 from /Users/ericpietrowicz/firmware/nau7802-test-delete-me/drivers/sensor/nau7802/nau7802_trigger.c:7:
/opt/nordic/ncs/v2.6.1/zephyr/include/zephyr/linker/linker-defs.h:26:10: fatal error: offsets.h: No such file or directory
   26 | #include <offsets.h>
      |          ^~~~~~~~~~~
compilation terminated.

2. After the first build, I am getting a mess of device tree errors that I can't easily parse.

note: in expansion of macro 'DT_INST_FOREACH_STATUS_OKAY'
  596 | DT_INST_FOREACH_STATUS_OKAY(CREATE_NAU7802_INST)

Does anyone have any ideas? I've attached a minimal version of the failing project here. I suspect it might be something with my Kconfigs (below) but I really have no idea as I just have so many linting errors all over the project.

menu "Zephyr"
source "Kconfig.zephyr"
endmenu

rsource "drivers/Kconfig"

nau7802-test-delete-me.zip

  • Hello,

    Could you please share the exact error message you're encountering while building? The snippet you provided doesn't give much insight into the issue you're facing. If possible, try attaching the entire build log here. You can use the "Insert" tab to do that.

    Kind regards,
    Abhijith

  • I'm sorry, please see updated .zip file. This contains a sample build that fails with the following error:

    [167/172] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /Users/ericpietrowicz/firmware/nau7802-test-delete-me/build/zephyr/zephyr_pre0.map 
    : && ccache /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/ericpietrowicz/firmware/nau7802-test-delete-me/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/libarch__arm__core.a  zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a  zephyr/arch/arch/arm/core/mpu/libarch__arm__core__mpu.a  zephyr/lib/libc/picolibc/liblib__libc__picolibc.a  zephyr/lib/libc/common/liblib__libc__common.a  zephyr/soc/soc/nrf52840/libsoc__nordic.a  zephyr/drivers/usb/device/libdrivers__usb__device.a  zephyr/drivers/usb/common/nrf_usbd_common/libdrivers__usb__common__nrf_usbd_common.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/hwinfo/libdrivers__hwinfo.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/regulator/libdrivers__regulator.a  zephyr/drivers/sensor/nordic/temp/libdrivers__sensor__nordic__temp.a  zephyr/drivers/sensor/st/lsm6dsl/libdrivers__sensor__st__lsm6dsl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/spi/libdrivers__spi.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/drivers/hw_cc3xx/lib..__nrf__drivers__hw_cc3xx.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp"  -L/Users/ericpietrowicz/firmware/nau7802-test-delete-me/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfp16-format=ieee  -mtp=soft  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  -DPICOLIBC_LONG_LONG_PRINTF_SCANF  /opt/nordic/ncs/v2.7.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.19.a  --specs=picolibc.specs  -lc  -lgcc && cd /Users/ericpietrowicz/firmware/nau7802-test-delete-me/build/zephyr && /opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/cmake -E true
    /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main':
    /Users/ericpietrowicz/firmware/nau7802-test-delete-me/src/main.c:21: undefined reference to `__device_dts_ord_110'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/f8037e9b83/bin/cmake --build /Users/ericpietrowicz/firmware/nau7802-test-delete-me/build
    6406.nau7802-test-delete-me.zip

  • Hello,

    From the logs you shared, the specific error is an undefined reference to __device_dts_ord_110, which typically means that the linker can't find a symbol that should be defined in the device tree or its associated source files. I recommend following the Zephyr guide on troubleshooting the device tree and checking if any of the steps mentioned will resolve the issue. Please let me know the update.

    Kind regards,

    Abhijith

  • I was able to figure this out but only by digging deep into the Zephyr Discord. I was missing a `Zephyr` folder in my `drivers` subdirectory with the following `module.yaml`:

    name: NAU7802_LOADCELL
    build:
      cmake: .
      kconfig: Kconfig
      settings:
        dts_root: .

    I then had to update my CMakeLists.txt to the following (note the list(APPEND...) line):

    cmake_minimum_required(VERSION 3.20.0)
    
    list(APPEND ZEPHYR_EXTRA_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/drivers")
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    
    project(nau7802-test-delete-me)
    
    target_sources(app PRIVATE src/main.c)
    

    I created a stand alone Github repository with the example that now compiles.

Related