Skip to content

Commit 7e1443a

Browse files
authored
Merge pull request #12424 from OpenNuvoton/nuvoton_gpio-irq_rtc-lxt
Nuvoton: Fix GPIO IRQ and RTC
2 parents d7f3341 + 769781c commit 7e1443a

File tree

28 files changed

+41855
-42909
lines changed

28 files changed

+41855
-42909
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/PeripheralPins.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const PinMap PinMap_GPIO[] = {
138138
{PG_14, GPIO_G, SYS_GPG_MFPH_PG14MFP_GPIO},
139139
{PG_15, GPIO_G, SYS_GPG_MFPH_PG15MFP_GPIO},
140140

141-
// GPIO H MFP
141+
// GPIO H MFP
142142
{PH_4, GPIO_H, SYS_GPH_MFPL_PH4MFP_GPIO},
143143
{PH_5, GPIO_H, SYS_GPH_MFPL_PH5MFP_GPIO},
144144
{PH_6, GPIO_H, SYS_GPH_MFPL_PH6MFP_GPIO},
@@ -646,4 +646,3 @@ const PinMap PinMap_CAN_RD[] = {
646646

647647
{NC, NC, 0}
648648
};
649-

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NPSA_NS/TARGET_NU_PREBUILD_SECURE/NuMaker-mbed-TZ-secure-example.hex

Lines changed: 242 additions & 243 deletions
Large diffs are not rendered by default.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NS/TARGET_NU_PREBUILD_SECURE/crypto_access_control.hex

Lines changed: 8266 additions & 8494 deletions
Large diffs are not rendered by default.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NS/TARGET_NU_PREBUILD_SECURE/spm_client.hex

Lines changed: 8243 additions & 8471 deletions
Large diffs are not rendered by default.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NS/TARGET_NU_PREBUILD_SECURE/spm_server.hex

Lines changed: 8401 additions & 8631 deletions
Large diffs are not rendered by default.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NS/TARGET_NU_PREBUILD_SECURE/spm_smoke.hex

Lines changed: 8240 additions & 8468 deletions
Large diffs are not rendered by default.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_NU_PFM_M2351_NS/TARGET_NU_PREBUILD_SECURE/tfm.hex

Lines changed: 8213 additions & 8440 deletions
Large diffs are not rendered by default.

targets/TARGET_NUVOTON/TARGET_M2351/crypto/crypto-misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ __STATIC_INLINE CRPT_T *CRYPTO_MODBASE(void)
5252
#if defined(SCU_INIT_PNSSET1_VAL) && (SCU_INIT_PNSSET1_VAL & (1<<18))
5353
return CRPT_NS;
5454
#else
55-
return CRPT;
55+
return CRPT_S;
5656
#endif
5757
}
5858

targets/TARGET_NUVOTON/TARGET_M2351/gpio_irq_api.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,13 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
182182
obj->irq_types &= ~irq_type;
183183
}
184184

185-
/* Update irq types */
185+
/* Update irq types:
186+
*
187+
* Implementations of GPIO_EnableInt(...) are inconsistent: disable or not irq type not enabled.
188+
* For consistency, disable GPIO_INT_BOTH_EDGE and then enable OR'ed irq types, GPIO_INT_RISING,
189+
* GPIO_INT_FALLING, or both.
190+
*/
191+
GPIO_DisableInt(gpio_base, pin_index);
186192
GPIO_EnableInt(gpio_base, pin_index, obj->irq_types);
187193
}
188194

targets/TARGET_NUVOTON/TARGET_M2351/rtc_api.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
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 */
125128
static 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

129132
static void rtc_init_impl(void);
130133
static void rtc_free_impl(void);
@@ -151,11 +154,10 @@ static void rtc_free_impl(void)
151154

152155
static 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

Comments
 (0)