<?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>How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37105/how-to-do-a-low-power-sleep-without-interrupts</link><description>I&amp;#39;m trying to do a low power sleep of 1s directly after a device reset, i.e. in Reset_Handler(). 
 During this stage, my application does not allow any interrupts. 
 So my question: how to do it actually? 
 
 Current attempt is as follows: 
 
 Without</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Apr 2019 14:31:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37105/how-to-do-a-low-power-sleep-without-interrupts" /><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/179806?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 14:31:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe8b3aeb-b316-4cb5-b7ce-62fd4b634e89</guid><dc:creator>rgrr2</dc:creator><description>&lt;p&gt;Ok, I&amp;#39;ve found a way to implement a low power delay which seems to work always.&lt;/p&gt;
&lt;p&gt;Beforehand the problem was, that depending on the state of the Cortex EV flag, the __WFE() did not return.&amp;nbsp; Situation could be reproduced if there have been the NFC-&amp;gt;GPIO configuration selected, which actually reprograms some values in UICR and then does a NVIC_SystemReset().&amp;nbsp; On this boot the loop hung.&lt;/p&gt;
&lt;p&gt;My solution is to use the watchdog timer for the low power boot delay, i.e. if RESETREAS shows 0, the watchdog is initialized to &amp;quot;bark&amp;quot; after 1s.&amp;nbsp; After init of this the program goes into an __WFE() loop and waits for the watchdog.&lt;/p&gt;
&lt;p&gt;On the watchdog reboot, RESETREAS shows nonzero and the program continues.&lt;/p&gt;
&lt;p&gt;Disadvantage is, that on application start, the DOG bit is always set in RESETREAS.&amp;nbsp; But I can actually live with that ;-)&lt;/p&gt;
&lt;p&gt;Hardy&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;PS: note, that this only works as low power delay on startup.&lt;/p&gt;
&lt;p&gt;PPS: just for the record: my feeling says, that NVIC_SystemReset() does not do a complete reset.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/143393?ContentTypeID=1</link><pubDate>Wed, 08 Aug 2018 13:55:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7629357-7f90-4eb1-9a55-cded00cc3ba6</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;What is the value of&amp;nbsp;SCB-&amp;gt;SCR register and&amp;nbsp;SCB-&amp;gt;CCR register before you enter&amp;nbsp;__WFE?&lt;/p&gt;
&lt;p&gt;You could also try to use &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.tools/dita/tools/nrf5x_command_line_tools/nrf5x_nrfjprogexe_reference.html?cp=5_1_3_0"&gt;nrfjprog&lt;/a&gt;, and call&amp;nbsp;nrfjprog --run, in case the CPU is somehow halted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/142983?ContentTypeID=1</link><pubDate>Mon, 06 Aug 2018 10:35:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:541cd8cf-bb96-4bda-b873-1adf74acf0bf</guid><dc:creator>rgrr2</dc:creator><description>&lt;p&gt;custom board, eclipse, Jlink Ultra+&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/142974?ContentTypeID=1</link><pubDate>Mon, 06 Aug 2018 09:22:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1efa8b7e-4988-4494-83e4-7a43b09e8c65</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;I&amp;#39;m not able to&amp;nbsp;recreate this&amp;nbsp;behavior.&lt;/p&gt;
&lt;p&gt;Is this a custom board or the nRF52-DK?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What toolchain / IDE are you using ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What kind of Jlink adapter is this?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/142758?ContentTypeID=1</link><pubDate>Fri, 03 Aug 2018 09:20:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea036ae4-466b-48f9-b8eb-e4795ebf5589</guid><dc:creator>rgrr2</dc:creator><description>&lt;p&gt;Almost no changes to startup_nrf52.s...&lt;/p&gt;
&lt;p&gt;Nevertheless I&amp;#39;ve found my culprit: it&amp;#39;s the Jlink adapter!&amp;nbsp; When I&amp;#39;m disconnecting it, device will start.&amp;nbsp; When it&amp;#39;s connected, __WFE() waits forever.&lt;/p&gt;
&lt;p&gt;Whats wrong with that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/142748?ContentTypeID=1</link><pubDate>Fri, 03 Aug 2018 08:22:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e8a35a3-3f2d-460b-b491-6cdb2586add3</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;This works fine here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void Reset_Handler_Delay( void )
{
   NRF_POWER-&amp;gt;TASKS_LOWPWR = 1;
   SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk; 

    //
    // enable clock as Internal 32KHz oscillator
    //
    NRF_CLOCK-&amp;gt;LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_RC &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART    = 1;
    while (NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED == 0) {
    }
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;

    NRF_RTC1-&amp;gt;TASKS_STOP  = 1;
    NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;
    NRF_RTC1-&amp;gt;PRESCALER   = 0;
    NRF_RTC1-&amp;gt;INTENCLR    = 0xffffffffUL;
    NRF_RTC1-&amp;gt;EVTENCLR    = 0xffffffffUL;
    NRF_RTC1-&amp;gt;INTENSET    = RTC_INTENSET_COMPARE3_Msk;         // TODO CC[0] and [1] are not working
    NRF_RTC1-&amp;gt;EVTENSET    = RTC_EVTENSET_COMPARE3_Msk;
    NRF_RTC1-&amp;gt;EVENTS_COMPARE[3] = 0;
    NRF_RTC1-&amp;gt;CC[3] = NRF_RTC1-&amp;gt;COUNTER + (1000 * 32768UL) / 1000UL;
    NRF_RTC1-&amp;gt;TASKS_START = 1;
    __SEV();
    while ( !NRF_RTC1-&amp;gt;EVENTS_COMPARE[3]) {
        __WFE();
    }

    NRF_RTC1-&amp;gt;TASKS_STOP = 1;
    NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;
    NRF_RTC1-&amp;gt;INTENCLR = 0xffffffffUL;
    NRF_RTC1-&amp;gt;EVTENCLR = 0xffffffffUL;
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTOP = 1;
    
    
    SCB-&amp;gt;SCR &amp;amp;= ~(1UL &amp;lt;&amp;lt; SCB_SCR_SEVONPEND_Pos);
    
    
}   // Reset_Handler_Delay&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;How does your&amp;nbsp;Reset_Handler look like ?&lt;/p&gt;
&lt;p&gt;What toolchain / IDE are you using ?&lt;/p&gt;
&lt;p&gt;If you are using Keil, have you made any changes in&amp;nbsp;arm_startup_nrf52.s ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/142736?ContentTypeID=1</link><pubDate>Fri, 03 Aug 2018 07:33:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b9222c4-76be-4e46-8fc8-af6653f65f02</guid><dc:creator>rgrr2</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;thanks for the suggestion.&amp;nbsp; Unfortunately it does not help, the MCU still stucks...&lt;/p&gt;
&lt;p&gt;Current code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;extern &amp;quot;C&amp;quot; void Reset_Handler_Delay( void )
{
    NRF_POWER-&amp;gt;TASKS_LOWPWR = 1;

    //
    // enable clock as Internal 32KHz oscillator
    //
    NRF_CLOCK-&amp;gt;LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_RC &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART    = 1;
    while (NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED == 0) {
    }
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;

    //
    // Start HF oscillator -&amp;gt; current consumption increases
    //
    NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART    = 1;
    while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0) {
    }

    SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk;

#if 0
    NRF_RTC1-&amp;gt;TASKS_STOP  = 1;
    NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;
    NRF_RTC1-&amp;gt;PRESCALER   = 0;
    NRF_RTC1-&amp;gt;INTENCLR    = 0xffffffffUL;
    NRF_RTC1-&amp;gt;EVTENCLR    = 0xffffffffUL;
    NRF_RTC1-&amp;gt;INTENSET    = RTC_INTENSET_COMPARE3_Msk;         // TODO CC[0] and [1] are not working
    NRF_RTC1-&amp;gt;EVTENSET    = RTC_EVTENSET_COMPARE3_Msk;
    NRF_RTC1-&amp;gt;EVENTS_COMPARE[3] = 0;
    NRF_RTC1-&amp;gt;CC[3] = NRF_RTC1-&amp;gt;COUNTER + (1000 * 32768UL) / 1000UL;
    NRF_RTC1-&amp;gt;TASKS_START = 1;
    while ( !NRF_RTC1-&amp;gt;EVENTS_COMPARE[3]) {
        __WFE();
    }

    NRF_RTC1-&amp;gt;TASKS_STOP = 1;
    NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;
    NRF_RTC1-&amp;gt;INTENCLR = 0xffffffffUL;
    NRF_RTC1-&amp;gt;EVTENCLR = 0xffffffffUL;
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTOP = 1;
#endif

#if 1
    NRF_TIMER0-&amp;gt;MODE = 0;
    NRF_TIMER0-&amp;gt;BITMODE = 3;
    NRF_TIMER0-&amp;gt;CC[0] = 1000;
    NRF_TIMER0-&amp;gt;PRESCALER = 10;
    NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;
    NRF_TIMER0-&amp;gt;TASKS_START = 1;
    while ( !NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0]) {
        __WFE();
    }
#endif

    SCB-&amp;gt;SCR &amp;amp;= ~(1UL &amp;lt;&amp;lt; SCB_SCR_SEVONPEND_Pos);
}   // Reset_Handler_Delay
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Neither loop (RTC/TIMER) terminates if __WFE() is contained.&amp;nbsp; Both terminate if __WFE() is removed.&lt;/p&gt;
&lt;p&gt;Any idea why?&amp;nbsp; Is there anything more required to generate an SEV?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do a low power sleep without interrupts?</title><link>https://devzone.nordicsemi.com/thread/142664?ContentTypeID=1</link><pubDate>Thu, 02 Aug 2018 15:11:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7e45e07-ed0d-4b46-b196-8a58ec49e9c9</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Try setting the&amp;nbsp;&lt;span&gt;SEVONPEND flag at the start of your&amp;nbsp;Reset_Handler_Delay() function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk; &lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Clear the flag at the end of your&amp;nbsp;Reset_Handler_Delay() function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;SCB-&amp;gt;SCR &amp;amp;= ~(1UL &amp;lt;&amp;lt; SCB_SCR_SEVONPEND_Pos);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Some more information about this can be found in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/2959/isn-t-nrf_rng--events_valrdy-an-event-you-can-wait-for-with-__wfe"&gt;this post&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>