Skip to content

Commit 9d42862

Browse files
nordic-pikrnordicjm
authored andcommitted
tests: benchmarks: pm_states: Add pm_states test
Add a test to check if power management states are switched correctly. Signed-off-by: Piotr Krzyzanowski <[email protected]>
1 parent 5ac665f commit 9d42862

File tree

8 files changed

+152
-0
lines changed

8 files changed

+152
-0
lines changed

scripts/ci/tags.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ ci_tests_benchmarks_current_consumption:
12441244
- nrf/include/nfc/
12451245
- nrf/subsys/nfc/
12461246
- nrf/tests/benchmarks/current_consumption/
1247+
- nrf/tests/benchmarks/pm_states/
12471248
- nrf/tests/benchmarks/power_consumption/
12481249
- nrfxlib/nfc/
12491250
- zephyr/boards/nordic/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
if(NOT SYSBUILD)
12+
message(FATAL_ERROR
13+
" This is a multi-image application that should be built using sysbuild.\n"
14+
" Add --sysbuild argument to west build command to prepare all the images.")
15+
endif()
16+
17+
project(pm_states)
18+
19+
target_sources(app PRIVATE src/main.c)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config NRF_DEFAULT_EMPTY
8+
default y
9+
10+
source "$(ZEPHYR_BASE)/share/sysbuild/Kconfig"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_SOC_NRF54H20_CPURAD_ENABLE=y
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&uart136 {
8+
status = "disabled";
9+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_ASSERT=y
2+
CONFIG_PM=y
3+
CONFIG_GPIO=y
4+
CONFIG_CONSOLE=n
5+
CONFIG_UART_CONSOLE=n
6+
CONFIG_SERIAL=n
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/devicetree.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/drivers/gpio.h>
10+
#include <zephyr/pm/pm.h>
11+
12+
#define PS_NODE DT_PATH(cpus, power_states)
13+
14+
#if DT_NODE_EXISTS(PS_NODE)
15+
#define PS_VAL(node) DT_PROP_OR(node, min_residency_us, 0),
16+
17+
static const uint32_t min_residencies[] = {DT_FOREACH_CHILD(PS_NODE, PS_VAL)};
18+
19+
#define PS_COUNT ARRAY_SIZE(min_residencies)
20+
#else
21+
static const uint32_t min_residencies[] = {};
22+
#define PS_COUNT 0
23+
#endif
24+
25+
static const struct gpio_dt_spec leds[] = {
26+
GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios),
27+
GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios),
28+
GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios),
29+
GPIO_DT_SPEC_GET(DT_ALIAS(led3), gpios),
30+
};
31+
#define LED_COUNT ARRAY_SIZE(leds)
32+
33+
static void notify_pm_state_entry(enum pm_state state)
34+
{
35+
switch (state) {
36+
case PM_STATE_SUSPEND_TO_IDLE:
37+
gpio_pin_set_dt(&leds[0], 1);
38+
break;
39+
case PM_STATE_SUSPEND_TO_RAM:
40+
gpio_pin_set_dt(&leds[2], 1);
41+
break;
42+
default:
43+
__ASSERT(true, "Unexpected PM state: %d", state);
44+
break;
45+
}
46+
}
47+
48+
static void notify_pm_state_exit(enum pm_state state)
49+
{
50+
for (size_t i = 0; i < LED_COUNT; i++) {
51+
gpio_pin_set_dt(&leds[i], 0);
52+
}
53+
}
54+
55+
static struct pm_notifier notifier = {
56+
.state_entry = notify_pm_state_entry,
57+
.state_exit = notify_pm_state_exit,
58+
};
59+
60+
int main(void)
61+
{
62+
int ret;
63+
64+
for (size_t i = 0; i < LED_COUNT; i++) {
65+
ret = gpio_is_ready_dt(&leds[i]);
66+
__ASSERT(ret, "Error: GPIO Device not ready");
67+
ret = gpio_pin_configure_dt(&leds[i], GPIO_OUTPUT_INACTIVE);
68+
__ASSERT(ret == 0, "Could not configure led GPIO");
69+
}
70+
71+
pm_notifier_register(&notifier);
72+
73+
k_msleep(1500);
74+
75+
if (PS_COUNT != 0) {
76+
while (1) {
77+
k_usleep(min_residencies[0] - 100);
78+
for (size_t i = 0; i < PS_COUNT; i++) {
79+
k_usleep(min_residencies[i] + 100);
80+
}
81+
k_busy_wait(400);
82+
}
83+
}
84+
85+
return 0;
86+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests:
2+
benchmarks.pm_states:
3+
sysbuild: true
4+
platform_allow:
5+
- nrf54h20dk/nrf54h20/cpuapp
6+
integration_platforms:
7+
- nrf54h20dk/nrf54h20/cpuapp
8+
harness: pytest
9+
harness_config:
10+
pytest_root:
11+
- "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_pm_states"
12+
tags:
13+
- ci_tests_benchmarks_current_consumption
14+
- ppk_power_measure

0 commit comments

Comments
 (0)