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.