How to enable sleep timer in wake stub?

iD2017
Posts: 3
Joined: Tue Oct 17, 2017 4:32 am

How to enable sleep timer in wake stub?

Postby iD2017 » Tue Oct 17, 2017 5:08 am

I have a simple application that must follow the following logic:

1. Go to deep sleep and wake on GPIO button press;
2. When GPIO button is pressed, a wake stub launches, checks if this is the first time the button was pressed, and if it is, immediately goes back to sleep (instead of waking the main processor). However, before going back to sleep, it launches an RTC timer such that EITHER the GPIO button being pressed a second time OR the timer expiring cause a wakeup.

How can I do this?

I know how to put the system in deep sleep with wake-up triggered by a GPIO button press using either of these:

Code: Select all

esp_sleep_enable_ext0_wakeup(WAKEUP_PIN, 0);

Code: Select all

const int ext_wakeup_pin_1 = 33;
const uint64_t mask = 1ULL << ext_wakeup_pin_1;
esp_sleep_enable_ext1_wakeup(mask, ESP_EXT1_WAKEUP_ALL_LOW);
I know how to put the system in deep sleep with wake-up triggered by a timer using this:

Code: Select all

const int deep_sleep_sec = 10;
esp_sleep_enable_timer_wakeup(deep_sleep_sec*1000000);
But how do I start a timer INSIDE THE WAKE STUB instead of launching the timer in the main program?

I have seen various posts asking variants of this question but have not yet found an answer.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How to enable sleep timer in wake stub?

Postby WiFive » Tue Oct 17, 2017 6:23 am

Basically do the equivalent of this https://github.com/espressif/esp-idf/bl ... des.c#L293
And set RTC_TIMER_TRIG_EN

iD2017
Posts: 3
Joined: Tue Oct 17, 2017 4:32 am

Re: How to enable sleep timer in wake stub?

Postby iD2017 » Tue Oct 17, 2017 3:12 pm

Thanks for the reply, but I don't see how that would work since this function:

Code: Select all

esp_err_t esp_sleep_enable_timer_wakeup(uint64_t time_in_us)
can only be called in the main program, not within the wake_stub.

How could I call RTC_TIMER_TRIG_EN and set the timer duration using the limited REG commands (like those below) available when programming in the wake_stub?

CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);

Who is online

Users browsing this forum: No registered users and 139 guests