how to retain GPIO state when system wakes up?

ThomasE
Posts: 3
Joined: Fri Feb 07, 2020 4:17 pm

how to retain GPIO state when system wakes up?

Postby ThomasE » Fri Feb 07, 2020 5:02 pm

Hi

I'm not sure if misunderstand the technical reference manual or if my code is incomplete. The manual says ...

"Users can use the hold function for the pads to retain the pad state through a core reset and system reset triggered by watchdog time-out or Deep-sleep events."

... and I would expect that the state of a GPIO pin, set and put on hold by an ULP program, does not change when the ULP program wakes up the chip.

Here's the code fragment I'm using in the ULP program to set and hold GPIO4 (D4).

Code: Select all

WRITE_RTC_REG(RTC_GPIO_OUT_REG, (14 + 10), 1, 1)
WRITE_RTC_REG(RTC_CNTL_HOLD_FORCE_REG, 8, 1, 0)
WRITE_RTC_REG(RTC_CNTL_HOLD_FORCE_REG, 8, 1, 1)
The GPIO state remains unchanged when the ULP program calls the "halt" command :D

When the ULP program calls the "wake" command, then the GPIO state gets changed :( For the counter chip it would be good if the GPIO state does not get changed by the starting ESP32.

Why do I need that?

To reduce the energy consumption I'm using a 8bit-counter chip (74HC590) to count pulses while the ESP32 is in deep sleep. The ULP code gets executed every second to read the counter value, store it, reset the counter and go to sleep again by calling the "halt" command. For debugging the ULP code writes debugging informations to a global field and wakes up the chip (the ULP timer does not get stopped). The main program of the chip prints the debugging data and goes to deep sleep.

Is it possible to retain the GPIO state when the system wakes up and if yes, how?

Thanks

Thomas

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

Re: how to retain GPIO state when system wakes up?

Postby boarchuz » Fri Feb 07, 2020 10:57 pm

It should be held. Are you reinitializing the pin / ULP on a deep sleep wakeup?

WiFive
Posts: 2965
Joined: Tue Dec 01, 2015 7:35 am

Re: how to retain GPIO state when system wakes up?

Postby WiFive » Sat Feb 08, 2020 1:01 pm

https://docs.espressif.com/projects/esp ... gpio_num_t

Actually I think this is broken in 4.1/4.2

wevets
Posts: 104
Joined: Sat Mar 09, 2019 2:56 am

Re: how to retain GPIO state when system wakes up?

Postby wevets » Sat Feb 08, 2020 7:23 pm

Several of the GPIO pins work during deep sleep and are accessible from the ULP. These keep their state on wake up, although as wake up causes a system reset, it's easy to re-initialize them to any desired state on wake reboot. But these GPIOs/RTC GPIOs will retain their state on transition to deep sleep. If you configure those pins as RTC GPIO pins in the main program, they are accessible in exactly the same way from the main processors and the ULP. These GPIOs and the mapping between GPIOs and RTC GPIOs is listed in section 4.11 of the Technical Reference manual. There are 17 of them.

ThomasE
Posts: 3
Joined: Fri Feb 07, 2020 4:17 pm

Re: how to retain GPIO state when system wakes up?

Postby ThomasE » Fri Feb 14, 2020 5:51 pm

Thanks for your fast answers and sorry for my delay ... we have public holidays this week here in Austria.

Attached you can find my test implementation which initializes the used pins once at power up, starts the RTC timer to wake up the ULP every second and then put the chip into deep sleep. The ULP code toggles the state of GPIO15 (D15) every second and holds the state -> the pin is high for a second followed by low for a second and so on ... that's how it should be.

When I remove the "//" from the begin of line 79 in ulp_code.S the chip wakes up and prints the trace information but the state of GPIO15 gets changed even if the pins do not get reinitialized by my code.
Attachments
ulp_code.S.c
(1.81 KiB) Downloaded 82 times
main.c
(3.31 KiB) Downloaded 100 times

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

Re: how to retain GPIO state when system wakes up?

Postby boarchuz » Sat Feb 15, 2020 3:25 am

Try changing your hold/unhold to the ULP equivalent of rtc_gpio_hold_en/rtc_gpio_hold_dis for the specific pin.
For 15, that would be:

Code: Select all

WRITE_RTC_REG(RTC_IO_TOUCH_PAD3_REG, 31, 1, 0) //unhold
WRITE_RTC_REG(RTC_IO_TOUCH_PAD3_REG, 31, 1, 1) //hold

ThomasE
Posts: 3
Joined: Fri Feb 07, 2020 4:17 pm

Re: how to retain GPIO state when system wakes up?

Postby ThomasE » Sat Feb 15, 2020 5:49 pm

Thanks boarchuz, your suggested change solved my problem :D

How did you find out that the ULP code should use RTC_IO_TOUCH_PAD3_REG instead of RTC_CNTL_HOLD_FORCE_REG to hold/unhold GPIO15?

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

Re: how to retain GPIO state when system wakes up?

Postby boarchuz » Sun Feb 16, 2020 1:20 pm

I'm not entirely sure why but I've had a tinker and looked at the TRM to try make sense of it. It does say that RTC_CNTL_HOLD_FORCE_REG (Register 30.34) is specifically for hibernation ("Set to preserve pad’s state during hibernation"), so I suppose it makes sense that it's not relevant when manipulating RTC IO with the ULP (ie. in deep sleep, as opposed to hibernation). It works, that's all that really matters!

Who is online

Users browsing this forum: rayf15 and 42 guests