32.5.6 Switching Main Clock Between the RC Oscillator and the Crystal Oscillator

When switching the source of the Main clock between the RC oscillator and the crystal oscillator, both oscillators must be enabled. After completion of the switch, the unused oscillator can be disabled.

If switching to the crystal oscillator, a check must be carried out to ensure that the oscillator is present and that its frequency is valid. Follow the sequence below:

  1. Enable the crystal oscillator by setting CKGR_MOR.MOSCXTEN. Configure the CKGR_MOR. MOSCXTST field with the crystal oscillator start-up time as defined in the section “Electrical Characteristics”.
  2. Wait for PMC_SR.MOSCXTS flag to rise, indicating the end of a start-up period of the crystal oscillator.
  3. Select the crystal oscillator as the source clock of the frequency meter by setting CKGR_MCFR.CCSS
  4. Initiate a frequency measurement by setting CKGR_MCFR.RCMEAS.
  5. Read CKGR_MCFR.MAINFRDY until its value equals 1.
  6. Read CKGR_MCFR.MAINF and compute the value of the crystal frequency.

    • If the MAINF value is valid, the Main clock can be switched to the crystal oscillator.