Hi,
I am trying to configure the internal reference clock for K65F180m in mqx. I have read the utasker documentation on MCG modes and have gone through the reference manual. I have certain doubts regarding MCG. It would be of great help if anyone can clarify them
SIM_SCGC4 ->SIM_SCGC4_USBOTG_MASK;
void __pe_initialize_hardware(void)
{
/* OSC Configure */
OSC_CR |= ~OSC_CR_ERCLKEN_MASK;
// /* after enter FEI Mode */
// Cpu_SetMCGModeFBE(0);
// Cpu_SetMCGModePBE(0);
// Cpu_SetMCGModePEE(0);
}
Hi
You have not specified clearly which internal reference clock that you would like to use - from the code I assume that it is IRC48M since this is enabled; IRC48MHz can be used as direct core clock source or as reference for PLL or FLL.
After a reset (any type) the MCG starts in FEI mode, meaning that the 32kHz IRC is being used as source for the FLL and the core is clocked at around 21MHz.
You can initialise and operate without any external oscillator.
The only time that an external crystal/oscillator is needed for the K65 is when you need to use HS USB PHY, in which case a 12MHz, 16MHz or 24MHz crystal/oscillator is required for its PLL to reference to.
Regards
Mark
P.S.
This is a strange command - it is setting all bits apart from the OSC_CR_ERCLKEN_MASK:
OSC_CR |= ~OSC_CR_ERCLKEN_MASK;
Hi,
When i make changes in the bsp for using the internal clock, the code doesn't get executed. It stays in the mcg loop forever waiting for lockup. I tried generating a code for K53 using processor expert (K65 is not supported in PEx 10.4) disabling the system oscillator. I enabled the mcg mode as BLPI and used the 4MHz clock. Then the generated code was imported to a new IAR C project. But there also same issue.
Anyone having the configuration needed to startup using internal oscillator. 4MHz fast IRC is also ok. The 48MHz IRC is internal to the micro controller right? Am i wrong?
Hi
It is still not clear which internal clock you want, but I am still assuming it is IRC48M, which is internal to the processor.
The following code switches the core to work directly with this clock.
MCG_C7 = MCG_C7_OSCSEL_IRC48MCLK; // route the IRC48M clock to the external reference clock input (this enables IRC48M) SIM_CLKDIV1 = (((SYSTEM_CLOCK_DIVIDE - 1) << 28) | ((BUS_CLOCK_DIVIDE - 1) << 24) | ((FLEX_CLOCK_DIVIDE - 1) << 20) | ((FLASH_CLOCK_DIVIDE - 1) << 16)); // prepare bus clock divides MCG_C1 = (MCG_C1_IREFS | MCG_C1_CLKS_EXTERN_CLK); // switch IRC48M reference to MCGOUTCLK while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST_EXTERN_CLK) {} // wait until the new source is valid (move to FBI using IRC48M external source is complete) MCG_C2 |= MCG_C2_LP; // set bypass to disable FLL and complete move to BLPE (in which PLL is also always disabled)
Regards
Mark