Hi all. I'm trying to initialize K70F150M, which uses external 12MHz oscillator at XTAL1 and external XTAL32 32kHz.
MCGOUTCLK supposed to be 150 MHz, target mode - PEE, selected PLL - PLL0.
Last initialization attempt probably damaged the board. Today I've got the new one, and need some help to initialize it.
So if initialization code could damage the device, I would like somebody inspect my code before writing it into the board.
Code screens are attached.
Prevoius discussion: K70F150M and external 12MHz oscillator
Solved! Go to Solution.
Loop line was changed to following:
while((MCG->S & MCG_S_CLKST_MASK) != MCG_S_CLKST(2)){}
C10 initialization was changed to
MCG->C10 = (uint8_t)( MCG_C10_RANGE1(0x02) | MCG_C10_EREFS1_MASK );
and clock for XTAL1 were added:
PORTE->PCR[24] &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07))); |
PORTE->PCR[25] &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07)));
It seems everything works now.
All I need now - to check frequency with the oscilloscope.
Hi
I don't think that it is possible to damage a device by programming the clock incorrectly. If settings a are not good the VCO will not be able to lock but after a reset it would be able to work again and the device recovered by performing an erase with teh debugger.
Since I never used XTAL1 as source I can't verify your code but below is the set up (showing hex values rather than defines or macros) for XTAL0 from 12MHz crystal for 150MHz system coock as reference. I didn't see any errors concering speeds.
Regards
Mark
MCG_C2 = 0xac; // select crystal oscillator
MCG_C1 = 0x98; // switch to external source (the FLL input clock is set to as close to its input range as possible, although this is not absolutely necessary if the FLL will not be used)
while (!(MCG_S & MCG_S_OSCINIT)) {} // loop until the crystal source has been selected
while (MCG_S & MCG_S_IREFST) {} // loop until the FLL source is no longer the internal reference clock
while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST_EXTERN_CLK) {} // loop until the external reference clock source is valid
MCG_C5 = 0; // 12M / 1 = 12MHz
MCG_C6 = 0x49; // 12MHz x 25 = 300MHz VCO = 150MHz PLL; move from state FEE to state PBE (or FBE)
while ((MCG_S & MCG_S_PLLST) == 0) {} // loop until the PLLS clock source becomes valid
while ((MCG_S & MCG_S_LOCK) == 0) {} // loop until PLL locks
SIM_CLKDIV1 = 0x01250000; // 150MHz system, 75MHz bus, 30MHz flex, 25MHz flash
MCG_C1 = 0x28; // switch to PLL clock
while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST_PLL) {} // loop until the PLL clock is selected
Hi Mark
>> I don't think that it is possible to damage a device by programming the clock incorrectly
Me too. But... Look at last messages of previous discussion via link I've gave.
Device is don't responding, I've tried all of the debug options in several IDEs, and two hardware adapters for programming of my board - "Device could not be powered up" - all what I see.
So I've send the broken board to it's manufacturer and am waiting for reply. Another boards are pretty good for programming, I'm able to erase them, to program them, etc.
Anyway thanks a lot - I've checked my clock dividers/multipliers, they are the same as yours.
P.S. I've tried to initialize k70 again. Fault. Infinite loop when entering PBE mode: while((MCG->S & MCG_C6_PLLS_MASK) != MCG_C6_PLLS_MASK )
Best regards, Alexander.
Loop line was changed to following:
while((MCG->S & MCG_S_CLKST_MASK) != MCG_S_CLKST(2)){}
C10 initialization was changed to
MCG->C10 = (uint8_t)( MCG_C10_RANGE1(0x02) | MCG_C10_EREFS1_MASK );
and clock for XTAL1 were added:
PORTE->PCR[24] &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07))); |
PORTE->PCR[25] &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07)));
It seems everything works now.
All I need now - to check frequency with the oscilloscope.