Skip to content

Commit 3819634

Browse files
peterhinchdpgeorge
authored andcommitted
stmhal: Make RTC init skip startup if LTE is already enabled and ready.
This prevents the loss of RTC time when exiting from standby mode, since the RTC is paused while it is being re-inited and this loses about 120ms. Thanks to @chuckbook for the patch.
1 parent b83d0b3 commit 3819634

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

stmhal/rtc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ void rtc_init(void) {
178178
RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
179179
RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
180180

181+
// if LTE enabled & ready --> no need to (re-)init RTC
182+
if ((RCC->BDCR & (RCC_BDCR_LSEON | RCC_BDCR_LSERDY)) == (RCC_BDCR_LSEON | RCC_BDCR_LSERDY)) {
183+
// remove Backup Domain write protection
184+
PWR->CR |= PWR_CR_DBP;
185+
// Clear source Reset Flag
186+
__HAL_RCC_CLEAR_RESET_FLAGS();
187+
// provide some status information
188+
rtc_info |= 0x40000 | (RCC->BDCR & 7) | (RCC->CSR & 3) << 8;
189+
return;
190+
}
191+
181192
mp_uint_t tick = HAL_GetTick();
182193

183194
if (HAL_RTC_Init(&RTCHandle) != HAL_OK) {

0 commit comments

Comments
 (0)