MQX K64 Custom Clock Configuration

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

MQX K64 Custom Clock Configuration

532 Views
csmgsarma
Contributor III

HI List

I am using a K64F120M micro with MQX(ver 4.1) on Kiel IDE. The external clock input is 50MHz. I wish to run my micro at a clock speed of 100MHz with PEE mode.

I have made these changes in bsp_cm.c:

/* Clock configuration 0 */
#define CPU_MCG_MODE_CONFIG_0                              (CPU_MCG_MODE_PEE | CPU_CLOCK_EXTERNAL_CLOCK_MASK | CPU_CLOCK_FAST_MASK) /* Clock generator mode */
#define CPU_CLOCK_VLP_CONFIG_0                             0U /* Very low power mode disabled */
#define CPU_MCG_C1_CONFIG_0                                0xB8U        //default = 0x28U /* MCG_C1 */
#define CPU_MCG_C2_CONFIG_0                                0x2CU         //default = 0x21U /* MCG_C2 */
#define CPU_MCG_C4_CONFIG_0                                0x00U  /* MCG_C4 */
#define CPU_MCG_C5_CONFIG_0                                0x18U        //default = 0x13U /* MCG_C5 */
#define CPU_MCG_C6_CONFIG_0                                0x5AU        //default = 0x58U /* MCG_C6 */
#define CPU_MCG_SC_CONFIG_0                                0x02U /* MCG_SC */
#define CPU_OSC_CR_CONFIG_0                                0x80U /* OSC_CR */
#define CPU_SIM_SOPT1_CONFIG_0                             0x00080000UL /* SIM_SOPT1 */
#define CPU_SIM_SOPT2_CONFIG_0                             0x00011800UL  //0x00010000UL /* SIM_SOPT2 */  FIXME!!
#define CPU_SIM_CLKDIV1_CONFIG_0                           0x99990000UL /* SIM_CLKDIV1 */ //default = 0x01240000UL

uint16_t _bsp_set_clock_configuration
(
    /* [IN] runtime clock configuration */
    const BSP_CLOCK_CONFIGURATION clock_configuration
)
{
    uint16_t    cpu_error = ERR_OK;
    uint32_t     result;

    cpu_error = CPU_SetClockConfiguration((uint8_t)clock_configuration);
    if (cpu_error != ERR_OK)    {
        return cpu_error;
    }

    //FIXME!! Testing
    SIM_SCGC5 = (0x00003E00UL); //Enable clocks for Port A through E.
    SIM_SCGC7 = (0x04UL);   //Enable MPU Clock.
    
    /* Change frequency for system timer */
    result = hwtimer_set_freq(&systimer, BSP_SYSTIMER_SRC_CLK, BSP_ALARM_FREQUENCY);
    if (MQX_OK != result)
    {
        return ERR_FAILED;
    }

    return ERR_OK;
}


I have arrived at these values from the reference manual and MQX BSP porting guide. My idea is to measure the clock out at the XTAL pin to ensure that my settings are made as expected.


My observations are:
    MCG_C1 = 0x28U
    MCG_C2 = 0x2CU         
    MCG_C5 = 0x13U
    MCG_C6 = 0x58U
    SIM_CLKDIV1 = 0x01240000UL

I see that my values are not written to the MCG and SIM registers. Is there something I am missing? Is there any reference project or code available for configuring clock settings.


Best regards
Sarma.

0 Kudos
Reply
2 Replies

17 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi CSMG Sarma

The clock setting scheme is quite confusing.

Initialize and setting clock module is complex task. Since we wanted focus on MQX as operating system, we delegate this task to Processor Expert tool.

The _bsp_initialize_hardware function is responsible for basic MCU setting and setting of the Multipurpose Clock Generator (MCG) module. It switches the MCG module from the reset state through the MCG state machine to the default configuration. See more information about the MCG Mode State Diagram in the reference manual for the selected Kinetis platform.

So, _bsp_initialize_hardware function is responsible for initialize clock module from reset state.

Function Cpu_SetClockConfiguration() is used for change clock settings.

Different situation happened when we want change this settings. We can reconfigure clock settings by Processor Expert, generate new code and this new code will overload the default setting in bsp_cm.c. See how the PE_LDD_VERSION is used for conditional compilation of either  the default code or the newly generated code.

I agree with you that clock setting scheme could be confusing and there missing some transparent documentation for clock module software architecture. Most useful could be in this document

c:\Freescale\Freescale_MQX_4_1\doc\tools\cw\MQX_Howto_Setup_Kinetis_Clock_UsingPE.pdf 

I hope it helps.


Have a great day,
Daniel

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

0 Kudos
Reply

17 Views
danielchen
NXP TechSupport
NXP TechSupport

Thanks Sarma for your sharing, it is helpful to other customers.

Regards

Daniel

0 Kudos
Reply