Hello, having trouble setting up to run off an external oscillator 24MHz, used MCUXpresso Config Tools v11 to produce some code but I can't use it directly as the project was generated with V1 SDKs so been trying to map it across with little success. The datasheet and user manual are unclear on if the PPL needs to be setup if you are just pointing the main clock to the input?
MCUXpresso Config Tools v11 suggested code
void BOARD_BootClockRUN(void)
{
/*!< Set up the clock sources */
/*!< Set up IRC */
POWER_DisablePD(kPDRUNCFG_PD_IRC_OUT); /*!< Ensure IRC OUT is on */
POWER_DisablePD(kPDRUNCFG_PD_IRC); /*!< Ensure IRC is on */
POWER_DisablePD(kPDRUNCFG_PD_SYSOSC); /*!< Ensure SYSOSC is on */
CLOCK_InitSysOsc(24000000U); /*!< Set main osc freq */
CLOCK_Select(kSYSPLL_From_SysOsc); /*!< set sysosc to pll select */
clock_sys_pll_t config;
config.src=kCLOCK_SysPllSrcSysosc; /*!< set pll src */
config.targetFreq = 24000000U; /*!< set pll target freq */
CLOCK_InitSystemPll(&config); /*!< set parameters */
CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcSysPllin); /*!< select pllin for main clock */
CLOCK_Select(kCLKOUT_From_Irc); /*!< select IRC for CLKOUT */
CLOCK_SetCoreSysClkDiv(1U);
POWER_EnablePD(kPDRUNCFG_PD_IRC_OUT); /*!< Disable IRC OUT */
POWER_EnablePD(kPDRUNCFG_PD_IRC); /*!< Disable IRC */
/*!< Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}
My version of code
void Setup_Clock(uint8_t MSel, uint8_t PSel)
{
//No bypass and higher freq range
Chip_Clock_SetPLLBypass(FALSE, TRUE);
//Turn on the SYS OSC by clearing the power down bit
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSOSC_PD);
//Select the PLL input in the extern ocs
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_SYSOSC);
//Setup FLASH access to 2 clocks (up to 30MHz)
Chip_FMC_SetFLASHAccess(FLASHTIM_30MHZ_CPU);
//Power down PLL to change the PLL divider ratio
Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_SYSPLL_PD);
//Configure the PLL M and P dividers
Chip_Clock_SetupSystemPLL(MSel, PSel);
//Turn on the PLL by clearing the power down bit
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSPLL_PD);
//Wait for PLL to lock
while (Chip_Clock_IsSystemPLLLocked() == FALSE)
{
}
//Set system clock divider to 1
Chip_Clock_SetSysClockDiv(1);
//Set main clock source to the system PLL IN
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLIN);
SystemCoreClockUpdate();
}
I am sure I am missing something obvious, any help would be gratefully received.