Skip to content

Commit 4cd33ba

Browse files
bjarki-andreasenkartben
authored andcommitted
samples: i2c: rtio: add i2c_rtio_loopback sample
Add sample which clearly and thorougly shows how to use RTIO with I2C controllers, both synchronously and async, comparing it with the "standard" I2C API, in an controlled environment. Both the I2C controller and I2C target are managed by the sample, using loopback to monitor and control the I2C transfers. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 2ca889f commit 4cd33ba

File tree

7 files changed

+510
-0
lines changed

7 files changed

+510
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(i2c_rtio_loopback)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.. zephyr:code-sample:: i2c-rtio-loopback
2+
:name: I2C RTIO loopback
3+
:relevant-api: rtio i2c_interface
4+
5+
Perform I2C transfers between I2C controller and custom I2C target using RTIO.
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates how to perform I2C transfers, synchronously and async
11+
using RTIO. It uses up to two I2C controllers, acting as I2C controller and
12+
target.
13+
14+
Requirements
15+
************
16+
17+
This sample requires either:
18+
19+
* Two I2C controllers, one supporting the I2C controller role, one supporting the
20+
I2C peripheral role, both connected to the same I2C bus.
21+
* An I2C controller supporting both I2C controller and peripheral role
22+
simultaneously.
23+
24+
.. note::
25+
26+
Remember to set up the I2C bus, connecting SCL and SDA pull-up resistors, and
27+
connecting the relevant I2C controllers to the bus physically.
28+
29+
Board support
30+
*************
31+
32+
Any board which meets the requirements must use an overlay to specify which
33+
I2C controller will act as the controller, and which as the peripheral, note
34+
that this could be the same controller. This is done using the devicetree
35+
aliases ``i2c-controller`` and ``i2c-controller-target`` respectively:
36+
37+
.. code-block:: devicetree
38+
39+
/ {
40+
aliases {
41+
i2c-controller = &i2c1;
42+
i2c-controller-target = &i2c2;
43+
};
44+
};
45+
46+
If necessary, add any board specific configs to the board specific overlay:
47+
48+
.. code-block:: cfg
49+
50+
CONFIG_I2C_TARGET_BUFFER_MODE=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_I2C_STM32_INTERRUPT=y
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
3+
/* I2C bus pins are exposed on the STMod+.
4+
*
5+
* Bus SDA SCL
6+
* Pin Hdr Pin Hdr
7+
* i2c1 PB9 CN3:10 PB8 CN3:7
8+
* i2c2 PH5 CN2:10 PH4 CN2:7
9+
*
10+
* Short Pin PB9 to PH5, and PB8 to PH4, for the test to pass.
11+
*/
12+
13+
/ {
14+
aliases {
15+
i2c-controller = &i2c1;
16+
i2c-controller-target = &i2c2;
17+
};
18+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_I2C=y
5+
CONFIG_RTIO=y
6+
CONFIG_I2C_RTIO=y
7+
CONFIG_I2C_TARGET=y
8+
CONFIG_I2C_TARGET_BUFFER_MODE=y
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sample:
2+
name: I2C RTIO loopback sample
3+
tests:
4+
sample.drivers.i2c.rtio_loopback:
5+
tags:
6+
- rtio
7+
- i2c_target
8+
platform_allow:
9+
- b_u585i_iot02a

0 commit comments

Comments
 (0)