From ef417cb359449e3c264bbbdb1c7d768d3f98227a Mon Sep 17 00:00:00 2001 From: Bartosz Miller Date: Fri, 24 Jan 2025 12:59:52 +0100 Subject: [PATCH] tests: benchmarks: Add TWIM suspend test with current measurement Call the suspend/resume manually and measure the current consumption. Signed-off-by: Bartosz Miller --- .../twim_suspend/CMakeLists.txt | 13 +++ .../twim_suspend/Kconfig.sysbuild | 11 +++ .../nrf54h20dk_nrf54h20_cpuapp_pm.overlay | 8 ++ .../nrf54l15dk_nrf54l15_cpuapp_pm.overlay | 8 ++ .../current_consumption/twim_suspend/prj.conf | 18 ++++ .../twim_suspend/remote/CMakeLists.txt | 12 +++ .../twim_suspend/remote/prj.conf | 7 ++ .../twim_suspend/remote/src/main.c | 14 ++++ .../twim_suspend/src/main.c | 82 +++++++++++++++++++ .../twim_suspend/sysbuild.cmake | 19 +++++ .../twim_suspend/testcase.yaml | 44 ++++++++++ 11 files changed, 236 insertions(+) create mode 100644 tests/benchmarks/current_consumption/twim_suspend/CMakeLists.txt create mode 100644 tests/benchmarks/current_consumption/twim_suspend/Kconfig.sysbuild create mode 100644 tests/benchmarks/current_consumption/twim_suspend/boards/nrf54h20dk_nrf54h20_cpuapp_pm.overlay create mode 100644 tests/benchmarks/current_consumption/twim_suspend/boards/nrf54l15dk_nrf54l15_cpuapp_pm.overlay create mode 100644 tests/benchmarks/current_consumption/twim_suspend/prj.conf create mode 100644 tests/benchmarks/current_consumption/twim_suspend/remote/CMakeLists.txt create mode 100644 tests/benchmarks/current_consumption/twim_suspend/remote/prj.conf create mode 100644 tests/benchmarks/current_consumption/twim_suspend/remote/src/main.c create mode 100644 tests/benchmarks/current_consumption/twim_suspend/src/main.c create mode 100644 tests/benchmarks/current_consumption/twim_suspend/sysbuild.cmake create mode 100644 tests/benchmarks/current_consumption/twim_suspend/testcase.yaml diff --git a/tests/benchmarks/current_consumption/twim_suspend/CMakeLists.txt b/tests/benchmarks/current_consumption/twim_suspend/CMakeLists.txt new file mode 100644 index 000000000000..75e980c22105 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/CMakeLists.txt @@ -0,0 +1,13 @@ +# +# Copyright (c) 2025 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(twim_suspend) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/benchmarks/current_consumption/twim_suspend/Kconfig.sysbuild b/tests/benchmarks/current_consumption/twim_suspend/Kconfig.sysbuild new file mode 100644 index 000000000000..c72396b7c358 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/Kconfig.sysbuild @@ -0,0 +1,11 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +source "${ZEPHYR_BASE}/share/sysbuild/Kconfig" + +config REMOTE_BOARD + string + default "$(BOARD)/nrf54h20/cpurad" if SOC_NRF54H20_CPUAPP diff --git a/tests/benchmarks/current_consumption/twim_suspend/boards/nrf54h20dk_nrf54h20_cpuapp_pm.overlay b/tests/benchmarks/current_consumption/twim_suspend/boards/nrf54h20dk_nrf54h20_cpuapp_pm.overlay new file mode 100644 index 000000000000..9c7ae9c523e3 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/boards/nrf54h20dk_nrf54h20_cpuapp_pm.overlay @@ -0,0 +1,8 @@ +/* + * Copyright (C) 2025 Nordic Semiconductor ASA + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +&i2c130 { + /delete-property/ zephyr,pm-device-runtime-auto; +}; diff --git a/tests/benchmarks/current_consumption/twim_suspend/boards/nrf54l15dk_nrf54l15_cpuapp_pm.overlay b/tests/benchmarks/current_consumption/twim_suspend/boards/nrf54l15dk_nrf54l15_cpuapp_pm.overlay new file mode 100644 index 000000000000..e992ea8bf734 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/boards/nrf54l15dk_nrf54l15_cpuapp_pm.overlay @@ -0,0 +1,8 @@ +/* + * Copyright (C) 2025 Nordic Semiconductor ASA + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +&i2c22 { + /delete-property/ zephyr,pm-device-runtime-auto; +}; diff --git a/tests/benchmarks/current_consumption/twim_suspend/prj.conf b/tests/benchmarks/current_consumption/twim_suspend/prj.conf new file mode 100644 index 000000000000..872ed6e4c1b7 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/prj.conf @@ -0,0 +1,18 @@ +CONFIG_I2C=y + +CONFIG_PM=y +CONFIG_PM_DEVICE=y +CONFIG_PM_DEVICE_RUNTIME=y +CONFIG_POWEROFF=y + +CONFIG_GPIO=n +CONFIG_BOOT_BANNER=n + +CONFIG_ASSERT=y + +# Enable for debugging purposes only +CONFIG_PRINTK=n +CONFIG_LOG=n +CONFIG_CONSOLE=n +CONFIG_UART_CONSOLE=n +CONFIG_SERIAL=n diff --git a/tests/benchmarks/current_consumption/twim_suspend/remote/CMakeLists.txt b/tests/benchmarks/current_consumption/twim_suspend/remote/CMakeLists.txt new file mode 100644 index 000000000000..97caab4871c3 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/remote/CMakeLists.txt @@ -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) diff --git a/tests/benchmarks/current_consumption/twim_suspend/remote/prj.conf b/tests/benchmarks/current_consumption/twim_suspend/remote/prj.conf new file mode 100644 index 000000000000..136c013a406a --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/remote/prj.conf @@ -0,0 +1,7 @@ +CONFIG_PM=y +CONFIG_POWEROFF=y +CONFIG_CONSOLE=n +CONFIG_UART_CONSOLE=n +CONFIG_SERIAL=n +CONFIG_GPIO=n +CONFIG_BOOT_BANNER=n diff --git a/tests/benchmarks/current_consumption/twim_suspend/remote/src/main.c b/tests/benchmarks/current_consumption/twim_suspend/remote/src/main.c new file mode 100644 index 000000000000..61b5b084a585 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/remote/src/main.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include + +int main(void) +{ + k_sleep(K_FOREVER); + + return 0; +} diff --git a/tests/benchmarks/current_consumption/twim_suspend/src/main.c b/tests/benchmarks/current_consumption/twim_suspend/src/main.c new file mode 100644 index 000000000000..ee0ddfafbd69 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/src/main.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include + +/* Note: logging is normally disabled for this test + * Enable only for debugging purposes + */ +LOG_MODULE_REGISTER(twim_suspend); + +#define SENSOR_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(bosch_bme680) +#define I2C_TEST_NODE DT_PARENT(SENSOR_NODE) +#define DEVICE_ADDRESS (uint8_t) DT_REG_ADDR(SENSOR_NODE) + +#define CHIP_ID_REGISTER_ADDRESS 0xD0 +#define VARIANT_ID_REGISTER_ADDRESS 0xF0 + +static const struct device *const i2c_device = DEVICE_DT_GET(I2C_TEST_NODE); + +/* + * Helper method for reading the BME688 I2C registers + */ +static uint8_t read_sensor_register(uint8_t register_address) +{ + int rc; + uint8_t response; + + rc = i2c_reg_read_byte(i2c_device, DEVICE_ADDRESS, register_address, &response); + printk("i2c_reg_read_byte ret: %d\n", rc); + __ASSERT_NO_MSG(rc == 0); + printk("I2C read reg, addr: 0x%x, val: 0x%x\n", register_address, response); + return response; +} + +int main(void) +{ + uint8_t response; + uint32_t i2c_config = I2C_SPEED_SET(I2C_SPEED_STANDARD) | I2C_MODE_CONTROLLER; + + printk("Device address 0x%x\n", DEVICE_ADDRESS); + printk("I2C speed setting: %d\n", I2C_SPEED_STANDARD); + + response = i2c_configure(i2c_device, i2c_config); + if (response != 0) { + printk("I2C configuration failed%d\n", response); + __ASSERT_NO_MSG(response == 0); + } + + response = pm_device_action_run(i2c_device, PM_DEVICE_ACTION_SUSPEND); + printk("PM_DEVICE_ACTION_SUSPEND status: %d\n", response); + __ASSERT_NO_MSG(response == 0); + + while (1) { + response = pm_device_action_run(i2c_device, PM_DEVICE_ACTION_RESUME); + printk("PM_DEVICE_ACTION_RESUME status: %d\n", response); + __ASSERT_NO_MSG(response == 0); + + response = read_sensor_register(CHIP_ID_REGISTER_ADDRESS); + printk("Chip_Id: %d\n", response); + __ASSERT_NO_MSG(response != 0); + + response = read_sensor_register(VARIANT_ID_REGISTER_ADDRESS); + printk("Variant_Id: %d\n", response); + __ASSERT_NO_MSG(response != 0); + + response = pm_device_action_run(i2c_device, PM_DEVICE_ACTION_SUSPEND); + printk("PM_DEVICE_ACTION_SUSPEND status: %d\n", response); + __ASSERT_NO_MSG(response == 0); + + printk("Good night\n"); + k_msleep(1000); + printk("Good morning\n"); + } + + return 0; +} diff --git a/tests/benchmarks/current_consumption/twim_suspend/sysbuild.cmake b/tests/benchmarks/current_consumption/twim_suspend/sysbuild.cmake new file mode 100644 index 000000000000..9da75190daa3 --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/sysbuild.cmake @@ -0,0 +1,19 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +if(SB_CONFIG_REMOTE_BOARD) + # Add remote project + ExternalZephyrProject_Add( + APPLICATION remote + SOURCE_DIR ${APP_DIR}/remote + 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(twim_suspend remote) + # Add dependency so that the remote image is flashed first. + sysbuild_add_dependencies(FLASH twim_suspend remote) +endif() diff --git a/tests/benchmarks/current_consumption/twim_suspend/testcase.yaml b/tests/benchmarks/current_consumption/twim_suspend/testcase.yaml new file mode 100644 index 000000000000..1561e7f06bcd --- /dev/null +++ b/tests/benchmarks/current_consumption/twim_suspend/testcase.yaml @@ -0,0 +1,44 @@ +common: + sysbuild: true + depends_on: i2c + +tests: + benchmarks.current_consumption.twim_suspend.nrf54h: + tags: + - ci_build + - ci_tests_benchmarks_multicore + - twim + - ppk_power_measure + platform_allow: + - nrf54h20dk/nrf54h20/cpuapp + integration_platforms: + - nrf54h20dk/nrf54h20/cpuapp + extra_args: + - SHIELD=pca63566 + - EXTRA_DTC_OVERLAY_FILE=boards/nrf54h20dk_nrf54h20_cpuapp_pm.overlay + - CONFIG_PM_S2RAM=y + - CONFIG_PM_S2RAM_CUSTOM_MARKING=y + harness: pytest + harness_config: + fixture: pca63566 + pytest_root: + - "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_power_consumption_twim" + + benchmarks.current_consumption.twim_suspend.nrf54l: + tags: + - ci_build + - ci_tests_benchmarks_multicore + - twim + - ppk_power_measure + platform_allow: + - nrf54l15dk/nrf54l15/cpuapp + integration_platforms: + - nrf54l15dk/nrf54l15/cpuapp + extra_args: + - SHIELD=pca63565 + - EXTRA_DTC_OVERLAY_FILE=boards/nrf54l15dk_nrf54l15_cpuapp_pm.overlay + harness: pytest + harness_config: + fixture: pca63565 + pytest_root: + - "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_power_consumption_twim"