Skip to content

Commit 4020c6d

Browse files
authored
Merge pull request #10436 from OpenNuvoton/nuvoton_nuc472_fix_power-down
NUC472: Workaround for unknown error with power-down
2 parents 016ce32 + 61271d0 commit 4020c6d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

targets/TARGET_NUVOTON/TARGET_NUC472/sleep.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ void hal_sleep(void)
4040

4141
/**
4242
* Enter power-down mode, in which HXT/HIRC are halted.
43+
*
44+
* \note On NUC472, on wake-up from power-down mode, we may meet hard fault or
45+
* some other unknown error. Before its cause is found, we enter idle mode
46+
* instead for a workaround. To simulate power-down mode with idle mode, we
47+
* also disable us_ticker during power-down period.
4348
*/
49+
#include "nu_modutil.h"
50+
const struct nu_modinit_s *nu_us_ticker_modinit(void);
4451
void hal_deepsleep(void)
4552
{
4653
#if DEVICE_SERIAL
@@ -49,9 +56,11 @@ void hal_deepsleep(void)
4956
}
5057
#endif
5158

59+
CLK_DisableModuleClock(nu_us_ticker_modinit()->clkidx);
5260
SYS_UnlockReg();
53-
CLK_PowerDown();
61+
CLK_Idle();
5462
SYS_LockReg();
63+
CLK_EnableModuleClock(nu_us_ticker_modinit()->clkidx);
5564
}
5665

5766
#endif

targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ static void tmr0_vec(void);
3838

3939
static const struct nu_modinit_s timer0_modinit = {TIMER_0, TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_PCLK, 0, TMR0_RST, TMR0_IRQn, (void *) tmr0_vec};
4040

41+
/* Externalize this function for hal_deepsleep() to get around unknown error
42+
* with power-down. */
43+
const struct nu_modinit_s *nu_us_ticker_modinit(void)
44+
{
45+
return &timer0_modinit;
46+
}
47+
4148
#define TIMER_MODINIT timer0_modinit
4249

4350
/* Track ticker status */

0 commit comments

Comments
 (0)