Control GPIO in deep sleep wake stub

StefanS
Posts: 10
Joined: Sat Jul 07, 2018 1:12 pm

Control GPIO in deep sleep wake stub

Postby StefanS » 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

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Control GPIO in deep sleep wake stub

Postby Ritesh » Sat Feb 02, 2019 1:41 pm

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.
Regards,
Ritesh Prajapati

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

Re: Control GPIO in deep sleep wake stub

Postby ESP_igrr » Sun Feb 03, 2019 1:09 am

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.

persan666
Posts: 28
Joined: Fri Feb 16, 2018 9:17 am

Re: Control GPIO in deep sleep wake stub

Postby persan666 » 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.

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Control GPIO in deep sleep wake stub

Postby Ritesh » Fri Mar 08, 2019 5:20 pm

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.
Regards,
Ritesh Prajapati

snutw_
Posts: 34
Joined: Wed Aug 21, 2024 1:48 pm

Re: Control GPIO in deep sleep wake stub

Postby snutw_ » Tue Oct 01, 2024 6:17 am

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

Who is online

Users browsing this forum: Baidu [Spider] and 123 guests