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