Skip to content

[nrf fromtree] tests: boards: nrf: i2s: i2s_divider: Confirm CLK value #2918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/boards/nrf/i2s/i2s_divider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(i2s_divider)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
i2s-node0 = &i2s0;
};
};

&pinctrl {
i2s0_default_alt: i2s0_default_alt {
group1 {
psels = <NRF_PSEL(I2S_SCK_M, 1, 5)>,
<NRF_PSEL(I2S_LRCK_M, 1, 6)>,
<NRF_PSEL(I2S_SDOUT, 1, 1)>,
<NRF_PSEL(I2S_SDIN, 1, 2)>;
};
};
};

&i2s0 {
status = "okay";
pinctrl-0 = <&i2s0_default_alt>;
pinctrl-names = "default";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
i2s-node0 = &i2s0;
};
};

&pinctrl {
i2s0_default_alt: i2s0_default_alt {
group1 {
psels = <NRF_PSEL(I2S_SCK_M, 1, 6)>,
<NRF_PSEL(I2S_LRCK_M, 1, 7)>,
<NRF_PSEL(I2S_SDOUT, 0, 4)>,
<NRF_PSEL(I2S_SDIN, 0, 5)>;
};
};
};

&uart1 {
status = "disabled";
};

&i2s0 {
status = "okay";
pinctrl-0 = <&i2s0_default_alt>;
pinctrl-names = "default";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
i2s-node0 = &i2s20;
};
};

&pinctrl {
i2s20_default_alt: i2s20_default_alt {
group1 {
psels = <NRF_PSEL(I2S_SCK_M, 1, 11)>,
<NRF_PSEL(I2S_LRCK_M, 1, 12)>,
<NRF_PSEL(I2S_SDOUT, 1, 8)>,
<NRF_PSEL(I2S_SDIN, 1, 9)>;
};
};
};

&i2s20 {
status = "okay";
pinctrl-0 = <&i2s20_default_alt>;
pinctrl-names = "default";
};
3 changes: 3 additions & 0 deletions tests/boards/nrf/i2s/i2s_divider/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_ZTEST=y
CONFIG_I2S=y
CONFIG_I2S_LOG_LEVEL_INF=y
167 changes: 167 additions & 0 deletions tests/boards/nrf/i2s/i2s_divider/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
#include <zephyr/drivers/i2s.h>
#include <zephyr/sys/iterable_sections.h>

#define I2S_DEV_NODE DT_ALIAS(i2s_node0)

#define WORD_SIZE 16U
#define NUMBER_OF_CHANNELS 2
#define FRAME_CLK_FREQ 44100

#define NUM_BLOCKS 2
#define TIMEOUT 1000

Check notice on line 20 in tests/boards/nrf/i2s/i2s_divider/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/boards/nrf/i2s/i2s_divider/src/main.c:20 -#define WORD_SIZE 16U +#define WORD_SIZE 16U #define NUMBER_OF_CHANNELS 2 -#define FRAME_CLK_FREQ 44100 +#define FRAME_CLK_FREQ 44100 #define NUM_BLOCKS 2 -#define TIMEOUT 1000 +#define TIMEOUT 1000

Check notice on line 20 in tests/boards/nrf/i2s/i2s_divider/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/boards/nrf/i2s/i2s_divider/src/main.c:20 -#define WORD_SIZE 16U +#define WORD_SIZE 16U #define NUMBER_OF_CHANNELS 2 -#define FRAME_CLK_FREQ 44100 +#define FRAME_CLK_FREQ 44100 #define NUM_BLOCKS 2 -#define TIMEOUT 1000 +#define TIMEOUT 1000
#define SAMPLES_COUNT 4
/* Each word has one bit set */
static const int16_t data[SAMPLES_COUNT] = {16, 32, 64, 128};

#define BLOCK_SIZE (2 * sizeof(data))

#ifdef CONFIG_NOCACHE_MEMORY
#define MEM_SLAB_CACHE_ATTR __nocache
#else
#define MEM_SLAB_CACHE_ATTR
#endif /* CONFIG_NOCACHE_MEMORY */

static char MEM_SLAB_CACHE_ATTR __aligned(WB_UP(32))
_k_mem_slab_buf_tx_0_mem_slab[NUM_BLOCKS * WB_UP(BLOCK_SIZE)];
STRUCT_SECTION_ITERABLE(k_mem_slab, tx_0_mem_slab) =
Z_MEM_SLAB_INITIALIZER(tx_0_mem_slab, _k_mem_slab_buf_tx_0_mem_slab,
WB_UP(BLOCK_SIZE), NUM_BLOCKS);

Check notice on line 38 in tests/boards/nrf/i2s/i2s_divider/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/boards/nrf/i2s/i2s_divider/src/main.c:38 - #define MEM_SLAB_CACHE_ATTR __nocache +#define MEM_SLAB_CACHE_ATTR __nocache #else - #define MEM_SLAB_CACHE_ATTR +#define MEM_SLAB_CACHE_ATTR #endif /* CONFIG_NOCACHE_MEMORY */ -static char MEM_SLAB_CACHE_ATTR __aligned(WB_UP(32)) - _k_mem_slab_buf_tx_0_mem_slab[NUM_BLOCKS * WB_UP(BLOCK_SIZE)]; -STRUCT_SECTION_ITERABLE(k_mem_slab, tx_0_mem_slab) = - Z_MEM_SLAB_INITIALIZER(tx_0_mem_slab, _k_mem_slab_buf_tx_0_mem_slab, - WB_UP(BLOCK_SIZE), NUM_BLOCKS); +static char MEM_SLAB_CACHE_ATTR + __aligned(WB_UP(32)) _k_mem_slab_buf_tx_0_mem_slab[NUM_BLOCKS * WB_UP(BLOCK_SIZE)]; +STRUCT_SECTION_ITERABLE(k_mem_slab, + tx_0_mem_slab) = Z_MEM_SLAB_INITIALIZER(tx_0_mem_slab, + _k_mem_slab_buf_tx_0_mem_slab, + WB_UP(BLOCK_SIZE), NUM_BLOCKS);

Check notice on line 38 in tests/boards/nrf/i2s/i2s_divider/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/boards/nrf/i2s/i2s_divider/src/main.c:38 - #define MEM_SLAB_CACHE_ATTR __nocache +#define MEM_SLAB_CACHE_ATTR __nocache #else - #define MEM_SLAB_CACHE_ATTR +#define MEM_SLAB_CACHE_ATTR #endif /* CONFIG_NOCACHE_MEMORY */ -static char MEM_SLAB_CACHE_ATTR __aligned(WB_UP(32)) - _k_mem_slab_buf_tx_0_mem_slab[NUM_BLOCKS * WB_UP(BLOCK_SIZE)]; -STRUCT_SECTION_ITERABLE(k_mem_slab, tx_0_mem_slab) = - Z_MEM_SLAB_INITIALIZER(tx_0_mem_slab, _k_mem_slab_buf_tx_0_mem_slab, - WB_UP(BLOCK_SIZE), NUM_BLOCKS); +static char MEM_SLAB_CACHE_ATTR + __aligned(WB_UP(32)) _k_mem_slab_buf_tx_0_mem_slab[NUM_BLOCKS * WB_UP(BLOCK_SIZE)]; +STRUCT_SECTION_ITERABLE(k_mem_slab, + tx_0_mem_slab) = Z_MEM_SLAB_INITIALIZER(tx_0_mem_slab, + _k_mem_slab_buf_tx_0_mem_slab, + WB_UP(BLOCK_SIZE), NUM_BLOCKS);
static const struct device *dev_i2s;

static const struct i2s_config default_i2s_cfg = {
.word_size = WORD_SIZE,
.channels = NUMBER_OF_CHANNELS,
.format = I2S_FMT_DATA_FORMAT_I2S,
.frame_clk_freq = FRAME_CLK_FREQ,
.block_size = BLOCK_SIZE,
.timeout = TIMEOUT,
.options = I2S_OPT_FRAME_CLK_MASTER | I2S_OPT_BIT_CLK_MASTER,
.mem_slab = &tx_0_mem_slab,
};

/** @brief Check actual PCM rate at frame_clk_freq=8000.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_08000)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 8000;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

/** @brief Check actual PCM rate at frame_clk_freq=16000.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_16000)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 16000;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

/** @brief Check actual PCM rate at frame_clk_freq=32000.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_32000)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 32000;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

/** @brief Check actual PCM rate at frame_clk_freq=44100.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_44100)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 44100;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

/** @brief Check actual PCM rate at frame_clk_freq=48000.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_48000)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 48000;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

/** @brief Check actual PCM rate at frame_clk_freq=88200.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_88200)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 88200;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

/** @brief Check actual PCM rate at frame_clk_freq=96000.
*
* - Configure I2S stream.
*/
ZTEST(drivers_i2s_clk_div, test_i2s_frame_clk_freq_96000)
{
struct i2s_config i2s_cfg = default_i2s_cfg;
int ret;

i2s_cfg.frame_clk_freq = 96000;

ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
zassert_ok(ret, "i2s_configure() returned %d", ret);
}

static void *suite_setup(void)
{
/* Check I2S Device. */
dev_i2s = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE);
zassert_not_null(dev_i2s, "I2S device not found");
zassert(device_is_ready(dev_i2s), "I2S device not ready");

return 0;
}

ZTEST_SUITE(drivers_i2s_clk_div, NULL, suite_setup, NULL, NULL, NULL);
32 changes: 32 additions & 0 deletions tests/boards/nrf/i2s/i2s_divider/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
tests:
boards.nrf.i2s.i2s_divider:
tags:
- drivers
- i2s
harness: console
harness_config:
type: multi_line
ordered: true
regex:
- "test_i2s_frame_clk_freq_08000"
- "I2S MCK frequency: 256000, actual PCM rate: 8000"
- "test_i2s_frame_clk_freq_16000"
- "I2S MCK frequency: 507936, actual PCM rate: 15873"
- "test_i2s_frame_clk_freq_32000"
- "I2S MCK frequency: 1032258, actual PCM rate: 32258"
- "test_i2s_frame_clk_freq_44100"
- "I2S MCK frequency: 1391304, actual PCM rate: 43478"
- "test_i2s_frame_clk_freq_48000"
- "I2S MCK frequency: 1523809, actual PCM rate: 47619"
- "test_i2s_frame_clk_freq_88200"
- "I2S MCK frequency: 2909090, actual PCM rate: 90909"
- "test_i2s_frame_clk_freq_96000"
- "I2S MCK frequency: 3200000, actual PCM rate: 100000"
- "PROJECT EXECUTION SUCCESSFUL"
platform_allow:
- nrf52840dk/nrf52840
- nrf5340dk/nrf5340/cpuapp
- nrf54l15dk/nrf54l15/cpuapp
integration_platforms:
- nrf52840dk/nrf52840
- nrf54l15dk/nrf54l15/cpuapp
14 changes: 7 additions & 7 deletions tests/drivers/i2s/i2s_speed/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,43 @@ config I2S_TEST_ALLOWED_DATA_OFFSET
value of this option may be needed when GPIO loopback is used.

config I2S_TEST_SKIP_SAMPLERATE_8000
bool "Skip short transfer tests at 8000 samples per socond"
bool "Skip short transfer tests at 8000 samples per second"
help
When set to 'y', short transfer tests at 8000 samples per second
will be skipped.

config I2S_TEST_SKIP_SAMPLERATE_16000
bool "Skip short transfer tests at 16000 samples per socond"
bool "Skip short transfer tests at 16000 samples per second"
help
When set to 'y', short transfer tests at 16000 samples per second
will be skipped.

config I2S_TEST_SKIP_SAMPLERATE_32000
bool "Skip short transfer tests at 32000 samples per socond"
bool "Skip short transfer tests at 32000 samples per second"
help
When set to 'y', short transfer tests at 32000 samples per second
will be skipped.

config I2S_TEST_SKIP_SAMPLERATE_44100
bool "Skip short transfer tests at 44100 samples per socond"
bool "Skip short transfer tests at 44100 samples per second"
help
When set to 'y', short transfer tests at 44100 samples per second
will be skipped.

config I2S_TEST_SKIP_SAMPLERATE_48000
bool "Skip short transfer tests at 48000 samples per socond"
bool "Skip short transfer tests at 48000 samples per second"
help
When set to 'y', short transfer tests at 48000 samples per second
will be skipped.

config I2S_TEST_SKIP_SAMPLERATE_88200
bool "Skip short transfer tests at 88200 samples per socond"
bool "Skip short transfer tests at 88200 samples per second"
help
When set to 'y', short transfer tests at 88200 samples per second
will be skipped.

config I2S_TEST_SKIP_SAMPLERATE_96000
bool "Skip short transfer tests at 96000 samples per socond"
bool "Skip short transfer tests at 96000 samples per second"
help
When set to 'y', short transfer tests at 96000 samples per second
will be skipped.
Loading