I'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:
extern "C" void Reset_Handler_Delay( void )
{
NRF_POWER->TASKS_LOWPWR = 1;
//
// enable clock as Internal 32KHz oscillator
//
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
}
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_RTC1->TASKS_STOP = 1;
NRF_RTC1->TASKS_CLEAR = 1;
NRF_RTC1->PRESCALER = 0;
NRF_RTC1->INTENCLR = 0xffffffffUL;
NRF_RTC1->EVTENCLR = 0xffffffffUL;
NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE3_Msk; // TODO CC[0] and [1] are not working
NRF_RTC1->EVTENSET = RTC_EVTENSET_COMPARE3_Msk;
NRF_RTC1->EVENTS_COMPARE[3] = 0;
NRF_RTC1->CC[3] = NRF_RTC1->COUNTER + (1000 * 32768UL) / 1000UL;
NRF_RTC1->TASKS_START = 1;
__SEV();
while ( !NRF_RTC1->EVENTS_COMPARE[3]) {
__WFE();
}
NRF_RTC1->TASKS_STOP = 1;
NRF_RTC1->TASKS_CLEAR = 1;
NRF_RTC1->INTENCLR = 0xffffffffUL;
NRF_RTC1->EVTENCLR = 0xffffffffUL;
NRF_CLOCK->TASKS_LFCLKSTOP = 1;
} // Reset_Handler_Delay
Without the __WFE() is is working (with high current of course), with __WFE() included, the loop hangs.
Thanks for suggestions.
Hardy