2022-01-11 03:51 AM
The case described occurs when multiple timers are used and one repetitive timer is tiggered right after another repetitive timer. The first code snippet below shows the current implementation and the second shows the fixed code.
static void RestartWakeupCounter(uint16_t Value)
{
/**
* The wakeuptimer has been disabled in the calling function to reduce the time to poll the WUTWF
* FLAG when the new value will have to be written
* __HAL_RTC_WAKEUPTIMER_DISABLE(phrtc);
*/
if(Value == 0)
{
SSRValueOnLastSetup = ReadRtcSsrValue();
/**
* Simulate that the Timer expired
*/
HAL_NVIC_SetPendingIRQ(CFG_HW_TS_RTC_WAKEUP_HANDLER_ID);
}
else
The line containing "__HAL_RTC_WAKEUPTIMER_ENABLE(phrtc);" must be added to the above code to fix the bug as shown in the code below.
static void RestartWakeupCounter(uint16_t Value)
{
/**
* The wakeuptimer has been disabled in the calling function to reduce the time to poll the WUTWF
* FLAG when the new value will have to be written
* __HAL_RTC_WAKEUPTIMER_DISABLE(phrtc);
*/
if(Value == 0)
{
SSRValueOnLastSetup = ReadRtcSsrValue();
/**
* Simulate that the Timer expired
*/
HAL_NVIC_SetPendingIRQ(CFG_HW_TS_RTC_WAKEUP_HANDLER_ID);
__HAL_RTC_WAKEUPTIMER_ENABLE(phrtc); /**< Enable the Wakeup Timer */
}
else
...
Solved! Go to Solution.
2022-02-01 07:00 AM
Is the bug reported after code review or because of problem seen in real
application ?
In case a problem has been seen in real application, that would be good to
report how to reproduce.
The current implementation seems correct.
When "Value" is set to 0, it means the following timer instant is already
passed.
So in the case there are two repetitive timers back to back, it means it has
been detected that the second timer already got its timeout while the first one
was processed by the application.
That's why the RTC timer is not restarted and only the NVIC is triggered to
fake a RTC timer that has been restarted and immediately timed out.
2022-02-01 07:00 AM
Is the bug reported after code review or because of problem seen in real
application ?
In case a problem has been seen in real application, that would be good to
report how to reproduce.
The current implementation seems correct.
When "Value" is set to 0, it means the following timer instant is already
passed.
So in the case there are two repetitive timers back to back, it means it has
been detected that the second timer already got its timeout while the first one
was processed by the application.
That's why the RTC timer is not restarted and only the NVIC is triggered to
fake a RTC timer that has been restarted and immediately timed out.
2022-02-02 03:17 AM
The problem was seen in a real application.
I understand. I believe then the actual problem was then in the use of the timerserver code.
The HW_TS_RTC_Wakeup_Handler was called from the HAL_RTCEx_WakeUpTimerEventCallback method which as can be seen below is before the clearing of the WUT flags.
2022-02-02 04:06 AM
OK. So let's consider this case as closed
Internal ticket 122000 => This is an internal tracking number. This ticket is not accessible by customers.
2022-02-08 08:12 AM
Going a bit deeper in this issue
It seems you are using HAL_RTCEx_WakeUpTimerIRQHandler from the NVIC which in turn call HAL_RTCEx_WakeUpTimerEventCallback.
However,
1/ This API was overrule
#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( )
So HAL_RTCEx_WakeUpTimerEventCallback shall be never called.
2/ even though HAL_RTCEx_WakeUpTimerEventCallback, it is not sure it will call in turn HW_TS_RTC_Wakeup_Handler(). I dont think there is any link.
Anyway, best is to make sure HW_TS_RTC_Wakeup_Handler() is the only handler called from the NVIC. Either directly or with the macro renaming from app_conf.h.
in all cases, HAL_RTCEx_WakeUpTimerIRQHandler shall be never entered.