[Solved] Can RTC IO output state be retained in hibernation mode?

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

[Solved] Can RTC IO output state be retained in hibernation mode?

Postby ESP_krzychb » Thu May 25, 2017 8:42 pm

Hey everybody,

According to ESP32 Datasheet V1.3 on page 22, in hibernation mode "some RTC GPIOs are active".

I understand they can be used as "ext0" or "ext1" wakeup sources after configuring them as inputs.

What if they are configured as outputs? Can they retain output state (high or low) that has been set up before putting the chip into hibernation mode?
Last edited by ESP_krzychb on Fri May 26, 2017 6:22 pm, edited 3 times in total.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Can RTC IO output state be retained in hibernation mode?

Postby ESP_igrr » Fri May 26, 2017 12:53 am

For RTC IOs you can use rtc_gpio_hold_en function.

For digital IOs there is a RTC_CNTL_DG_PAD_FORCE_HOLD bit which forces all pads to hold their state.

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: Can RTC IO output state be retained in hibernation mode?

Postby ESP_krzychb » Fri May 26, 2017 6:23 am

Thanks @ESP_igrr!
Works great from both main program (using rtc_gpio_hold_en / dis) and from ULP (using individual registers and bits).

EDIT:
A short description how to use hold enable / disable functionality together with an ULP program is available under https://github.com/krzychb/ulp-loop

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

Re: [Solved] Can RTC IO output state be retained in hibernation mode?

Postby davdav » Mon May 20, 2019 1:23 pm

krzychb wrote:
Fri May 26, 2017 6:23 am
Thanks @ESP_igrr!
Works great from both main program (using rtc_gpio_hold_en / dis) and from ULP (using individual registers and bits).

EDIT:
A short description how to use hold enable / disable functionality together with an ULP program is available under https://github.com/krzychb/ulp-loop
Hi @krzychb, I have studied and tested your example code and it is very usefull to understand deep-sleep and RTC GPIOs.
I have a question: in my case I need to put in hybernation (i.e. deep-sleep within only RTC timer, no slow/fast memory, no ULP) retaining GPIO23 (which is not RTC).
I have written a very simple test:

Code: Select all

main(){
    printf("RESET:%d;wake:%d\n", rtc_get_reset_reason(0), esp_sleep_get_wakeup_cause());

	//wait start
	uint8_t cnt=0;
	while (cnt < 3)
	{
		printf("startWait:%d\n", cnt);
		vTaskDelay(pdMS_TO_TICKS(1000));
		cnt++;
	}

    //Config gpio_num_23
	gpio_config_t config = {
            .pin_bit_mask = BIT64(GPIO_NUM_23),
            .mode = GPIO_MODE_OUTPUT,
			.pull_up_en = GPIO_PULLUP_DISABLE,
			.pull_down_en = GPIO_PULLDOWN_DISABLE
    };
    ESP_ERROR_CHECK(gpio_config(&config));

	cnt = 0;
	while (cnt < 3)
	{
		printf("After config:%d\n", cnt);
		vTaskDelay(pdMS_TO_TICKS(1000));
		cnt++;
	}

	// Wake up in 5 seconds
	esp_sleep_enable_timer_wakeup(5000000);

	printf("set LOW GPIO_NUM_23 and HOLD\n");
	gpio_set_level(GPIO_NUM_23,0);
	gpio_deep_sleep_hold_en();
	
	printf("going to DEEP SLEEP\n");
	
	esp_deep_sleep_start();
}
GPIO_NUM_23 is retained during deep sleep as expected but when ESP32 wake up (I checked from rtc_get_reset_reason(0) which is "DEEPSLEEP_RESET" and esp_sleep_get_wakeup_cause() which is "ESP_SLEEP_WAKEUP_TIMER")
the pin goes high (I guess for its internal pull-up) until the "gpio_config" function is called.

Is it mandatory to introduce a wake stub in order to retain the GPIO level after wake-up from deep sleep?

Thanks

andrewandroid
Posts: 7
Joined: Sat Dec 26, 2020 7:33 am

Re: Can RTC IO output state be retained in hibernation mode?

Postby andrewandroid » Sat Dec 26, 2020 8:53 am

ESP_igrr wrote:
Fri May 26, 2017 12:53 am
For RTC IOs you can use rtc_gpio_hold_en function.

For digital IOs there is a RTC_CNTL_DG_PAD_FORCE_HOLD bit which forces all pads to hold their state.
Hi ESP_Igrr,

That sounds perfect! Could you please provide an example of how to set that bit on, for beginners like me?

Pushing my luck, is there a way to set this in Arduino IDE for ESP32?

Cheers
Andrew

Who is online

Users browsing this forum: Bing [Bot] and 113 guests