Skip to content

NUC472: Workaround for unknown error with power-down #10436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion targets/TARGET_NUVOTON/TARGET_NUC472/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ void hal_sleep(void)

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

CLK_DisableModuleClock(nu_us_ticker_modinit()->clkidx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about free us_ticker instead here? So that you don't risk receiving unwanted interrupt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ronny-Liu The sequence of us_ticker_free() > CLK_Idle() > us_ticker_init() in hal_deepsleep() will reset us_ticker counter. Some tests like mbed-os-tests-mbed_hal-sleep and mbed-os-tests-mbed_hal-sleep_manager require us_ticker counter to continue on wake-up from power-down. Besides, hal_deepsleep() is called in interrupt-disabled context by sleep_manager_sleep_auto(), so the unwanted interrupt can be avoided.

SYS_UnlockReg();
CLK_PowerDown();
CLK_Idle();
SYS_LockReg();
CLK_EnableModuleClock(nu_us_ticker_modinit()->clkidx);
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ static void tmr0_vec(void);

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

/* Externalize this function for hal_deepsleep() to get around unknown error
* with power-down. */
const struct nu_modinit_s *nu_us_ticker_modinit(void)
{
return &timer0_modinit;
}

#define TIMER_MODINIT timer0_modinit

/* Track ticker status */
Expand Down