compile lsm6dso example for a nrf5340

I'm trying to compile the lsm6dso example for a nrf5340. I also tried the nrf52832, but I get the same error.

v2.4.2\zephyr\samples\sensor\lsm6dso

prj.conf:

CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y 
(yellow squiggly)
##CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD was assigned the value y, but got the value n. Missing dependencies:
##<choice LSM6DSO_TRIGGER_MODE>

CONFIG_CBPRINTF_FP_SUPPORT=y
---

PS C:\nrf\lsm6dso> west build -b nrf5340dk_nrf5340_cpuapp
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: C:/nrf/lsm6dso
-- CMake version: 3.20.5
-- Using NCS Toolchain 2.4.0 for building. (C:/ncs/toolchains/31f4403e35/cmake)
-- Found Python3: C:/ncs/toolchains/31f4403e35/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
-- Cache files will be written to: C:/ncs/v2.4.2/zephyr/.cache
-- Zephyr version: 3.3.99 (C:/ncs/v2.4.2/zephyr)
-- Found west (found suitable version "1.0.0", minimum required is "0.7.1")
-- Board: nrf5340dk_nrf5340_cpuapp
-- Found host-tools: zephyr 0.16.0 (C:/ncs/toolchains/31f4403e35/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.16.0 (C:/ncs/toolchains/31f4403e35/opt/zephyr-sdk)
-- Found Dtc: C:/ncs/toolchains/31f4403e35/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found BOARD.dts: C:/ncs/v2.4.2/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
-- Generated zephyr.dts: C:/nrf/lsm6dso/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/nrf/lsm6dso/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/nrf/lsm6dso/build/zephyr/dts.cmake

warning: The choice symbol LSM6DSO_TRIGGER_GLOBAL_THREAD (defined at
drivers/sensor/lsm6dso/Kconfig:28) was selected (set =y), but no symbol ended up as the choice
selection. See
docs.zephyrproject.org/.../kconfig.html and/or look
up LSM6DSO_TRIGGER_GLOBAL_THREAD in the menuconfig/guiconfig interface. The Application Development
Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
might be helpful too.

Parsing C:/ncs/v2.4.2/zephyr/Kconfig
Loaded configuration 'C:/ncs/v2.4.2/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
Merged configuration 'C:/nrf/lsm6dso/prj.conf'
Configuration saved to 'C:/nrf/lsm6dso/build/zephyr/.config'
Kconfig header saved to 'C:/nrf/lsm6dso/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
CMake Warning at C:/ncs/v2.4.2/zephyr/CMakeLists.txt:839 (message):
No SOURCES given to Zephyr library: lib__libc__common

Excluding target from build.


-- Configuring done
-- Generating done
-- Build files have been written to: C:/nrf/lsm6dso/build
←[92m-- west build: building application
[1/171] Generating include/generated/version.h
-- Zephyr version: 3.3.99 (C:/ncs/v2.4.2/zephyr), build: v3.3.99-ncs1-1
[35/171] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj
C:\ncs\toolchains\31f4403e35\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DUSE_PARTITION_MANAGER=0 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.4.2/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.4.2/zephyr/soc/arm/nordic_nrf/nrf53 -IC:/ncs/v2.4.2/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.4.2/nrf/include -IC:/ncs/v2.4.2/nrf/tests/include -IC:/ncs/v2.4.2/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.4.2/modules/hal/nordic/nrfx -IC:/ncs/v2.4.2/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.4.2/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.4.2/zephyr/modules/hal_nordic/nrfx/. -isystem C:/ncs/v2.4.2/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -isystem C:/ncs/v2.4.2/nrfxlib/crypto/nrf_cc312_platform/include -fno-strict-aliasing -Os -imacros C:/nrf/lsm6dso/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs --sysroot=C:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.4.2/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/nrf/lsm6dso=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.4.2/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.4.2=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
In file included from C:/ncs/v2.4.2/zephyr/include/zephyr/sys/util_macro.h:34,
from C:/ncs/v2.4.2/zephyr/include/zephyr/sys/atomic.h:16,
from C:/ncs/v2.4.2/zephyr/include/zephyr/kernel_includes.h:21,
from C:/ncs/v2.4.2/zephyr/include/zephyr/kernel.h:17,
from ../src/main.c:8:
../src/main.c: In function 'main':
C:/ncs/v2.4.2/zephyr/include/zephyr/sys/util.h:91:55: error: size of unnamed array is negative
91 | #define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
| ^
C:/ncs/v2.4.2/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
72 | #define __DEBRACKET(...) __VA_ARGS__
| ^~~~~~~~~~~
C:/ncs/v2.4.2/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
| ^~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.4.2/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~
C:/ncs/v2.4.2/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1'
180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~~~
C:/ncs/v2.4.2/zephyr/include/zephyr/device.h:278:9: note: in expansion of macro 'COND_CODE_1'
278 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
| ^~~~~~~~~~~
C:/ncs/v2.4.2/zephyr/include/zephyr/device.h:280:22: note: in expansion of macro 'ZERO_OR_COMPILE_ERROR'
280 | (ZERO_OR_COMPILE_ERROR(0)))
| ^~~~~~~~~~~~~~~~~~~~~
../src/main.c:110:42: note: in expansion of macro 'DEVICE_DT_GET_ONE'
110 | const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);
| ^~~~~~~~~~~~~~~~~
[44/171] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/cbprintf_packaged.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\31f4403e35\opt\bin\cmake.EXE' --build 'C:\nrf\lsm6dso\build'
PS C:\nrf\lsm6dso>

Parents
  • Hi,

    It seems you get this error because the sensor device is not defined in the devicetree for the target that you are building for. Not all samples in Zephyr are created for Nordic boards, so you need to define the sensor yourself and assign it to one of the i2c/spi nodes. I would recommend you to go through the nRF Connect SDK Fundamentals tutorial to learn how this is done, specifically lesson 6 is directly relevant to your problem. 

    The shield used in the lesson 6, exercise 1 contains the sensor you are trying to use, so you should be able to use a similar devicetree definition for the nRF5340/nRF52832 boards as well.

    Best regards,
    Jørgen

  • Thanks! I made progress programming directly with I2C. I tried switching devices to the LSM6DSO32 and using the Zephry sample. I almost got it work, but if fails here:

    const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso32); //compile error

    I am new to Zephyr. I thought I set everything up correctly, but I am missing something. Can you take a look at my attached to see if it's something obvious?

    https://github.com/mej558/lsm6dso_7.git

    int main(void)
    {
    	const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso32);
    	// const struct device *const dev = NULL; // this compiles...
    
    	if (!device_is_ready(dev)) {
    		printk("%s: device not ready.\n", dev->name);
    		return 0;
    	}
    
    #ifdef CONFIG_LSM6DSO_TRIGGER
    	printf("Testing LSM6DSO sensor in trigger mode.\n\n");
    	test_trigger_mode(dev);
    #else
    	printf("Testing LSM6DSO sensor in polling mode.\n\n");
    	test_polling_mode(dev);
    #endif
    	return 0;
    }

    [156/156] Generating ../bin/tfm_s.bin
    [15/220] Performing install step for 'tfm'
    -- Install configuration: "MinSizeRel"
    [213/220] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf -fuse-ld=bfd -T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=C:/nrf/lsm6dso_7/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/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/picolibc/liblib__libc__picolibc.a zephyr/lib/libc/common/liblib__libc__common.a zephyr/soc/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/subsys/random/libsubsys__random.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/entropy/libdrivers__entropy.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/i2c/libdrivers__i2c.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/subsys/nrf_security/src/zephyr/libmbedtls_zephyr.a modules/nrf/modules/tfm/zephyr/libtfm_api_nrf.a modules/trusted-firmware-m/libtfm_api.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp" -LC:/nrf/lsm6dso_7/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a tfm/secure_fw/s_veneers.o -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_DOUBLE_PRINTF_SCANF modules/nrf/subsys/nrf_security/src/libmbedcrypto.a C:/ncs/v2.5.1/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_mbedtls_3.0.13.a modules/nrf/subsys/nrf_security/src/libmbedcrypto_base.a -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee C:/ncs/v2.5.1/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_3.0.13.a --specs=picolibc.specs -lc -lgcc && cmd.exe /C "cd /D C:\nrf\lsm6dso_7\build\zephyr && C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.exe -E true""
    c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `z_impl_sensor_channel_get':
    C:/ncs/v2.5.1/zephyr/include/zephyr/drivers/sensor.h:767: undefined reference to `__device_dts_ord_128'
    c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `test_polling_mode':
    C:\nrf\lsm6dso_7\build/../src/main.c:101: undefined reference to `__device_dts_ord_128'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.EXE' --build 'C:\nrf\lsm6dso_7\build'

Reply
  • Thanks! I made progress programming directly with I2C. I tried switching devices to the LSM6DSO32 and using the Zephry sample. I almost got it work, but if fails here:

    const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso32); //compile error

    I am new to Zephyr. I thought I set everything up correctly, but I am missing something. Can you take a look at my attached to see if it's something obvious?

    https://github.com/mej558/lsm6dso_7.git

    int main(void)
    {
    	const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso32);
    	// const struct device *const dev = NULL; // this compiles...
    
    	if (!device_is_ready(dev)) {
    		printk("%s: device not ready.\n", dev->name);
    		return 0;
    	}
    
    #ifdef CONFIG_LSM6DSO_TRIGGER
    	printf("Testing LSM6DSO sensor in trigger mode.\n\n");
    	test_trigger_mode(dev);
    #else
    	printf("Testing LSM6DSO sensor in polling mode.\n\n");
    	test_polling_mode(dev);
    #endif
    	return 0;
    }

    [156/156] Generating ../bin/tfm_s.bin
    [15/220] Performing install step for 'tfm'
    -- Install configuration: "MinSizeRel"
    [213/220] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf -fuse-ld=bfd -T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=C:/nrf/lsm6dso_7/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/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/picolibc/liblib__libc__picolibc.a zephyr/lib/libc/common/liblib__libc__common.a zephyr/soc/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/subsys/random/libsubsys__random.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/entropy/libdrivers__entropy.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/i2c/libdrivers__i2c.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/subsys/nrf_security/src/zephyr/libmbedtls_zephyr.a modules/nrf/modules/tfm/zephyr/libtfm_api_nrf.a modules/trusted-firmware-m/libtfm_api.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp" -LC:/nrf/lsm6dso_7/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a tfm/secure_fw/s_veneers.o -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_DOUBLE_PRINTF_SCANF modules/nrf/subsys/nrf_security/src/libmbedcrypto.a C:/ncs/v2.5.1/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_mbedtls_3.0.13.a modules/nrf/subsys/nrf_security/src/libmbedcrypto_base.a -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee C:/ncs/v2.5.1/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_3.0.13.a --specs=picolibc.specs -lc -lgcc && cmd.exe /C "cd /D C:\nrf\lsm6dso_7\build\zephyr && C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.exe -E true""
    c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `z_impl_sensor_channel_get':
    C:/ncs/v2.5.1/zephyr/include/zephyr/drivers/sensor.h:767: undefined reference to `__device_dts_ord_128'
    c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `test_polling_mode':
    C:\nrf\lsm6dso_7\build/../src/main.c:101: undefined reference to `__device_dts_ord_128'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.EXE' --build 'C:\nrf\lsm6dso_7\build'

Children
Related