Skip to content

Commit ee1acf1

Browse files
rugeGerritsenadamkondraciuk
authored andcommitted
[nrf fromlist] soc: nordic: nrf54h: s2ram: Use ARM SCB save/restore funcs
This reduced the amount of duplicate code and unifies the code with other platforms. With this change fewer registers are stored and restored. See also comment in scb.h for scb_context stating that only essential registers are stored and restored. No longer stored: - ICSR - SCR - CFSR - HFSR - DFSR - MMFAR - BFAR - AFSR No longer used: - SHPR[3..12]. This backup register was declared in the wrong way. In core_cm33.h and core_cm4.h this is declared as an array of 12 uint8_t's. That is 3 uint32_t's. Orignal SCB retention was added in 2055f7d. Upstream PR #: 97073 Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent 4364ba7 commit ee1acf1

File tree

1 file changed

+4
-56
lines changed

1 file changed

+4
-56
lines changed

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <zephyr/arch/cpu.h>
77
#include <zephyr/arch/arm/mpu/arm_mpu.h>
8+
#include <zephyr/arch/arm/cortex_m/scb.h>
89
#include <zephyr/arch/common/pm_s2ram.h>
910
#include <zephyr/linker/sections.h>
1011
#include <zephyr/sys/util.h>
@@ -30,23 +31,6 @@ typedef struct {
3031
uint8_t IPR[NVIC_MEMBER_SIZE(IPR)];
3132
} _nvic_context_t;
3233

33-
typedef struct {
34-
uint32_t ICSR;
35-
uint32_t VTOR;
36-
uint32_t AIRCR;
37-
uint32_t SCR;
38-
uint32_t CCR;
39-
uint32_t SHPR[12U];
40-
uint32_t SHCSR;
41-
uint32_t CFSR;
42-
uint32_t HFSR;
43-
uint32_t DFSR;
44-
uint32_t MMFAR;
45-
uint32_t BFAR;
46-
uint32_t AFSR;
47-
uint32_t CPACR;
48-
} _scb_context_t;
49-
5034
#if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING)
5135
typedef struct {
5236
uint32_t FPCCR;
@@ -61,7 +45,7 @@ struct backup {
6145
#if defined(CONFIG_ARM_MPU)
6246
struct z_mpu_context_retained mpu_context;
6347
#endif
64-
_scb_context_t scb_context;
48+
struct scb_context scb_context;
6549
#if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING)
6650
_fpu_context_t fpu_context;
6751
#endif
@@ -83,42 +67,6 @@ static void nvic_restore(_nvic_context_t *backup)
8367
memcpy((uint32_t *)NVIC->IPR, backup->IPR, sizeof(NVIC->IPR));
8468
}
8569

86-
static void scb_save(_scb_context_t *backup)
87-
{
88-
backup->ICSR = SCB->ICSR;
89-
backup->VTOR = SCB->VTOR;
90-
backup->AIRCR = SCB->AIRCR;
91-
backup->SCR = SCB->SCR;
92-
backup->CCR = SCB->CCR;
93-
memcpy(backup->SHPR, (uint32_t *)SCB->SHPR, sizeof(SCB->SHPR));
94-
backup->SHCSR = SCB->SHCSR;
95-
backup->CFSR = SCB->CFSR;
96-
backup->HFSR = SCB->HFSR;
97-
backup->DFSR = SCB->DFSR;
98-
backup->MMFAR = SCB->MMFAR;
99-
backup->BFAR = SCB->BFAR;
100-
backup->AFSR = SCB->AFSR;
101-
backup->CPACR = SCB->CPACR;
102-
}
103-
104-
static void scb_restore(_scb_context_t *backup)
105-
{
106-
SCB->ICSR = backup->ICSR;
107-
SCB->VTOR = backup->VTOR;
108-
SCB->AIRCR = backup->AIRCR;
109-
SCB->SCR = backup->SCR;
110-
SCB->CCR = backup->CCR;
111-
memcpy((uint32_t *)SCB->SHPR, backup->SHPR, sizeof(SCB->SHPR));
112-
SCB->SHCSR = backup->SHCSR;
113-
SCB->CFSR = backup->CFSR;
114-
SCB->HFSR = backup->HFSR;
115-
SCB->DFSR = backup->DFSR;
116-
SCB->MMFAR = backup->MMFAR;
117-
SCB->BFAR = backup->BFAR;
118-
SCB->AFSR = backup->AFSR;
119-
SCB->CPACR = backup->CPACR;
120-
}
121-
12270
#if defined(CONFIG_FPU)
12371
static void fpu_power_down(void)
12472
{
@@ -175,7 +123,7 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
175123
int ret;
176124

177125
SET_MCUBOOT_RESUME_MAGIC();
178-
scb_save(&backup_data.scb_context);
126+
z_arm_save_scb_context(&backup_data.scb_context);
179127
#if defined(CONFIG_FPU)
180128
#if !defined(CONFIG_FPU_SHARING)
181129
fpu_save(&backup_data.fpu_context);
@@ -204,7 +152,7 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
204152
z_arm_restore_mpu_context(&backup_data.mpu_context);
205153
#endif
206154
nvic_restore(&backup_data.nvic_context);
207-
scb_restore(&backup_data.scb_context);
155+
z_arm_restore_scb_context(&backup_data.scb_context);
208156

209157
return ret;
210158
}

0 commit comments

Comments
 (0)