Skip to content

Commit 4a1d612

Browse files
committed
Nuvoton: Fix delay code with RTC clock source
Explicitly configure RTC clock source to LXT Update targets: - NUMAKER_PFM_NANO130 - NUMAKER_PFM_NUC472 - NUMAKER_PFM_M453 - NUMAKER_PFM_M487/NUMAKER_IOT_M487 - NUMAKER_M252KG - NUMAKER_IOT_M263A
1 parent 86fcae5 commit 4a1d612

File tree

6 files changed

+31
-37
lines changed

6 files changed

+31
-37
lines changed

targets/TARGET_NUVOTON/TARGET_M251/rtc_api.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,10 @@ void rtc_free(void)
107107

108108
int rtc_isenabled(void)
109109
{
110-
// NOTE: To access (RTC) registers, clock must be enabled first.
111-
if (! (CLK->APBCLK0 & CLK_APBCLK0_RTCCKEN_Msk)) {
112-
// Enable IP clock
113-
CLK_EnableModuleClock(rtc_modinit.clkidx);
114-
}
110+
// To access (RTC) registers, clock must be enabled first.
111+
// For TZ, with RTC being secure, we needn't call the secure gateway versions.
112+
CLK_EnableModuleClock(rtc_modinit.clkidx);
113+
CLK_SetModuleClock(rtc_modinit.clkidx, rtc_modinit.clksrc, rtc_modinit.clkdiv);
115114

116115
RTC_T *rtc_base = (RTC_T *) NU_MODBASE(rtc_modinit.modname);
117116

targets/TARGET_NUVOTON/TARGET_M261/rtc_api.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* NOTE: This dependents on real hardware.
3333
*/
34-
#define NU_RTCCLK_PER_SEC ((CLK->CLKSEL3 & CLK_CLKSEL3_SC0SEL_Msk) ? __LIRC : __LXT)
34+
#define NU_RTCCLK_PER_SEC __LXT
3535

3636
/* Strategy for implementation of RTC HAL
3737
*
@@ -85,7 +85,7 @@ static time_t t_write = 0;
8585
/* Convert date time from H/W RTC to struct TM */
8686
static void rtc_convert_datetime_hwrtc_to_tm(struct tm *datetime_tm, const S_RTC_TIME_DATA_T *datetime_hwrtc);
8787

88-
static const struct nu_modinit_s rtc_modinit = {RTC_0, RTC_MODULE, 0, 0, 0, RTC_IRQn, NULL};
88+
static const struct nu_modinit_s rtc_modinit = {RTC_0, RTC_MODULE, CLK_CLKSEL3_RTCSEL_LXT, 0, 0, RTC_IRQn, NULL};
8989

9090
void rtc_init(void)
9191
{
@@ -106,11 +106,10 @@ void rtc_free(void)
106106

107107
int rtc_isenabled(void)
108108
{
109-
// NOTE: To access (RTC) registers, clock must be enabled first.
110-
if (! (CLK->APBCLK0 & CLK_APBCLK0_RTCCKEN_Msk)) {
111-
// Enable IP clock
112-
CLK_EnableModuleClock(rtc_modinit.clkidx);
113-
}
109+
// To access (RTC) registers, clock must be enabled first.
110+
// For TZ, with RTC being secure, we needn't call the secure gateway versions.
111+
CLK_EnableModuleClock(rtc_modinit.clkidx);
112+
CLK_SetModuleClock(rtc_modinit.clkidx, rtc_modinit.clksrc, rtc_modinit.clkdiv);
114113

115114
RTC_T *rtc_base = (RTC_T *) NU_MODBASE(rtc_modinit.modname);
116115

targets/TARGET_NUVOTON/TARGET_M451/rtc_api.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* NOTE: This dependents on real hardware.
3232
*/
33-
#define NU_RTCCLK_PER_SEC ((CLK->CLKSEL3 & CLK_CLKSEL3_SC0SEL_Msk) ? __LIRC : __LXT)
33+
#define NU_RTCCLK_PER_SEC __LXT
3434

3535
/* Strategy for implementation of RTC HAL
3636
*
@@ -84,7 +84,7 @@ static time_t t_write = 0;
8484
/* Convert date time from H/W RTC to struct TM */
8585
static void rtc_convert_datetime_hwrtc_to_tm(struct tm *datetime_tm, const S_RTC_TIME_DATA_T *datetime_hwrtc);
8686

87-
static const struct nu_modinit_s rtc_modinit = {RTC_0, RTC_MODULE, 0, 0, 0, RTC_IRQn, NULL};
87+
static const struct nu_modinit_s rtc_modinit = {RTC_0, RTC_MODULE, CLK_CLKSEL3_RTCSEL_LXT, 0, 0, RTC_IRQn, NULL};
8888

8989
void rtc_init(void)
9090
{
@@ -105,11 +105,10 @@ void rtc_free(void)
105105

106106
int rtc_isenabled(void)
107107
{
108-
// NOTE: To access (RTC) registers, clock must be enabled first.
109-
if (! (CLK->APBCLK0 & CLK_APBCLK0_RTCCKEN_Msk)) {
110-
// Enable IP clock
111-
CLK_EnableModuleClock(rtc_modinit.clkidx);
112-
}
108+
// To access (RTC) registers, clock must be enabled first.
109+
// For TZ, with RTC being secure, we needn't call the secure gateway versions.
110+
CLK_EnableModuleClock(rtc_modinit.clkidx);
111+
CLK_SetModuleClock(rtc_modinit.clkidx, rtc_modinit.clksrc, rtc_modinit.clkdiv);
113112

114113
// NOTE: Check RTC Init Active flag to support crossing reset cycle.
115114
return !! (RTC->INIT & RTC_INIT_ACTIVE_Msk);

targets/TARGET_NUVOTON/TARGET_M480/rtc_api.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* NOTE: This dependents on real hardware.
3232
*/
33-
#define NU_RTCCLK_PER_SEC ((CLK->CLKSEL3 & CLK_CLKSEL3_SC0SEL_Msk) ? __LIRC : __LXT)
33+
#define NU_RTCCLK_PER_SEC __LXT
3434

3535
/* Strategy for implementation of RTC HAL
3636
*
@@ -84,7 +84,7 @@ static time_t t_write = 0;
8484
/* Convert date time from H/W RTC to struct TM */
8585
static void rtc_convert_datetime_hwrtc_to_tm(struct tm *datetime_tm, const S_RTC_TIME_DATA_T *datetime_hwrtc);
8686

87-
static const struct nu_modinit_s rtc_modinit = {RTC_0, RTC_MODULE, 0, 0, 0, RTC_IRQn, NULL};
87+
static const struct nu_modinit_s rtc_modinit = {RTC_0, RTC_MODULE, CLK_CLKSEL3_RTCSEL_LXT, 0, 0, RTC_IRQn, NULL};
8888

8989
void rtc_init(void)
9090
{
@@ -105,11 +105,10 @@ void rtc_free(void)
105105

106106
int rtc_isenabled(void)
107107
{
108-
// NOTE: To access (RTC) registers, clock must be enabled first.
109-
if (! (CLK->APBCLK0 & CLK_APBCLK0_RTCCKEN_Msk)) {
110-
// Enable IP clock
111-
CLK_EnableModuleClock(rtc_modinit.clkidx);
112-
}
108+
// To access (RTC) registers, clock must be enabled first.
109+
// For TZ, with RTC being secure, we needn't call the secure gateway versions.
110+
CLK_EnableModuleClock(rtc_modinit.clkidx);
111+
CLK_SetModuleClock(rtc_modinit.clkidx, rtc_modinit.clksrc, rtc_modinit.clkdiv);
113112

114113
// NOTE: Check RTC Init Active flag to support crossing reset cycle.
115114
return !! (RTC->INIT & RTC_INIT_ACTIVE_Msk);

targets/TARGET_NUVOTON/TARGET_NANO100/rtc_api.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ void rtc_free(void)
105105

106106
int rtc_isenabled(void)
107107
{
108-
// NOTE: To access (RTC) registers, clock must be enabled first.
109-
if (! (CLK->APBCLK & CLK_APBCLK_RTC_EN_Msk)) {
110-
// Enable IP clock
111-
CLK_EnableModuleClock(rtc_modinit.clkidx);
112-
}
108+
// To access (RTC) registers, clock must be enabled first.
109+
// For TZ, with RTC being secure, we needn't call the secure gateway versions.
110+
CLK_EnableModuleClock(rtc_modinit.clkidx);
111+
CLK_SetModuleClock(rtc_modinit.clkidx, rtc_modinit.clksrc, rtc_modinit.clkdiv);
113112

114113
// NOTE: Check RTC Init Active flag to support crossing reset cycle.
115114
return !! (RTC->INIR & RTC_INIR_ACTIVE_Msk);

targets/TARGET_NUVOTON/TARGET_NUC472/rtc_api.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ void rtc_free(void)
105105

106106
int rtc_isenabled(void)
107107
{
108-
// NOTE: To access (RTC) registers, clock must be enabled first.
109-
if (! (CLK->APBCLK0 & CLK_APBCLK0_RTCCKEN_Msk)) {
110-
// Enable IP clock
111-
CLK_EnableModuleClock(rtc_modinit.clkidx);
112-
}
113-
108+
// To access (RTC) registers, clock must be enabled first.
109+
// For TZ, with RTC being secure, we needn't call the secure gateway versions.
110+
CLK_EnableModuleClock(rtc_modinit.clkidx);
111+
CLK_SetModuleClock(rtc_modinit.clkidx, rtc_modinit.clksrc, rtc_modinit.clkdiv);
112+
114113
// NOTE: Check RTC Init Active flag to support crossing reset cycle.
115114
return !! (RTC->INIT & RTC_INIT_INIT_Active_Msk);
116115
}

0 commit comments

Comments
 (0)