Skip to content

Commit 6a7c878

Browse files
lstnlmeijemac
authored andcommitted
system off sample: nrf54h20 alignement
Enabled LATCH reading on sw1 this need additiona REATAIN bits manipulation. Changed console to be handled automatically, otherwise there are some unknown characters when console is suspended. Removed obsolete configs. Signed-off-by: Łukasz Stępnicki <[email protected]>
1 parent 87abca1 commit 6a7c878

File tree

5 files changed

+46
-36
lines changed

5 files changed

+46
-36
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
&uart135 {
1+
&uart136 {
22
zephyr,pm-device-runtime-auto;
3+
disable-rx;
34
};

samples/boards/nordic/system_off/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ CONFIG_PM_DEVICE=y
33
CONFIG_PM_DEVICE_RUNTIME=y
44
CONFIG_UART_ASYNC_API=y
55
CONFIG_GPIO=y
6-
CONFIG_NRF_REGTOOL_VERBOSITY=2
76
CONFIG_CRC=y
87
CONFIG_POWEROFF=y
98
CONFIG_HWINFO=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
&uart135 {
22
status = "disabled";
33
zephyr,pm-device-runtime-auto;
4+
disable-rx;
45
};

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,11 @@
1414
int main(void)
1515
{
1616

17-
1817
if (IS_ENABLED(CONFIG_CONSOLE)) {
1918
printf("%s system off demo. Ready for system off.\n", CONFIG_BOARD);
2019
}
2120

22-
z_nrf_grtc_wakeup_prepare(1000);
23-
24-
if (0) {
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-
k_sleep(K_FOREVER);
28-
} else {
29-
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);*/
30-
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);*/
31-
32-
sys_poweroff();
33-
}
21+
sys_poweroff();
3422

3523
return 0;
3624
}

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

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#endif
3030
#if defined(CONFIG_GPIO_WAKEUP_ENABLE)
3131
static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
32+
static const uint32_t port_sw0 = DT_PROP(DT_GPIO_CTLR_BY_IDX(DT_ALIAS(sw0), gpios, 0), port);
3233
#endif
3334
#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE)
3435
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
@@ -65,32 +66,38 @@ int main(void)
6566
{
6667
int rc;
6768
uint32_t reset_cause;
68-
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
6969
uint32_t nrf_pin_sw1 = 32 * port_sw1 + sw1.pin;
7070
bool do_poweroff = true;
7171

72-
if (!device_is_ready(cons)) {
73-
printf("%s: device not ready.\n", cons->name);
74-
return 0;
72+
if (nrf_gpio_pin_latch_get(nrf_pin_sw1)) {
73+
nrf_gpio_pin_latch_clear(nrf_pin_sw1);
74+
#if defined(CONFIG_SOC_NRF54H20)
75+
/* Set gpio default if sense is set, prevent 300uA additional current after wakeup
76+
* This is only needed for nrf54 series as PIN config is different from PAD config.
77+
* After wakeup from system-off, SENSE bit is not reset but INPUT is.
78+
*/
79+
if (nrf_gpio_pin_sense_get(nrf_pin_sw1) != GPIO_PIN_CNF_SENSE_Disabled) {
80+
nrf_gpio_cfg_default(nrf_pin_sw1);
81+
}
82+
#endif
83+
do_poweroff = false;
7584
}
7685

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-
// }
82-
8386
printf("\n%s system off demo\n", CONFIG_BOARD);
8487
hwinfo_get_reset_cause(&reset_cause);
8588
rc = print_reset_cause(reset_cause);
8689

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-
}
90+
#if defined(CONFIG_SOC_NRF54H20)
91+
#if defined(CONFIG_GPIO_WAKEUP_ENABLE)
92+
/* Set gpio default if sense is set, prevent 300uA additional current after wakeup
93+
* This is only needed for nrf54 series as PIN config is different from PAD config.
94+
* After wakeup from system-off, SENSE bit is not reset but INPUT is.
95+
*/
96+
uint32_t nrf_pin_sw0 = 32 * port_sw0 + sw0.pin;
97+
if(nrf_gpio_pin_sense_get(nrf_pin_sw0) != GPIO_PIN_CNF_SENSE_Disabled) {
98+
nrf_gpio_cfg_default(nrf_pin_sw0);
9399
}
100+
#endif
94101
#endif
95102

96103
if (rc < 0) {
@@ -120,10 +127,10 @@ int main(void)
120127
printf("Retained data not supported\n");
121128
}
122129

123-
124130
k_sleep(K_MSEC(4000));
125131

126132
#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
133+
127134
int err = z_nrf_grtc_wakeup_prepare(DEEP_SLEEP_TIME_S * USEC_PER_SEC);
128135

129136
if (err < 0) {
@@ -145,6 +152,10 @@ int main(void)
145152
printf("Could not configure sw0 GPIO interrupt (%d)\n", rc);
146153
return 0;
147154
}
155+
156+
#if defined(CONFIG_SOC_NRF54H20)
157+
nrf_gpio_pin_retain_disable(nrf_pin_sw0);
158+
#endif
148159
#endif
149160
#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE)
150161
comparator_set_trigger(comp_dev, COMPARATOR_TRIGGER_BOTH_EDGES);
@@ -163,16 +174,26 @@ int main(void)
163174
return 0;
164175
}
165176

177+
#if defined(CONFIG_SOC_NRF54H20)
178+
nrf_gpio_pin_retain_disable(nrf_pin_sw1);
179+
#endif
180+
166181
if (do_poweroff) {
167182
printf("Entering system off; press sw0 or sw1 to restart\n");
168183
} else {
169184
printf("Button sw1 pressed, not entering system off\n");
170185
}
171186

172-
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
173-
if (rc < 0) {
174-
printf("Could not suspend console (%d)\n", rc);
175-
return 0;
187+
if (IS_ENABLED(CONFIG_PM_DEVICE) && IS_ENABLED(CONFIG_SERIAL)) {
188+
static const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
189+
int err;
190+
enum pm_device_state state;
191+
192+
if (dev) {
193+
do {
194+
err = pm_device_state_get(dev, &state);
195+
} while ((err == 0) && (state == PM_DEVICE_STATE_ACTIVE));
196+
}
176197
}
177198

178199
if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {

0 commit comments

Comments
 (0)