<?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>Trouble shutting down device and rebooting</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106402/trouble-shutting-down-device-and-rebooting</link><description>I am having an issue where ONLY in release mode. 
 When charging the device through the USB port, if it is unplugged I want to put the device into sleep mode. Following this the device becomes unresponsive - the power button doesn&amp;#39;t work and the only</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Dec 2023 10:23:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106402/trouble-shutting-down-device-and-rebooting" /><item><title>RE: Trouble shutting down device and rebooting</title><link>https://devzone.nordicsemi.com/thread/459328?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2023 10:23:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3429c64f-483c-432e-a5f9-f81a37321700</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Aerosensor"]If I run the device with &amp;quot;Release&amp;quot; compilation settings, and just look at the output with the j-link rtt viewer, does that count as debug mode?[/quote]
&lt;p&gt;You are using RTT logging and ahve the RTT viewer connected via SWD the debug interface is in use, and this prevents system off mode. So it is expected that&amp;nbsp;sd_power_system_off() will return immediately. The device is not in a normal state though, but rather in emulated system off (see &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=5_0_0_4_2_2#unique_458937164"&gt;System OFF mode&lt;/a&gt;&amp;nbsp;for more details).&lt;/p&gt;
[quote user="Aerosensor"]Fundamental question though, is should &amp;quot;sd_power_system_off()&amp;quot; immediately cause the system to power off?&amp;nbsp;&amp;nbsp;[/quote]
&lt;p&gt;If you are not debugging, then yes, it should make the system enter system off mode immediately. And wake-up from system off mode is always in form of a reset, so execution will never reach whatever is after the call to&amp;nbsp;&lt;span&gt;sd_power_system_off() (unless debugging, that is).&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble shutting down device and rebooting</title><link>https://devzone.nordicsemi.com/thread/459315?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2023 09:58:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16358743-8543-49d6-bc93-d336c7bde857</guid><dc:creator>Aerosensor</dc:creator><description>&lt;p&gt;If I run the device with &amp;quot;Release&amp;quot; compilation settings, and just look at the output with the j-link rtt viewer, does that count as debug mode?&amp;nbsp; This is the output.&amp;nbsp; Interestingly the &amp;quot;Shoudln&amp;#39;t get here&amp;quot; timestamp is zero..&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[13391386] &amp;lt;info&amp;gt; velo_power: Shut down all...
[13391393] &amp;lt;info&amp;gt; velo_power: Resetting GPIOS
[13391403] &amp;lt;info&amp;gt; velo_power: Set GPIOs for wake...
[13391413] &amp;lt;info&amp;gt; velo_power: Shut down all done...
[13391418] &amp;lt;info&amp;gt; velo_driver: _shutdown done
[00000000] &amp;lt;info&amp;gt; velo_power: Shouldnt get here..&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Fundamental question though, is should &amp;quot;sd_power_system_off()&amp;quot; immediately cause the system to power off?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble shutting down device and rebooting</title><link>https://devzone.nordicsemi.com/thread/459302?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2023 08:57:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:455944c6-f806-419d-a902-78d7694913d3</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;System OFF mode does not work when debugging, so in that case it is expected that&amp;nbsp;&lt;code&gt;sd_power_system_off()&lt;/code&gt; returns. This is for instance why the power management module in nrf_pwr_mgmt.c has this special handling for debug builds:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        // Enter System OFF.
#ifdef SOFTDEVICE_PRESENT
        if (nrf_sdh_is_enabled())
        {
            ret_code_t ret_code = sd_power_system_off();
            ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
            UNUSED_VARIABLE(ret_code);
#ifdef DEBUG
            while (true)
            {
                /* Since the CPU is kept on in an emulated System OFF mode, it is recommended
                 * to add an infinite loop directly after entering System OFF, to prevent
                 * the CPU from executing code that normally should not be executed. */
                __WFE();

            }
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But for release builds (where DEBUG is not defined), execution would continue if you try to enter system off while debugging.&lt;/p&gt;
&lt;p&gt;Also, note that when the device enters system off mode, there are only a few possible wake-up sources, and except for pin reset, these needs to be explicitly enabled. For GPIO, you need to configure the sense mechanism for it to be able to wake the device up from system off, which you can do with&amp;nbsp;&lt;code&gt;nrf_gpio_cfg_sense_input()&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>