2929#include "tfm_ns_lock.h"
3030#endif
3131
32- /* NOTE: BSP RTC driver judges secure/non-secure RTC by PC. This implementation cannot support non-secure RTC
33- * controlled by secure executable. A better way would be that secure/non-secure RTC base is passed
34- * to RTC API as an argument like most other APIs. With BSP RTC driver unchanged, we must enforce
35- * secure RTC. */
32+ /* Secure attribution of RTC
33+ *
34+ * We need RTC to be secure for security concern.
35+ *
36+ * On M2351, configured to secure
37+ * On M2351, hard-wired to secure
38+ */
3639#if defined(SCU_INIT_PNSSET2_VAL ) && (SCU_INIT_PNSSET2_VAL & (1 << 1 ))
3740#error ("Limited by BSP/RTC, we can only support secure RTC.")
3841#endif
@@ -70,7 +73,7 @@ void rtc_write(time_t t)
7073 *
7174 * NOTE: This dependents on real hardware.
7275 */
73- #define NU_RTCCLK_PER_SEC ((CLK->CLKSEL3 & CLK_CLKSEL3_SC0SEL_Msk) ? __LIRC : __LXT)
76+ #define NU_RTCCLK_PER_SEC (__LXT)
7477
7578/* Strategy for implementation of RTC HAL
7679 *
@@ -124,7 +127,7 @@ static time_t t_write = 0;
124127/* Convert date time from H/W RTC to struct TM */
125128static void rtc_convert_datetime_hwrtc_to_tm (struct tm * datetime_tm , const S_RTC_TIME_DATA_T * datetime_hwrtc );
126129
127- static const struct nu_modinit_s rtc_modinit = {RTC_0 , RTC_MODULE , 0 , 0 , 0 , RTC_IRQn , NULL };
130+ static const struct nu_modinit_s rtc_modinit = {RTC_0 , RTC_MODULE , CLK_CLKSEL3_RTCSEL_LXT , 0 , 0 , RTC_IRQn , NULL };
128131
129132static void rtc_init_impl (void );
130133static void rtc_free_impl (void );
@@ -151,11 +154,10 @@ static void rtc_free_impl(void)
151154
152155static int32_t rtc_isenabled_impl (void )
153156{
154- // NOTE: To access (RTC) registers, clock must be enabled first.
155- if (! (CLK -> APBCLK0 & CLK_APBCLK0_RTCCKEN_Msk )) {
156- // Enable IP clock
157- CLK_EnableModuleClock_S (rtc_modinit .clkidx );
158- }
157+ // To access (RTC) registers, clock must be enabled first.
158+ // For TZ, with RTC being secure, we needn't call the secure gateway versions.
159+ CLK_EnableModuleClock (rtc_modinit .clkidx );
160+ CLK_SetModuleClock (rtc_modinit .clkidx , rtc_modinit .clksrc , rtc_modinit .clkdiv );
159161
160162 RTC_T * rtc_base = (RTC_T * ) NU_MODBASE (rtc_modinit .modname );
161163
0 commit comments