29
29
#include "tfm_ns_lock.h"
30
30
#endif
31
31
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
+ */
36
39
#if defined(SCU_INIT_PNSSET2_VAL ) && (SCU_INIT_PNSSET2_VAL & (1 << 1 ))
37
40
#error ("Limited by BSP/RTC, we can only support secure RTC.")
38
41
#endif
@@ -70,7 +73,7 @@ void rtc_write(time_t t)
70
73
*
71
74
* NOTE: This dependents on real hardware.
72
75
*/
73
- #define NU_RTCCLK_PER_SEC ((CLK->CLKSEL3 & CLK_CLKSEL3_SC0SEL_Msk) ? __LIRC : __LXT)
76
+ #define NU_RTCCLK_PER_SEC (__LXT)
74
77
75
78
/* Strategy for implementation of RTC HAL
76
79
*
@@ -124,7 +127,7 @@ static time_t t_write = 0;
124
127
/* Convert date time from H/W RTC to struct TM */
125
128
static void rtc_convert_datetime_hwrtc_to_tm (struct tm * datetime_tm , const S_RTC_TIME_DATA_T * datetime_hwrtc );
126
129
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 };
128
131
129
132
static void rtc_init_impl (void );
130
133
static void rtc_free_impl (void );
@@ -151,11 +154,10 @@ static void rtc_free_impl(void)
151
154
152
155
static int32_t rtc_isenabled_impl (void )
153
156
{
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 );
159
161
160
162
RTC_T * rtc_base = (RTC_T * ) NU_MODBASE (rtc_modinit .modname );
161
163
0 commit comments