使用者要呼叫 systemcoreclockupdate,去更新CyclesPerUs ,CLK_SysTickDelay 會根據CyclesPerUs 計算
void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
{
uint32_t u32Freq, u32ClkSrc;
uint32_t u32HclkDiv;
/* Update PLL Clock */
PllClock = CLK_GetPLLClockFreq();
u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLK_S_Msk;
if(u32ClkSrc != CLK_CLKSEL0_HCLK_S_PLL) {
/* Use the clock sources directly */
u32Freq = gau32ClkSrcTbl[u32ClkSrc];
} else {
/* Use PLL clock */
u32Freq = PllClock;
}
u32HclkDiv = (CLK->CLKDIV & CLK_CLKDIV_HCLK_N_Msk) + 1;
/* Update System Core Clock */
SystemCoreClock = u32Freq / u32HclkDiv;
CyclesPerUs = (SystemCoreClock + 500000) / 1000000;
}
|