The issue of RTC not retaining its time is fixed in the upcoming KSDK 1.2 release, the problem was identified to a reset call issued in the HAL_Init function. Below is a patch that could be applied to the KSDK 1.1 RTC driver to fix this issue.
diff --git a/platform/hal/src/rtc/fsl_rtc_hal.c b/platform/hal/src/rtc/fsl_rtc_hal.c
index 905b59d..8fc188c 100644
--- a/platform/hal/src/rtc/fsl_rtc_hal.c
+++ b/platform/hal/src/rtc/fsl_rtc_hal.c
@@ -263,15 +263,15 @@ void RTC_HAL_Disable(uint32_t rtcBaseAddr)
void RTC_HAL_Init(uint32_t rtcBaseAddr)
{
- uint32_t seconds = 0x1;
-
- /* Resets the RTC registers except for the SWR bit */
- RTC_HAL_SoftwareReset(rtcBaseAddr);
- RTC_HAL_SoftwareResetFlagClear(rtcBaseAddr);
-
- /* Set TSR register to 0x1 to avoid the TIF bit being set in the SR register */
- RTC_HAL_SetSecsReg(rtcBaseAddr, seconds);
+ if(BR_RTC_SR_TIF(rtcBaseAddr))
+ {
+ /* Resets the RTC registers except for the SWR bit */
+ RTC_HAL_SoftwareReset(rtcBaseAddr);
+ RTC_HAL_SoftwareResetFlagClear(rtcBaseAddr);
+ /* Set TSR register to 0x1 to avoid the TIF bit being set in the SR register */
+ RTC_HAL_SetSecsReg(rtcBaseAddr, 1U);
+ }
/* Clear the interrupt enable register */
RTC_HAL_SetSecsIntCmd(rtcBaseAddr, false);
RTC_HAL_SetAlarmIntCmd(rtcBaseAddr, false);