Skip to content

Commit 572bae3

Browse files
committed
Nuvoton: Fix failure to change WDT clock source
WDT clock source selection and its enablement bits are protected. Add unlock sequence before write to them.
1 parent 2162aaa commit 572bae3

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

targets/TARGET_NUVOTON/TARGET_M451/watchdog_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
9999
if (! wdt_hw_inited) {
100100
wdt_hw_inited = 1;
101101

102+
SYS_UnlockReg();
103+
102104
/* Enable IP module clock */
103105
CLK_EnableModuleClock(WDT_MODULE);
104106

@@ -109,6 +111,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
109111
CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDTSEL_LIRC, 0);
110112
#endif
111113

114+
SYS_LockReg();
115+
112116
/* Set up IP interrupt */
113117
NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler);
114118
NVIC_EnableIRQ(WDT_IRQn);

targets/TARGET_NUVOTON/TARGET_M480/watchdog_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
9898
if (! wdt_hw_inited) {
9999
wdt_hw_inited = 1;
100100

101+
SYS_UnlockReg();
102+
101103
/* Enable IP module clock */
102104
CLK_EnableModuleClock(WDT_MODULE);
103105

@@ -108,6 +110,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
108110
CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDTSEL_LIRC, 0);
109111
#endif
110112

113+
SYS_LockReg();
114+
111115
/* Set up IP interrupt */
112116
NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler);
113117
NVIC_EnableIRQ(WDT_IRQn);

targets/TARGET_NUVOTON/TARGET_NANO100/watchdog_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
101101
if (! wdt_hw_inited) {
102102
wdt_hw_inited = 1;
103103

104+
SYS_UnlockReg();
105+
104106
/* Enable IP module clock */
105107
CLK_EnableModuleClock(WDT_MODULE);
106108

107109
/* Select IP clock source */
108110
CLK_SetModuleClock(WDT_MODULE, 0, 0);
109111

112+
SYS_LockReg();
113+
110114
/* Set up IP interrupt */
111115
NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler);
112116
NVIC_EnableIRQ(WDT_IRQn);

targets/TARGET_NUVOTON/TARGET_NUC472/watchdog_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
9898
if (! wdt_hw_inited) {
9999
wdt_hw_inited = 1;
100100

101+
SYS_UnlockReg();
102+
101103
/* Enable IP module clock */
102104
CLK_EnableModuleClock(WDT_MODULE);
103105

@@ -108,6 +110,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
108110
CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDTSEL_LIRC, 0);
109111
#endif
110112

113+
SYS_LockReg();
114+
111115
/* Set up IP interrupt */
112116
NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler);
113117
NVIC_EnableIRQ(WDT_IRQn);

0 commit comments

Comments
 (0)