<?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>WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106576/wdt-continues-to-run-while-in-deep-sleep-mode</link><description>My project utilizes the deep sleep or systemOff() function to minimize battery consumption. I&amp;#39;m at the final stages of development and I&amp;#39;ve run into some strange behavior. There are two occasions where we want the device to go to sleep. It is important</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 27 Mar 2024 20:16:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106576/wdt-continues-to-run-while-in-deep-sleep-mode" /><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/476219?ContentTypeID=1</link><pubDate>Wed, 27 Mar 2024 20:16:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:975c1ee6-39a4-4665-86af-b2351b8ca67f</guid><dc:creator>byedusoft</dc:creator><description>&lt;p&gt;I found this this explanation in the &amp;quot;Product Specification&amp;quot; of the nRF528xx:&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000080;"&gt;6.9.2 Port event&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000080;"&gt;PORT is an event that can be generated from multiple input pins using the GPIO DETECT signal.&amp;nbsp;The event will be generated on the rising edge of the DETECT signal. See GPIO &amp;mdash; General purpose input/output on page 141 for more information about the DETECT signal.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000080;"&gt;The GPIO DETECT signal will not wake the system up again if the system is put into System ON IDLE while&amp;nbsp;the DETECT signal is high. Clear all DETECT sources before entering sleep. If the LATCH register is used as&amp;nbsp;a source, a new rising edge will be generated on DETECT if any bit in LATCH is still high after clearing all&amp;nbsp;or part of the register. This could occur if one of the PINx.DETECT signals is still high, for example. See Pin&amp;nbsp;configuration on page 142 for more information.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000080;"&gt;Setting the system to System OFF while DETECT is high will cause a wakeup from System OFF reset.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/462403?ContentTypeID=1</link><pubDate>Wed, 03 Jan 2024 07:25:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27a559cf-376b-4c39-9116-123a74c2b884</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Sorry about the late reply, but I had to discuss this with a colleague and test it on our end.&lt;/p&gt;
&lt;p&gt;The watchdog is definitely not what triggers a reset while you&amp;#39;re in system off, as it is not active while the device is in system off (configuration etc. is lost). So the reset must come from somewhere else.&lt;/p&gt;
&lt;p&gt;What we could think of is that the WDT is shorter than the time it takes to do the flash erase and write when going to system OFF, so a reset is triggered while you&amp;#39;re doing the erase and thus it wakes up not being able to find what it&amp;#39;s looking for when waking up.&lt;/p&gt;
&lt;p&gt;Can you try disabling the watchdog timer to see if that makes a difference at all? I think that&amp;#39;s an experiment worth while. You can also check the RESETREAS register to get the reset reason. That way we can confirm whether your application goes to system OFF or not at all at least.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/461262?ContentTypeID=1</link><pubDate>Wed, 20 Dec 2023 11:28:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44732294-5dad-4b8a-87ef-61ae90a92fc1</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I just want to let you know that Simon is out of office and that he will get back to you when he returns.&lt;/p&gt;
&lt;p&gt;Happy holidays and best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460664?ContentTypeID=1</link><pubDate>Sun, 17 Dec 2023 03:27:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c69dfe74-7a3c-4c32-9643-fe8c02b3aac9</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;Simon,&lt;/p&gt;
&lt;p&gt;I just figured it would make sense to package them together since the data save and shutdown actions should always happen together, never apart. I have tried increasing that delay all the way as high as 1 second without a change in behavior. I had also tried separating the FLASH erase and write functions and the call to sleep without change. I am currently getting good results by switching the critical battery alert from a direct call to the sleep_system() function into a call to first stop the inactivity timer and then restart it with a starting value of 1. I figure there has to be something going on behind the scenes before the timer&amp;#39;s event handler is fired that is helping. Just wish I knew what it was.&lt;/p&gt;
&lt;p&gt;It may be interesting to note that if either the call to erase or the call to write to FLASH remain, it fails. Both commands have to be removed for proper operation of the sleep_system() function when called from the main loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460532?ContentTypeID=1</link><pubDate>Fri, 15 Dec 2023 12:08:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df356dcd-a7a2-4eb8-bfee-439d6769b268</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi again Kenneth&lt;/p&gt;
&lt;p&gt;Why exactly do you write to flash in the&lt;strong&gt; sleep_system()&lt;/strong&gt; call? From your snippet showing the &lt;strong&gt;sleep_system()&lt;/strong&gt; function I think what happens is that the device tries going to sleep before the flash erase/write procedures are complete.&lt;/p&gt;
&lt;p&gt;Can you try increasing the delay to see if that helps? Or put these calls into a separate function that waits until the flash operations are complete before calling the shutdown&amp;nbsp;function.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460441?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2023 21:39:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eade465e-6f38-4ce9-ad59-2ba4a4837a09</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;I will definitely look into Zephyr for future projects. For now, this project is expecting user interaction 4-5 times per day. Even on the outside, that gets us 5+ years of use. I&amp;#39;m afraid that&amp;#39;s probably more life than we can expect from the tiny batteries that we&amp;#39;re using.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460422?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2023 16:22:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a343ea1-1293-446f-9894-d979afed61a5</guid><dc:creator>matt.heins</dc:creator><description>&lt;p&gt;It sounds like the flash write is perhaps not completing or failing. Perhaps there is a priority issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you looked at this sample?&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/boards/nrf/system_off/README.html"&gt;https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/boards/nrf/system_off/README.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It shows how to retain some RAM. The flash is only good for 10k write/erase cycles which could become an issue. Looking at the code, it enters deep sleep differently than your code. Perhaps this method includes some safeguards to prevent issues like what you are seeing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460268?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2023 01:59:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81d559e8-0c94-4aa0-aef5-e70219e30247</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;Good thinking. High-jacking the timer&amp;#39;s event handler seems to be working so I&amp;#39;m going to call this closed but this feels very hacky. I&amp;#39;d still like to know what I&amp;#39;m missing; why I can&amp;#39;t get this to work from my main function. I feel like this is going to come up again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460247?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2023 00:17:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d7e9ade-36ca-4491-8888-d89d7af608ef</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;If I debug it I get a&amp;nbsp;SOFTDEVICE: ASSERTION FAILED error.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460246?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 23:58:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ed45dcc-71b9-4e98-af65-5520aad736ff</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;It seems like a race condition, or something. With the calls to erase and write to FLASH removed from the sleep_system() function it will behave as expected. I still don&amp;#39;t understand why accessing the FLASH doesn&amp;#39;t have an effect on functionality as long as the sleep_system() function is called from the timer event handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460243?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 23:17:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:840a92cf-3ac3-4263-b53a-274db76f72bc</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;Running the code repeatedly shows that even when triggered by the inactivity timer event, a small percentage of the time it doesn&amp;#39;t properly enter sleep and cannot be woken by the power&amp;nbsp;button interrupt (currently the only way it&amp;#39;s set up to wake). I&amp;#39;ve tried shutting off the timers at the beginning of the sleep function but still no change.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460223?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 20:25:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e21d2730-d7df-4b6c-bdcd-4162907b5429</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;Okay, a bit of history. I modeled this project off of a tutorial which used the nrf_pwr_mgmt API. When I implemented this into my earlier code everything seemed to work with the BLE, but without a BLE connection it was going to sleep during my custom functions. I got frustrated and scrapped the&amp;nbsp;&lt;span&gt;nrf_pwr_mgmt API with the intent to manually engage the deep sleep mode. That was part of the problem. I have now switched back to using the nrf API (for some reason, something I&amp;#39;ve added prevents it from going to sleep with or without a BLE connection now, which is fine) and am using the nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF) to achieve the same ends.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;One more thing, I&amp;#39;ve changed my sleep function to this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;void sleep_system(void){

  uint32_t new_data [3] = {combination, ble_flags, battery_vthresh};  //  Backup important data.
  
  flash_erase(p_flash_adr_base);

  flash_write(p_flash_adr_base, new_data);

  nrf_delay_ms(100);  //  Make sure backup is complete before running systemOff() as it will reset the MCU and erase RAM memory.

  nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);

}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The call to the sleep function from the inactivity timer event handler still works but if I execute the critical battery shutdown like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt; if(return_flag == flag_code_batt_crit){

      nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);

    }&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;the device sleeps like it should, but when I call it like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if(return_flag == flag_code_batt_crit){

      sleep_system();

    }
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;it reverts back to the earlier behavior that the FLASH write fails (no error, just evident upon the next startup that the FLASH is empty), and the system fails going to sleep presumably because the WDT still running though it&amp;#39;s setup to pause during sleep and hault.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Finally, I pulled the call to&amp;nbsp;nrf_pwr_mgmt_shutdown() from the sleep_system() function and placed it after the call to sleep_system() in both the timer event handler and the main loop where it checks the battery flag. Same weird repeated FLASH write fail and reset. Still works from the timer event handler. Any ideas why a previous call to erase/write to flash should prevent a shutdown? Not as important but still curious, anyone know why the power management system doesn&amp;#39;t sleep my board on timeout anymore? (Maybe this is all somehow tied up with the app timers I use.)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460189?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 16:06:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1625a40f-753d-4cfd-9f04-b6eb558e977d</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I think you answered your own question; there will be no further timer event interrupt to exit sleep if the sleep was started in the timer event interrupt. If you want the same behaviour for the critical interrupt, have the critical interrupt either invoke the timer interrupt (thus blocking the timer interrupt) or better set a flag in the critical interrupt which the next timer interrupt will see and thus invoke sleep from the timer interrupt thus blocking the same ie not in main.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460134?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 12:14:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bd92b68-5a96-4640-9b08-fda0a5e4a345</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t looked closely at your code yet, but it sounds like you&amp;#39;re trying to go to sleep within an interrupt or something so the power-down process is stopped halfway because something else starts before the device reaches system OFF mode.&lt;/p&gt;
&lt;p&gt;Either that, or the reason it keeps waking up is that the pin that signals critical low time also wakes up the circuit because it is configured as a wake-up pin for instance.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460031?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 01:11:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb3e8be4-17b5-472f-afdb-91bf1ce94db8</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;I think I narrowed it down a bit.&lt;/p&gt;
&lt;p&gt;I removed the WDT and I&amp;#39;m still getting the same results. I did notice that none of the timers are getting shut off during the issue; my LED is controlled by a timer and it continues to blink when the&amp;nbsp;program sleeps due to a critical battery flag but not during sleep triggered from the inactivity timer. The only difference I can see is that my sleep function is being called in the main loop for a critical battery but it&amp;#39;s being called inside the event handler of the inactivity timer. Is there something that&amp;#39;s going on inside the timer interrupt that is allowing proper operation that I can include in the main loop?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460030?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 01:04:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64c968f9-e5db-4b98-bbdc-92b9c7611545</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;Yes, &lt;span&gt;NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED&amp;nbsp;is set to 1.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460028?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2023 00:28:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fb34571-0d33-444b-b428-82db33df3d2a</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Once-upon-a-time&amp;nbsp;NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED had to be set to &amp;#39;1&amp;#39; in sdk_config.h ..&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if (NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED &amp;amp;&amp;amp; __FPU_PRESENT)
    #define PWR_MGMT_FPU_SLEEP_PREPARE()     pwr_mgmt_fpu_sleep_prepare()

     __STATIC_INLINE void pwr_mgmt_fpu_sleep_prepare(void)
     {&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is called from within &lt;em&gt;nrf_pwr_mgmt_run()&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT continues to run while in deep sleep mode.</title><link>https://devzone.nordicsemi.com/thread/460024?ContentTypeID=1</link><pubDate>Tue, 12 Dec 2023 23:29:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f1c4f11-695c-4e7f-8065-6a1a23c7abaf</guid><dc:creator>trackerfx</dc:creator><description>&lt;p&gt;I guess I should mention the WDT specifics. I&amp;#39;ve set up the WDT to pause during sleep and halt. Here&amp;#39;s the setup for it:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void setup_wdt(void){

  uint32_t err_code = NRF_SUCCESS;

  nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
  config.reload_value = wdt_time;
  config.behaviour = NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT;

  err_code = nrf_drv_wdt_init(&amp;amp;config, wdt_evt_handler);
  APP_ERROR_CHECK(err_code);
  
  err_code = nrf_drv_wdt_channel_alloc(&amp;amp;m_channel_id);
  APP_ERROR_CHECK(err_code);
  
  nrf_drv_wdt_enable();

  nrf_delay_ms(100);

}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>