-
Notifications
You must be signed in to change notification settings - Fork 511
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
Fixes the issue that gen3 devices cannot be woken up by RTC. #2134
Conversation
@@ -284,6 +285,16 @@ extern "C" void RTC_IRQ_HANDLER(void) { | |||
sTimerMicrosAtLastOverflow = getCurrentTime(); | |||
sTickCountAtLastOverflow = DWT->CYCCNT; | |||
__set_PRIMASK(pri); | |||
} else if (nrf_rtc_event_pending(RTC_INSTANCE, NRF_RTC_EVENT_TICK)) { |
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.
Do we know which event in particular causes this? While it is fine to just clear everything in the handler, we should have been able to do that in hal_timer_init()
after waking up from sleep and enable only what is required.
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.
We make use of the NRF_RTC_EVENT_COMPARE_0
event. Clearing events in hal_timer_init()
doesn't work after waking up from sleep, as the interrupt handler is executed immediately following __enable_irq();
, which is before hal_timer_init()
being executed.
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.
That should not be happening though, right? We unbump the priority level of both the GPIOTE and RTC interrupts right before calling __enable_irq()
. If they do get triggered that's a bug in the sleep code. This has also been working previously just fine for quite a while. This is not new code.
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.
Just to clarify: I meant that calling __enable_irq()
at that point in sleep code does not unblock interrupts with priorities >= 2
because we are still under effect of BASEPRI
. We do re-enable interrupts with priority >= 5
while waiting for SoftDevice to do certain things, but that should also not apply to RTC as it's configured normally at 6.
Problem
System.sleep(SystemSleepConfiguration().mode(SystemSleepMode::STOP).duration(3s));
doesn't work on Gen3 platforms.Solution
This issue is caused by not clearing RTC event in its interrupt handler. After device being woken up in
hal_sleep_enter()
, it will repeat entering the RTC interrupt handler.Steps to Test
user/tests/wiring/sleep20
Example App
Completeness