2025-02-17 02:57 PM
STM32L151RET6
Is the RTC affected by the microcontroller reset?
The system is placed in stop mode and is reset every 2 seconds by the watchdog.
After 24 hours of operation, I find a delay of approximately 20 seconds.
If I do not use stop mode and let the system run normally, these delays do not occur.
It behaves as if the microcontroller reset affects the RTC.
Has anyone else encountered this situation?
Solved! Go to Solution.
2025-02-19 09:17 PM
I used this code sequence for RTC initialization
The function is called at each system reset generated by WATGHDOG
(at every 2 seconds - that's what the application requires)
void RTC_Configuration(void)
{
if (((RTC->ISR & RTC_ISR_INITS) != 0))
return;
RTC_InitReg(); // here is the code for RTC init registers
}
But in the system clocks initialization function which is also called every 2 seconds
according to the code below
void RCC_Configuration(void)
{
SystemClockInitReg(); // system clock registers config
/* config RTC clock */
PWR->CR |= PWR_CR_DBP; // Enable backup write protection
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_LSEConfig(RCC_LSE_ON);
RCC_RTCCLKCmd(ENABLE);
PWR_RtcAccessDisable();
PWR->CR &= ~PWR_CR_DBP; // Disable backup write protection
}
Config RTC clock in this function was my mistake because it is not
under INITS flag condition
RCC_LSEConfig(uint8_t RCC_LSE) turn OFF the LSE for a while
/*
* @PAram RCC_LSE : specifies the new state of the LSE.
* This parameter can be one of the following values :
*@arg RCC_LSE_OFF : turn OFF the LSE oscillator, LSERDY flag goes low after
* 6 LSE oscillator clock cycles.
* @arg RCC_LSE_ON : turn ON the LSE oscillator
* @arg RCC_LSE_Bypass : LSE oscillator bypassed with external clock
* @retval None
*/
void RCC_LSEConfig(uint8_t RCC_LSE)
{
/* Check the parameters */
assert_param(IS_RCC_LSE(RCC_LSE));
/* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
*(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE_OFF;
/* Set the new LSE configuration -------------------------------------------*/
*(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE;
}
I have modified that two functions like below:
void RTC_Configuration(void)
{
if (((RTC->ISR & RTC_ISR_INITS) != 0))
return;
PWR->CR |= PWR_CR_DBP; // Enable backup write protection
/* config RTC clock */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_LSEConfig(RCC_LSE_ON);
RCC_RTCCLKCmd(ENABLE);
PWR_RtcAccessDisable();
RTC_InitReg(); // here is the code for RTC init registers
PWR->CR &= ~PWR_CR_DBP; // Disable backup write protection
}
void RCC_Configuration(void)
{
SystemClockInitReg(); // system clock registers config
}
Config RTC clock is performed just one time at system power-up
INITS became true after calendar setting
and the RTC config is not execcuted anymore
Now it is working perfect
2025-02-18 12:39 AM
I mention that the RTC initialization is done only at the first power up after which at each reset generated by IWDG I check the INITS bit of the ISR register. If it is set (and it is) I don't reinitialize the RTC.
Date and time are kept, except that there is that 18 seconds delay after 24 hours of operation in this mode.
2025-02-18 06:50 AM
Hello @costi
Thank you for sharing your observations. To better understand and assist with your issue, could you please provide more details on the following points:
1. How did you measure the delay?
- Please describe the method and tools you used to measure the 18-second delay after 24 hours of operation.
2. Could you share more details about your setup?
- Details about your RTC configuration and initialization process.
- Information on how you are handling the watchdog reset and any relevant code snippets.
- System Clock configuration.
If possible, please share your project so that we can assist you more effectively.
2025-02-18 09:36 PM
The system is powered from two voltage sources. One of them is a CR2032 battery. When remaining powered from this battery, the system enters stop mode and every 2 seconds is reset by the watchdog. After reset one pin of the microcontroller is tested. If the pin status is 0 logic it goes back to stop mode, if it is 1 logic it goes back to normal operation. The calendar is shown on a display, including seconds. After 24 hours I notice this delay of 18 seconds. If the system is operating normally, powered from the main power supply, this delay does not appear. RTC initialization is done only once when setting the calendar.
2025-02-19 09:17 PM
I used this code sequence for RTC initialization
The function is called at each system reset generated by WATGHDOG
(at every 2 seconds - that's what the application requires)
void RTC_Configuration(void)
{
if (((RTC->ISR & RTC_ISR_INITS) != 0))
return;
RTC_InitReg(); // here is the code for RTC init registers
}
But in the system clocks initialization function which is also called every 2 seconds
according to the code below
void RCC_Configuration(void)
{
SystemClockInitReg(); // system clock registers config
/* config RTC clock */
PWR->CR |= PWR_CR_DBP; // Enable backup write protection
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_LSEConfig(RCC_LSE_ON);
RCC_RTCCLKCmd(ENABLE);
PWR_RtcAccessDisable();
PWR->CR &= ~PWR_CR_DBP; // Disable backup write protection
}
Config RTC clock in this function was my mistake because it is not
under INITS flag condition
RCC_LSEConfig(uint8_t RCC_LSE) turn OFF the LSE for a while
/*
* @PAram RCC_LSE : specifies the new state of the LSE.
* This parameter can be one of the following values :
*@arg RCC_LSE_OFF : turn OFF the LSE oscillator, LSERDY flag goes low after
* 6 LSE oscillator clock cycles.
* @arg RCC_LSE_ON : turn ON the LSE oscillator
* @arg RCC_LSE_Bypass : LSE oscillator bypassed with external clock
* @retval None
*/
void RCC_LSEConfig(uint8_t RCC_LSE)
{
/* Check the parameters */
assert_param(IS_RCC_LSE(RCC_LSE));
/* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
*(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE_OFF;
/* Set the new LSE configuration -------------------------------------------*/
*(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE;
}
I have modified that two functions like below:
void RTC_Configuration(void)
{
if (((RTC->ISR & RTC_ISR_INITS) != 0))
return;
PWR->CR |= PWR_CR_DBP; // Enable backup write protection
/* config RTC clock */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_LSEConfig(RCC_LSE_ON);
RCC_RTCCLKCmd(ENABLE);
PWR_RtcAccessDisable();
RTC_InitReg(); // here is the code for RTC init registers
PWR->CR &= ~PWR_CR_DBP; // Disable backup write protection
}
void RCC_Configuration(void)
{
SystemClockInitReg(); // system clock registers config
}
Config RTC clock is performed just one time at system power-up
INITS became true after calendar setting
and the RTC config is not execcuted anymore
Now it is working perfect