Skip to content

NANO130: Change PLL clock source to HIRC instead of HXT #7406

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
Jul 6, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

would this be better in the target configuration that hardcoded here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@0xc0170 Do you mean below? They must be defined in source code, so that they can be chosen from in targets.json or mbed_app.json.

#define NU_HXT_PLL  1
#define NU_HIRC_PLL 2

#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. */
Expand Down
5 changes: 5 additions & 0 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3953,6 +3953,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"],
Expand Down