From 47bf9ee51cc739070d40407c18a08765726f1692 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Thu, 25 Aug 2022 14:56:57 -0700 Subject: [PATCH] samples: sensors: add a new one for lsm6dso as I2C on I3C bus This adds some skeleton files to enable using LSM6DSO on I3C bus while still acting like a I2C device. The new files here are simply to provide a way to have overlay for each board that would not conflict with the pure I2C one. Also this is set to build only because it require external hardware that is not necessary on the board being tested. Signed-off-by: Daniel Leung --- .../sensor/lsm6dso_i2c_on_i3c/CMakeLists.txt | 8 ++ samples/sensor/lsm6dso_i2c_on_i3c/README.rst | 78 +++++++++++++++++++ .../boards/mimxrt685_evk_cm33.conf | 4 + .../boards/mimxrt685_evk_cm33.overlay | 24 ++++++ samples/sensor/lsm6dso_i2c_on_i3c/prj.conf | 7 ++ samples/sensor/lsm6dso_i2c_on_i3c/sample.yaml | 17 ++++ 6 files changed, 138 insertions(+) create mode 100644 samples/sensor/lsm6dso_i2c_on_i3c/CMakeLists.txt create mode 100644 samples/sensor/lsm6dso_i2c_on_i3c/README.rst create mode 100644 samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.conf create mode 100644 samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.overlay create mode 100644 samples/sensor/lsm6dso_i2c_on_i3c/prj.conf create mode 100644 samples/sensor/lsm6dso_i2c_on_i3c/sample.yaml diff --git a/samples/sensor/lsm6dso_i2c_on_i3c/CMakeLists.txt b/samples/sensor/lsm6dso_i2c_on_i3c/CMakeLists.txt new file mode 100644 index 00000000000..e8d59f2305d --- /dev/null +++ b/samples/sensor/lsm6dso_i2c_on_i3c/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(lsm6dso_i2c_on_i3c) + +FILE(GLOB app_sources ../lsm6dso/src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/sensor/lsm6dso_i2c_on_i3c/README.rst b/samples/sensor/lsm6dso_i2c_on_i3c/README.rst new file mode 100644 index 00000000000..eb449879638 --- /dev/null +++ b/samples/sensor/lsm6dso_i2c_on_i3c/README.rst @@ -0,0 +1,78 @@ +.. _lsm6dso_i2c_on_i3c: + +LSM6DSO: IMU Sensor Monitor (I2C on I3C bus) +############################################ + +Overview +******** +This sample sets the date rate of LSM6DSO accelerometer and gyroscope to +12.5Hz and enables a trigger on data ready. It displays on the console +the values for accelerometer and gyroscope. + +Requirements +************ + +This sample uses the LSM6DSO sensor controlled using the I2C interface +exposed by the I3C controller. It has been tested using the LSM6DSO on +the evaluation board STEVAL-MKI196V1 connected to the I3C header +on :ref:`mimxrt685_evk`. + +References +********** + +- LSM6DSO http://www.st.com/en/mems-and-sensors/lsm6dso.html + +Building and Running +******************** + +This project outputs sensor data to the console. It requires an LSM6DSO +sensor (for example, the one on evaluation board STEVAL-MKI196V1). + +Building on mimxrt685_evk_cm33 board +==================================== + +.. zephyr-app-commands:: + :zephyr-app: samples/sensor/lsm6dso_i2c_on_i3c + :host-os: unix + :board: mimxrt685_evk_cm33 + :goals: build + :compact: + +Board Preparations +================== + +mimxrt685_evk_cm33 +------------------ + +On the board :ref:`mimxrt685_evk`, the I3C pins are exposed on the J18 +header, where: + + * SCL is on pin 1 + * SDA is on pin 2 + * Internal pull-up is on pin 3 (which is connected to pin 2 already) + * Ground is on pin4 + +LSM6DSO +^^^^^^^ + +A LSM6DSO sensor needs to be connected to this header. For example, +the evaluation board STEVAL-MKI196V1 can be used. This needs to be +prepared so that the LSM6DSO sensor has address 0x6B (i.e. 0xD6, +left-shifed). + +Sample Output +============= + +.. code-block:: console + + Testing LSM6DSO sensor in trigger mode. + + accel x:-0.650847 ms/2 y:-5.300102 ms/2 z:-8.163114 ms/2 + gyro x:-0.167835 dps y:-0.063377 dps z:0.002367 dps + trig_cnt:1 + + accel x:0.341575 ms/2 y:5.209773 ms/2 z:-7.938787 ms/2 + gyro x:-0.034284 dps y:-0.004428 dps z:-0.003512 dps + trig_cnt:2 + + diff --git a/samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.conf b/samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.conf new file mode 100644 index 00000000000..4256bd1d958 --- /dev/null +++ b/samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.conf @@ -0,0 +1,4 @@ +# Requires GPIO lines for interrupts, +# so disable trigger mode and use polling mode for now. +CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=n +CONFIG_LSM6DSO_TRIGGER_NONE=y diff --git a/samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.overlay b/samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.overlay new file mode 100644 index 00000000000..68087d8e2a9 --- /dev/null +++ b/samples/sensor/lsm6dso_i2c_on_i3c/boards/mimxrt685_evk_cm33.overlay @@ -0,0 +1,24 @@ +&i3c0 { + status = "okay"; + + /* + * There might be other connected I2C devices + * (for example, if using Arduino shield) which + * cannot tolerate high clock speed. So slow + * down the clock. + */ + i2c-scl-hz = <400000>; + i3c-scl-hz = <400000>; + i3c-od-scl-hz = <400000>; + + clk-divider = <12>; + clk-divider-slow = <1>; + clk-divider-tc = <1>; + + lsm6dso0: lsm6dso@6b0000000000000050 { + compatible = "st,lsm6dso"; + reg = <0x6b 0x00 0x50>; + + status = "okay"; + }; +}; diff --git a/samples/sensor/lsm6dso_i2c_on_i3c/prj.conf b/samples/sensor/lsm6dso_i2c_on_i3c/prj.conf new file mode 100644 index 00000000000..ff3cf22cc85 --- /dev/null +++ b/samples/sensor/lsm6dso_i2c_on_i3c/prj.conf @@ -0,0 +1,7 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_CBPRINTF_FP_SUPPORT=y + +CONFIG_I3C=y +CONFIG_SENSOR=y + +CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y diff --git a/samples/sensor/lsm6dso_i2c_on_i3c/sample.yaml b/samples/sensor/lsm6dso_i2c_on_i3c/sample.yaml new file mode 100644 index 00000000000..02ef4aa90f8 --- /dev/null +++ b/samples/sensor/lsm6dso_i2c_on_i3c/sample.yaml @@ -0,0 +1,17 @@ +sample: + name: LSM6DSO accelerometer and gyrometer sensor (I2C on I3C bus) +tests: + sample.sensor.lsm6dso.i2c_on_i3c_bus: + harness: console + tags: sensors + depends_on: i3c + filter: dt_compat_enabled("st,lsm6dso") + timeout: 15 + build_only: true + harness_config: + type: multi_line + ordered: true + regex: + - "accel x:[-.0-9]* ms/2 y:[-.0-9]* ms/2 z:[-.0-9]* ms/2" + - "gyro x:[-.0-9]* dps y:[-.0-9]* dps z:[-.0-9]* dps" + - "trig_cnt:[0-9]*"