From 01578a363c1c7645da83735daa4c41c93664d05c Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 6 Feb 2025 12:47:39 +0100 Subject: [PATCH 01/10] [nrf fromtree] drivers: i2c: i2c_nrfx_twis: patch dma buf mem section The macros placing the DMA memory buffer in the appropriate section in RAM was malformed. This PR fixes it. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit bb2833de548d80100eab925e45a6413c180942b3) --- drivers/i2c/i2c_nrfx_twis.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c_nrfx_twis.c b/drivers/i2c/i2c_nrfx_twis.c index c70750286b69..9e2b0759f2a3 100644 --- a/drivers/i2c/i2c_nrfx_twis.c +++ b/drivers/i2c/i2c_nrfx_twis.c @@ -32,13 +32,13 @@ DT_IRQ(SHIM_NRF_TWIS_NODE(id), priority) #define SHIM_NRF_TWIS_HAS_MEMORY_REGIONS(id) \ - DT_NODE_HAS_PROP(id, memory_regions) + DT_NODE_HAS_PROP(SHIM_NRF_TWIS_NODE(id), memory_regions) #define SHIM_NRF_TWIS_LINKER_REGION_NAME(id) \ LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(SHIM_NRF_TWIS_NODE(id), memory_regions)) #define SHIM_NRF_TWIS_BUF_ATTR_SECTION(id) \ - __attribute__((__section__(SHIM_NRF_TWIS_LINKER_REGION_NAME, ()))) + __attribute__((__section__(SHIM_NRF_TWIS_LINKER_REGION_NAME(id)))) #define SHIM_NRF_TWIS_BUF_ATTR(id) \ COND_CODE_1( \ From e7290cda6759da4ed350a479b4a1c1c06b577cd9 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 6 Feb 2025 12:48:49 +0100 Subject: [PATCH 02/10] [nrf fromtree] tests: drivers: i2c: target_api: add nrf54h20 Add nrf54h20 to test suite. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 37c3efc13b30251b20a27764e11e1c109198962c) --- .../boards/nrf54h20dk_nrf54h20_cpuapp.conf | 4 + .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 78 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.conf create mode 100644 tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.overlay diff --git a/tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.conf b/tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.conf new file mode 100644 index 000000000000..7dfef7da2839 --- /dev/null +++ b/tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2025 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_I2C_NRFX_TWIS_BUF_SIZE=256 diff --git a/tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.overlay new file mode 100644 index 000000000000..2fc033d534a6 --- /dev/null +++ b/tests/drivers/i2c/i2c_target_api/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * SDA = P2.8 and P2.9 + * SCL = P1.2 and P1.3 + */ + +&pinctrl { + i2c130_default: i2c130_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c130_sleep: i2c130_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + i2c131_default: i2c131_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c131_sleep: i2c131_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +&i2c130 { + clock-frequency = ; + pinctrl-0 = <&i2c130_default>; + pinctrl-1 = <&i2c130_sleep>; + pinctrl-names = "default", "sleep"; + zephyr,concat-buf-size = <256>; + memory-regions = <&cpuapp_dma_region>; + status = "okay"; + + eeprom1: eeprom@56 { + compatible = "zephyr,i2c-target-eeprom"; + reg = <0x56>; + address-width = <8>; + size = <256>; + }; +}; + +&i2c131 { + compatible = "nordic,nrf-twis"; + clock-frequency = ; + pinctrl-0 = <&i2c131_default>; + pinctrl-1 = <&i2c131_sleep>; + pinctrl-names = "default", "sleep"; + memory-regions = <&cpuapp_dma_region>; + status = "okay"; + + eeprom0: eeprom@54 { + compatible = "zephyr,i2c-target-eeprom"; + reg = <0x54>; + address-width = <8>; + size = <256>; + }; +}; From 3e2764da299310d5c717d5b21241efccd418cbc4 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 6 Feb 2025 12:56:33 +0100 Subject: [PATCH 03/10] [nrf fromtree] tests: drivers: i2c: target_api: add nrf54l15 to test suite Add nrf54l15 cpuapp to test suite. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 769936165d96003fbe7b13409d26f97b0a5a8658) --- .../boards/nrf54l15dk_nrf54l15_cpuapp.conf | 4 + .../boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 74 +++++++++++++++++++ .../drivers/i2c/i2c_target_api/testcase.yaml | 3 + 3 files changed, 81 insertions(+) create mode 100644 tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.conf create mode 100644 tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.overlay diff --git a/tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.conf new file mode 100644 index 000000000000..9a83d7afb811 --- /dev/null +++ b/tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_I2C_NRFX_TWIS_BUF_SIZE=256 diff --git a/tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.overlay new file mode 100644 index 000000000000..dee8b41f0483 --- /dev/null +++ b/tests/drivers/i2c/i2c_target_api/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * SDA = P1.8 and P1.9 + * SCL = P1.10 and P1.11 + */ + +&pinctrl { + i2c21_default: i2c21_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c21_sleep: i2c21_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + i2c22_default: i2c22_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c22_sleep: i2c22_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +&i2c21 { + pinctrl-0 = <&i2c21_default>; + pinctrl-1 = <&i2c21_sleep>; + pinctrl-names = "default", "sleep"; + zephyr,concat-buf-size = <256>; + status = "okay"; + + eeprom1: eeprom@56 { + compatible = "zephyr,i2c-target-eeprom"; + reg = <0x56>; + address-width = <8>; + size = <256>; + }; +}; + +&i2c22 { + compatible = "nordic,nrf-twis"; + pinctrl-0 = <&i2c22_default>; + pinctrl-1 = <&i2c22_sleep>; + pinctrl-names = "default", "sleep"; + status = "okay"; + + eeprom0: eeprom@54 { + compatible = "zephyr,i2c-target-eeprom"; + reg = <0x54>; + address-width = <8>; + size = <256>; + }; +}; diff --git a/tests/drivers/i2c/i2c_target_api/testcase.yaml b/tests/drivers/i2c/i2c_target_api/testcase.yaml index fe3efa19615c..588b7f7a43d9 100644 --- a/tests/drivers/i2c/i2c_target_api/testcase.yaml +++ b/tests/drivers/i2c/i2c_target_api/testcase.yaml @@ -54,5 +54,8 @@ tests: - max32675evkit - max32680evkit/max32680/m4 - max32690evkit/max32690/m4 + - nrf5340dk/nrf5340/cpuapp + - nrf54h20dk/nrf54h20/cpuapp + - nrf54l15dk/nrf54l15/cpuapp integration_platforms: - max32690evkit/max32690/m4 From 75a90aa8c0bd719f39ec4617be8442daa44bfd88 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Tue, 11 Feb 2025 10:12:13 +0100 Subject: [PATCH 04/10] [nrf fromtree] drivers: i2c: nrfx_twim_rtio: fix dma buf section attr The buffer used for the TWIM DMA needs to be allocated to the section provided with the memory-regions dt prop. The macros for doing this where malformed. This commit fixes and cleans up the macros. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 62815dd9e711ce4f97532aa5f50fa367942749cb) --- drivers/i2c/i2c_nrfx_twim_rtio.c | 43 ++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/i2c_nrfx_twim_rtio.c b/drivers/i2c/i2c_nrfx_twim_rtio.c index acc2576c1bac..3c7db82bd5b5 100644 --- a/drivers/i2c/i2c_nrfx_twim_rtio.c +++ b/drivers/i2c/i2c_nrfx_twim_rtio.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "i2c_nrfx_twim_common.h" @@ -174,6 +175,31 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev) COND_CODE_0(CONCAT_BUF_SIZE(idx), (COND_CODE_0(FLASH_BUF_MAX_SIZE(idx), (0), (1))), (1)) #define MSG_BUF_SIZE(idx) MAX(CONCAT_BUF_SIZE(idx), FLASH_BUF_MAX_SIZE(idx)) +#define MSG_BUF_HAS_MEMORY_REGIONS(idx) \ + DT_NODE_HAS_PROP(I2C(idx), memory_regions) + +#define MSG_BUF_LINKER_REGION_NAME(idx) \ + LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(I2C(idx), memory_regions)) + +#define MSG_BUF_ATTR_SECTION(idx) \ + __attribute__((__section__(MSG_BUF_LINKER_REGION_NAME(idx)))) + +#define MSG_BUF_ATTR(idx) \ + COND_CODE_1( \ + MSG_BUF_HAS_MEMORY_REGIONS(idx), \ + (MSG_BUF_ATTR_SECTION(idx)), \ + () \ + ) + +#define MSG_BUF_SYM(idx) \ + _CONCAT_3(twim_, idx, _msg_buf) + +#define MSG_BUF_DEFINE(idx) \ + static uint8_t MSG_BUF_SYM(idx)[MSG_BUF_SIZE(idx)] MSG_BUF_ATTR(idx) + +#define MAX_TRANSFER_SIZE(idx) \ + BIT_MASK(DT_PROP(I2C(idx), easydma_maxcnt_bits)) + #define I2C_NRFX_TWIM_RTIO_DEVICE(idx) \ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \ BUILD_ASSERT(I2C_FREQUENCY(idx) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \ @@ -183,9 +209,7 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev) IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), nrfx_isr, \ nrfx_twim_##idx##_irq_handler, 0); \ } \ - IF_ENABLED( \ - USES_MSG_BUF(idx), \ - (static uint8_t twim_##idx##_msg_buf[MSG_BUF_SIZE(idx)] I2C_MEMORY_SECTION(idx);)) \ + IF_ENABLED(USES_MSG_BUF(idx), (MSG_BUF_DEFINE(idx);)) \ I2C_RTIO_DEFINE(_i2c##idx##_twim_rtio, \ DT_INST_PROP_OR(n, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \ DT_INST_PROP_OR(n, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \ @@ -204,22 +228,15 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev) .msg_buf_size = MSG_BUF_SIZE(idx), \ .irq_connect = irq_connect##idx, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2C(idx)), \ - IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = twim_##idx##_msg_buf,)) \ - .max_transfer_size = \ - BIT_MASK(DT_PROP(I2C(idx), easydma_maxcnt_bits)), \ + IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = MSG_BUF_SYM(idx),)) \ + .max_transfer_size = MAX_TRANSFER_SIZE(idx), \ }, \ .ctx = &_i2c##idx##_twim_rtio, \ }; \ PM_DEVICE_DT_DEFINE(I2C(idx), twim_nrfx_pm_action, PM_DEVICE_ISR_SAFE); \ I2C_DEVICE_DT_DEFINE(I2C(idx), i2c_nrfx_twim_rtio_init, PM_DEVICE_DT_GET(I2C(idx)), NULL, \ &twim_##idx##z_config, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \ - &i2c_nrfx_twim_driver_api) - -#define I2C_MEMORY_SECTION(idx) \ - COND_CODE_1(I2C_HAS_PROP(idx, memory_regions), \ - (__attribute__((__section__( \ - LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(I2C(idx), memory_regions)))))), \ - ()) + &i2c_nrfx_twim_driver_api); #ifdef CONFIG_HAS_HW_NRF_TWIM0 I2C_NRFX_TWIM_RTIO_DEVICE(0); From b75bdf70870dc7d975408dbbb5ba0bb6f677dc5f Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Tue, 11 Feb 2025 10:37:35 +0100 Subject: [PATCH 05/10] [nrf fromtree] drivers: i2c: nrfx_twim_rtio: use msg_buf for rx if required The DMA buffer needs to be used both for tx and rx if required. Extend RTIO driver variant to use DMA buffer and copy received data from it to user buffer. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 125752e7cccb4d6dd2f5f4124d7ef3b1cda360b4) --- drivers/i2c/i2c_nrfx_twim_rtio.c | 34 +++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c_nrfx_twim_rtio.c b/drivers/i2c/i2c_nrfx_twim_rtio.c index 3c7db82bd5b5..da10e267b9c8 100644 --- a/drivers/i2c/i2c_nrfx_twim_rtio.c +++ b/drivers/i2c/i2c_nrfx_twim_rtio.c @@ -26,6 +26,11 @@ struct i2c_nrfx_twim_rtio_config { struct i2c_rtio *ctx; }; +struct i2c_nrfx_twim_rtio_data { + uint8_t *user_rx_buf; + uint16_t user_rx_buf_size; +}; + static bool i2c_nrfx_twim_rtio_msg_start(const struct device *dev, uint8_t flags, uint8_t *buf, size_t buf_len, uint16_t i2c_addr) { @@ -44,12 +49,28 @@ static bool i2c_nrfx_twim_rtio_msg_start(const struct device *dev, uint8_t flags static bool i2c_nrfx_twim_rtio_start(const struct device *dev) { const struct i2c_nrfx_twim_rtio_config *config = dev->config; + struct i2c_nrfx_twim_rtio_data *data = dev->data; struct i2c_rtio *ctx = config->ctx; struct rtio_sqe *sqe = &ctx->txn_curr->sqe; struct i2c_dt_spec *dt_spec = sqe->iodev->data; switch (sqe->op) { case RTIO_OP_RX: + if (!nrf_dma_accessible_check(&config->common.twim, sqe->rx.buf)) { + if (sqe->rx.buf_len > config->common.msg_buf_size) { + return i2c_rtio_complete(ctx, -ENOSPC); + } + + data->user_rx_buf = sqe->rx.buf; + data->user_rx_buf_size = sqe->rx.buf_len; + return i2c_nrfx_twim_rtio_msg_start(dev, + I2C_MSG_READ | sqe->iodev_flags, + config->common.msg_buf, + data->user_rx_buf_size, + dt_spec->addr); + } + + data->user_rx_buf = NULL; return i2c_nrfx_twim_rtio_msg_start(dev, I2C_MSG_READ | sqe->iodev_flags, sqe->rx.buf, sqe->rx.buf_len, dt_spec->addr); case RTIO_OP_TINY_TX: @@ -144,8 +165,14 @@ static void i2c_nrfx_twim_rtio_submit(const struct device *dev, struct rtio_iode static void event_handler(nrfx_twim_evt_t const *p_event, void *p_context) { const struct device *dev = p_context; + const struct i2c_nrfx_twim_rtio_config *config = dev->config; + struct i2c_nrfx_twim_rtio_data *data = dev->data; int status = p_event->type == NRFX_TWIM_EVT_DONE ? 0 : -EIO; + if (data->user_rx_buf) { + memcpy(data->user_rx_buf, config->common.msg_buf, data->user_rx_buf_size); + } + i2c_nrfx_twim_rtio_complete(dev, status); } @@ -214,6 +241,7 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev) DT_INST_PROP_OR(n, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \ DT_INST_PROP_OR(n, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \ PINCTRL_DT_DEFINE(I2C(idx)); \ + static struct i2c_nrfx_twim_rtio_data twim_##idx##z_data; \ static const struct i2c_nrfx_twim_rtio_config twim_##idx##z_config = { \ .common = \ { \ @@ -234,9 +262,9 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev) .ctx = &_i2c##idx##_twim_rtio, \ }; \ PM_DEVICE_DT_DEFINE(I2C(idx), twim_nrfx_pm_action, PM_DEVICE_ISR_SAFE); \ - I2C_DEVICE_DT_DEFINE(I2C(idx), i2c_nrfx_twim_rtio_init, PM_DEVICE_DT_GET(I2C(idx)), NULL, \ - &twim_##idx##z_config, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \ - &i2c_nrfx_twim_driver_api); + I2C_DEVICE_DT_DEFINE(I2C(idx), i2c_nrfx_twim_rtio_init, PM_DEVICE_DT_GET(I2C(idx)), \ + &twim_##idx##z_data, &twim_##idx##z_config, POST_KERNEL, \ + CONFIG_I2C_INIT_PRIORITY, &i2c_nrfx_twim_driver_api); #ifdef CONFIG_HAS_HW_NRF_TWIM0 I2C_NRFX_TWIM_RTIO_DEVICE(0); From 1112302996ee4d37d1e4c9f4115579ee1e341fd7 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 8 Jan 2025 13:32:47 +0100 Subject: [PATCH 06/10] [nrf fromtree] samples: drivers: i2c: rtio_loopback: add nrf boards Add nRF boards to the rtio_loopback sample. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 7d5a912cedf73cf347d7c18bec61dfaed5555348) --- .../boards/nrf5340dk_nrf5340_cpuapp.conf | 4 ++ .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 43 ++++++++++++ .../boards/nrf54l15dk_nrf54l15_cpuapp.conf | 4 ++ .../boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 67 +++++++++++++++++++ samples/drivers/i2c/rtio_loopback/sample.yaml | 2 + 5 files changed, 120 insertions(+) create mode 100644 samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.conf create mode 100644 samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.overlay create mode 100644 samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.conf create mode 100644 samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.overlay diff --git a/samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000..64627ec86880 --- /dev/null +++ b/samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_I2C_TARGET_BUFFER_MODE=y diff --git a/samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.overlay b/samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.overlay new file mode 100644 index 000000000000..21bf0e503a4d --- /dev/null +++ b/samples/drivers/i2c/rtio_loopback/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * SDA = P0.26 and P1.2 + * SCL = P0.25 and P1.3 + */ + +/ { + aliases { + i2c-controller = &i2c1; + i2c-controller-target = &i2c2; + }; +}; + +&pinctrl { + i2c2_default: i2c2_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c2_sleep: i2c2_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +&i2c2 { + compatible = "nordic,nrf-twis"; + pinctrl-0 = <&i2c2_default>; + pinctrl-1 = <&i2c2_sleep>; + pinctrl-names = "default", "sleep"; + status = "okay"; +}; diff --git a/samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.conf new file mode 100644 index 000000000000..9a83d7afb811 --- /dev/null +++ b/samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_I2C_NRFX_TWIS_BUF_SIZE=256 diff --git a/samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.overlay new file mode 100644 index 000000000000..4a7d2fe02a6f --- /dev/null +++ b/samples/drivers/i2c/rtio_loopback/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * SDA = P1.8 and P1.9 + * SCL = P1.10 and P1.11 + */ + +/ { + aliases { + i2c-controller = &i2c21; + i2c-controller-target = &i2c22; + }; +}; + +&pinctrl { + i2c21_default: i2c21_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c21_sleep: i2c21_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + i2c22_default: i2c22_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c22_sleep: i2c22_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +&i2c21 { + pinctrl-0 = <&i2c21_default>; + pinctrl-1 = <&i2c21_sleep>; + pinctrl-names = "default", "sleep"; + zephyr,concat-buf-size = <256>; + status = "okay"; +}; + +&i2c22 { + compatible = "nordic,nrf-twis"; + pinctrl-0 = <&i2c22_default>; + pinctrl-1 = <&i2c22_sleep>; + pinctrl-names = "default", "sleep"; + status = "okay"; +}; diff --git a/samples/drivers/i2c/rtio_loopback/sample.yaml b/samples/drivers/i2c/rtio_loopback/sample.yaml index 6effc59a9f8c..e7d5563f5b1b 100644 --- a/samples/drivers/i2c/rtio_loopback/sample.yaml +++ b/samples/drivers/i2c/rtio_loopback/sample.yaml @@ -7,3 +7,5 @@ tests: - i2c_target platform_allow: - b_u585i_iot02a + - nrf5340dk/nrf5340/cpuapp + - nrf54l15dk/nrf54l15/cpuapp From fc1a73cd5feae41de798fff8b8bfada357c30394 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Tue, 11 Feb 2025 10:40:38 +0100 Subject: [PATCH 07/10] [nrf fromtree] samples: drivers: i2c: rtio_loopback: add nrf54h20 Add nrf54h20 board support to the i2c rtio loopback sample. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 5c7f47de0fdeac237c420bc06070bf8d9d0dec03) --- .../boards/nrf54h20dk_nrf54h20_cpuapp.conf | 4 ++ .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 71 +++++++++++++++++++ samples/drivers/i2c/rtio_loopback/sample.yaml | 1 + 3 files changed, 76 insertions(+) create mode 100644 samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.conf create mode 100644 samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.overlay diff --git a/samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.conf b/samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.conf new file mode 100644 index 000000000000..9a83d7afb811 --- /dev/null +++ b/samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_I2C_NRFX_TWIS_BUF_SIZE=256 diff --git a/samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.overlay new file mode 100644 index 000000000000..928b52a66f57 --- /dev/null +++ b/samples/drivers/i2c/rtio_loopback/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * SDA = P2.8 and P2.9 + * SCL = P1.2 and P1.3 + */ + +/ { + aliases { + i2c-controller = &i2c130; + i2c-controller-target = &i2c131; + }; +}; + +&pinctrl { + i2c130_default: i2c130_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c130_sleep: i2c130_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + i2c131_default: i2c131_default { + group1 { + psels = , + ; + bias-pull-up; + }; + }; + + i2c131_sleep: i2c131_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +&i2c130 { + clock-frequency = ; + pinctrl-0 = <&i2c130_default>; + pinctrl-1 = <&i2c130_sleep>; + pinctrl-names = "default", "sleep"; + zephyr,concat-buf-size = <256>; + memory-regions = <&cpuapp_dma_region>; + status = "okay"; +}; + +&i2c131 { + compatible = "nordic,nrf-twis"; + clock-frequency = ; + pinctrl-0 = <&i2c131_default>; + pinctrl-1 = <&i2c131_sleep>; + pinctrl-names = "default", "sleep"; + memory-regions = <&cpuapp_dma_region>; + status = "okay"; +}; diff --git a/samples/drivers/i2c/rtio_loopback/sample.yaml b/samples/drivers/i2c/rtio_loopback/sample.yaml index e7d5563f5b1b..5f495ad63126 100644 --- a/samples/drivers/i2c/rtio_loopback/sample.yaml +++ b/samples/drivers/i2c/rtio_loopback/sample.yaml @@ -9,3 +9,4 @@ tests: - b_u585i_iot02a - nrf5340dk/nrf5340/cpuapp - nrf54l15dk/nrf54l15/cpuapp + - nrf54h20dk/nrf54h20/cpuapp From b207d1ab2861b3a0d08d56b39fc8dd31ed6d4e1a Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 9 Jan 2025 12:26:05 +0100 Subject: [PATCH 08/10] [nrf fromtree] drivers: i2c: nrfx_twim_rtio: cast buf to non-const RTIO correctly declares tx buffers as const, however, the existing I2C API and NRFX (SDK) drivers don't. Therefor cast the const buf to non-const when passing the tx buf to the twim driver from the RTIO call to avoid the const warning. The tx buffer is being treated as const data naturally in the NRFX driver, its just not declared as such since we reuse the buffer for both RX and TX data. Alternatively the SDK and "shim" drivers built on top of it need to be updated, which is quite a bit of work :) Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 2e0092356fb834cca14114f35f31c450cd925efc) --- drivers/i2c/i2c_nrfx_twim_rtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_nrfx_twim_rtio.c b/drivers/i2c/i2c_nrfx_twim_rtio.c index da10e267b9c8..8b5f2c625f8f 100644 --- a/drivers/i2c/i2c_nrfx_twim_rtio.c +++ b/drivers/i2c/i2c_nrfx_twim_rtio.c @@ -96,7 +96,8 @@ static bool i2c_nrfx_twim_rtio_start(const struct device *dev) sqe->tx.buf = config->common.msg_buf; } return i2c_nrfx_twim_rtio_msg_start(dev, I2C_MSG_WRITE | sqe->iodev_flags, - sqe->tx.buf, sqe->tx.buf_len, dt_spec->addr); + (uint8_t *)sqe->tx.buf, sqe->tx.buf_len, + dt_spec->addr); case RTIO_OP_I2C_CONFIGURE: (void)i2c_nrfx_twim_configure(dev, sqe->i2c_config); return false; From 53e9c3d79b6dc06873429da6def970c8ed86c729 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 13 Feb 2025 13:56:59 +0100 Subject: [PATCH 09/10] [nrf fromtree] samples: drivers: i2c: rtio_loopback: add fixture Add i2c_bus_short fixture to the rtio_loopback sample to ensure it is only run on boards with the bus shorted. The i2c_bus_short fixture is also used in the i2c_target_api test suite. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 846b4687154af5f57ba5a32610ec868d5f4ae61d) --- samples/drivers/i2c/rtio_loopback/sample.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/drivers/i2c/rtio_loopback/sample.yaml b/samples/drivers/i2c/rtio_loopback/sample.yaml index 5f495ad63126..68a752df9473 100644 --- a/samples/drivers/i2c/rtio_loopback/sample.yaml +++ b/samples/drivers/i2c/rtio_loopback/sample.yaml @@ -5,6 +5,9 @@ tests: tags: - rtio - i2c_target + harness: ztest + harness_config: + fixture: i2c_bus_short platform_allow: - b_u585i_iot02a - nrf5340dk/nrf5340/cpuapp From 8d630aa5b9263e865118be4b43b2f3749f09c134 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 20 Feb 2025 15:46:15 +0100 Subject: [PATCH 10/10] [nrf fromtree] samples: drivers: i2c: rtio_loopback: change harness to console The harness was set to ztest, but the sample requires the console harness to match on the "sample complete" line, its not actually using ztest. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 7ee4011166ae0467d6830bccd337f9c8f583acda) --- samples/drivers/i2c/rtio_loopback/sample.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/drivers/i2c/rtio_loopback/sample.yaml b/samples/drivers/i2c/rtio_loopback/sample.yaml index 68a752df9473..a9d41fbf8cd4 100644 --- a/samples/drivers/i2c/rtio_loopback/sample.yaml +++ b/samples/drivers/i2c/rtio_loopback/sample.yaml @@ -5,9 +5,12 @@ tests: tags: - rtio - i2c_target - harness: ztest + harness: console harness_config: fixture: i2c_bus_short + type: one_line + regex: + - "sample complete" platform_allow: - b_u585i_iot02a - nrf5340dk/nrf5340/cpuapp