AnsweredAssumed Answered

MQX K64 Custom Clock Configuration

Question asked by CSMG Sarma on Apr 17, 2017
Latest reply on Apr 19, 2017 by Daniel Chen

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