Skip to content
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

tests: benchmarks: multicore: idle_spim_loopback: Add test for SPIM120 #18571

Merged
merged 2 commits into from
Nov 6, 2024
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
19 changes: 19 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

if(NOT SYSBUILD)
message(FATAL_ERROR
" This is a multi-image application that should be built using sysbuild.\n"
" Add --sysbuild argument to west build command to prepare all the images.")
endif()

project(idle_spim_loopback)

target_sources(app PRIVATE src/main.c)
22 changes: 22 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

config TEST_SLEEP_DURATION_MS
int "Amount of time (in miliseconds) the core is sleeping"
default 1000
help
Set sleep duration to TEST_SLEEP_DURATION_MS miliseconds.
Based on the value of 'min-residency-us' specified for each power state defined in the DTS,
core enters the lowest possible power state.

config DATA_FIELD
int "Number of bytes exchanged in single SPI transceive operation"
default 4
help
Set number of bytes exchanged in single spi_transceive() operation.
Values from 1 to 16 bytes are confirmed to work correctly.

source "Kconfig.zephyr"
10 changes: 10 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"

config REMOTE_BOARD
string "The board used for remote target"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&pinctrl {
spi130_default_alt: spi130_default_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 0)>,
<NRF_PSEL(SPIM_MOSI, 0, 7)>,
<NRF_PSEL(SPIM_MISO, 0, 6)>;
};
};

spi130_sleep_alt: spi130_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 0)>,
<NRF_PSEL(SPIM_MISO, 0, 6)>,
<NRF_PSEL(SPIM_MOSI, 0, 7)>;
low-power-enable;
};
};
};

&spi130 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi130_default_alt>;
pinctrl-1 = <&spi130_sleep_alt>;
pinctrl-names = "default", "sleep";
overrun-character = <0x00>;
memory-regions = <&cpuapp_dma_region>;
zephyr,pm-device-runtime-auto;
dut_spi_dt: test-spi-dev@0 {
compatible = "vnd,spi-device";
reg = <0>;
spi-max-frequency = <DT_FREQ_M(4)>;
};
};

&exmif {
status = "disabled";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&pinctrl {
spi120_default: spi120_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 7, 3)>,
<NRF_PSEL(SPIM_MISO, 7, 6)>,
<NRF_PSEL(SPIM_MOSI, 7, 7)>;
};
};

spi120_sleep: spi120_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 7, 3)>,
<NRF_PSEL(SPIM_MISO, 7, 6)>,
<NRF_PSEL(SPIM_MOSI, 7, 7)>;
low-power-enable;
};
};
};

&spi130 {
status = "disabled";
/delete-property/ dut_spi_dt;
};

&spi120 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi120_default>;
pinctrl-1 = <&spi120_sleep>;
pinctrl-names = "default", "sleep";
overrun-character = <0x00>;
memory-regions = <&dma_fast_region>;
zephyr,pm-device-runtime-auto;
dut_spi_dt: test-spi-dev@0 {
compatible = "vnd,spi-device";
reg = <0>;
spi-max-frequency = <DT_FREQ_M(4)>;
};
};

&exmif {
status = "disabled";
};
5 changes: 5 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_SPI=y

CONFIG_NRF_REGTOOL_VERBOSITY=1
21 changes: 21 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/prj_s2ram.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CONFIG_PM=y
CONFIG_PM_S2RAM=y
CONFIG_PM_S2RAM_CUSTOM_MARKING=y
CONFIG_POWEROFF=y
CONFIG_NRFS_MRAM_SERVICE_ENABLED=n

CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y

# Enable for debugging purposes only
CONFIG_BOOT_BANNER=n
CONFIG_NCS_BOOT_BANNER=n
CONFIG_PRINTK=n
CONFIG_LOG=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_SERIAL=n

CONFIG_SPI=y
CONFIG_ASSERT=y
CONFIG_NRFS=y
180 changes: 180 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(idle_spim_loopback, LOG_LEVEL_INF);

#include <zephyr/kernel.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/linker/devicetree_regions.h>
#include <zephyr/pm/device_runtime.h>

#include <nrfs_backend_ipc_service.h>
#include <nrfs_gdpwr.h>

#define DELTA (1)

#define SPI_MODE (SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_LINES_SINGLE | SPI_TRANSFER_MSB \
| SPI_MODE_CPHA | SPI_MODE_CPOL)

static struct spi_dt_spec spim_spec = SPI_DT_SPEC_GET(DT_NODELABEL(dut_spi_dt), SPI_MODE, 0);

#define MEMORY_SECTION(node) \
COND_CODE_1(DT_NODE_HAS_PROP(node, memory_regions), \
(__attribute__((__section__( \
LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(node, memory_regions)))))), \
())

static uint8_t spim_buffer[2 * CONFIG_DATA_FIELD]
MEMORY_SECTION(DT_BUS(DT_NODELABEL(dut_spi_dt)));

/* Variables used to make SPI active for ~1 second */
static struct k_timer my_timer;
static bool timer_expired;

void my_timer_handler(struct k_timer *dummy)
{
timer_expired = true;
}

/* Required to power off the GD2 and GD3 domains
* Will be removed when GD handling
* is implemented in sdk-zephyr
*/
static void gdpwr_handler(nrfs_gdpwr_evt_t const *p_evt, void *context)
{
switch (p_evt->type) {
case NRFS_GDPWR_REQ_APPLIED:
printk("GDPWR handler - response received: 0x%x, CTX=%d\n", p_evt->type,
(uint32_t)context);
break;
case NRFS_GDPWR_REQ_REJECTED:
printk("GDPWR handler - request rejected: 0x%x, CTX=%d\n", p_evt->type,
(uint32_t)context);
break;
default:
printk("GDPWR handler - unexpected event: 0x%x, CTX=%d\n", p_evt->type,
(uint32_t)context);
break;
}
}

/* Required to power off the GD2 and GD3 domains
* Will be removed when GD handling
* is implemented in sdk-zephyr
*/
static void clear_global_power_domains_requests(void)
{
int service_status;
int tst_ctx = 1;

service_status = nrfs_gdpwr_init(gdpwr_handler);
printk("Response: %d\n", service_status);
printk("Sending GDPWR DISABLE request for: GDPWR_POWER_DOMAIN_ACTIVE_SLOW\n");
service_status = nrfs_gdpwr_power_request(GDPWR_POWER_DOMAIN_ACTIVE_SLOW,
GDPWR_POWER_REQUEST_CLEAR, (void *)tst_ctx++);
printk("Response: %d\n", service_status);
printk("Sending GDPWR DISABLE request for: GDPWR_POWER_DOMAIN_ACTIVE_FAST\n");
service_status = nrfs_gdpwr_power_request(GDPWR_POWER_DOMAIN_ACTIVE_FAST,
GDPWR_POWER_REQUEST_CLEAR, (void *)tst_ctx++);
printk("Response: %d\n", service_status);
printk("Sending GDPWR DISABLE request for: GDPWR_POWER_DOMAIN_MAIN_SLOW\n");
service_status = nrfs_gdpwr_power_request(GDPWR_POWER_DOMAIN_MAIN_SLOW,
GDPWR_POWER_REQUEST_CLEAR, (void *)tst_ctx);
printk("Response: %d\n", service_status);
}

int main(void)
{
int ret;
int counter = 0;
uint8_t acc = 0;
bool test_pass;

/* SPI buffer sets */
struct spi_buf tx_spi_buf = {
.buf = &spim_buffer[0],
.len = CONFIG_DATA_FIELD
};
struct spi_buf_set tx_spi_buf_set = {
.buffers = &tx_spi_buf,
.count = 1
};

struct spi_buf rx_spi_buf = {
.buf = &spim_buffer[CONFIG_DATA_FIELD],
.len = CONFIG_DATA_FIELD
};
struct spi_buf_set rx_spi_buf_set = {
.buffers = &rx_spi_buf,
.count = 1
};

nrfs_backend_wait_for_connection(K_FOREVER);
clear_global_power_domains_requests();

LOG_INF("%s runs as a SPI HOST", CONFIG_BOARD_TARGET);
LOG_INF("%d bytes of data exchanged at once", CONFIG_DATA_FIELD);

ret = spi_is_ready_dt(&spim_spec);
if (!ret) {
LOG_ERR("Error: SPI device is not ready");
}
__ASSERT(ret, "Error: SPI device is not ready\n");

k_timer_init(&my_timer, my_timer_handler, NULL);

/* Run test forever */
while (1) {
test_pass = true;
timer_expired = false;

/* start a one-shot timer that expires after 1 second */
k_timer_start(&my_timer, K_MSEC(1000), K_NO_WAIT);

/* SPI active transmissions for ~ 1 second */
while (!timer_expired) {
/* Generate pseudo random tx_data for current test */
for (int i = 0; i < CONFIG_DATA_FIELD; i++) {
*((uint8_t *) tx_spi_buf.buf + i) = acc;
acc += DELTA;
}

/* Transmit data */
ret = spi_transceive_dt(&spim_spec, &tx_spi_buf_set, &rx_spi_buf_set);
if (ret != 0) {
LOG_ERR("spi_transceive_dt, err: %d", ret);
}
__ASSERT(ret == 0, "Error: spi_transceive_dt, err: %d\n", ret);

/* Check if the received data is consistent with the data sent */
for (int i = 0; i < CONFIG_DATA_FIELD; i++) {
uint8_t received = *((uint8_t *) rx_spi_buf.buf + i);
uint8_t transmitted = *((uint8_t *) tx_spi_buf.buf + i);

if (received != transmitted) {
LOG_ERR("FAIL: rx[%d] = %d, expected %d",
i, received, transmitted);
test_pass = false;
__ASSERT(false, "Run %d - FAILED\n", counter);
}
}
} /* while (!timer_expired) */

/* Report if communication was successful */
if (test_pass) {
LOG_INF("Run %d - PASS", counter);
} else {
LOG_INF("Run %d - FAILED", counter);
}
counter++;

/* Sleep / enter low power state */
k_msleep(CONFIG_TEST_SLEEP_DURATION_MS);
}

return 0;
}
22 changes: 22 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "")
message(FATAL_ERROR "REMOTE_BOARD must be set to a valid board name")
endif()

# Add remote project
ExternalZephyrProject_Add(
APPLICATION remote
SOURCE_DIR ${APP_DIR}/../../power_consumption/common/remote_sleep_forever
BOARD ${SB_CONFIG_REMOTE_BOARD}
BOARD_REVISION ${BOARD_REVISION}
)

# Add a dependency so that the remote image will be built and flashed first
add_dependencies(idle_spim_loopback remote)
# Add dependency so that the remote image is flashed first.
sysbuild_add_dependencies(FLASH idle_spim_loopback remote)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SB_CONFIG_REMOTE_BOARD="nrf54h20dk/nrf54h20/cpurad"
Loading
Loading