I have a FRDM-KL25Z and I'm trying to change the power mode from FEI to FBI. I want to run on FBI mode with a internal frequency of 4 MHz. I've used the following code to do the job:
|mcg_mode_error_t mcgModeError = CLOCK_HAL_SetFbiMode(MCG, kMcgDcoRangeSelLow, kMcgIrcFast, 1, NULL);|
The problem is that the firmware stops running during the CLOCK_HAL_SetFbiMode function. I've added a breakpoint inside this function and I saw that the problem is in the following line:
MCG_WR_C1(base, (MCG_RD_C1(base) & ~(MCG_C1_CLKS_MASK | MCG_C1_IREFS_MASK))
| (MCG_C1_CLKS(kMcgClkOutSrcInternal) /* CLKS = 1 */
| MCG_C1_IREFS(kMcgFllSrcInternal))); /* IREFS = 1 */
I realized that if I change the CLOCK_HAL_SetFbiMode function, to force it to write on MCG_C1 register after writing on MCG_C2 register, the firmware works!
Do you think there is a problem in CLOCK_HAL_SetFbiMode function?