Hi,
I've just tried without debbugger attached but I'm still not able to recover back to FEI mode (IREFST remains '0', also w/o debbuger).
I've added some visual debug using the leds:
- green led -> ON when FEE mode is active;
- yellow led -> ON when FEI mode is active;
- orange led -> toggled in main loop;
- blue led -> ON entering / OFF exiting the LOC ISR handler (MCG_IRQHandler);
I'm disabling the external clock (CLOCK_DeinitOsc0) within the SW2 button ISR (PORTC_IRQHandler);
As soon as I press the button, the green led is turned OFF, the orange led stops toggling and the blue led is turned ON but never OFF (code is stuck in while loop checking the IREFST field).
Here's the code I'm using.
#include "fsl_clock.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
void MCG_IRQHandler (void)
{
GPIO_ClearPinsOutput (GPIOD, (1 << 7));
CLOCK_SetOsc0MonitorMode (kMCG_MonitorNone);
NVIC_DisableIRQ (MCG_IRQn);
GPIO_SetPinsOutput (GPIOD, (1 << 4));
CLOCK_SetFeiMode (kMCG_Dmx32Default, kMCG_DrsLow, NULL);
GPIO_ClearPinsOutput (GPIOD, (1 << 5));
GPIO_SetPinsOutput (GPIOD, (1 << 7));
}
void PORTC_IRQHandler (void)
{
CLOCK_DeinitOsc0 ();
}
int main (void)
{
port_pin_config_t tlButtonConfig;
gpio_pin_config_t tlLedConfig;
osc_config_t tlOscConfig;
uint32_t u32lI;
tlButtonConfig.pullSelect = kPORT_PullUp;
tlButtonConfig.slewRate = kPORT_FastSlewRate;
tlButtonConfig.passiveFilterEnable = kPORT_PassiveFilterDisable;
tlButtonConfig.openDrainEnable = kPORT_OpenDrainEnable;
tlButtonConfig.driveStrength = kPORT_HighDriveStrength;
tlButtonConfig.mux = kPORT_MuxAsGpio;
tlButtonConfig.lockRegister = kPORT_UnlockRegister;
tlLedConfig.pinDirection = kGPIO_DigitalOutput;
tlLedConfig.outputLogic = 1;
tlOscConfig.freq = 8000000;
tlOscConfig.capLoad = 0U;
tlOscConfig.workMode = kOSC_ModeOscLowPower;
tlOscConfig.oscerConfig.enableMode = 0;
CLOCK_EnableClock (kCLOCK_PortC);
CLOCK_EnableClock (kCLOCK_PortD);
PORT_SetPinMux (PORTD, 4, kPORT_MuxAsGpio);
PORT_SetPinMux (PORTD, 5, kPORT_MuxAsGpio);
PORT_SetPinMux (PORTD, 6, kPORT_MuxAsGpio);
PORT_SetPinMux (PORTD, 7, kPORT_MuxAsGpio);
GPIO_PinInit (GPIOD, 4, &tlLedConfig);
GPIO_PinInit (GPIOD, 5, &tlLedConfig);
GPIO_PinInit (GPIOD, 6, &tlLedConfig);
GPIO_PinInit (GPIOD, 7, &tlLedConfig);
PORT_SetPinConfig (PORTC, 7, &tlButtonConfig);
PORT_SetPinInterruptConfig (PORTC, 7, kPORT_InterruptFallingEdge);
NVIC_EnableIRQ (PORTC_IRQn);
NVIC_EnableIRQ (MCG_IRQn);
CLOCK_InitOsc0(&tlOscConfig);
CLOCK_SetXtal0Freq(tlOscConfig.freq);
CLOCK_SetSimSafeDivs();
CLOCK_SetFeeMode (0, kMCG_Dmx32Default, kMCG_DrsLow, NULL);
GPIO_ClearPinsOutput (GPIOD, (1 << 4));
CLOCK_SetOsc0MonitorMode (kMCG_MonitorInt);
while (1)
{
for (u32lI = 0; u32lI < 100000; u32lI++)
{
;
}
GPIO_TogglePinsOutput (GPIOD, (1 << 6));
}
}