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: Add TWIM suspend test with current measurement #20068

Merged
merged 1 commit into from
Jan 27, 2025
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
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
@@ -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;
};
18 changes: 18 additions & 0 deletions tests/benchmarks/current_consumption/twim_suspend/prj.conf
Original file line number Diff line number Diff line change
@@ -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
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,7 @@
CONFIG_PM=y
CONFIG_POWEROFF=y
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_SERIAL=n
CONFIG_GPIO=n
CONFIG_BOOT_BANNER=n
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>

int main(void)
{
k_sleep(K_FOREVER);

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

#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/pm/device.h>

/* 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;
}
Original file line number Diff line number Diff line change
@@ -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
nordic-bami marked this conversation as resolved.
Show resolved Hide resolved
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()
44 changes: 44 additions & 0 deletions tests/benchmarks/current_consumption/twim_suspend/testcase.yaml
Original file line number Diff line number Diff line change
@@ -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"