Skip to content

Commit a1cf65b

Browse files
nordic-krchlstnl
authored andcommitted
samples: boards: nrf: system_off: Add nrf54h20 support
1 parent 59e6864 commit a1cf65b

File tree

7 files changed

+121
-2
lines changed

7 files changed

+121
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2024 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
source "share/sysbuild/Kconfig"
6+
7+
config REMOTE_CORE_BOARD
8+
string
9+
default "nrf54h20dk/nrf54h20/cpurad" if $(BOARD) = "nrf54h20dk"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(nrf_system_off_remote)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_PM_DEVICE=y
2+
CONFIG_POWEROFF=y
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright (c) 2024 Nordic Semiconductor ASA
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/device.h>
8+
#include <zephyr/pm/device.h>
9+
#include <zephyr/sys/poweroff.h>
10+
#include <hal/nrf_memconf.h>
11+
12+
int main(void)
13+
{
14+
int rc;
15+
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
16+
17+
printf("%s system off demo. Ready for system off.\n", CONFIG_BOARD);
18+
19+
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
20+
if (rc < 0) {
21+
printf("Could not suspend console (%d)\n", rc);
22+
return 0;
23+
}
24+
25+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);
26+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);
27+
28+
sys_poweroff();
29+
30+
return 0;
31+
}

samples/boards/nordic/system_off/src/main.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
2929
#endif
3030
#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE)
31+
static const uint32_t port_sw1 = DT_PROP(DT_GPIO_CTLR_BY_IDX(DT_ALIAS(sw1), gpios, 0), port);
3132
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
3233
#endif
3334

@@ -60,12 +61,19 @@ int main(void)
6061
int rc;
6162
uint32_t reset_cause;
6263
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
64+
uint32_t nrf_pin_sw1 = 32 * port_sw1 + sw1.pin;
65+
bool do_poweroff = true;
6366

6467
if (!device_is_ready(cons)) {
6568
printf("%s: device not ready.\n", cons->name);
6669
return 0;
6770
}
6871

72+
if (nrf_gpio_pin_latch_get(nrf_pin_sw1)) {
73+
nrf_gpio_pin_latch_clear(nrf_pin_sw1);
74+
do_poweroff = false;
75+
}
76+
6977
printf("\n%s system off demo\n", CONFIG_BOARD);
7078
hwinfo_get_reset_cause(&reset_cause);
7179
rc = print_reset_cause(reset_cause);
@@ -114,20 +122,37 @@ int main(void)
114122
return 0;
115123
}
116124

125+
rc = gpio_pin_configure_dt(&sw1, GPIO_INPUT);
126+
if (rc < 0) {
127+
printf("Could not configure sw1 GPIO (%d)\n", rc);
128+
return 0;
129+
}
130+
117131
rc = gpio_pin_interrupt_configure_dt(&sw0, GPIO_INT_LEVEL_ACTIVE);
118132
if (rc < 0) {
119133
printf("Could not configure sw0 GPIO interrupt (%d)\n", rc);
120134
return 0;
121135
}
122-
123-
printf("Entering system off; press sw0 to restart\n");
136+
//code reorder needed
124137
#endif
125138
#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE)
126139
comparator_set_trigger(comp_dev, COMPARATOR_TRIGGER_BOTH_EDGES);
127140
comparator_trigger_is_pending(comp_dev);
128141
printf("Entering system off; change signal level at comparator input to restart\n");
129142
#endif
130143

144+
rc = gpio_pin_interrupt_configure_dt(&sw1, GPIO_INT_LEVEL_ACTIVE);
145+
if (rc < 0) {
146+
printf("Could not configure sw0 GPIO interrupt (%d)\n", rc);
147+
return 0;
148+
}
149+
150+
if (do_poweroff) {
151+
printf("Entering system off; press sw0 or sw1 to restart\n");
152+
} else {
153+
printf("Button sw1 pressed, not entering system off\n");
154+
}
155+
131156
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
132157
if (rc < 0) {
133158
printf("Could not suspend console (%d)\n", rc);
@@ -140,6 +165,17 @@ int main(void)
140165
retained_update();
141166
}
142167

168+
if (do_poweroff) {
169+
#if CONFIG_SOC_NRF54H20_CPUAPP
170+
/* Local RAM0 (TCM) is currently not used so retention can be disabled. */
171+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);
172+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);
173+
#endif
174+
sys_poweroff();
175+
} else {
176+
k_sleep(K_FOREVER);
177+
}
178+
143179
hwinfo_clear_reset_cause();
144180
sys_poweroff();
145181

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if("${SB_CONFIG_REMOTE_CORE_BOARD}" STREQUAL "")
5+
message(FATAL_ERROR
6+
"Target ${BOARD} not supported for this sample. "
7+
"There is no remote board selected in Kconfig.sysbuild")
8+
endif()
9+
10+
set(REMOTE_APP remote)
11+
12+
ExternalZephyrProject_Add(
13+
APPLICATION ${REMOTE_APP}
14+
SOURCE_DIR ${APP_DIR}/${REMOTE_APP}
15+
BOARD ${SB_CONFIG_REMOTE_CORE_BOARD}
16+
)
17+
18+
# Add dependencies so that the remote sample will be built first
19+
# This is required because some primary cores need information from the
20+
# remote core's build, such as the output image's LMA
21+
add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP})
22+
sysbuild_add_dependencies(CONFIGURE ${DEFAULT_IMAGE} ${REMOTE_APP})

soc/nordic/nrf54h/soc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,18 @@ void soc_early_init_hook(void)
147147
{
148148
int err;
149149

150+
if (IS_ENABLED(CONFIG_ICACHE)) {
151+
nrf_memconf_ramblock_control_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID,
152+
RAMBLOCK_CONTROL_BIT_ICACHE, true);
153+
}
154+
150155
sys_cache_instr_enable();
156+
157+
if (IS_ENABLED(CONFIG_DCACHE)) {
158+
nrf_memconf_ramblock_control_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID,
159+
RAMBLOCK_CONTROL_BIT_DCACHE, true);
160+
}
161+
151162
sys_cache_data_enable();
152163

153164
power_domain_init();

0 commit comments

Comments
 (0)