COIDE系统导入的System_nano1xxx.c中的sysinit_clock文件如下:
/**
* @brief Enable chip clock source and select CPU clock.
* @param None
* @return None
*/
void SysInit_Clock(void)
{
__IO uint32_t delayCnt;
/* Enable system clock source, HIRC and LIRC are default enabled */
UNLOCKREG();
CLK->PWRCTL |= (CLK_PWRCTL_HXT_EN | CLK_PWRCTL_LXT_EN);
LOCKREG();
/* Select HCLK from HIRC */
CLK->CLKDIV0 &= ~CLK_CLKDIV0_HCLK_MASK; /* divider is 0 */
UNLOCKREG();
CLK->CLKSEL0 = (CLK->CLKSEL0 & ~CLK_CLKSEL0_HCLK_MASK) | CLK_CLKSEL0_HCLK_HIRC; /* HCLK = 12MHz */
LOCKREG();
/* Update CPU Clock Frequency */
SystemCoreClockUpdate();
}
新唐自带的bsp中的System_nano1xxx.c中的sysinit_clock文件如下:
void SysInit_Clock(void)
{
__IO uint32_t delayCnt;
/* Enable system clock source, HIRC and LIRC are default enabled */
UNLOCKREG();
CLK->PWRCTL |= (CLK_PWRCTL_HXT_EN | CLK_PWRCTL_LXT_EN);
LOCKREG();
/* Enable PLL out to 96MHz */
CLK->PLLCTL = (CLK_PLLCTL_PLLSRC_HXT | PLL_IN_12M_OUT_96M);
/* Waits for PLL clock stable */
for (delayCnt=0; delayCnt<100000; delayCnt++)
if (CLK->CLKSTATUS & CLK_CLKSTATUS_PLL_STB) break;
/* Change HCLK to PLL output */
if (delayCnt < 100000) {
CLK->CLKDIV0 = (CLK->CLKDIV0 & ~CLK_CLKDIV0_HCLK_MASK) | 2; /* divider is 3 */
UNLOCKREG();
CLK->CLKSEL0 = (CLK->CLKSEL0 & ~CLK_CLKSEL0_HCLK_MASK) | CLK_CLKSEL0_HCLK_PLL; /* HCLK = 32MHz */
LOCKREG();
}
/* Set HCLK back to HIRC if error happens */
if (CLK->CLKSTATUS & CLK_CLKSTATUS_CLK_SW_FAIL) {
CLK->CLKDIV0 &= ~CLK_CLKDIV0_HCLK_MASK; /* divider is 0 */
UNLOCKREG();
CLK->CLKSEL0 = (CLK->CLKSEL0 & ~CLK_CLKSEL0_HCLK_MASK) | CLK_CLKSEL0_HCLK_HIRC; /* HCLK = 12MHz */
LOCKREG();
}
/* Update CPU Clock Frequency */
SystemCoreClockUpdate();
}
使用nano130开发板时一直不能正确配置时钟,最后发现了这个问题,系统coide开发者能修改下。 |