How to wake up from deep sleep?

17 Feb 2011

Hi Experts,

I can not wake up from deep sleep mode by RTC or WDT interrupt.

I searched the forum, and it seems that this is because the mbed is in debug mode by default, is this correct? And how can I make wakeup work?

Thanks!

Regards, Jessamine

17 Feb 2011

You need to detach the mbed interface. See here.

18 Feb 2011

Hi Igor,

Thank you very much for the reply.

I tried the new interface firmware, but it does not work. I am new to mbed, could you please help me check the following step, and see if I have made any stupid error in the test steps or test program?

1. Download the interface firmware file to mbed, and disconnect the USB,as well as the additional power connected to VIN. Then connect the USB again, and find the interface firmware file disappeared. Does this mean the interface firmware is successfully used?

2. Copy my program to mbed, and then disconnect the USB, and use the additional power. Press reset to run the program.

I am using offline compilation, and the NXP driver library. The program like this:

void RTC_IRQHandler(void)
{
        if(RTC_GetIntPending(LPC_RTC, RTC_INT_ALARM))
        {
                LED_On(LED4);
                RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);
                RTC_Cmd(LPC_RTC, DISABLE);
                NVIC_DisableIRQ(RTC_IRQn);
        }
}

int test_deepsleep(void)
{
        LED_On(LED1);

        RTC_Init(LPC_RTC);
        RTC_ResetClockTickCounter(LPC_RTC);
        RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
        RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10);

        RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE);
        RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
        RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);
        RTC_Cmd(LPC_RTC, ENABLE);
        NVIC_EnableIRQ(RTC_IRQn);

        LED_On(LED2);
        CLKPWR_DeepSleep(); 
  
        LED_On(LED3);
        while(1);
        return 1;
}

When I run the program, only LED1 and LED2 are turned on, LED3 and LED4 are not.

Thanks very much!

Regards, Jessamine

18 Feb 2011

I don't see a call to semihost_powerdown().

21 Feb 2011

Hi Igor,

Thanks for your reply.

I am not quite understand how to use semihost_powerdown().

According to some code posted semihost_powerdown() is use to power down the USB interface chip. And I really see the main blue LED turned off after calling semihost_powerdown().

But what is the relation between semihost_powerdown() and deepsleep? I have two understandings: 1. semihost_powerdown() is used to powerdown USB, and the debug mode is disabled after the calling of semihost_powerdown(). So I need to call DeepSleep(), and wake it up after semihost_powerdown().

Following are the code I used, the DeepSleep function is defined in PowerControl:http://mbed.org/users/no2chem/programs/5yk95

#include "mbed.h"
#include "PowerControl/PowerControl.h"

Timeout flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
void flip() {
    led2 = !led2;
}

#define USR_POWERDOWN    (0x104)
int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg); 
}

int main() {
    led2 = 1;
    led3 = semihost_powerdown();

    flipper.attach(&flip, 5.0); // setup flipper to call flip after 2 seconds
    led4 = 1;
    DeepSleep();
    // spin in a main loop. flipper will interrupt it to call flip
    while(1) {
        led1 = !led1;
        wait(0.2);
    }
}

If I change DeepSleep() to Sleep(), the program works, but DeepSleep() not work.

2. semihost_powerdown() itself is a function used for deepsleep. I need to change the parameter "USR_POWERDOWN" to other parameter to make it deep sleep. What parameter shall I use?

Igor, is any of these understanding correct? Or neither is correct? How can I utilize semihost_powerdown() to wake up mbed from deep sleep?

Thank you very much!

Regards,

Jessamine

05 Oct 2011

I think that I have example code that was able to get the watchdog to do a reset from DeepSleep, see info at

http://mbed.org/forum/bugs-suggestions/topic/434/?page=1#comment-14029

It might have one of the missing steps for your DeepSleep wakeup code.