activate pullups un rtc gpio during the wake up stub

eccessivo
Posts: 7
Joined: Tue Apr 14, 2020 4:38 pm

activate pullups un rtc gpio during the wake up stub

Postby eccessivo » Fri Feb 19, 2021 9:03 am

Hi all!
please help me to understand what i am doing wrong.
I can't manipulate the status of the pullups and pull down during the wake up stub on rtc gpio 25,26,27
Here is the code:
  1. //esp32 is in deepsleep with pullups and pull down disabled
  2. //wake up is triggered and the wake up sub is executed. here is some code from my wake up stub:
  3. //Set the pins as input ,pull ups enabled, to be digital read
  4.  
  5. PIN_FUNC_SELECT(GPIO_PIN_REG_27, PIN_FUNC_GPIO);
  6.   PIN_FUNC_SELECT(GPIO_PIN_REG_26, PIN_FUNC_GPIO);
  7.   PIN_FUNC_SELECT(GPIO_PIN_REG_25, PIN_FUNC_GPIO);
  8.  
  9.   PIN_INPUT_ENABLE(GPIO_PIN_REG_27);
  10.   PIN_INPUT_ENABLE(GPIO_PIN_REG_26);
  11.   PIN_INPUT_ENABLE(GPIO_PIN_REG_25);
  12.  
  13.   REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT27);
  14.   REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT26);
  15.   REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT25);
  16.  
  17.   REG_CLR_BIT(GPIO_PIN_REG_27, FUN_PD);
  18.   REG_SET_BIT(GPIO_PIN_REG_27, FUN_PU);
  19.  
  20.   REG_CLR_BIT(GPIO_PIN_REG_26, FUN_PD);
  21.   REG_SET_BIT(GPIO_PIN_REG_26, FUN_PU);
  22.  
  23.   REG_CLR_BIT(GPIO_PIN_REG_25, FUN_PD);
  24.   REG_SET_BIT(GPIO_PIN_REG_25, FUN_PU);
  25.  
  26. //read and store the value of each pin (code is omitted)
  27. //deacitvate all pullups ad pulldown
  28. REG_CLR_BIT(GPIO_PIN_REG_27, FUN_PD);
  29.   REG_CLR_BIT(GPIO_PIN_REG_27, FUN_PU);
  30.  
  31.   REG_CLR_BIT(GPIO_PIN_REG_26, FUN_PD);
  32.   REG_CLR_BIT(GPIO_PIN_REG_26, FUN_PU);
  33.  
  34.   REG_CLR_BIT(GPIO_PIN_REG_25, FUN_PD);
  35.   REG_CLR_BIT(GPIO_PIN_REG_25, FUN_PU);
  36. // go back to sleep within the wakeup stub
[/Codebox][/Codebox]

boarchuz
Posts: 364
Joined: Tue Aug 21, 2018 5:28 am

Re: activate pullups un rtc gpio during the wake up stub

Postby boarchuz » Fri Feb 19, 2021 11:33 am

According to the note here:
https://github.com/espressif/esp-idf/bl ... #L113-L115
// SOC_GPIO_SUPPORT_RTC_INDEPENDENT not defined. On ESP32 those PADs which have RTC functions must
// set pullup/down/capability via RTC register. On ESP32-S2, Digital IOs have their own registers to
// control pullup/down/capability, independent with RTC registers.
you'll need to use RTC registers as 26-27 are RTC GPIOs.

See how IDF does pullx according to RTC GPIO or not:
https://github.com/espressif/esp-idf/bl ... .c#L80-L97

eccessivo
Posts: 7
Joined: Tue Apr 14, 2020 4:38 pm

Re: activate pullups un rtc gpio during the wake up stub

Postby eccessivo » Sat Feb 20, 2021 8:56 am

Thank you for your reply. Is very interesting.
Before to write this reply i made a some tries to get it working but i had no luck.
The problem is that i can't call this function rtc_gpio_pullup_en() within the wakeup stub. During the stub i can access only the basic ROM functions to make direct register manipulation (as i do in the posted code) otherwise i get a esp32 reset.
Following your suggestion i am trying to figure out which register are manipulated by the "rtc_gpio_pullup_en()" function to do the same but using the rom functions.
Any one can help?
TNX in advance

eccessivo
Posts: 7
Joined: Tue Apr 14, 2020 4:38 pm

Re: activate pullups un rtc gpio during the wake up stub

Postby eccessivo » Sat Feb 20, 2021 2:37 pm

A further update...
Rtc register involved in setting pullups and pull down seems to be:
IO_MUX_x_REG (x: GPIO0-GPIO39).
but unfortunately by setting the pullups on this register during the wakeup stub doesn't have any effect...... I am getting mad!
Here is the code:
  1. (GPIO_PIN_REG_4, PIN_FUNC_GPIO);
  2.   PIN_FUNC_SELECT(GPIO_PIN_REG_27, PIN_FUNC_GPIO);
  3.   PIN_FUNC_SELECT(GPIO_PIN_REG_26, PIN_FUNC_GPIO);
  4.   PIN_FUNC_SELECT(GPIO_PIN_REG_25, PIN_FUNC_GPIO);
  5.  
  6.   PIN_INPUT_ENABLE(GPIO_PIN_REG_27);
  7.   PIN_INPUT_ENABLE(GPIO_PIN_REG_26);
  8.   PIN_INPUT_ENABLE(GPIO_PIN_REG_25);
  9.  
  10.  
  11.   REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT27);
  12.   REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT26);
  13.   REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT25);
  14.  
  15.   REG_CLR_BIT(GPIO_PIN_REG_27, FUN_PD);
  16.   REG_SET_BIT(GPIO_PIN_REG_27, FUN_PU);
  17.  
  18.   REG_CLR_BIT(GPIO_PIN_REG_26, FUN_PD);
  19.   REG_SET_BIT(GPIO_PIN_REG_26, FUN_PU);
  20.  
  21.   REG_CLR_BIT(GPIO_PIN_REG_25, FUN_PD);
  22.   REG_SET_BIT(GPIO_PIN_REG_25, FUN_PU);
  23.  
  24. //manipulation of the IO_MUX_x_REG (x: GPIO0-GPIO39). register. bit 3 would connect the pullup
  25.    
  26. REG_SET_BIT(GPIO_PIN_REG_27, (BIT(3)));
  27. REG_SET_BIT(GPIO_PIN_REG_26, (BIT(3)));
  28. REG_SET_BIT(GPIO_PIN_REG_25, (BIT(3)));
Attachments
2021-02-20.png
2021-02-20.png (415.4 KiB) Viewed 178 times


eccessivo
Posts: 7
Joined: Tue Apr 14, 2020 4:38 pm

Re: activate pullups un rtc gpio during the wake up stub

Postby eccessivo » Sat Feb 20, 2021 5:43 pm

Hi WiFive, i followed the link but can you better explain ? how can i use it?

eccessivo
Posts: 7
Joined: Tue Apr 14, 2020 4:38 pm

Re: activate pullups un rtc gpio during the wake up stub

Postby eccessivo » Sat Feb 20, 2021 5:59 pm

Hi All,
Thanks to your help i solved:
to eneble to pullup within the wake up stub, i added these lines to set the bit in the proper registers (suggested by WiFive):
  1.  REG_SET_BIT(RTC_IO_TOUCH_PAD7_REG, RTC_IO_TOUCH_PAD7_RUE_M);
  2.  REG_SET_BIT(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_RUE_M);
  3.  REG_SET_BIT(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_RUE_M);

Who is online

Users browsing this forum: Baidu [Spider], WiFive and 33 guests