KL26 RTC crystal as an input to the FLL in the MCG peripheral

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

KL26 RTC crystal as an input to the FLL in the MCG peripheral

Jump to solution
1,295 Views
nurichard
Contributor III

Hello,

I am trying to get a KL26Z256VMC2 0N40H to use the RTC crystal as the clock source.

As far as I can tell the following process should do it, but it does not work for some reason.

The first step that goes wrong is when I attempt to set MCG_C7.OSCSEL to 1 (Selects 32 kHz RTC Oscillator - see KL26P121M48SF4RM KL26 Sub-Family Reference Manual, Rev. 3.2, October 2013).

When I attempt to view the register in a debugger, it is clear that the assignment has not worked.  Using the debugger to manually set the bit does not work either; it always reads as zero.

This has been ported from the K10 where it works successfully

1) Set the SIM_CLKDIV1 to configure the clock dividers: SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1);

2) Disable RTC interrupts: RTC_IER = 0;

3) Set an appropriate RTC capacitive load

4) Enable the RTC and enable clock usage:  RTC_CR |= RTC_CR_OSCE_MASK; RTC_CR &= ~RTC_CR_CLKO_MASK;

5) Initialise the time counters to zero while counting is temporarily disabled)

6) Wait for 4096 RTC oscillation counts to be counted to ensure the RTC is stable

7) Select the external RTC oscillator as the external clock source: MCG_C7 = 0x1;   *** This does not work on the KL26; reading back this register reveals that MCG_C7 remains 0 ***

8) Make sure FLL is selected: MCG_C6 = 0;

9) Configuring the clock source to be the external reference: MCG_C1 = 0;

10) Waiting to make sure that the external reference has been used (waiting for MCG_S.IREFST to become zero) *** The FLL never actually switches to use the external reference ***

11) Configure the FLL to use an appropriate multiplier from the default x640 and wait for the FLL lock time before continuing

I can not get the KL26 past the check in step 10.

The RTC crystal is correctly oscillating at ~32.8kHz according to my oscilloscope.

Step 7 does not work on the KL26

I also noticed that MCG_S is almost always 0x12 on the KL26: IREFST = 1 and OSCINIT0 = 1 (I have occasionally seen it as 0x10 before 6).  (NB: on the K10, MCG_S starts out as 0x10 at step 1 and changes to 0x00 during step 10)

I do not know why my KL26 is almost always reporting that OSC module's crystal is initialised, even at the start of the crt0 assembler unless it is referring to the RTC oscillator on the KL26 (but not on the K10)

The errata for mask 0N40H does not suggest that there is a problem with the RTC or FLL that could be causing this.

Please can anyone tell me:

1) That it definitely is possible to use the RTC reference to derive the main clocks on the KL26

2) What am I doing wrong to select the RTC as the external clock source in step 7

3) Why MGC_S.OSCINIT0 is almost always reporting that the OSC module initialisation period has elapsed on the KL26 when only the RTC has ever been enabled (OSC0_CR always reads 0 from entry into the reset handler onwards)

4) If I am missing something fundamental in the process above

Thank you all for any help you can provide,

Richard

Tags (4)
0 Kudos
1 Solution
770 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

If customer want to use RTC and also use external RTC clock as FLL reference clock, customer need to use 32.768KHz connect to system oscillator0.

More detailed info, please check attached picture.

FLL clock source.jpg

And I also attached an example about how to use 32.768KHz clock as FLL reference clock.

Wish it helps.

View solution in original post

0 Kudos
4 Replies
770 Views
nurichard
Contributor III

For anyone interested:

The K10 and KL26 differ slightly in the working methods of configuring the RTC 32kHz oscillator.

The K10 allows you to use MCG_C7 to select the 32kHz RTC reference as a clock source (i.e. MCG_C2.EREFS0 == 0).

The KL26 doesn't seem to let you do this (despite the documentation for MCG_C7 being no different to the K10); you must configure it as an external crystal by setting MCG_C2.EREFS0 = 1

Richard

0 Kudos
771 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

If customer want to use RTC and also use external RTC clock as FLL reference clock, customer need to use 32.768KHz connect to system oscillator0.

More detailed info, please check attached picture.

FLL clock source.jpg

And I also attached an example about how to use 32.768KHz clock as FLL reference clock.

Wish it helps.

0 Kudos
770 Views
nurichard
Contributor III

Ma Hui,

Thank you for your help!

Richard

0 Kudos
770 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Richard,

I am checking with this issue. It will take some time to gather the answer, Thank you for the patience.

B.R.

Ma Hui

0 Kudos