<?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>Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65341/setting-nrf52840-to-deep-sleep-sytem-off-and-waking-up-on-dedicated-pin-interrupt</link><description>Hello All, 
 I am working on the development of a product based on the nFR52840 SoC (SDK 16 and softdevice 14) and have several pheripherals connected to the chip, one of which is the nRF9160 SiP. My question is a 2 parter; 
 1. I can software shutdown</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 04 Sep 2020 09:31:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65341/setting-nrf52840-to-deep-sleep-sytem-off-and-waking-up-on-dedicated-pin-interrupt" /><item><title>RE: Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.</title><link>https://devzone.nordicsemi.com/thread/268003?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 09:31:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06cb0866-4f1c-4a79-a5f1-5468bacd171f</guid><dc:creator>Styve Naoue</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;As previously adviced, I have tested out the recommendations from &lt;a href="https://devzone.nordicsemi.com/members/male"&gt;Martin Lesund&lt;/a&gt; but I stumbled into another issue in the &lt;strong&gt;nrf_pwr_mgmt_shutdown(nrf_pwr_mgmt_shutdown_t shutdown_type)&amp;nbsp;&lt;/strong&gt;in nrf_pwr_mgmt.c&amp;nbsp; which calls the following;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function runs the shutdown procedure.
 */
static void shutdown_process(void)
{
    NRF_LOG_INFO(&amp;quot;Shutdown started. Type %d&amp;quot;, m_pwr_mgmt_evt);
    // Executing all callbacks.
    for (/* m_handlers_iter is initialized in nrf_pwr_mgmt_init(). Thanks to that each handler is
            called only once.*/;
         nrf_section_iter_get(&amp;amp;m_handlers_iter) != NULL;
         nrf_section_iter_next(&amp;amp;m_handlers_iter))
    {
        nrf_pwr_mgmt_shutdown_handler_t * p_handler =
            (nrf_pwr_mgmt_shutdown_handler_t *) nrf_section_iter_get(&amp;amp;m_handlers_iter);
        if ((*p_handler)(m_pwr_mgmt_evt))
        {
            NRF_LOG_INFO(&amp;quot;SysOff handler 0x%08X =&amp;gt; ready&amp;quot;, (unsigned int)*p_handler);
        }
        else
        {
            // One of the modules is not ready.
            NRF_LOG_INFO(&amp;quot;SysOff handler 0x%08X =&amp;gt; blocking&amp;quot;, (unsigned int)*p_handler);
            return;
        }
    }

    PWR_MGMT_CPU_USAGE_MONITOR_SUMMARY();
    NRF_LOG_INFO(&amp;quot;Shutdown complete.&amp;quot;);
    NRF_LOG_FINAL_FLUSH();

    if ((m_pwr_mgmt_evt == NRF_PWR_MGMT_EVT_PREPARE_RESET)
     || (m_pwr_mgmt_evt == NRF_PWR_MGMT_EVT_PREPARE_DFU))
    {
        NVIC_SystemReset();
    }
    else
    {
        // 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
             
        }
           
#endif // SOFTDEVICE_PRESENT
        nrf_power_system_off();
    }
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The retcode is 2 the &lt;strong&gt;ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));&amp;nbsp;&lt;/strong&gt;fails causing the program to crash, being it in Debug as well as in release mode. I also tried the&lt;strong&gt;&amp;nbsp;sd_power_system_off()&amp;nbsp;&lt;/strong&gt;but it fails too with the retcode = 4095.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could someone have a solution to this ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.</title><link>https://devzone.nordicsemi.com/thread/267291?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 15:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f094a84-02c2-4fd5-b41b-fce8dd8f6754</guid><dc:creator>Styve Naoue</dc:creator><description>&lt;p&gt;Hello &lt;a href="https://devzone.nordicsemi.com/members/male"&gt;Martin Lesund&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have been trying out power management library and I used the&amp;nbsp;&lt;strong&gt;&lt;em&gt;nrf_gpio_cfg_sense_input(pin Num, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW)&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;to assigne the wakeup pin. This works well in the&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;quot;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.0%2Fpwr_mgmt_example.html&amp;amp;cp=7_1_4_6_21" rel="noopener noreferrer" target="_blank"&gt;Power Management &amp;quot; sample&lt;/a&gt;&amp;quot; but when I port it to my firmware and try to use btn 4 to put the device to sleep, it crashes with the following error:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: Power management allowed to reset to DFU mode.&lt;br /&gt;&amp;lt;error&amp;gt; app: ERROR 3735928559 [Unknown error code] at C:\...\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c:418&lt;br /&gt;PC at: 0x0003DC77&lt;br /&gt;&amp;lt;error&amp;gt; app: End of error report&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;em&gt;&lt;strong&gt;ret_code_t ret_code = sd_power_system_off();&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&lt;/em&gt;return 2 from nrf_pwr_mgmt.c line 417, even though the softdevice is enabled.&lt;/p&gt;
&lt;p&gt;I could not trace back to the problem, do you have any idea on why this occurs and the solution to it?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks again .&lt;/p&gt;
&lt;p&gt;here is the shutdown handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Handler for shutdown preparation.
*/
bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
{
uint32_t err_code;

if (m_is_ready == false)
{
m_sysoff_started = true;
return false;
}

switch (event)
{
case NRF_PWR_MGMT_EVT_PREPARE_SYSOFF:
NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_SYSOFF&amp;quot;);
err_code = bsp_buttons_disable();
APP_ERROR_CHECK(err_code);
break;

case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_WAKEUP&amp;quot;);
err_code = bsp_buttons_disable();
// Suppress NRF_ERROR_NOT_SUPPORTED return code.
UNUSED_VARIABLE(err_code);

// err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
// // Suppress NRF_ERROR_NOT_SUPPORTED return code.
// UNUSED_VARIABLE(err_code);

nrf_gpio_cfg_sense_input(24, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);

err_code = bsp_nfc_sleep_mode_prepare();
// Suppress NRF_ERROR_NOT_SUPPORTED return code.
UNUSED_VARIABLE(err_code);
break;

case NRF_PWR_MGMT_EVT_PREPARE_DFU:
NRF_LOG_ERROR(&amp;quot;Entering DFU is not supported by this example.&amp;quot;);
APP_ERROR_HANDLER(NRF_ERROR_API_NOT_IMPLEMENTED);
break;

case NRF_PWR_MGMT_EVT_PREPARE_RESET:
NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_RESET&amp;quot;);
break;
}

err_code = app_timer_stop_all();
APP_ERROR_CHECK(err_code);

return true;
}

/**@brief Register application shutdown handler with priority 0. */
NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.</title><link>https://devzone.nordicsemi.com/thread/267274?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 13:53:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:423f9954-fe37-4947-b6da-7d1bf7c6295b</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Styve,&lt;br /&gt;Sounds good, let me know how it goes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.</title><link>https://devzone.nordicsemi.com/thread/267046?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 20:39:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b7a6150-8e50-4d84-915b-090bc8ad6f0a</guid><dc:creator>Styve Naoue</dc:creator><description>&lt;p&gt;Hello Martin,&lt;/p&gt;
&lt;p&gt;thanks for you reply. I would take a look and try to implement as adviced. I will update the ticket with the outcome I get.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting nRF52840 to deep sleep (sytem-off) and waking up on dedicated pin interrupt.</title><link>https://devzone.nordicsemi.com/thread/267030?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 14:39:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58bd4e0d-740f-448c-9e1d-a3e5da74e07e</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Styve,&lt;br /&gt;&lt;br /&gt;For nRF52840 and using the SDK 16 I would advice looking into the&lt;span&gt;&amp;nbsp;&amp;quot;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.0%2Fpwr_mgmt_example.html&amp;amp;cp=7_1_4_6_21" rel="noopener noreferrer" target="_blank"&gt;Power Management &amp;quot; sample&lt;/a&gt;&lt;span&gt;&amp;nbsp;in the use that as reference.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br /&gt;For nRF9160 I would advice you to use the Serial LTE modem sample in NCS as reference. Especially&amp;nbsp;the &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/applications/serial_lte_modem/src/main.c#L95" rel="noopener noreferrer" target="_blank"&gt;enter_sleep() function&lt;/a&gt;&amp;nbsp;as reference.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Martin L.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>