2929#endif
3030#if defined(CONFIG_GPIO_WAKEUP_ENABLE )
3131static 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 )
3435static 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