-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Implemented GPIO wake-up for ESP32-C3 #13333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5a4a088
to
07e52c6
Compare
Hello, I started working on this and found your solution. I can verify that these changes works for XIAO ESP32C3. However there imho are few issues:
|
Hello there. I'm just make new PR for the current codebase, so it can be merged. according to espressif doc any gpio pins can be used for lightsleep wakeup source, for the deepsleep only RTC_GPIO can be used as wakeup source.
current PR behaviour:
|
@puppet13th I agree: RTC_VALID_EXT_PINS macro need to allow for pins 0 to 5 for deep sleep wakeup (from the espressif docs: "RTC: GPIO0-5 can be used to wake up the chip from Deep-sleep mode. Other GPIOs can only wake up the chip from Light-sleep mode.") |
This PR already included C3, although we can only use pin 0 to 5. it will throw value error when using other pin when calling deepsleep().
code example for testing deepsleep: from machine import Pin, deepsleep, wake_reason
import esp32
print( 'wake reason :', wake_reason() )
esp32.wake_on_ext1( [ Pin( 5 ), ], esp32.WAKEUP_ALL_LOW )
deepsleep( 10_000 ) code output:
wake reason should be 4 if triggered by timer. |
great, looking forward to test it. Please let me know when I can download an image with the new PR... |
don't know when will it get merged,you can compile the firmware from my fork or use this precompiled firmware. |
I'll use the file as I don't have the compilation environment for micropython set up... |
Just installed the file mentioned above and the code seems to work as it should. See code extract below.
|
@dpgeorge Is there anything to do to have this branch merged into the main code line? |
One detail:
then PIN_WAKE is 2
then PIN_WAKE is 7 it is strange and it complicates checking machine.wake_reason(). |
There is an error in modmachine.c of this PR. PIN_WAKE is defined twice in the local dictionary. |
pardon me if this is a dumb question: is there a way to ask for what pin(s) caused the wake up other than reading the pins at startup? It seems that machine.wake_ext1_pins() is not coded for this port... BTW there seems to be a PR (#7990) with code ready to go for this as well... |
Updated ESP_SLEEP_WAKEUP_GPIO QSTR to GPIO_WAKE.
|
@dpgeorge Is there anything I can do to help having this branch merged into the main code line? |
@puppet13th based on SR 7990 and other discussions, I just extended your version of modmachine.c to support "machine.wake_gpio_pins()" that returns a list of pins that triggered the wakeup for the C3. Do you want the code? I think it would make this PR more complete... |
This is the diff between your version of modmachine.c and the one I've used. The only thing I don't know is how to write the first conditional compiling as it comes at the end of a multiline #define statement: I didn't figure out how to make it work so in my compile run I removed the #if and made this an unconditional change. The code is taken from sr7990 but instead of using the ...get_ext1_wakeup_status... I am using the gpio version of it. 83,85d82 |
This firmware works very well on esp32 c3 xiao wake up, but on the ble connection, it can connect normally for the first time, and it will be reconnected infinitely after recovery, the same code works very well on the latest version of micropython, how can you release another version of C3 wakeup compiled firmware with the latest version |
I did compile it for myself a few months back... I think you probably will have to go the same way... |
I have updated the changes from SR 13333 and 7990 (own mods to it) to the latest esp dev kit and the latest micropython code (downloaded friday). All works for my case. if you have a dropbox or something similar where I can upload it I can share the new version with you. If someone has interest in creating a SR to try to make this go into the baseline please let me know and I will share the changed files (4 files in all). |
9feabef
to
66df592
Compare
updated micropython#9583 to current codebase( 1.22.0). Signed-off-by: Rinaldi Jandrinata <puppet13th@gmail.com>
Signed-off-by: Rinaldi Jandrinata <puppet13th@gmail.com>
Signed-off-by: Rinaldi Jandrinata <puppet13th@gmail.com>
Signed-off-by: Rinaldi Jandrinata <puppet13th@gmail.com>
66df592
to
3d0def2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@puppet13th Thanks for keeping this PR up to date for a long time, and sorry no maintainer got back to you when you originally submitted this. I'll ask the same question that I asked on the original PR: Are you still interested in working on it?
(Below is the review I left on the original PR, which still applies here.)
The approach looks pretty good, and I think it should clean up even more if rebased as we've added more guards based on SoC capability macros rather than chip type. That should make it pretty minimal to have this work on C6 as well.
One thing I am wondering is whether it'd be cleaner to add this support via the machine.Pin.irq(wake=) argument (see `esp32/machine_pin.c). This is the standard non-port-specific way to do wakeup, and it's actually a good fit for the C3 because there isn't the weird distinction between EXT0 and EXT1. Let me know what you think.
@projectgus You may want to check out #15498 as well. I took the liberty a while ago of unifying a couple of things and bring the code up to date... |
Thanks @m-cas, I'd missed your PR was the latest incarnation. I'm going to close this one in favour of #15498. @puppet13th let me know if you'd like to resume here instead. |
updated #9583 to current codebase.