Skip to content

Commit 44a67ea

Browse files
aviscontikartben
authored andcommitted
samples/sensor: Add sample to read RTIO stream using drdy
Add sample to read from up to 10 streaming devices, using the sensor_stream() API and the RTIO framework: https://docs.zephyrproject.org/latest/services/rtio/index.html The devices has to be aliased as streamN (0 <= N <= 9) in DT, and will be instantiated using SENSOR_DT_STREAM_IODEV() macro. Currently the sample gets/prints data on SENSOR_TRIG_DATA_READY trigger basis for the following sensor channels: - SENSOR_CHAN_ACCEL_XYZ Signed-off-by: Armando Visconti <[email protected]>
1 parent afe0abe commit 44a67ea

File tree

11 files changed

+415
-0
lines changed

11 files changed

+415
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2024 STMicroelectronics
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
project(stream_drdy)
8+
9+
FILE(GLOB app_sources src/*.c)
10+
target_sources(app PRIVATE ${app_sources})

samples/sensor/stream_drdy/README.rst

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
.. zephyr:code-sample:: stream_drdy
2+
:name: Generic device sample streaming using Data Ready trigger
3+
:relevant-api: sensor_interface
4+
5+
Get accelerometer data frames from a sensor using SENSOR_TRIG_DATA_READY.
6+
7+
Overview
8+
********
9+
10+
This sample application demonstrates how to stream accel data using the
11+
:ref:`RTIO framework <rtio>` based :ref:`Read and Decode method <sensor-read-and-decode>`.
12+
13+
The streaming is started using the sensor_stream() API and it is self-sustained by the
14+
SENSOR_TRIG_DATA_READY trigger.
15+
16+
Currently the sample gets/prints data only for the accel sensor channel:
17+
18+
- SENSOR_CHAN_ACCEL_XYZ
19+
20+
Building and Running
21+
********************
22+
23+
This sample supports up to 10 streaming devices. Each device needs
24+
to be aliased as ``streamN`` where ``N`` goes from ``0`` to ``9``. For example:
25+
26+
.. code-block:: devicetree
27+
28+
/ {
29+
aliases {
30+
stream0 = &lsm6dsv16x_6b_x_nucleo_iks4a1;
31+
};
32+
};
33+
34+
Example devicetree overlays and configurations are already available for sensortile_box_pro,
35+
nucleo_f401re and nucleo_h503rb in the boards directory:
36+
37+
- :zephyr_file:`samples/sensor/stream_drdy/boards/sensortile_box_pro.overlay`
38+
39+
DT overlay file for the sensortile_box_pro board.
40+
41+
- :zephyr_file:`samples/sensor/stream_drdy/boards/sensortile_box_pro.conf`
42+
43+
Configuration file for the sensortile_box_pro board.
44+
45+
- :zephyr_file:`samples/sensor/stream_drdy/boards/nucleo_f401re.overlay`
46+
47+
DT overlay file for the nucleo_f401re board.
48+
49+
- :zephyr_file:`samples/sensor/stream_drdy/boards/nucleo_f401re.conf`
50+
51+
Configuration file for the nucleo_f401re board.
52+
53+
- :zephyr_file:`samples/sensor/stream_drdy/boards/nucleo_h503rb.overlay`
54+
55+
DT overlay file for the nucleo_h503rb board.
56+
57+
- :zephyr_file:`samples/sensor/stream_drdy/boards/nucleo_h503rb.conf`
58+
59+
Configuration file for the nucleo_h503rb board.
60+
61+
For example, build and run sample for sensortile_box_pro with:
62+
63+
.. zephyr-app-commands::
64+
:zephyr-app: samples/sensor/stream_drdy
65+
:board: sensortile_box_pro
66+
:goals: build flash
67+
:compact:
68+
69+
Sample Output
70+
=============
71+
72+
The following example output is for a lsm6dsv16x IMU device with accelerometer sensor.
73+
The board used is a sensortile_box_pro.
74+
75+
.. code-block:: console
76+
77+
XL data for lsm6dsv16x@0 7320515312ns (-0.387584, 0.224894, 9.766184)
78+
XL data for lsm6dsv16x@0 7321538600ns (-0.363659, 0.282314, 9.948014)
79+
XL data for lsm6dsv16x@0 7322561362ns (-0.301454, 0.172259, 9.775754)
80+
XL data for lsm6dsv16x@0 7323584881ns (-0.210539, 0.153119, 9.857099)
81+
XL data for lsm6dsv16x@0 7324608368ns (-0.287099, 0.167474, 9.852314)
82+
XL data for lsm6dsv16x@0 7325631281ns (-0.306239, 0.181829, 9.847529)
83+
XL data for lsm6dsv16x@0 7326654425ns (-0.272744, 0.167474, 9.842744)
84+
XL data for lsm6dsv16x@0 7327677993ns (-0.296669, 0.224894, 9.981509)
85+
XL data for lsm6dsv16x@0 7328701506ns (-0.282314, 0.210539, 9.828389)
86+
XL data for lsm6dsv16x@0 7329724306ns (-0.244034, 0.153119, 9.866669)
87+
XL data for lsm6dsv16x@0 7330747556ns (-0.234464, 0.119624, 9.780539)
88+
XL data for lsm6dsv16x@0 7331771000ns (-0.239249, 0.148334, 9.933659)
89+
XL data for lsm6dsv16x@0 7332794575ns (-0.220109, 0.119624, 9.833174)
90+
XL data for lsm6dsv16x@0 7333817437ns (-0.205754, 0.119624, 9.823604)
91+
XL data for lsm6dsv16x@0 7334840643ns (-0.205754, 0.148334, 9.866669)
92+
XL data for lsm6dsv16x@0 7335864162ns (-0.186614, 0.129194, 9.861884)
93+
XL data for lsm6dsv16x@0 7336887593ns (-0.196184, 0.110054, 9.804464)
94+
XL data for lsm6dsv16x@0 7337910356ns (-0.181829, 0.133979, 9.938444)
95+
XL data for lsm6dsv16x@0 7338933650ns (-0.215324, 0.081344, 9.536504)
96+
XL data for lsm6dsv16x@0 7339957075ns (-0.157904, 0.119624, 9.995864)
97+
XL data for lsm6dsv16x@0 7340980675ns (-0.205754, 0.110054, 9.809249)
98+
XL data for lsm6dsv16x@0 7342003487ns (-0.177044, 0.143549, 9.971939)
99+
XL data for lsm6dsv16x@0 7343026593ns (-0.172259, 0.100484, 9.794894)
100+
XL data for lsm6dsv16x@0 7344050168ns (-0.177044, 0.124409, 9.881024)
101+
XL data for lsm6dsv16x@0 7345073643ns (-0.191399, 0.124409, 9.986294)
102+
XL data for lsm6dsv16x@0 7346096587ns (-0.191399, 0.105269, 9.790109)
103+
104+
References
105+
==========
106+
107+
.. target-notes::
108+
109+
.. _RTIO framework:
110+
https://docs.zephyrproject.org/latest/services/rtio/index.html
111+
112+
.. _x-nucleo-iks4a1:
113+
http://www.st.com/en/ecosystems/x-nucleo-iks4a1.html
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2024 STMicroelectronics
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_I2C_RTIO=y
5+
CONFIG_LSM6DSV16X_STREAM=y
6+
CONFIG_LSM6DSV16X_ENABLE_TEMP=y
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2024 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <zephyr/dt-bindings/sensor/lsm6dsv16x.h>
7+
8+
9+
/*
10+
* Nucleo F401RE board + shield iks4a1
11+
*
12+
* This devicetree overlay file will be automatically picked by the Zephyr
13+
* build system when building the sample for the nucleo_f401re board.
14+
*/
15+
16+
/ {
17+
aliases {
18+
stream0 = &lsm6dsv16x_6b_x_nucleo_iks4a1;
19+
};
20+
};
21+
22+
&arduino_i2c {
23+
lsm6dsv16x_6b_x_nucleo_iks4a1: lsm6dsv16x@6b {
24+
compatible = "st,lsm6dsv16x";
25+
reg = <0x6b>;
26+
accel-odr = <LSM6DSV16X_DT_ODR_AT_120Hz>;
27+
accel-range = <LSM6DSV16X_DT_FS_16G>;
28+
int2-gpios = <&arduino_header 10 GPIO_ACTIVE_HIGH>; /* D4 (PB5) */
29+
drdy-pin = <2>;
30+
drdy-pulsed;
31+
};
32+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2024 STMicroelectronics
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_I2C_RTIO=y
5+
CONFIG_LSM6DSV16X_STREAM=y
6+
CONFIG_LSM6DSV16X_ENABLE_TEMP=y
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2024 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <zephyr/dt-bindings/sensor/lsm6dsv16x.h>
7+
8+
9+
/*
10+
* Nucleo F401RE board + shield iks4a1
11+
*
12+
* This devicetree overlay file will be automatically picked by the Zephyr
13+
* build system when building the sample for the nucleo_f401re board.
14+
*/
15+
16+
/ {
17+
aliases {
18+
stream0 = &lsm6dsv16x_6b_x_nucleo_iks4a1;
19+
};
20+
};
21+
22+
&arduino_i2c {
23+
lsm6dsv16x_6b_x_nucleo_iks4a1: lsm6dsv16x@6b {
24+
compatible = "st,lsm6dsv16x";
25+
reg = <0x6b>;
26+
accel-odr = <LSM6DSV16X_DT_ODR_AT_120Hz>;
27+
accel-range = <LSM6DSV16X_DT_FS_16G>;
28+
int2-gpios = <&arduino_header 10 GPIO_ACTIVE_HIGH>; /* D4 (PB5) */
29+
drdy-pin = <2>;
30+
drdy-pulsed;
31+
};
32+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 STMicroelectronics
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_SPI_RTIO=y
5+
CONFIG_LSM6DSV16X_STREAM=y
6+
CONFIG_LSM6DSV16X_ENABLE_TEMP=y
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <zephyr/dt-bindings/sensor/lsm6dsv16x.h>
7+
8+
9+
/*
10+
* This devicetree overlay file will be automatically picked by the Zephyr
11+
* build system when building the sample for the sensortile_box_pro board.
12+
*/
13+
14+
/ {
15+
aliases {
16+
stream0 = &lsm6dsv16x_0;
17+
};
18+
};
19+
20+
&spi2 {
21+
lsm6dsv16x_0: lsm6dsv16x@0 {
22+
compatible = "st,lsm6dsv16x";
23+
24+
accel-odr = <LSM6DSV16X_DT_ODR_AT_960Hz>;
25+
accel-range = <LSM6DSV16X_DT_FS_16G>;
26+
};
27+
};

samples/sensor/stream_drdy/prj.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2024 STMicroelectronics
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_STDOUT_CONSOLE=y
5+
CONFIG_SENSOR=y
6+
CONFIG_SENSOR_ASYNC_API=y
7+
CONFIG_CBPRINTF_FP_SUPPORT=y
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sample:
2+
name: Stream sample on Data Ready trigger
3+
tests:
4+
sample.sensor.stream_drdy:
5+
harness: console
6+
tags: sensors
7+
filter: dt_alias_exists("stream0")
8+
harness_config:
9+
type: one_line
10+
regex:
11+
- "^\\s*[0-9A-Za-z_,+-.]*@[0-9A-Fa-f]* \\[m\/s\\^2\\]: \
12+
\\(\\s*-?[0-9\\.]*,\\s*-?[0-9\\.]*,\\s*-?[0-9\\.]*\\)$"

0 commit comments

Comments
 (0)