-
Notifications
You must be signed in to change notification settings - Fork 1.3k
sleep and wakeup for nrf52 #4236
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
… ports/nrf/supervisor/port.c
@dhalbert Mind doing this review? |
I converted this to a draft for now. @jun2sak Should I wait for you to do further work, or are you requesting some feedback on the work so far? Thanks. |
@dhalbert I have done most of my implementation, but I would like to hear from you to decide further work. (1) (2) |
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.
Thanks for working on this. I left a bunch of comments, but some would change as you clean up the draft. I will reply to other things in another comment that quotes from your comments.
This is quite possible if you just use System ON. The power consumption can still be negligible. You don't have to use System OFF if it is inconvenient. See the chart below from the datasheet. System ON with wake from RTC can be about 1.5 - 3uA, which is still wonderfully low. SYSTEM OFF gets it below 1 uA in certain circumstances. You could choose which to do based on which alarms are set. But to start you don't have to differentiate and could just use System ON for now.
This is something we really want to have. What were the stumbling blocks?
The constructor should raise a
This looks useful and could be quite handy for other debugging. But could you clean it up a bit and rename it to something like |
@dhalbert Thank you for your comments. I will make another push in a couple of days. |
@jun2sak I've pushed fixes to the CI issues, just some simple pre-commit formatting problems. Is this working now, or does it need further fixes? I will try and load it up on my NRF52, if I can find where my dev board is buried... |
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.
Tested this on the Feather NRF52840 across real/fake light/deep sleep types, and it works well across all modes. The only functional issue it has is not retaining a system tick across deep sleep, which causes the USB enumeration delay to occur every time it tries to deep sleep, but that's only a minor power loss with longer sleep periods and likely solvable with a follow up issue.
There are also a couple of stylistic things that could still be changed - common_hal_alarm_pretending_deep_sleep
can be simplified since it doesn't need to detect non-alarm wakeups, there are blocks of commented-out debugging stuff left over, and the debugging content in serial.h should probably be made generic and more consistent with other ports like STM. But at this point we've got a lot of new Alarm content backed up behind this PR and I think it's probably best if we merge it now and do a bit of sweeping later, potentially when merging #4606.
Note that this required a few final edits, including some formatting changes and a couple of module exclusions to make the new code fit on existing small NRF boards like the Simmel. I've also reverted the changes to main - the existing sleep loop is already capable of detecting a fake sleep wakeup, and changing it to an on-the-spot return breaks the ESP32-S2 and STM32 builds of Alarm. |
@hierophect I have a couple of things to be fixed. I will merge your code and commit with my code in this weekend. |
@hierophect After the above commit, I got the message saying I dismissed your review. I am sorry if I broke any rule here. But I think I have successfully merged your changes. |
@jun2sak No problem, please go ahead and make further changes. Reviews get dismissed automatically when code changes are pushed. It's nothing wrong. We just re-review the new changes. |
I have committed what I have been working for these days -- merging some latest changes and simplifying system_on_idle_until_alarm(). I found it work on my nRF52840 board, but I understand following items are left undone.
|
@jun2sak thanks for cleaning up the internals! Looks good to me. There's just a little bit of formatting stuff to take care of, I can just pull and do it real quick today though. For the future, you can look into using I'll give this another test. Regarding the problems:
|
I believe some review comments like this one require attention before this PR is merged. |
I have implemented alarm (deep and light sleep) for nrf52.
PinAlarm, TimeAlarm and SleepMemory work on my nRF52840 board. My code is based on esp32s2 alarm implementation, with HW specific parts re-implemented.
Set CIRCUITPY_ALARM = 1 in config.mk file to enable the alarm function (already defined in mpconfigport.mk).
Please refer to README_impl.txt below.
I am not sure whether this works on other typical nRF52 boards,
and the source files contain some debugging codes.
Please let me know how to go on with this PR.
README_impl.txt
[added in place here for easy reading --dhalbert]:
alarm (sleep and wakeup) implementation for nRF52 [Feb 21, 2021]
implemented:
light sleep (=System ON, WFI)
restriction:
(RTC stops while System OFF)
(can be changed by NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
in nrfx_config.h)
does not work properly.
todo:
debugging functions:
(ports/nrf/supervisor/port.c)
It is useful to debug sleep & wakeup while USB connection is off,
but it is not so smart implementation. Will be removed.