Page 1 of 1
Configuring GPIO using registers in the stub code
Posted: Sun Apr 16, 2017 2:17 pm
by akdogan
I need to have access to the GPIO as soon as esp32 wakes up from deep sleep. I cannot wait until the start of the user code, which is way too slow due to slow flash wakeup (several hundred miliseconds?). What would be the correct register programming for the corresponding ROM functions:
Code: Select all
gpio_pad_select_gpio(BUTTON_GPIO);
gpio_set_direction(BUTTON_GPIO, GPIO_MODE_INPUT);
gpio_set_pull_mode(BUTTON_GPIO, GPIO_PULLUP_ONLY);
I'll put that code into the sub code in the IRAM.
Best wishes.
Re: Configuring GPIO using registers in the stub code
Posted: Sun Apr 16, 2017 4:02 pm
by ESP_igrr
This would depend on whether the pin you wish to use is an RTC_IO or not.
Assuming this is not an RTC IO, you may take a look at the source code of gpio_set_direction and gpio_set_pull_mode functions. They are not defined in ROM, see components/driver/gpio.c.
gpio_pad_select_gpio function is equivalent to PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO). Note that GPIO_PIN_MUX_REG array is not available in the wake stub, so you need to replace it with GPIO_PIN_REG_x where x is the pin number.
Re: Configuring GPIO using registers in the stub code
Posted: Sun Apr 16, 2017 8:11 pm
by akdogan
I'm using GPIO-15, but I can change this choice to another one if needed. Yes you are right gpio_set_direction and gpio_set_pull_mode are not rom functions, and I found the corresponding code in "driver/gpio.c". Thank you. I'll try it.
What about "gpio_pad_select_gpio"? I dig a little, and decided to try GPIO_FUNC3_IN_SEL_CFG_REG. Would this be correct? gpio_pad_select_gpio function is listed in "rom/gpio.h", seems to be a rom function.
Thank you again, and kind regards.
Re: Configuring GPIO using registers in the stub code
Posted: Sun Apr 16, 2017 9:31 pm
by akdogan
Your reply was quite helpful. Thank you. After studying the gpio.c, I solved the problem. I also found out that I have to deinit gpio after wakeup from deep sleep. Thus, for the record, the following lines shows the corresponding simplified lines in the esp_wake_deep_sleep stub to read () from a specific pin (GPIO15) in the stub.
Code: Select all
// rtc_gpio_deinit(GPIO_NUM_15);
CLEAR_PERI_REG_MASK(RTC_IO_TOUCH_PAD3_REG, RTC_IO_TOUCH_PAD3_MUX_SEL_M);
//gpio_pad_select_gpio(GPIO_NUM_15);
PIN_FUNC_SELECT(GPIO_PIN_REG_15, PIN_FUNC_GPIO);
//gpio_set_direction(GPIO_NUM_15, GPIO_MODE_INPUT);
PIN_INPUT_ENABLE(GPIO_PIN_REG_15);
REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT15);
//gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY);
REG_CLR_BIT(GPIO_PIN_REG_15, FUN_PD);
REG_SET_BIT(GPIO_PIN_REG_15, FUN_PU);
// Read GPIO-15
level = REG_GET_BIT(GPIO_IN_REG, BIT15) == BIT15;
Best wishes.