-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add LPTICKER tests #8129
Add LPTICKER tests #8129
Conversation
targets/TARGET_STM/rtc_api.c
Outdated
@@ -389,6 +389,7 @@ void rtc_set_wake_up_timer(timestamp_t timestamp) | |||
} | |||
|
|||
RtcHandle.Instance = RTC; | |||
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle); |
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.
Is this really needed as rtc_deactivate_wake_up_timer function was already called in lp_ticker_set_interrupt before calling rtc_set_wake_up_timer?
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.
Yes, rtc_deactivate_wake_up_timer by itself is not sufficient. If HAL_RTCEx_DeactivateWakeUpTimer is removed then this test will fail.
targets/TARGET_STM/lp_ticker.c
Outdated
@@ -203,6 +203,10 @@ void lp_ticker_set_interrupt(timestamp_t timestamp) | |||
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM); | |||
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp); | |||
|
|||
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) { | |||
} |
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.
Can you explain what is being done here ? Isn't there a risk to spend "a lot" of time in this while loop ?
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.
Yes, this would cause blocking behavior in a critical section which is problematic. Without this delay the call to lp_ticker_clear_interrupt
doesn't actually stop a spurious ticker interrupt from firing. Is it possible to prevent a spurious interrupt here without blocking? If so could you share the sequence so I could incorporate it into this PR?
Alternatively, if a fix cannot be found, I could modify the test to ignore spurious interrupts when LPTICKER_DELAY_TICKS > 0. The LowPowerTickerWrapper layer filters out spurious interrupts so when enabled these will not propagate to higher layers. What are you thoughts on this @LMESTM?
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.
Test header and HAL lp ticker header (defined behavior, test functions) should be updated and additional test cases should be documented.
TESTS/mbed_hal/lp_ticker/main.cpp
Outdated
|
||
const uint32_t mask = (1 << lp_ticker_get_info()->bits) - 1; | ||
|
||
for (uint32_t i = 0; i < 100-0; i++) { |
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.
I believe that 100-0
should be 100
.
Update the low power ticker test to verify that the low power ticker does not fire too early. Also add a test to verify that the low power ticker can be safely rescheduled right before or after a match occurs.
b631242
to
3a12625
Compare
Hi @mprse I updated the PR to address your comment and add test function declarations. The defined behavior that was being violated is already specified: Lines 69 to 70 in 7a0c9a6
Both ST implementations of the low power ticker violate this (At least on the STM32L432):
|
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.
@c1728p9 Thanks for updating test header file and potential bugs section.
Tests looks good only one minor issue mentioned earlier (100-0
) is to be fixed.
@LMESTM @jeromecoutant Please review |
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.
Tests looks good!
Marking this as "do not merge" until the blocking of the LP ticker is addressed. |
Hi Russ I propose:
|
3a12625
to
c904b43
Compare
Hi @jeromecoutant I descoped this PR to just the tests as you suggested. |
/morph build |
Build : SUCCESSBuild number : 3310 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2944 |
Test : FAILUREBuild number : 3117 |
Failures related to the new test case, please review |
Please review the test failures or this can be closed until it's updated |
Closing this since progress appears to have idled. Feel free to repoen once updates are availaible. |
Description
When both tickless and LPTICKER_DELAY_TICKS are enabled some ST devices randomly get stuck sleeping forever. This is because the wake up time passed to the rtc is ignored if the previous match is about to occur. This causes the device to get stuck in sleep.
This patch#8242 prevents matches from getting dropped by the rtc by deactivating the rtc wake up timer before setting a new value.This patch also makes a related fix for the lp ticker to prevent a spurious interrupt. Note - the lp ticker implementation does correctly set the second match interrupt so it did not have problems with LowPowerTickerWrappper/LPTICKER_DELAY_TICKS.Events leading up to this failure for the RTC:
-LowPowerTickerWrapper gets ticker interrupt but treats it as a
spurious interrupt and drops it since it comes in too early
This PR also adds tests to catch this regression in the future.
Pull request type