Skip to content

Commit

Permalink
tests: benchmarks: Verify power management for UARTE (using s2ram)
Browse files Browse the repository at this point in the history
Verify PM ability to handle UARTE  power management
This sample uses GPIO loopback

Signed-off-by: Bartosz Miller <[email protected]>
  • Loading branch information
nordic-bami committed Sep 20, 2024
1 parent cfb2a11 commit c9afb28
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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(WARNING
" 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_uarte)

target_sources(app PRIVATE src/main.c)
10 changes: 10 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2023 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"
61 changes: 61 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. _multicore_idle_uarte_test:

Multicore idle UARTE test
###################

.. contents::
:local:
:depth: 2

The test benchmarks the idle and s2ram behavior of an application that runs on multiple cores.
It uses a system timer as a wake-up source.

Requirements
************

The test supports the following development kits:

.. table-from-rows:: /includes/sample_board_rows.txt
:header: heading
:rows: nrf54h20dk_nrf54h20_cpuapp
:rows: UART135 TX connected to RX and CTS to RTS

Overview
********

The test demonstrates how to build a multicore idle application with :ref:`configuration_system_overview_sysbuild`.

When building with sysbuild, the build system adds child images based on the options selected in the project's additional configuration and build files.
This test shows how to inform the build system about dedicated sources for additional images.
The test comes with the following additional files:

* :file:`Kconfig.sysbuild` - This file is used to add :ref:`sysbuild Kconfig options <configuration_system_overview_sysbuild>` that are passed to all the images.
* :file:`sysbuild.cmake` - The CMake file adds additional images using the :c:macro:`ExternalZephyrProject_Add` macro.
You can also add the dependencies for the images if required.

Both the application and remote cores use the same :file:`main.c` that prints the name of the DK on which the application is programmed.

Building and running
********************

.. |test path| replace:: :file:`tests/benchmarks/multicore/idle`

.. include:: /includes/build_and_run_test.txt

The remote board must be specified using ``SB_CONFIG_REMOTE_BOARD``.
To build the test, use configuration setups from :file:`testcase.yaml` using the ``-T`` option.
See the following examples:

nRF54H20 DK
You can build the test for application and radio cores as follows:

.. code-block:: console
west build -p -b nrf54h20dk/nrf54h20/cpuapp -T benchmarks.multicore.idle_twim.nrf54h20dk_cpuapp_cpurad.s2ram .
Testing
=======

After programming the test to your development kit, complete the following steps to test it:

#. Connect the PPK2 Power Profiler Kit or other current measurement device
#. Reset the kit
#. Observe the current consumption: high when UARTE is active, low when device sleeps
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&cpuapp_dma_region {
status="okay";
};

&pinctrl {
uart135_default_alt: uart135_default_alt {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 6)>,
<NRF_PSEL(UART_RX, 0, 7)>,
<NRF_PSEL(UART_RTS, 0, 8)>,
<NRF_PSEL(UART_CTS, 0, 9)>;
};
};

uart135_sleep_alt: uart135_sleep_alt {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 6)>,
<NRF_PSEL(UART_RX, 0, 7)>,
<NRF_PSEL(UART_RTS, 0, 8)>,
<NRF_PSEL(UART_CTS, 0, 9)>;
low-power-enable;
};
};
};

dut: &uart135 {
status = "okay";
memory-regions = <&cpuapp_dma_region>;
pinctrl-0 = <&uart135_default_alt>;
pinctrl-1 = <&uart135_sleep_alt>;
pinctrl-names = "default", "sleep";
current-speed = <115200>;
hw-flow-control;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include "nrf54h20dk_nrf54h20_common.dtsi"

/ {
power-states {
idle: idle {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-idle";
min-residency-us = <100000>;
};

s2ram: s2ram {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-ram";
min-residency-us = <800000>;
};
};
};

&cpu {
cpu-power-states = <&idle &s2ram>;
};
22 changes: 22 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CONFIG_SERIAL=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_UART_USE_RUNTIME_CONFIGURE=y
CONFIG_UART_ASYNC_API=y

CONFIG_PM=y
CONFIG_PM_S2RAM=y
CONFIG_PM_S2RAM_CUSTOM_MARKING=y
CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y
CONFIG_POWEROFF=y

CONFIG_GPIO=n
CONFIG_BOOT_BANNER=n
CONFIG_NRFS_MRAM_SERVICE_ENABLED=n
CONFIG_CLOCK_CONTROL=n

# Enable for debugging purposes only
CONFIG_PRINTK=n
CONFIG_LOG=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
12 changes: 12 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# 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})
project(remote)

target_sources(app PRIVATE src/main.c)
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
*/

&uart135 {
status = "disabled";
/delete-property/memory-regions;
};
9 changes: 9 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/remote/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_PM=y
CONFIG_POWEROFF=y
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_SERIAL=n
CONFIG_GPIO=n
CONFIG_BOOT_BANNER=n
CONFIG_NRFS_MRAM_SERVICE_ENABLED=n
CONFIG_CLOCK_CONTROL=n
17 changes: 17 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/remote/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>

int main(void)
{
k_msleep(500);
while (1) {
k_msleep(2000);
}

return 0;
}
113 changes: 113 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/drivers/uart.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

/* Note: logging is normally disabled for this test
* Enable only for debugging purposes
*/
LOG_MODULE_REGISTER(idle_uarte);

#if DT_NODE_EXISTS(DT_NODELABEL(dut))
#define UART_NODE DT_NODELABEL(dut)
#else
#error Improper device tree configuration, UARTE test node not available
#endif

#define UART_ACTION_BASE_TIMEOUT_US 1000
#define TEST_BUFFER_LEN 10

static const struct device *const uart_dev = DEVICE_DT_GET(UART_NODE);

const uint8_t test_pattern[TEST_BUFFER_LEN] = {0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x20};
static uint8_t test_buffer[TEST_BUFFER_LEN];
static volatile uint8_t uart_error_counter;

/*
* Callback function for UART async transmission
*/
static void async_uart_callback(const struct device *dev, struct uart_event *evt, void *user_data)
{
printk("Callback !\n");
switch (evt->type) {
case UART_TX_DONE:
printk("UART_TX_DONE\n");
break;
case UART_TX_ABORTED:
printk("UART_TX_ABORTED\n");
break;
case UART_RX_RDY:
printk("UART_RX_RDY\n");
for (int index = 0; index < TEST_BUFFER_LEN; index++) {
printk("test_pattern[%d]=%d\n", index, test_pattern[index]);
printk("test_buffer[%d]=%d\n", index, test_buffer[index]);
if (test_buffer[index] != test_pattern[index]) {
printk("Recieived data byte %d does not match pattern 0x%x != "
"0x%x\n",
index, test_buffer[index], test_pattern[index]);
}
}
break;
case UART_RX_BUF_RELEASED:
printk("UART_RX_BUF_RELEASED\n");
break;
case UART_RX_BUF_REQUEST:
printk("UART_RX_BUF_REQUEST\n");
break;
case UART_RX_DISABLED:
printk("UART_RX_DISABLED\n");
break;
default:
break;
}
}

int main(void)
{
int err;
struct uart_config test_uart_config = {.baudrate = 115200,
.parity = UART_CFG_PARITY_ODD,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
.flow_ctrl = UART_CFG_FLOW_CTRL_RTS_CTS};

err = uart_configure(uart_dev, &test_uart_config);
if (err != 0) {
printk("Unexpected error when configuring UART: %d\n", err);
return -1;
}

err = uart_rx_disable(uart_dev);
if (err != 0) {
printk("Unexpected error when disabling RX: %d\n", err);
return -1;
}

err = uart_callback_set(uart_dev, async_uart_callback, NULL);
if (err != 0) {
printk("Unexpected error when setting callback %d\n", err);
return -1;
}

while (1) {
printk("Hello\n");

uart_rx_enable(uart_dev, test_buffer, TEST_BUFFER_LEN,
5 * UART_ACTION_BASE_TIMEOUT_US);
uart_tx(uart_dev, test_pattern, TEST_BUFFER_LEN, UART_ACTION_BASE_TIMEOUT_US);
k_msleep(250);
uart_rx_disable(uart_dev);
k_msleep(250);

printk("Good night\n");
k_msleep(2000);
}

return 0;
}
26 changes: 26 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2023 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}/remote
BOARD ${SB_CONFIG_REMOTE_BOARD}
BOARD_REVISION ${BOARD_REVISION}
)
set_property(GLOBAL APPEND PROPERTY PM_DOMAINS CPUNET)
set_property(GLOBAL APPEND PROPERTY PM_CPUNET_IMAGES remote)
set_property(GLOBAL PROPERTY DOMAIN_APP_CPUNET remote)
set(CPUNET_PM_DOMAIN_DYNAMIC_PARTITION remote CACHE INTERNAL "")

# Add a dependency so that the remote image will be built and flashed first
add_dependencies(idle_uarte remote)
# Add dependency so that the remote image is flashed first.
sysbuild_add_dependencies(FLASH idle_uarte remote)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SB_CONFIG_REMOTE_BOARD="nrf54h20dk/nrf54h20/cpurad"
19 changes: 19 additions & 0 deletions tests/benchmarks/multicore/idle_uarte/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
common:
sysbuild: true
depends_on: gpio
tags: ci_build ci_tests_benchmarks_multicore uarte


tests:
benchmarks.multicore.idle_uarte.nrf54h20dk_cpuapp_cpurad.s2ram:
harness: pytest
platform_allow:
- nrf54h20dk/nrf54h20/cpuapp
extra_args:
- FILE_SUFFIX=s2ram
- SB_CONF_FILE=sysbuild/nrf54h20dk_nrf54h20_cpurad.conf
- DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_s2ram.overlay"
harness_config:
fixture: ppk_power_measure
pytest_root:
- "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_power_consumption"

0 comments on commit c9afb28

Please sign in to comment.