Page 1 of 1

Control GPIO in deep sleep wake stub

Posted: Sat Feb 02, 2019 10:23 am
by StefanS
I'd like to control a GPIO PIN in the deep sleep wake stub.
I tried the following code but the GPIO does not turn on.

Code: Select all

#define SU_HARDWARE_PWRREG GPIO_NUM_23
void RTC_IRAM_ATTR esp_wake_deep_sleep(void)
{
	esp_default_wake_deep_sleep();
	gpio_pad_select_gpio(SU_HARDWARE_PWRREG);

	// Ripped from gpio_set_level
	if(SU_HARDWARE_PWRREG < 32)
		GPIO.out_w1ts = (1 << SU_HARDWARE_PWRREG);
	else
		GPIO.out1_w1ts.data = (1 << (SU_HARDWARE_PWRREG - 32));

	// Ripped from gpio_set_direction
	if(SU_HARDWARE_PWRREG < 32)
		GPIO.enable_w1ts = (0x1 << SU_HARDWARE_PWRREG);
	else
		GPIO.enable1_w1ts.data = (0x1 << (SU_HARDWARE_PWRREG - 32));
	gpio_matrix_out(SU_HARDWARE_PWRREG, SIG_GPIO_OUT_IDX, false, false);
}
Do I need to enable somethng else before I can control the GPIOs?

Thank you

Re: Control GPIO in deep sleep wake stub

Posted: Sat Feb 02, 2019 1:41 pm
by Ritesh
StefanS wrote:
Sat Feb 02, 2019 10:23 am
I'd like to control a GPIO PIN in the deep sleep wake stub.
I tried the following code but the GPIO does not turn on.

Code: Select all

#define SU_HARDWARE_PWRREG GPIO_NUM_23
void RTC_IRAM_ATTR esp_wake_deep_sleep(void)
{
	esp_default_wake_deep_sleep();
	gpio_pad_select_gpio(SU_HARDWARE_PWRREG);

	// Ripped from gpio_set_level
	if(SU_HARDWARE_PWRREG < 32)
		GPIO.out_w1ts = (1 << SU_HARDWARE_PWRREG);
	else
		GPIO.out1_w1ts.data = (1 << (SU_HARDWARE_PWRREG - 32));

	// Ripped from gpio_set_direction
	if(SU_HARDWARE_PWRREG < 32)
		GPIO.enable_w1ts = (0x1 << SU_HARDWARE_PWRREG);
	else
		GPIO.enable1_w1ts.data = (0x1 << (SU_HARDWARE_PWRREG - 32));
	gpio_matrix_out(SU_HARDWARE_PWRREG, SIG_GPIO_OUT_IDX, false, false);
}
Do I need to enable somethng else before I can control the GPIOs?

Thank you
Hi,

I think the steps you have followed are wrong. Means first you have to set GPIO matrix functionality then set direction and then set level.

Did you try your code into normal scenario without deep sleep mode and wake up call? Is it working fine into that scenario?

So, I suggest to check first into normal mode if works fine then would you please check any other GPIO apart from that? If still not working into deep sleep wake up and working into normal mode then need to check in details after that.

So, please check first as I suggested then let me know ow result for that.

Re: Control GPIO in deep sleep wake stub

Posted: Sun Feb 03, 2019 1:09 am
by ESP_igrr
StefanS: which pin number are you trying to control? Some pins default to RTC function after reset, so switching them to GPIO function would be an extra step missing from your code. This is done using registers in RTC block, see rtc_gpio_deinit function.

If the pin is not an RTC pin, it might be something else; in this case the suggestion from Ritesh to try doing the same from app code first seems reasonable.

Re: Control GPIO in deep sleep wake stub

Posted: Fri Mar 08, 2019 3:28 pm
by persan666
Hi,

Did you find any solution to this?

I am struggling with setting gpio14 in wake-up stub.

Re: Control GPIO in deep sleep wake stub

Posted: Fri Mar 08, 2019 5:20 pm
by Ritesh
persan666 wrote:
Fri Mar 08, 2019 3:28 pm
Hi,

Did you find any solution to this?

I am struggling with setting gpio14 in wake-up stub.
We have already provided few suggestions for that. So try with that suggestios first then let us know if you still have any issue regarding that.

Re: Control GPIO in deep sleep wake stub

Posted: Tue Oct 01, 2024 6:17 am
by snutw_
You can just:
REG_WRITE(GPIO_ENABLE1_W1TS_REG, BIT...X...); (GPIO_ENABLE_W1TS_REGfor GPIO under 32)
REG_WRITE(GPIO_OUT1_W1TS_REG, BIT...X...); (GPIO_OUT_W1TS_REG for GPIO under 32)

from #include "soc/gpio_reg.h".
(while in #include "soc/io_mux_reg.h" you have for example PIN_PULLUP_DIS, PIN_PULLDWN_DIS... etc.)
At least on ESP32S3 it works