Clock configuration problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clock configuration problem

953 Views
john71
Senior Contributor I

First I set the parameters

const mcg_config_t mcgConfig_BOARD_BootClockRUN =

    {

        .mcgMode = kMCG_ModePEE,                  /* PEE - PLL Engaged External */

        .irclkEnableMode = kMCG_IrclkEnable,      /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */

        .ircs = kMCG_IrcSlow,                     /* Slow internal reference clock selected */

        .fcrdiv = 0x0U,                           /* Fast IRC divider: divided by 1 */

        .frdiv = 0x0U,                            /* FLL reference clock divider: divided by 32 */

        .drs = kMCG_DrsLow,                       /* Low frequency range */

        .dmx32 = kMCG_Dmx32Default,               /* DCO has a default range of 25% */

        .oscsel = kMCG_OscselOsc,                 /* Selects System Oscillator (OSCCLK) */

        .pll0Config =

            {

                .enableMode = MCG_PLL_DISABLE,    /* MCGPLLCLK disabled */

                .prdiv = 0x2U,                   /* PLL Reference divider: divided by 25 */

                .vdiv = 0x20U,                    /* VCO divider: multiplied by 48 */

                //.prdiv = 0x18U,                   /* PLL Reference divider: divided by 25 */

                //.vdiv = 0x18U,                    /* VCO divider: multiplied by 48 */

            },

    };

const sim_clock_config_t simConfig_BOARD_BootClockRUN =

    {

        .pllFllSel = SIM_PLLFLLSEL_MCGPLLCLK_CLK, /* PLLFLL select: MCGPLLCLK clock */

        .er32kSrc = SIM_OSC32KSEL_RTC32KCLK_CLK,  /* OSC32KSEL select: RTC32KCLK clock (32.768kHz) */

        .clkdiv1 = 0x01130000U,                    /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV2: /2, OUTDIV3: /2, OUTDIV4: /4 */

    };

const osc_config_t oscConfig_BOARD_BootClockRUN =

    {

        .freq = 20000000U,                        /* Oscillator frequency: 50000000Hz */

        .capLoad = (OSC_CAP0P),                   /* Oscillator capacity load: 0pF */

        .workMode = kOSC_ModeExt,                 /* Use external clock */

        .oscerConfig =

            {

                .enableMode = kOSC_ErClkEnable,   /* Enable external reference clock, disable external reference clock in STOP mode */

            }

    };

My external clock is 20000000 so I set prdiv = 0x2U and vdiv = 0x20U in order to get PLL = 100000000 (maximum system clock for MK10DN512)

And prescalers clkdiv1 = 0x01130000U to get SYS_CLK = PLL and BUS_CLK = PLL/2

Then I use the library function

void BOARD_BootClockRUN(void)

{

    /* Set the system clock dividers in SIM to safe value. */

    CLOCK_SetSimSafeDivs();

    /* Initializes OSC0 according to board configuration. */

    CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);

    CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);

    /* Configure FLL external reference divider (FRDIV). */

    CLOCK_CONFIG_SetFllExtRefDiv(mcgConfig_BOARD_BootClockRUN.frdiv);

    /* Set MCG to PEE mode. */

    CLOCK_BootToPeeMode(mcgConfig_BOARD_BootClockRUN.oscsel,

                        kMCG_PllClkSelPll0,

                        &mcgConfig_BOARD_BootClockRUN.pll0Config);

    /* Configure the Internal Reference clock (MCGIRCLK). */

    CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode,

                                  mcgConfig_BOARD_BootClockRUN.ircs,

                                  mcgConfig_BOARD_BootClockRUN.fcrdiv);

    /* Set the clock configuration in SIM module. */

    CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);

    /* Set SystemCoreClock variable. */

 

    //SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;

   

     SystemCoreClock = CLOCK_GetFreq(SYS_CLK);

     BusClock = CLOCK_GetFreq(BUS_CLK);

   

}

It stacks at function CLOCK_SetPbeMode on

while ((MCG->S & (MCG_S_IREFST_MASK | MCG_S_CLKST_MASK)) !=

           (MCG_S_IREFST(kMCG_FllSrcExternal) | MCG_S_CLKST(kMCG_ClkOutStatExt)))

    {

    }

 

How can I configure clocks?

2 Replies

712 Views
john71
Senior Contributor I

The problem was prdiv = 0x2U and vdiv = 0x20U - it's not absolute values - it bits in registers.

now SYS_CLK = 96000000 BUS_CLK = 48000000

0 Kudos
Reply

712 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Evgeny Erenburg,

The MCUXpresso Clock Tools will generate these codes by itself after you configure the corresponding clock.
You don't need to manually modify these codes.

MK10DN512 20MHz external clock.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------