diff --git a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c index 74cd964403..9b3ddc356c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c @@ -95,11 +95,14 @@ void lp_ticker_init(void) TIMER_EnableInt((TIMER_T *) NU_MODBASE(timer2_modinit.modname)); TIMER_EnableWakeup((TIMER_T *) NU_MODBASE(timer2_modinit.modname)); - // Schedule wakeup to match semantics of lp_ticker_get_compare_match() - lp_ticker_set_interrupt(wakeup_tick); + // NOTE: TIMER_Start() first and then lp_ticker_set_interrupt(); otherwise, we may get stuck in lp_ticker_read() because + // timer is not running. // Start timer TIMER_Start((TIMER_T *) NU_MODBASE(timer2_modinit.modname)); + + // Schedule wakeup to match semantics of lp_ticker_get_compare_match() + lp_ticker_set_interrupt(wakeup_tick); } timestamp_t lp_ticker_read() diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c index 5ed5a719c0..f581b5a910 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c @@ -94,11 +94,14 @@ void lp_ticker_init(void) TIMER_EnableInt((TIMER_T *) NU_MODBASE(timer2_modinit.modname)); TIMER_EnableWakeup((TIMER_T *) NU_MODBASE(timer2_modinit.modname)); - // Schedule wakeup to match semantics of lp_ticker_get_compare_match() - lp_ticker_set_interrupt(wakeup_tick); + // NOTE: TIMER_Start() first and then lp_ticker_set_interrupt(); otherwise, we may get stuck in lp_ticker_read() because + // timer is not running. // Start timer TIMER_Start((TIMER_T *) NU_MODBASE(timer2_modinit.modname)); + + // Schedule wakeup to match semantics of lp_ticker_get_compare_match() + lp_ticker_set_interrupt(wakeup_tick); } timestamp_t lp_ticker_read()