Skip to content

Commit 9bc2e5a

Browse files
committed
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 b1d23e5 commit 9bc2e5a

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
@@ -389,6 +389,7 @@ void rtc_set_wake_up_timer(timestamp_t timestamp)
389389
}
390390

391391
RtcHandle.Instance = RTC;
392+
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
392393
if (HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, WakeUpCounter, RTC_WAKEUPCLOCK_RTCCLK_DIV4) != HAL_OK) {
393394
error("rtc_set_wake_up_timer init error\n");
394395
}
@@ -410,10 +411,7 @@ void rtc_fire_interrupt(void)
410411
void rtc_deactivate_wake_up_timer(void)
411412
{
412413
RtcHandle.Instance = RTC;
413-
__HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle);
414-
__HAL_RTC_WAKEUPTIMER_DISABLE(&RtcHandle);
415-
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&RtcHandle, RTC_IT_WUT);
416-
__HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle);
414+
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
417415
NVIC_DisableIRQ(RTC_WKUP_IRQn);
418416
}
419417

0 commit comments

Comments
 (0)