KL03 core clock and timer clock clock from External oscillator.

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

KL03 core clock and timer clock clock from External oscillator.

886 Views
andrewbarnes
Contributor I

I'm new to the KL03 family but have used micro controllers from TI for years.  I'm evaluating the KL03 and I want to the core clock and timer clock to be sourced from a MHz external oscillator.  I understand that the clock needs to be fed to the EXTAL pin but I'm a little lost on the controller setup to use it for the core and time ( I'll be using the timer in compare OUT mode).

 

I have Kinetis Design Studio installed and I have SDK 2.0 project.  Could someone help me with the details on configuring the KL03?  Most of my issue is not knowing how to use the SDK.  I've tried the following without success.

 

void _ext_clk_init(void)
{

 


    const mcglite_config_t mcgliteConfig = {
        .outSrc = kMCGLITE_ClkSrcExt,
        .irclkEnableMode = kMCGLITE_IrclkEnable,
        .ircs = kMCGLITE_ClkSrcExt,
        .fcrdiv = kMCGLITE_LircDivBy1,
        .lircDiv2 = kMCGLITE_LircDivBy1,
        .hircEnableInNotHircMode = false,
    };

 

    const sim_clock_config_t simConfig =
    {
#if (defined(FSL_FEATURE_SIM_OPT_HAS_OSC32K_SELECTION) && FSL_FEATURE_SIM_OPT_HAS_OSC32K_SELECTION)
        .er32kSrc = 0U, /* SIM_SOPT1[OSC32KSEL]. */
#endif
        .clkdiv1 = 0x00010000U, /* SIM_CLKDIV1. */
    };

 

    CLOCK_SetSimSafeDivs();

 

    CLOCK_SetMcgliteConfig(&mcgliteConfig);

 

    CLOCK_SetSimConfig(&simConfig);

 

    // external clock  runs at  1.863MHz
    SystemCoreClock = 1863000U;

 

    return;
}

After calling the above function I toggle a LED on the FRDM-LK03Z eval board and the frequency of the LED toggle is the clock divided by 79 which leads me to believe I'm on the right track.

 

Thanks to all to replay and those who simply look.

Labels (1)
0 Kudos
2 Replies

526 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Andrew Barnes

In References manual you can find:

pastedImage_2.png

As you can see here, there are 3 modules that you need to configure to setup core clock and timer clock with external clock; System oscillator, MCG_lite and CLKGEN (SIM).

You mentioned that you have installed SDK 2.0, Have you tried driver_examples provided in this package? there is an mcglite example located in {SDK_2.0 path installed}\boards\frdmkl03z\driver_examples\mcglite. This example first uses BOARD_BootClockRUN function to set Core clock: 48MHz and Bus clock: 24MHz. And after it configures 4 different clock modes; HIRC mode, LIRC2M mode, EXT mode and LIRC8M mode.

In this example they use the following configuration for the the MCG_lite in the clock EXT mode:

 /* MCG_Lite configuration for EXT mode. */
    mcglite_config_t mcgliteConfigExt;
    mcgliteConfigExt.outSrc = kMCGLITE_ClkSrcExt;
    mcgliteConfigExt.irclkEnableMode = 0U;
    mcgliteConfigExt.ircs = kMCGLITE_Lirc8M;
    mcgliteConfigExt.fcrdiv = kMCGLITE_LircDivBy2;
    mcgliteConfigExt.lircDiv2 = kMCGLITE_LircDivBy4;
    mcgliteConfigExt.hircEnableInNotHircMode = false;

/* Set EXT mode */
   CLOCK_SetMcgliteConfig(&mcgliteConfigExt);‍‍‍‍‍‍‍‍‍‍‍

And it uses the BOARD_InitOsc0(); to configure the System oscillator module, in this example it uses a external crystal:

void BOARD_InitOsc0(void)
{
    const osc_config_t oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
                                    .capLoad = 0U,
                                    .workMode = kOSC_ModeOscLowPower,
                                    .oscerConfig = {
                                        .enableMode = kOSC_ErClkEnable,
                                    }};
    CLOCK_InitOsc0(&oscConfig);
    /* Passing the XTAL0 frequency to clock driver. */
    CLOCK_SetXtal0Freq(BOARD_XTAL0_CLK_HZ); // BOARD_XTAL0_CLK_HZ is defined as 32768U
}‍‍‍‍‍‍‍‍‍‍‍‍

And CLKGEN (OUTDIV1 and OUTDIV4) doesn't change. So, in this example they use the following path in this mode:

pastedImage_2.png

Your clock configuration depends in your application, but if you want to use external clock for core clock and timer you can take as base this example and use OSCERCLK for a TPM or a LPTMR. One thing to consider is that FRDM-KL03Z uses an external crystal, but if you just want to use an external oscillator in the EXTAL0 pin, you should change .workMode = kOSC_ModeExt. Also if you want to change the OUTDIV1 and OUTDIV4 you can set a new simConfig and use CLOCK_SetSimConfig(&simConfig);

I recommend you to check the Reference Manual (attached), chapter 24 and chapter 25.

Hope this information could helps you and if you have any other question please don't hesitate to ask us.
Have a great day,
Jorge Alcala

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

0 Kudos

527 Views
beaurogers
Contributor II

Hello, this question is a long time ago, but I am wondering on the FRDM-KL03Z board if the EXTAL0 pin is imbedded but not accessible. As in, despite not being able to measure any signal, can I assume that there is in fact a signal that is being sent to the microprocessor? I have been trying to get the built in 32kHz crystal oscillator to trigger the LPTMR but I have had nothing work.

-Beau

0 Kudos