<?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>Cannot wakeup if DETECT asserted before entering SYSOFF</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100361/cannot-wakeup-if-detect-asserted-before-entering-sysoff</link><description>Hello 
 We have a product made with nrf52840 and powered with coin battery. There is a button for user to turn on/off (52840 entering and exiting from SYSOFF mode). In working mode, the button is configured with push event to trigger a shutdown process</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 Jul 2023 08:15:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100361/cannot-wakeup-if-detect-asserted-before-entering-sysoff" /><item><title>RE: Cannot wakeup if DETECT asserted before entering SYSOFF</title><link>https://devzone.nordicsemi.com/thread/435881?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2023 08:15:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca443665-be42-4584-b5f2-46c396190df0</guid><dc:creator>Changchun</dc:creator><description>&lt;p&gt;Update&lt;/p&gt;
&lt;p&gt;I understood where the race condition comes from. B&lt;span&gt;sp_buttons_disable only set the pin to NO_SENSE but did not prevent a pending event from being servered. nrf_gpio_cfg_sense_set is called in port event handler to flip sense level direction. Need to&amp;nbsp;call nrfx_gpiote_in_uninit&amp;nbsp; to clear&amp;nbsp;port_handlers_pins, then pending event will be ignored.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot wakeup if DETECT asserted before entering SYSOFF</title><link>https://devzone.nordicsemi.com/thread/429062?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2023 16:25:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c7eb808-6c1c-4627-8477-a73014176a0f</guid><dc:creator>Changchun</dc:creator><description>&lt;p&gt;Anyway I can solve the problem. Just check the pin sense configuration, if it is not correct, suspend shutdown procedure with return false, and try to continue shutdown after 200 ms. My shutdown handler is as below&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event)
{
    ret_code_t err_code;
    static bool has_called = false;

    if (!has_called)
    {
        err_code = bsp_buttons_disable();
        APP_ERROR_CHECK(err_code);
        err_code = app_timer_stop(m_power_ctrl_timer);
        APP_ERROR_CHECK(err_code);

        has_called = true;
    }

    if (NRF_PWR_MGMT_EVT_PREPARE_WAKEUP == event)
    {
        err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_sense_t sense = nrf_gpio_pin_sense_get(bsp_board_button_idx_to_pin(BTN_ID_WAKEUP));

        if (NRF_GPIO_PIN_NOSENSE == sense)
        {
            err_code = app_timer_start(m_power_ctrl_timer, APP_TIMER_TICKS(200), NULL);
            APP_ERROR_CHECK(err_code);

            return false;
        }
    }

    return true;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In the timer callback just call&amp;nbsp;nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_CONTINUE)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot wakeup if DETECT asserted before entering SYSOFF</title><link>https://devzone.nordicsemi.com/thread/429057?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2023 15:54:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b17ac2d3-9340-422e-aafc-9ecac0e4e416</guid><dc:creator>Changchun</dc:creator><description>&lt;p&gt;Yes, I checked the pin configuration after calling bsp_wakeup_button_enable,&amp;nbsp;nrf_gpio_pin_sense_get always return DISABLED if the button is pressed at around time, and wakeup pin does not work. I do not understand what is race condition you mentioned. It looks to me&amp;nbsp;&lt;span&gt;bsp_wakeup_button_enable just write to a register.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot wakeup if DETECT asserted before entering SYSOFF</title><link>https://devzone.nordicsemi.com/thread/429016?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2023 12:58:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75f5c74c-fca9-4cfe-92a6-ee1349f16ddc</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I have not tested this myself byt based on the description of the issue, it seems that there could be a race condition in how you are handling the events. It seems there there can be a situation where the pin is not configured with sense and input connected even after the button press.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can verify this by reading into the GPIO register values for this pin configuration register to see that when the issue happens, the pin configuration register has its sense and input connect configured correctly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>