AnsweredAssumed Answered

Loss Of Clock: FEE to FEI within ISR (OSC0 monitor IRQ)

Question asked by alessandro morniroli on Nov 14, 2016
Latest reply on Nov 25, 2016 by alessandro morniroli

Hi,

 

I'm working on a project that requires to recover from FEE  to FEI mode in case of Loss Of Clock (LOC).

 

I'd like to perform this action within the ISR of MCG handler.

 

In a previous project, I had an external 32kHz used as external reference clock for the RTC oscillator. I have never been able to recover from FEE to FEI in case of LOC (you can read this topic for more informations K22 - can't change from FEE to FEI in case of Loss Of Clock).

 

From what I've understood, this should be a legal operation (Recovering from loss of external reference clock (LOCS0 = 1)

 

I'm using a TWR-K21D50M as proto board, w/ KSDK 2.0.

 

This is the code I'm using.

 

/*
* Copyright (c) 2013 - 2016, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
*   of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
*   list of conditions and the following disclaimer in the documentation and/or
*   other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
*   contributors may be used to endorse or promote products derived from this
*   software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


/**
* This is template for main module created by New Kinetis SDK 2.x Project Wizard. Enjoy!
**/


#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"

#include "fsl_clock.h"

void MCG_IRQHandler (void)
{
    CLOCK_SetOsc0MonitorMode (kMCG_MonitorNone);

    NVIC_DisableIRQ (MCG_IRQn);

    CLOCK_SetFeiMode (kMCG_Dmx32Default, kMCG_DrsLow, NULL);
}

/*!
* @brief Application entry point.
*/

int main(void) {
  /* Init board hardware. */
  BOARD_InitPins();
  BOARD_BootClockRUN();
  BOARD_InitDebugConsole();

  /* Add your code here */
  osc_config_t oscConfig;

  oscConfig.freq = 8000000;
  oscConfig.capLoad = 0U;
  oscConfig.workMode = kOSC_ModeOscLowPower;
  oscConfig.oscerConfig.enableMode = kOSC_ErClkEnable;

  CLOCK_InitOsc0(&oscConfig);

  CLOCK_SetXtal0Freq(8000000);

  /* Set clock divider to safe value to switch mode */
  CLOCK_SetSimSafeDivs();

  CLOCK_SetFeeMode (0, kMCG_Dmx32Default, kMCG_DrsLow, NULL);

  CLOCK_SetOsc0MonitorMode (kMCG_MonitorInt);

  NVIC_EnableIRQ (MCG_IRQn);

  CLOCK_DeinitOsc0 ();

  for(;;) { /* Infinite loop to avoid leaving the main function */
    __asm("NOP"); /* something to use as a breakpoint stop while looping */
  }
}

 

 

 

I've got stuck within the function CLOCK_SetFeiMode (kMCG_Dmx32Default, kMCG_DrsLow, NULL): IREFST field of register MCG_S remains set to '0'.

 

 

Am I missing something?

 

I've attacched the Kinetis Design Studio I'm using for testing.

Best regards,

 

Alessandro

Original Attachment has been moved to: loc.zip

Outcomes