Skip to content

Commit 9a4104d

Browse files
gbarkadiuszkartben
authored andcommitted
tests: power_wakeup_timer: Tests the RTC alarm’s ability to wake the CPU
As above, the test verify the ability to wake up CPU from the lowest power state. The test has been prepared for stm32l562e_dk board. Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
1 parent 21f7e5f commit 9a4104d

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(power_wakeup_timer)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&rtc {
8+
compatible = "st,stm32-rtc";
9+
reg = < 0x40002800 0xc00 >;
10+
interrupts = < 0x2 0x0 >;
11+
clocks = < &rcc 0x58 0x400 >, < &rcc 0x2 0x16890 >;
12+
prescaler = < 0x8000 >;
13+
status = "okay";
14+
wakeup-source;
15+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_RTC=y
5+
CONFIG_RTC_ALARM=y
6+
CONFIG_RTC_STM32=y
7+
CONFIG_PM=y
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/rtc.h>
9+
10+
#define RTC_ALARM_FIELDS \
11+
(RTC_ALARM_TIME_MASK_SECOND | RTC_ALARM_TIME_MASK_MINUTE | RTC_ALARM_TIME_MASK_HOUR)
12+
13+
static const struct device *rtc = DEVICE_DT_GET(DT_NODELABEL(rtc));
14+
15+
static k_tid_t my_tid;
16+
17+
#define MY_STACK_SIZE 500
18+
#define MY_PRIORITY 5
19+
20+
struct k_thread my_thread_data;
21+
K_THREAD_STACK_DEFINE(my_stack_area, MY_STACK_SIZE);
22+
23+
void my_entry_point(void *, void *, void *)
24+
{
25+
printk("Going sleep.\n");
26+
k_msleep(3000);
27+
}
28+
29+
/* Fri Jan 01 2021 13:29:50 GMT+0000 */
30+
static const struct rtc_time rtc_time = {
31+
.tm_sec = 50,
32+
.tm_min = 29,
33+
.tm_hour = 13,
34+
.tm_mday = 1,
35+
.tm_mon = 0,
36+
.tm_year = 121,
37+
.tm_wday = 5,
38+
.tm_yday = 1,
39+
.tm_isdst = -1,
40+
.tm_nsec = 0,
41+
};
42+
43+
/* Fri Jan 01 2021 13:29:51 GMT+0000 */
44+
static const struct rtc_time alarm_time = {
45+
.tm_sec = 51,
46+
.tm_min = 29,
47+
.tm_hour = 13,
48+
.tm_mday = 1,
49+
.tm_mon = 0,
50+
.tm_year = 121,
51+
.tm_wday = 5,
52+
.tm_yday = 1,
53+
.tm_isdst = -1,
54+
.tm_nsec = 0,
55+
};
56+
57+
static void wakeup_cb(const struct device *dev, uint16_t id, void *user_data)
58+
{
59+
printk("Wake up by alarm.\n");
60+
k_thread_abort(my_tid);
61+
}
62+
63+
int main(void)
64+
{
65+
int ret;
66+
uint16_t mask = RTC_ALARM_FIELDS;
67+
68+
ret = rtc_set_time(rtc, &rtc_time);
69+
if (ret < 0) {
70+
return 0;
71+
}
72+
73+
ret = rtc_alarm_set_time(rtc, 0, mask, &alarm_time);
74+
if (ret < 0) {
75+
return 0;
76+
}
77+
78+
ret = rtc_alarm_set_callback(rtc, 0, wakeup_cb, NULL);
79+
if (ret < 0) {
80+
return 0;
81+
}
82+
83+
printk("Created the thread.\n");
84+
my_tid = k_thread_create(&my_thread_data, my_stack_area,
85+
K_THREAD_STACK_SIZEOF(my_stack_area), my_entry_point, NULL, NULL,
86+
NULL, MY_PRIORITY, 0, K_NO_WAIT);
87+
88+
k_thread_join(my_tid, K_FOREVER);
89+
90+
while (1) {
91+
arch_nop();
92+
}
93+
return 0;
94+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
common:
5+
harness: power
6+
harness_config:
7+
fixture: pm_probe
8+
pytest_dut_scope: session
9+
power_measurements:
10+
elements_to_trim: 100
11+
min_peak_distance: 40
12+
min_peak_height: 0.008
13+
peak_padding: 40
14+
measurement_duration: 2
15+
num_of_transitions: 1
16+
expected_rms_values: [0.26, 140]
17+
tolerance_percentage: 10
18+
19+
tests:
20+
pm.power_wakeup_timer:
21+
platform_allow:
22+
- stm32l562e_dk
23+
tags:
24+
- pm
25+
26+
pm.power_wakeup_timer.pm_device:
27+
platform_allow:
28+
- stm32l562e_dk
29+
tags:
30+
- pm
31+
extra_args:
32+
- CONFIG_PM_DEVICE=y

0 commit comments

Comments
 (0)