<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>system off</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96865/system-off</link><description>Hi 
 Our goal is to wake up the board from system_off and read which button wakes it up. Can you provide an example for reference? 
 Use ncs 2.2.0 
 nrf52840Dk</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Feb 2023 10:35:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96865/system-off" /><item><title>RE: system off</title><link>https://devzone.nordicsemi.com/thread/411317?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 10:35:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7760cce4-e30c-45d1-804c-6faa2b53fde8</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Technically neither should be &amp;quot;available&amp;quot; in system off mode.&lt;/p&gt;
&lt;p&gt;But the active Jlink debug connection needed for RTT also &lt;em&gt;disables&lt;/em&gt; system OFF mode - it downgrades to simulated system off.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: system off</title><link>https://devzone.nordicsemi.com/thread/411305?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 10:13:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e41550d3-f69c-4ebd-8524-e785486ec276</guid><dc:creator>Huizong</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It works fine when using uart output log.but It fails when using jlink rrt output log. Is jlink rtt log not available in system off mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: system off</title><link>https://devzone.nordicsemi.com/thread/411076?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 11:28:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e11fe590-763a-488a-a2dc-ab3af2eb48d7</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The simplest would be to just test the exact changes I sugtested to the esample, which I tested and work out of the box on a nRF52840 DK. That said, I am a bit unsure about what SDK you use as this does not build out of the box with NCS 2.2.0 (to use the logger you need to include&amp;nbsp; #include &amp;lt;&lt;strong&gt;zephyr&lt;/strong&gt;/logging/log.h&amp;gt;). Anyway, as logging is not enabled in the sample etc and not relevant here, I just replaced it with printk and fixed a few other things (button numbering, line breaks), and tested on my end, and this works as expected. Please note that you need to wait for the device to enter system off mode for this demo to be efficient.&lt;/p&gt;
&lt;p&gt;Here I wait for it entering system off mode, then wake it up by button 3. Then I wait and wake it up by botton 4. Lastly, I press both buttons, and you will see that as well.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.2.99-ncs1 ***

nrf52840dk_nrf52840 system off demo
Busy-wait 2 s
Entering system off; press BUTTON3 or BUTTON4 to restart
*** Booting Zephyr OS build v3.2.99-ncs1 ***

nrf52840dk_nrf52840 system off demo
BUTTON3 woke me up!
Busy-wait 2 s
Entering system off; press BUTTON3 or BUTTON4 to restart
*** Booting Zephyr OS build v3.2.99-ncs1 ***

nrf52840dk_nrf52840 system off demo
BUTTON4 woke me up!
Busy-wait 2 s
Entering system off; press BUTTON3 or BUTTON4 to restart
*** Booting Zephyr OS build v3.2.99-ncs1 ***

nrf52840dk_nrf52840 system off demo
BUTTON3 woke me up!
BUTTON4 woke me up!
Busy-wait 2 s
Entering system off; press BUTTON3 or BUTTON4 to restart&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the modified code from you that I used:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/init.h&amp;gt;
#include &amp;lt;zephyr/pm/pm.h&amp;gt;
#include &amp;lt;zephyr/pm/device.h&amp;gt;
#include &amp;lt;zephyr/pm/policy.h&amp;gt;
#include &amp;lt;soc.h&amp;gt;
#include &amp;quot;retained.h&amp;quot;
#include &amp;lt;hal/nrf_gpio.h&amp;gt;

#define BUSY_WAIT_S 2U
#define SLEEP_S 2U


static void print_wakeup_source(void)
{
    if (nrf_gpio_pin_latch_get(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios))) {
        printk(&amp;quot;BUTTON3 woke me up!\n&amp;quot;);
		nrf_gpio_pin_latch_clear(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios));
       }
    if (nrf_gpio_pin_latch_get(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios))) {
        printk(&amp;quot;BUTTON4 woke me up!\n&amp;quot;);
		nrf_gpio_pin_latch_clear(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios));
    }
}


void main(void)
{
	int rc;
	const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));

	if (!device_is_ready(cons)) {
		printk(&amp;quot;%s: device not ready.\n&amp;quot;, cons-&amp;gt;name);
		return;
	}

	printk(&amp;quot;\n%s system off demo\n&amp;quot;, CONFIG_BOARD);

	print_wakeup_source();
	
	/* Configure to generate PORT event (wakeup) on button 3 or 4 press. */
	nrf_gpio_cfg_input(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios),
			   NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_sense_set(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios),
			       NRF_GPIO_PIN_SENSE_LOW);
	nrf_gpio_cfg_input(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios),
			   NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_sense_set(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios),
			       NRF_GPIO_PIN_SENSE_LOW);

	printk(&amp;quot;Busy-wait %u s\n&amp;quot;, BUSY_WAIT_S);
	k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
	k_sleep(K_SECONDS(SLEEP_S));
	rc = pm_device_action_run(cons, PM_DEVICE_ACTION_RESUME);

	printk(&amp;quot;Entering system off; press BUTTON3 or BUTTON4 to restart\n&amp;quot;);

	if (IS_ENABLED(CONFIG_APP_RETENTION)) {
		/* Update the retained state */
		retained.off_count += 1;
		retained_update();
	}

	/* Above we disabled entry to deep sleep based on duration of
	 * controlled delay.  Here we need to override that, then
	 * force entry to deep sleep on any delay.
	 */
	pm_state_force(0u, &amp;amp;(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});

	/* Now we need to go sleep. This will let the idle thread runs and
	 * the pm subsystem will use the forced state. To confirm that the
	 * forced state is used, lets set the same timeout used previously.
	 */
	k_sleep(K_SECONDS(SLEEP_S));

	printk(&amp;quot;ERROR: System off failed\n&amp;quot;);
	while (true) {
		/* spin to avoid fall-off behavior */
	}
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: system off</title><link>https://devzone.nordicsemi.com/thread/411051?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 09:25:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:038c524c-c913-4688-bbb9-3df29030d123</guid><dc:creator>Huizong</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/eith"&gt;Einar Thorsrud&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I followed the steps to test, but the result is a failure. I attach main.c and log for your reference. Am I missing any steps?&lt;/p&gt;
&lt;pre id="tw-target-text" class="tw-data-text tw-text-large tw-ta" dir="ltr"&gt;&lt;span class="Y2IQFc" lang="en"&gt;Can you test on nrf52840 dk? And give me suggestions&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/p.png" /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/init.h&amp;gt;
#include &amp;lt;zephyr/pm/pm.h&amp;gt;
#include &amp;lt;zephyr/pm/device.h&amp;gt;
#include &amp;lt;zephyr/pm/policy.h&amp;gt;
#include &amp;lt;soc.h&amp;gt;
#include &amp;quot;retained.h&amp;quot;
#include &amp;lt;hal/nrf_gpio.h&amp;gt;

#define BUSY_WAIT_S 2U
#define SLEEP_S 2U

#if CONFIG_LOG
  #include &amp;lt;logging/log.h&amp;gt;
  LOG_MODULE_REGISTER(WAKEUP, LOG_LEVEL_DBG);
#endif

static void print_wakeup_source(void)
{
    if (nrf_gpio_pin_latch_get(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios))) {
        LOG_DBG(&amp;quot;BUTTON3 woke me up!&amp;quot;);
		nrf_gpio_pin_latch_clear(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios));
       }
    if (nrf_gpio_pin_latch_get(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios))) {
        LOG_DBG(&amp;quot;BUTTON4 woke me up!&amp;quot;);
		nrf_gpio_pin_latch_clear(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios));
    }
}


void main(void)
{
	int rc;
	const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));

	if (!device_is_ready(cons)) {
		LOG_DBG(&amp;quot;%s: device not ready.\n&amp;quot;, cons-&amp;gt;name);
		return;
	}

	LOG_DBG(&amp;quot;\n%s system off demo\n&amp;quot;, CONFIG_BOARD);

	print_wakeup_source();
	
	/* Configure to generate PORT event (wakeup) on button 3 or 4 press. */
	nrf_gpio_cfg_input(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios),
			   NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_sense_set(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw2), gpios),
			       NRF_GPIO_PIN_SENSE_LOW);
	nrf_gpio_cfg_input(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios),
			   NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_sense_set(NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(sw3), gpios),
			       NRF_GPIO_PIN_SENSE_LOW);

	LOG_DBG(&amp;quot;Busy-wait %u s\n&amp;quot;, BUSY_WAIT_S);
	k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
	k_sleep(K_SECONDS(SLEEP_S));
	rc = pm_device_action_run(cons, PM_DEVICE_ACTION_RESUME);

	LOG_DBG(&amp;quot;Entering system off; press BUTTON1 or BUTTON2 to restart\n&amp;quot;);

	if (IS_ENABLED(CONFIG_APP_RETENTION)) {
		/* Update the retained state */
		retained.off_count += 1;
		retained_update();
	}

	/* Above we disabled entry to deep sleep based on duration of
	 * controlled delay.  Here we need to override that, then
	 * force entry to deep sleep on any delay.
	 */
	pm_state_force(0u, &amp;amp;(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});

	/* Now we need to go sleep. This will let the idle thread runs and
	 * the pm subsystem will use the forced state. To confirm that the
	 * forced state is used, lets set the same timeout used previously.
	 */
	k_sleep(K_SECONDS(SLEEP_S));

	LOG_DBG(&amp;quot;ERROR: System off failed\n&amp;quot;);
	while (true) {
		/* spin to avoid fall-off behavior */
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: system off</title><link>https://devzone.nordicsemi.com/thread/410891?ContentTypeID=1</link><pubDate>Mon, 20 Feb 2023 13:09:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:998f9242-5c56-4189-9234-20f1af87c5e9</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can check the LATCH register as explained in&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/48588/how-to-differentiate-which-gpio-causing-device-to-wake-up-from-system-off/192889"&gt;this post&lt;/a&gt;. You can use &lt;code&gt;nrf_gpio_pin_latch_get()&lt;/code&gt; and&amp;nbsp;&lt;code&gt;nrf_gpio_pin_latch_clear()&lt;/code&gt; to achieve it. See this diff from the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/zephyr/samples/boards/nrf/system_off/README.html"&gt;nRF5x System Off demo&lt;/a&gt;&amp;nbsp;from nRF Connect SDK 2.2.0 for an example of how you can do it:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8103.main.c.diff"&gt;devzone.nordicsemi.com/.../8103.main.c.diff&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>