Hi Kerry !
I can see picture is more complicate. Config tool ( I'm using latest MCUEXpresso and SDK ) generate the next function for RTC clock initialization.
And this sequence have effect for my RTC initialization what is executed later on.
/*FUNCTION**********************************************************************
*
* Function Name : CLOCK_CONFIG_SetRtcClock
* Description : This function is used to configuring RTC clock including
* enabling RTC oscillator.
* Param capLoad : RTC oscillator capacity load
* Param enableOutPeriph : Enable (1U)/Disable (0U) clock to peripherals
*
*END**************************************************************************/
static void CLOCK_CONFIG_SetRtcClock(uint32_t capLoad, uint8_t enableOutPeriph)
{
/* RTC clock gate enable */
CLOCK_EnableClock(kCLOCK_Rtc0);
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the Rtc oscillator is not already enabled */
/* Set the specified capacitor configuration for the RTC oscillator */
RTC_SetOscCapLoad(RTC, capLoad);
/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}
/* Output to other peripherals */
if (enableOutPeriph) {
RTC->CR &= ~RTC_CR_CLKO_MASK;
}
else {
RTC->CR |= RTC_CR_CLKO_MASK;
}
/* Set the XTAL32/RTC_CLKIN frequency based on board setting. */
CLOCK_SetXtal32Freq(BOARD_XTAL32K_CLK_HZ);
/* Set RTC_TSR if there is fault value in RTC */
if (RTC->SR & RTC_SR_TIF_MASK) {
RTC -> TSR = RTC -> TSR;
}
/* RTC clock gate disable */
CLOCK_DisableClock(kCLOCK_Rtc0);
}
And first power on reset , show 0 status and default time what is in registers
-- RTC ( status 0x0 ) -> 1970-01-01 00:00:00
-- Power-on Reset
And after SW reset ( NVIC_SystemReset() ) status is set to 0x4 what means kRTC_AlarmFlag ( ? )
And I configure RTC according SDK example.
-- RTC ( status 0x4 ) -> 2018-08-08 19:00:00
-- Software Reset
It means I should just do the next sequence.
1. Enable RTC clock
CLOCK_EnableClock(kCLOCK_Rtc0);
2. Read Year register and if it 1970 ( or less than 2018)
Execute full initialization sequence , like in SDK example.
3. Clean RTC status if Alarm is set there.
Is any glue why it is set over SW reset ?
What do you think about this sequence ?
Unfortunately it is not part of SDK and we should design it.
Regards,
Eugene