KL25Z custom board with KSDK 2.0: clock registers won't change accordingly

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

KL25Z custom board with KSDK 2.0: clock registers won't change accordingly

759 Views
gustavsl
Contributor III

On my custom board with MKL25Z128, I'm using KSDK 2.0 with Keil MDK and initializing the clock with the following function to use the internal oscillator (no crystal):

void BOARD_BootClockRUN(void) {

    const sim_clock_config_t simConfig = {
        .pllFllSel = 0U,        /* PLLFLLSEL select FLL. */
        .er32kSrc = 3U,         /* ERCLK32K selection, use LPO. */
        .clkdiv1 = 0x00000000U, /* SIM_CLKDIV1. */
    };

 

    CLOCK_SetSimSafeDivs();
    CLOCK_BootToFeiMode(kMCG_Dmx32Default,kMCG_DrsMid,NULL);
    CLOCK_SetInternalRefClkConfig(kMCG_IrclkEnable, kMCG_IrcFast, 0);
    CLOCK_SetSimConfig(&simConfig);
 }

While debugging, I see that the CLOCK_SetSimSafeDivs() function correctly alters the SIM_CLKDIV1 register.

However, when CLOCK_BootToFeiMode executes, the registers won't change to the specified parameters. As an example, the DRST_DRS bit in MCG_C4 should be set to 1, but the function doesn't modify it and it still keeps the value 2.

 

Also, in the CLOCK_SetInternalRefClkConfig function, the MCG_C1 bit CLKS is not set to 1 to select the internal reference clock, but keeps the value 2, which selects the external reference clock.

 

My application sets a LPTMR interrupt using the LPO (1kHz) clock, but when I set, e.g., a 1 second interrupt, it triggers every 1.2 seconds.

 

I tried setting the same clock configuration (internal clock, 41.94MHz) and creating the LPTMR interrupt using Processor Expert and KDS and it works correctly, so I thought it might be something related to KSDK.

 

Any clues?

 

Thanks,

 

Gustavo.

Labels (1)
0 Kudos
3 Replies

577 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Regarding your question that "My application sets a LPTMR interrupt using the LPO (1kHz) clock, but when I set, e.g., a 1 second interrupt, it triggers every 1.2 seconds.", I think the LPTMR interrupt period accuracy is only dependent on the LPO clock accuracy, as you know that the LPO is inaccurate, pls refer to section 2.2.2 LVD and POR operating requirements in data sheet of KL25, I copy it here:

pastedImage_1.png

so it is possible that you get 1.1S when you set the it as 1.0s

If you need accurate interrupt period with LPTMR, I suggest you use external 32.768KHz crystal.

Hope it can help you

BR

Xiangjun Rong

0 Kudos

577 Views
gustavsl
Contributor III

Also, for my clock configuration code above, since I'm using the internal clock, shouldn't the IREFS and IRCKLEN bits on MCG_C1 be enabled?

Keil it shows that external clock is selected even after configuration:

keil_clock_mcgc1.PNG

Based on the Processor Expert generated code, IRCKLEN and IREFS should be 1 and CLKS should be 0.

If I try to manually write the values to MCG->C1, they won't work.

Any tips?

Thanks,

Gustavo.

0 Kudos

577 Views
gustavsl
Contributor III

Thank you for your response.

Looking at my Processor Expert configuration which correctly triggers the LPTMR interrupt to trigger every 1 second, it selects the IRCLK (2MHz), prescales it to 62.5kHz and counts to 62500 to give 1Hz.

How can I achieve this same clock path configuration using KSDK? I attached a screenshot showing my PE configuration.

clock_path_lptmr_pe.PNG 

Thank you,

Gustavo.

0 Kudos