void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable IRC22M clock */
SYSCLK->PWRCON |= SYSCLK_PWRCON_IRC22M_EN_Msk;
/* Waiting for IRC22M clock ready */
SYS_WaitingForClockReady(SYSCLK_CLKSTATUS_IRC22M_STB_Msk);
/* Switch HCLK clock source to IRC22M */
SYSCLK->CLKSEL0 = SYSCLK_CLKSEL0_HCLK_IRC22M;
/* Set PLL to Power-down mode and PLL_STB bit in CLKSTATUS register will be cleared by hardware.*/
SYSCLK->PLLCON |= SYSCLK_PLLCON_PD_Msk;
/* Enable external 12MHz XTAL */
SYSCLK->PWRCON |= SYSCLK_PWRCON_XTL12M_EN_Msk;
/* Enable PLL and Set PLL frequency */
SYSCLK->PLLCON = PLLCON_SETTING;
/* Waiting for clock ready */
SYS_WaitingForClockReady(SYSCLK_CLKSTATUS_PLL_STB_Msk | SYSCLK_CLKSTATUS_XTL12M_STB_Msk);
/* Switch HCLK clock source to PLL, STCLK to HCLK/2 */
SYSCLK->CLKSEL0 = SYSCLK_CLKSEL0_STCLK_HCLK_DIV2 | SYSCLK_CLKSEL0_HCLK_PLL;
/* Enable UART clock */
SYSCLK->APBCLK = SYSCLK_APBCLK_UART0_EN_Msk;
/* UART clock source */
SYSCLK->CLKSEL1 = SYSCLK_CLKSEL1_UART_PLL;
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
//SystemCoreClockUpdate();
PllClock = PLL_CLOCK; // PLL
SystemCoreClock = PLL_CLOCK / 1; // HCLK
CyclesPerUs = PLL_CLOCK / 1000000; // For SYS_SysTickDelay()
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set P3 multi-function pins for UART0 RXD and UART0 TXD */
SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0;
/* Lock protected registers */
SYS_LockReg();
}
这是库函数里面最基础的一个,如上面红色字体的函数,因为我用内部的时钟,所以认为对我的工程师多余的,打算删除。
绿色字体的部分,不理解用处在于哪里?是否也可以拿掉呢?
|