Skip to content

Commit 852da8d

Browse files
committed
wip: soft off bringup ironside
Temp changes added grtc channel disable to avoid wakeups when going to soft off Signed-off-by: Łukasz Stępnicki <[email protected]>
1 parent 477aa35 commit 852da8d

File tree

5 files changed

+117
-7
lines changed

5 files changed

+117
-7
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void)
364364
return grtc_start_value;
365365
}
366366

367-
#if defined(CONFIG_POWEROFF) && defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
367+
#if defined(CONFIG_POWEROFF)
368+
#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
368369
int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
369370
{
370371
nrfx_err_t err_code;
@@ -426,6 +427,91 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
426427
k_spin_unlock(&lock, key);
427428
return 0;
428429
}
430+
#else
431+
int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
432+
{
433+
//nrfx_err_t err_code;
434+
//static uint8_t systemoff_channel;
435+
//uint64_t now = counter();
436+
//nrfx_grtc_sleep_config_t sleep_cfg;
437+
/* Minimum time that ensures valid execution of system-off procedure. */
438+
//uint32_t minimum_latency_us;
439+
uint32_t chan;
440+
//int ret;
441+
442+
// nrfx_grtc_sleep_configuration_get(&sleep_cfg);
443+
// minimum_latency_us =
444+
// (sleep_cfg.waketime + sleep_cfg.timeout) * USEC_PER_SEC / LFCLK_FREQUENCY_HZ +
445+
// CONFIG_NRF_GRTC_SYSCOUNTER_SLEEP_MINIMUM_LATENCY;
446+
// sleep_cfg.auto_mode = false;
447+
// nrfx_grtc_sleep_configure(&sleep_cfg);
448+
449+
// if (minimum_latency_us > wake_time_us) {
450+
// return -EINVAL;
451+
// }
452+
453+
//k_spinlock_key_t key = k_spin_lock(&lock);
454+
455+
// err_code = nrfx_grtc_channel_alloc(&systemoff_channel);
456+
// if (err_code != NRFX_SUCCESS) {
457+
// k_spin_unlock(&lock, key);
458+
// return -ENOMEM;
459+
// }
460+
//(void)nrfx_grtc_syscounter_cc_int_disable(systemoff_channel);
461+
// ret = compare_set(systemoff_channel,
462+
// now + wake_time_us * sys_clock_hw_cycles_per_sec() / USEC_PER_SEC, NULL,
463+
// NULL);
464+
// if (ret < 0) {
465+
// k_spin_unlock(&lock, key);
466+
// return ret;
467+
// }
468+
// for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK;
469+
for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK;
470+
grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) {
471+
/* Clear all GRTC channels except the systemoff_channel. */
472+
chan = u32_count_trailing_zeros(grtc_chan_mask);
473+
// if (chan != systemoff_channel) {
474+
nrfx_grtc_syscounter_cc_disable(chan);
475+
//}
476+
}
477+
#if 0
478+
#if defined(CONFIG_SOC_NRF54H20_CPUAPP)
479+
for (uint32_t grtc_chan_mask = 0x70;
480+
grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) {
481+
/* Clear all GRTC channels except the systemoff_channel. */
482+
chan = u32_count_trailing_zeros(grtc_chan_mask);
483+
// if (chan != systemoff_channel) {
484+
nrfx_grtc_syscounter_cc_disable(chan);
485+
// }
486+
}
487+
#endif
488+
#if defined(CONFIG_SOC_NRF54H20_CPURAD)
489+
//for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK;
490+
for (uint32_t grtc_chan_mask = 0xFF80;
491+
grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) {
492+
/* Clear all GRTC channels except the systemoff_channel. */
493+
chan = u32_count_trailing_zeros(grtc_chan_mask);
494+
//if (chan != systemoff_channel) {
495+
nrfx_grtc_syscounter_cc_disable(chan);
496+
//}
497+
}
498+
#endif
499+
#endif
500+
// /* Make sure that wake_time_us was not triggered yet. */
501+
// if (nrfx_grtc_syscounter_compare_event_check(systemoff_channel)) {
502+
// k_spin_unlock(&lock, key);
503+
// return -EINVAL;
504+
// }
505+
506+
// /* This mechanism ensures that stored CC value is latched. */
507+
//uint32_t wait_time =
508+
// nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 +
509+
// MAX_CC_LATCH_WAIT_TIME_US;
510+
k_busy_wait(1000);
511+
// k_spin_unlock(&lock, key);
512+
return 0;
513+
}
514+
#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */
429515
#endif /* CONFIG_POWEROFF */
430516

431517
uint32_t sys_clock_cycle_get_32(void)
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

samples/boards/nordic/system_off/remote/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ CONFIG_UART_ASYNC_API=y
66
CONFIG_SERIAL=n
77
CONFIG_CONSOLE=n
88
CONFIG_UART_CONSOLE=n
9-
CONFIG_NRF_REGTOOL_VERBOSITY=2

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
#include <zephyr/pm/device_runtime.h>
1010
#include <zephyr/sys/poweroff.h>
1111
#include <hal/nrf_memconf.h>
12+
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
1213

1314
int main(void)
1415
{
16+
17+
1518
if (IS_ENABLED(CONFIG_CONSOLE)) {
1619
printf("%s system off demo. Ready for system off.\n", CONFIG_BOARD);
1720
}
1821

22+
z_nrf_grtc_wakeup_prepare(1000);
23+
1924
if (0) {
2025
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);*/
2126
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);*/

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,25 @@ int main(void)
7474
return 0;
7575
}
7676

77-
if (nrf_gpio_pin_latch_get(nrf_pin_sw1)) {
78-
nrf_gpio_pin_latch_clear(nrf_pin_sw1);
79-
do_poweroff = false;
80-
}
77+
/* TODO: this is always set and locks entering power off after gpio wakeup */
78+
// if (nrf_gpio_pin_latch_get(nrf_pin_sw1)) {
79+
// nrf_gpio_pin_latch_clear(nrf_pin_sw1);
80+
// do_poweroff = false;
81+
// }
8182

8283
printf("\n%s system off demo\n", CONFIG_BOARD);
8384
hwinfo_get_reset_cause(&reset_cause);
8485
rc = print_reset_cause(reset_cause);
8586

87+
#if defined(CONFIG_SOC_NRF54H20_CPUAPP)
88+
/* Temporary set gpio default if sense is set, prevent 300uA additional current after wakeup */
89+
for (int i = 0; i < 12; i++) {
90+
if (nrf_gpio_pin_sense_get(i) != GPIO_PIN_CNF_SENSE_Disabled) {
91+
nrf_gpio_cfg_default(i);
92+
}
93+
}
94+
#endif
95+
8696
if (rc < 0) {
8797
printf("Reset cause not supported.\n");
8898
return 0;
@@ -110,6 +120,9 @@ int main(void)
110120
printf("Retained data not supported\n");
111121
}
112122

123+
124+
k_sleep(K_MSEC(4000));
125+
113126
#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
114127
int err = z_nrf_grtc_wakeup_prepare(DEEP_SLEEP_TIME_S * USEC_PER_SEC);
115128

@@ -168,7 +181,7 @@ int main(void)
168181
retained_update();
169182
}
170183

171-
k_sleep(K_MSEC(4000));
184+
172185
if (do_poweroff) {
173186
#if CONFIG_SOC_NRF54H20_CPUAPP
174187
/* Local RAM0 (TCM) is currently not used so retention can be disabled. */

0 commit comments

Comments
 (0)