Example of LSM6DS not compilng

Hello  i tried a lot but i am unable to Compile this , its is expected examples available in sdk should compile smoothly if there are no changes in it,

 i was expecting remote support i trying from 2 days am too fustrated, pls support via zoom or google meet or linkedin :swapnilsurule,

===================================================================================

main.c :


/*
 * Copyright (c) 2020 Yestin Sun
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>

static inline float out_ev(struct sensor_value *val)
{
    return (val->val1 + (float)val->val2 / 1000000);
}

static void fetch_and_display(const struct device *dev)
{
    struct sensor_value x, y, z;
    static int trig_cnt;

    trig_cnt++;

    /* lsm6ds3 accel */
    sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &x);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &y);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &z);

    printf("accel x:%f ms/2 y:%f ms/2 z:%f ms/2
",
            (double)out_ev(&x), (double)out_ev(&y), (double)out_ev(&z));

    /* lsm6ds3 gyro */
    sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &x);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &y);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &z);

    printf("gyro x:%f rad/s y:%f rad/s z:%f rad/s
",
            (double)out_ev(&x), (double)out_ev(&y), (double)out_ev(&z));

    printf("trig_cnt:%d

", trig_cnt);
}

static int set_sampling_freq(const struct device *dev)
{
    int ret = 0;
    struct sensor_value odr_attr;

    /* set accel/gyro sampling frequency to 12.5 Hz */
    odr_attr.val1 = 12.5;
    odr_attr.val2 = 0;

    ret = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
            SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr);
    if (ret != 0) {
        printf("Cannot set sampling frequency for accelerometer.\n");
        return ret;
    }

    ret = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
            SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr);
    if (ret != 0) {
        printf("Cannot set sampling frequency for gyro.\n");
        return ret;
    }

    return 0;
}

#ifdef CONFIG_LSM6DSO_TRIGGER
static void trigger_handler(const struct device *dev,
                const struct sensor_trigger *trig)
{
    fetch_and_display(dev);
}

static void test_trigger_mode(const struct device *dev)
{
    struct sensor_trigger trig;

    if (set_sampling_freq(dev) != 0)
        return;

    trig.type = SENSOR_TRIG_DATA_READY;
    trig.chan = SENSOR_CHAN_ACCEL_XYZ;

    if (sensor_trigger_set(dev, &trig, trigger_handler) != 0) {
        printf("Could not set sensor type and channel\n");
        return;
    }
}

#else
static void test_polling_mode(const struct device *dev)
{
    if (set_sampling_freq(dev) != 0) {
        return;
    }

    while (1) {
        fetch_and_display(dev);
        k_sleep(K_MSEC(1000));
    }
}
#endif

int main(void)
{
    const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso3);

    if (!device_is_ready(dev)) {
        printk("%s: device not ready.\n", dev->name);
        return 0;
    }

#ifdef CONFIG_LSM6DSO_TRIGGER
    printf("Testing LSM6DS3 sensor in trigger mode.\n\n");
    test_trigger_mode(dev);
#else
    printf("Testing LSM6DS3 sensor in polling mode.\n\n");
    test_polling_mode(dev);
#endif
    return 0;
}

===========================================================================================

prj.conf
CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y


CONFIG_SENSOR_LSM6DS3=y
CONFIG_CBPRINTF_FP_SUPPORT=y

# Set trigger support options correctly

CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y
CONFIG_SENSOR=y                 # Enable sensor drivers
CONFIG_LSM6DSO=y                # Enable the LSM6DSO driver
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y  # Use the global thread for trigger handling


CONFIG_I2C_NRFX=y                     # Nordic's I2C driver for nRF devices
CONFIG_I2C_NRF_TWIM=y                 # Enable I2C using the TWIM peripheral
CONFIG_GPIO=y                         # Enable GPIO support (for interrupt lines)
CONFIG_GPIO_NRFX=y                    # Nordic GPIO driver
==============================================================================================
CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(lsm6ds3_project)

target_sources(app PRIVATE src/main.c)

=================================================================================================

Latest Error
* Executing task: nRF Connect: Build: lsm6ds3_project_5/build (active)

Building lsm6ds3_project_5
C:\Windows\system32\cmd.exe /d /s /c "west build --build-dir c:/nordic/lsm6ds3_project_5/build c:/nordic/lsm6ds3_project_5"

-- west build: generating a build system
Loading Zephyr default modules (Zephyr base (cached)).
-- Application: C:/nordic/lsm6ds3_project_5
-- CMake version: 3.21.0
-- Cache files will be written to: C:/ncs/v2.6.1/zephyr/.cache
-- Zephyr version: 3.5.99 (C:/ncs/v2.6.1/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nrf52840dk_nrf52840
-- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
-- Found BOARD.dts: C:/ncs/v2.6.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Found devicetree overlay: C:/nordic/lsm6ds3_project_5/nrf52840dk_nrf52840.overlay
-- Generated zephyr.dts: C:/nordic/lsm6ds3_project_5/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/nordic/lsm6ds3_project_5/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/nordic/lsm6ds3_project_5/build/zephyr/dts.cmake

warning: LSM6DSO (defined at drivers/sensor/lsm6dso/Kconfig:6) was assigned the value 'y' but got
the value 'n'. Check these unsatisfied dependencies: DT_HAS_ST_LSM6DSO_ENABLED (=n). See
docs.zephyrproject.org/.../kconfig.html and/or look up LSM6DSO 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.


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.


C:/nordic/lsm6ds3_project_5/prj.conf:5: warning: attempt to assign the value 'y' to the undefined symbol SENSOR_LSM6DS3

C:/nordic/lsm6ds3_project_5/prj.conf:18: warning: attempt to assign the value 'y # Enable I2C using the TWIM peripheral' to the undefined symbol I2C_NRF_TWIM
Parsing C:/ncs/v2.6.1/zephyr/Kconfig
Loaded configuration 'C:/ncs/v2.6.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
Merged configuration 'C:/nordic/lsm6ds3_project_5/prj.conf'

error: Aborting due to Kconfig warnings

CMake Error at C:/ncs/v2.6.1/zephyr/cmake/modules/kconfig.cmake:358 (message):
command failed with return code: 1
Call Stack (most recent call first):
C:/ncs/v2.6.1/nrf/cmake/modules/kconfig.cmake:29 (include)
C:/ncs/v2.6.1/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
CMakeLists.txt:2 (find_package)


-- Configuring incomplete, errors occurred!
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\cf2149caf2\opt\bin\cmake.EXE' -DWEST_PYTHON=C:/ncs/toolchains/cf2149caf2/opt/bin/python.exe '-Bc:\nordic\lsm6ds3_project_5\build' -GNinja '-Sc:\nordic\lsm6ds3_project_5'

* The terminal process terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
 
Parents
  • The error in your log clearly mentions that the device tree entry is missing for your sensor.

    warning: LSM6DSO (defined at drivers/sensor/lsm6dso/Kconfig:6) was assigned the value 'y' but got
    the value 'n'. Check these unsatisfied dependencies: DT_HAS_ST_LSM6DSO_ENABLED (=n). See
    http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_LSM6DSO and/or look up LSM6DSO 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.

    If this error is not very obvious for you then I recommend you to read nRF Connect SDK Intermediate course, Lesson 2 - Debugging, provides a section on Troubleshooting the devicetree. It discusses common errors you might face while working with the devicetree.

    To add the LSM6DSO sensor to the device tree of the nRF52 DK, you need to modify the device tree source (DTS) file for your board. The DTS file is usually located in the boards directory of your Zephyr project.
    Here is an example of how you might add the LSM6DSO sensor to the I2C bus:

    &i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        clock-frequency = <I2C_BITRATE_FAST>;
    
        lsm6dso@6a {
            compatible = "st,lsm6dso";
            reg = <0x6a>;
            irq-gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
            status = "okay";
        };
    };
    Please use the above for reference only and you need to adjust the value of the gpio number used for irq-gpios which matches your setup.
    There are also a lot of undefined symbols you tried to define in the prj.conf, not sure where you got those values from? 
    I recommend you start with ncs\2.7.0\zephyr\samples\sensor\lsm6dso, add the device tree node as above in the device overlay file and go from there.
Reply
  • The error in your log clearly mentions that the device tree entry is missing for your sensor.

    warning: LSM6DSO (defined at drivers/sensor/lsm6dso/Kconfig:6) was assigned the value 'y' but got
    the value 'n'. Check these unsatisfied dependencies: DT_HAS_ST_LSM6DSO_ENABLED (=n). See
    http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_LSM6DSO and/or look up LSM6DSO 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.

    If this error is not very obvious for you then I recommend you to read nRF Connect SDK Intermediate course, Lesson 2 - Debugging, provides a section on Troubleshooting the devicetree. It discusses common errors you might face while working with the devicetree.

    To add the LSM6DSO sensor to the device tree of the nRF52 DK, you need to modify the device tree source (DTS) file for your board. The DTS file is usually located in the boards directory of your Zephyr project.
    Here is an example of how you might add the LSM6DSO sensor to the I2C bus:

    &i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        clock-frequency = <I2C_BITRATE_FAST>;
    
        lsm6dso@6a {
            compatible = "st,lsm6dso";
            reg = <0x6a>;
            irq-gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
            status = "okay";
        };
    };
    Please use the above for reference only and you need to adjust the value of the gpio number used for irq-gpios which matches your setup.
    There are also a lot of undefined symbols you tried to define in the prj.conf, not sure where you got those values from? 
    I recommend you start with ncs\2.7.0\zephyr\samples\sensor\lsm6dso, add the device tree node as above in the device overlay file and go from there.
Children
  • bro i was expecting little remote support , i can share my screen i did 6-7 attempts, just 20-25 min google meet call. i  was stuck there 3 days ago, just errors are changing but it isnt compiling(building), 
    last recent logs it shows boilarplate.....

    Call Stack (most recent call first):
    C:/ncs/v2.6.1/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
    C:/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
    C:/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
    CMakeLists.txt:4 (find_package)


    -- Configuring incomplete, errors occurred!

    Exercise 1 form lesson 6 in Fundamental course, it is too not working even after doing everything step by step,
    Even from Kconfig GUI its not allowing to enable LSM6DSO , 

    pls let me know, whenever  you are available..

  • Hello Swapnil,

    Apologies for the delayed response. I was unwell over the weekend and just resumed work today, which caused the delay. I’m sorry if this caused any inconvenience.

    As my colleague explained, the error you're encountering is related to the use of the DEVICE_DT_GET_ONE macro in the code when building the sample for the nRF52840 Development Kit. The macro is expecting device tree nodes that might not be properly defined for the nRF52840DK.

    To be more precise, the DEVICE_DT_GET_ONE(st_lsm6dso) macro is trying to fetch a device node for the LSM6DSO sensor from the device tree. If you review the README of this sample, you'll find that it is not supported out of the box for the nRF52840, as it was tested specifically for the STM32L562E-DK board. The STM32 board likely has this sensor enabled and configured by default in its device tree, but the nRF52840DK does not.

    To resolve this, you need to modify the device tree for the nRF52840DK to include the configuration for the LSM6DSO sensor over I2C. You can do this by creating or modifying an overlay file (refer to the one shared by my colleague).

    Nordic_Swapnil said:
    bro i was expecting little remote support , i can share my screen i did 6-7 attempts, just 20-25 min google meet call.

    I’m afraid we don’t provide support this way. The only proper channel for support is via Devzone.

    Nordic_Swapnil said:
    Exercise 1 form lesson 6 in Fundamental course, it is too not working even after doing everything step by step,

    I'm not sure what the issue with the DevAcademy lessons is. The lessons work properly for me. Since you haven't provided any details on the error, I can't comment on the issue you're experiencing. You might want to refer to the solution provided for the particular exercise. Check the solution and ensure you have followed all the steps correctly.

    Kind Regards,

    Abhijith

Related