diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/TARGET_NUMAKER_PFM_NANO130/mbed_overrides.c b/targets/TARGET_NUVOTON/TARGET_NANO100/TARGET_NUMAKER_PFM_NANO130/mbed_overrides.c index f3778c22cd..c17d7022b5 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/TARGET_NUMAKER_PFM_NANO130/mbed_overrides.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/TARGET_NUMAKER_PFM_NANO130/mbed_overrides.c @@ -52,8 +52,36 @@ void mbed_sdk_init(void) /* Set HCLK source form HXT and HCLK source divide 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HXT, CLK_HCLK_CLK_DIVIDER(1)); - /* Set HCLK frequency 42MHz */ - CLK_SetCoreClock(42000000); + /* Select HXT/HIRC to clock PLL + * + * Comparison between HXT/HIRC-clocked PLL: + * 1. Spare HXT on board if only HIRC is used. + * 2. HIRC has shorter stable time. + * 3. HXT has better accuracy. USBD requires HXT-clocked PLL. + * 4. HIRC has shorter wake-up time from power-down mode. + * Per test, wake-up time from power-down mode would take: + * T1. 1~13 ms (proportional to deep sleep time) with HXT-clocked PLL as HCLK clock source + * T2. <1 ms with HIRC-clocked PLL as HCLK clock source + * T1 will fail Greentea test which requires max 10 ms wake-up time. + * + * If we just call CLK_SetCoreClock(FREQ_42MHZ) to configure HCLK to 42 MHz, + * it will go T1 with HXT already enabled in front. So we manually configure + * it to choose HXT/HIRC-clocked PLL. + */ +#define NU_HXT_PLL 1 +#define NU_HIRC_PLL 2 + +#ifndef NU_CLOCK_PLL +#define NU_CLOCK_PLL NU_HIRC_PLL +#endif + +#if (NU_CLOCK_PLL == NU_HXT_PLL) + CLK_EnablePLL(CLK_PLLCTL_PLL_SRC_HXT, FREQ_42MHZ*2); + CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_HCLK_CLK_DIVIDER(2)); +#elif (NU_CLOCK_PLL == NU_HIRC_PLL) + CLK_EnablePLL(CLK_PLLCTL_PLL_SRC_HIRC, FREQ_42MHZ*2); + CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_HCLK_CLK_DIVIDER(2)); +#endif /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */ diff --git a/targets/targets.json b/targets/targets.json index 550b894359..39a9bdcbb6 100755 --- a/targets/targets.json +++ b/targets/targets.json @@ -3952,6 +3952,11 @@ "gpio-irq-debounce-sample-rate": { "help": "Select GPIO IRQ debounce sample rate: GPIO_DBCLKSEL_1, GPIO_DBCLKSEL_2, GPIO_DBCLKSEL_4, ..., or GPIO_DBCLKSEL_32768", "value": "GPIO_DBCLKSEL_16" + }, + "clock-pll": { + "help": "Choose clock source to clock PLL: NU_HXT_PLL or NU_HIRC_PLL", + "macro_name": "NU_CLOCK_PLL", + "value": "NU_HIRC_PLL" } }, "inherits": ["Target"],