Skip to content

Commit 19a78cd

Browse files
[nrf fromlist] soc: nordic: s2ram: Align s2ram marking procedures
Rework Nordic specific S2RAM marking procedures. The S2RAM marking procedures must not disrupt the stack due to the TLS pointer not yet being initialized during their execution. Upstream PR: zephyrproject-rtos/zephyr#80039 Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent d90712a commit 19a78cd

File tree

4 files changed

+94
-23
lines changed

4 files changed

+94
-23
lines changed

soc/nordic/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endif()
1414
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
1515
if(CONFIG_ARM)
1616
zephyr_library_sources_ifdef(CONFIG_NRF_PLATFORM_HALTIUM soc_lrcconf.c)
17+
zephyr_library_sources_ifdef(CONFIG_PM_S2RAM_CUSTOM_MARKING pm_s2ram.S)
1718
endif()
1819

1920
if((CONFIG_SOC_SERIES_NRF54HX OR CONFIG_SOC_SERIES_NRF92X) AND CONFIG_CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS)

soc/nordic/common/pm_s2ram.S

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief Nordic suspend-to-RAM code (S2RAM)
10+
*/
11+
12+
#include <zephyr/toolchain.h>
13+
#include <zephyr/arch/cpu.h>
14+
#include <zephyr/arch/common/pm_s2ram.h>
15+
16+
17+
GTEXT(pm_s2ram_mark_set)
18+
SECTION_FUNC(TEXT, pm_s2ram_mark_set)
19+
/*
20+
* Restore the PC and continue
21+
*/
22+
mov r15, r1
23+
24+
GTEXT(pm_s2ram_mark_check_and_clear)
25+
SECTION_FUNC(TEXT, pm_s2ram_mark_check_and_clear)
26+
/*
27+
* Set return value to 0
28+
*/
29+
mov r0, #0
30+
31+
/*
32+
* Load check RESETREAS register
33+
*/
34+
ldr r2, =CONFIG_NRF_RESETINFO_PERIPH_ADDRESS
35+
ldr r5, =CONFIG_NRF_RESETREAS_LOCAL_REG_OFFSET
36+
ldr r3, [r5, r2]
37+
ldr r6, =CONFIG_NRF_RESETREAS_LOCAL_UNRETAINEDWAKE_FIELD
38+
cmp r3, r6
39+
40+
bne exit
41+
42+
/*
43+
* Clear RESETREAS
44+
*/
45+
str r0, [r5, r2]
46+
47+
/*
48+
* Load RESTOREVALID register
49+
*/
50+
ldr r5, =CONFIG_NRF_RESTOREVALID_REG_OFFSET
51+
ldr r3, [r5, r2]
52+
53+
/*
54+
* Clear RESTOREVALID
55+
*/
56+
str r0, [r5, r2]
57+
58+
/*
59+
* Check RESTOREVALID register
60+
*/
61+
ldr r5, =CONFIG_NRF_RESTOREVALID_PRESENT_FIELD
62+
cmp r3, r5
63+
bne exit
64+
65+
/*
66+
* Set return value to 1
67+
*/
68+
mov r0, #1
69+
exit:
70+
/*
71+
* Restore the PC and continue
72+
*/
73+
mov r15, r1

soc/nordic/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,24 @@ config NRF_REGTOOL_GENERATE_UICR
1414
config NRF_REGTOOL_GENERATE_BICR
1515
default y
1616

17+
config NRF_RESETINFO_PERIPH_ADDRESS
18+
hex
19+
default 0x5201E000
20+
21+
config NRF_RESETREAS_LOCAL_REG_OFFSET
22+
hex
23+
default 0x4A4
24+
25+
config NRF_RESTOREVALID_REG_OFFSET
26+
hex
27+
default 0x4C0
28+
29+
config NRF_RESETREAS_LOCAL_UNRETAINEDWAKE_FIELD
30+
hex
31+
default 0x10
32+
33+
config NRF_RESTOREVALID_PRESENT_FIELD
34+
hex
35+
default 0x1
36+
1737
endif # SOC_NRF54H20_CPUAPP || SOC_NRF54H20_ENGB_CPUAPP

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,3 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
126126

127127
return ret;
128128
}
129-
130-
void pm_s2ram_mark_set(void)
131-
{
132-
/* empty */
133-
}
134-
135-
bool pm_s2ram_mark_check_and_clear(void)
136-
{
137-
bool unretained_wake;
138-
bool restore_valid;
139-
uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO);
140-
141-
if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) {
142-
return false;
143-
}
144-
unretained_wake = reset_reason & NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK;
145-
nrf_resetinfo_resetreas_local_set(NRF_RESETINFO, 0);
146-
147-
restore_valid = nrf_resetinfo_restore_valid_check(NRF_RESETINFO);
148-
nrf_resetinfo_restore_valid_set(NRF_RESETINFO, false);
149-
150-
return (unretained_wake & restore_valid) ? true : false;
151-
}

0 commit comments

Comments
 (0)