Retain GPIO (not RTC) in deepsleep and in wake stub

davdav
Posts: 208
Joined: Thu Nov 17, 2016 2:33 pm

Retain GPIO (not RTC) in deepsleep and in wake stub

Postby davdav » Tue May 21, 2019 11:09 am

Hi Everybody,

I need to retain a GPIO which is not in RTC controller (in my case GPIO22) in deepsleep. Below it is a simple test:

-application setup GPIO22 as output and it is turned on.
-a wake-up timer of 5 seconds is setup
-esp32 is put in deep_sleep
-a wake stub is provided to setup GPIO22 as ouput and turn on the pin

Code: Select all

#include <stdio.h>
#include <string.h>
#include "esp_sleep.h"
#include "esp_attr.h"
#include "rom/rtc.h"
#include "rom/ets_sys.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

static const char RTC_RODATA_ATTR wake_str[] = "wake\n";
static void RTC_IRAM_ATTR wake_stub()
{
	REG_WRITE(GPIO_ENABLE_REG, BIT22);
	REG_WRITE(GPIO_OUT_W1TS_REG, BIT22);//GPIO22 HIGH (set)

	// print wake
	ets_printf(wake_str);

	esp_default_wake_deep_sleep();

	// Return from the wake stub function to continue
	// booting the firmware.
	return;
}

void app_main(void)
{
    if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
        printf("Wake up from deep sleep\n");
    } else {
        printf("Not a deep sleep wake up\n");

    }
    //Config gpio_num_22 as output
	gpio_config_t config = {
            .pin_bit_mask = BIT64(GPIO_NUM_22),
            .mode = GPIO_MODE_OUTPUT,
			.pull_up_en = GPIO_PULLUP_DISABLE,
			.pull_down_en = GPIO_PULLDOWN_DISABLE
    };
    ESP_ERROR_CHECK(gpio_config(&config));

	printf("set HIGH GPIO_NUM_22 and HOLD\n");
	ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_22, 1));
	gpio_deep_sleep_hold_en();

	printf("Enable wakeUP in 5 seconds\n");
	esp_sleep_enable_timer_wakeup(5000000);

    // Set the wake stub function
    esp_set_deep_sleep_wake_stub(&wake_stub);

    // Enter deep sleep
    esp_deep_sleep_start();
}
Everything works as expected but if I use an oscilloscope I can see a glitch on the pin of about 320us which I think it is between the device exit deepsleep and the wakeup stub.

How to solve this?
Should I use an RTC pin?


Thanks

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

Re: Retain GPIO (not RTC) in deepsleep and in wake stub

Postby WiFive » Tue May 21, 2019 11:31 am

gpio_hold_en

davdav
Posts: 208
Joined: Thu Nov 17, 2016 2:33 pm

Re: Retain GPIO (not RTC) in deepsleep and in wake stub

Postby davdav » Tue May 21, 2019 12:10 pm

WiFive wrote:
Tue May 21, 2019 11:31 am
gpio_hold_en
Uhm..it seems to work.

At this point: I'm a little confused. gpio_hold_en() should be used when device is NOT in deep_sleep.
Need to study the docs again..

Thanks

Who is online

Users browsing this forum: No registered users and 109 guests