TWR-K20D72M: init_bsp.c: two clock configurations: why?

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

TWR-K20D72M: init_bsp.c: two clock configurations: why?

1,553 Views
markkalior
Contributor II

Does anyone know why there are two:

_bsp_set_clock_configuration(BSP_CLOCK_CONFIGURATION_AUTOTRIM);   // This seems to use the internal clock

then

_bsp_set_clock_configuration(BSP_CLOCK_CONFIGURATION_STARTUP);   // ...which is BSP_CLOCK_CONFIGARATION_72MHZ.   Which uses the external crystal.  

Why not just have the STARTUP?

0 Kudos
Reply
6 Replies

1,370 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi

Before auto trimming process, the MCG should be set to one of the following modes (FEE,FBE,BLPE,PEE,PBE), and value is in the range <8; 16>Mhz.

the first configuration, the MCG is switched to  (PEE, 12M), next auto trimming process started.

the second configuration, the MCG is switched to (PEE, 72M)


Have a nice day,
Daniel

0 Kudos
Reply

1,370 Views
markkalior
Contributor II

Daniel;

Okay, I understand what code says, but is it required?    Can the MK20DX256VMC10 be configured directly to PEE, 100Mhz?    Why does the evaluation board set the MCG in two stages?   Will the part not start, if just one MCG config is used?

Mark 

0 Kudos
Reply

1,370 Views
DavidS
NXP Employee
NXP Employee

Hi Mark,

Short answer....you do not need to do the autotrim step.

Regards,

David

0 Kudos
Reply

1,370 Views
markkalior
Contributor II

David;

Thanks.   ....but, do i need configure the MCG twice?

I have an external crystal why not configure the MCG once?

Do you know why the code configures the MCG twice?   The first with internal crystal, then again with external crystal?   Does the external crystal ciruit sometimes doesn't work or start?  So, if you have the internal crystal working the circuit can limp along?

Mark

0 Kudos
Reply

1,370 Views
DavidS
NXP Employee
NXP Employee

Hi Mark,

Sorry not to be clear.

You don't need to call MCG twice.

To skip the autotrim feature do the following in init_bsp.c:

    /* MCG initialization and internal oscillators trimming */

#if 0 //DES 0=test, 1=default code

    if (CM_ERR_OK != _bsp_set_clock_configuration(BSP_CLOCK_CONFIGURATION_AUTOTRIM))

    {

        return MQX_TIMER_ISR_INSTALL_FAIL;

    }

    if (CM_ERR_OK != _bsp_osc_autotrim())

    {

        return MQX_TIMER_ISR_INSTALL_FAIL;

    }

#endif

    /* Switch to startup clock configuration */

    if (CM_ERR_OK != _bsp_set_clock_configuration(BSP_CLOCK_CONFIGURATION_STARTUP))

    {

        return MQX_TIMER_ISR_INSTALL_FAIL;

    }

Regards,

David

0 Kudos
Reply

1,370 Views
markkalior
Contributor II

Thanks.