Skip to content

Commit db7b228

Browse files
jeromecoutantadbridge
authored andcommitted
STM32 LPTICKER with RTC : Fix tickless and lp wrapper
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 prevents matches from getting dropped by the rtc by deactivating the rtc wake up timer before setting a new value. Events leading up to this failure for the RTC: -1st call to lp_ticker_set_interrupt -delay until ticker interrupt is about to fire -2nd call to lp_ticker_set_interrupt -interrupt for 1st call fires and match time for 2nd call is dropped -LowPowerTickerWrapper gets ticker interrupt but treats it as a spurious interrupt and drops it since it comes in too early -device enters sleep without a wakeup source and locks up
1 parent 3d0acbc commit db7b228

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

targets/TARGET_STM/lp_ticker.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ uint32_t lp_ticker_read(void)
258258

259259
void lp_ticker_set_interrupt(timestamp_t timestamp)
260260
{
261-
lp_ticker_disable_interrupt();
262261
rtc_set_wake_up_timer(timestamp);
263262
}
264263

targets/TARGET_STM/rtc_api.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ void rtc_set_wake_up_timer(timestamp_t timestamp)
381381
}
382382

383383
RtcHandle.Instance = RTC;
384+
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
384385
if (HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, WakeUpCounter, RTC_WAKEUPCLOCK_RTCCLK_DIV4) != HAL_OK) {
385386
error("rtc_set_wake_up_timer init error\n");
386387
}
@@ -402,10 +403,7 @@ void rtc_fire_interrupt(void)
402403
void rtc_deactivate_wake_up_timer(void)
403404
{
404405
RtcHandle.Instance = RTC;
405-
__HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle);
406-
__HAL_RTC_WAKEUPTIMER_DISABLE(&RtcHandle);
407-
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&RtcHandle, RTC_IT_WUT);
408-
__HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle);
406+
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
409407
NVIC_DisableIRQ(RTC_WKUP_IRQn);
410408
}
411409

0 commit comments

Comments
 (0)