mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Revision:
186:707f6e361f3e
Parent:
184:08ed48f1de7f
--- a/targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c	Thu Apr 19 17:12:19 2018 +0100
+++ b/targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c	Fri Jun 22 16:45:37 2018 +0100
@@ -100,7 +100,7 @@
 
 void rtc_free(void)
 {
-    // N/A
+    CLK_DisableModuleClock(rtc_modinit.clkidx);
 }
 
 int rtc_isenabled(void)
@@ -136,9 +136,18 @@
         if (! _rtc_maketime(&datetime_tm, &t_hwrtc_origin, RTC_FULL_LEAP_YEAR_SUPPORT)) {
             return 0;
         }
+
+        /* Load t_write from RTC spare register to cross reset cycle */
+        RTC_WaitAccessEnable();
+        RTC_EnableSpareAccess();
+        RTC_WaitAccessEnable();
+        t_write = RTC_READ_SPARE_REGISTER(0);
+        RTC_WaitAccessEnable();
+        while (! (RTC->SPRCTL & RTC_SPRCTL_SPRRWRDY_Msk));
     }
 
     S_RTC_TIME_DATA_T hwrtc_datetime_2K_present;
+    RTC_WaitAccessEnable();
     RTC_GetDateAndTime(&hwrtc_datetime_2K_present);
     /* Convert date time from H/W RTC to struct TM */
     rtc_convert_datetime_hwrtc_to_tm(&datetime_tm, &hwrtc_datetime_2K_present);
@@ -161,6 +170,15 @@
 
     t_write = t;
 
+    /* Store t_write to RTC spare register to cross reset cycle */
+    RTC_WaitAccessEnable();
+    RTC_EnableSpareAccess();
+    RTC_WaitAccessEnable();
+    RTC_WRITE_SPARE_REGISTER(0, t_write);
+    RTC_WaitAccessEnable();
+    while (! (RTC->SPRCTL & RTC_SPRCTL_SPRRWRDY_Msk));
+
+    RTC_WaitAccessEnable();
     RTC_SetDateAndTime((S_RTC_TIME_DATA_T *) &DATETIME_HWRTC_ORIGIN);
     /* NOTE: When engine is clocked by low power clock source (LXT/LIRC), we need to wait for 3 engine clocks. */
     wait_us((NU_US_PER_SEC / NU_RTCCLK_PER_SEC) * 3);