This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Oscillator fault interrupt and clock system lock - FR5969, cs_03 demo

Hello experts,

I am trying to understand what the oscillator fault ISR is doing. Code is below, it is exactly the same as the cs_03 demo for FR5969 except I added CSCTL0_H = 0x00 to enable CS locking. In the demo the clock system is left unlocked, and it works just as described: fault is generated, then it is cleared, and the LED blinks.

If I lock the CS registers, however (CSCTL0_H = 0x00) then the ISR is still triggered and the fault bits are cleared but the LED does not blink and the breakpoint in the ISR takes me to an assembly code block, when I step into it. Technically, the ISR instruction:

CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag

should not even work if the CS registers are locked, but it does somehow because if I scope the ACLK with CS locked and ISR enabled, the ACLK output defaults to MODCLK, and then comes back to LFXT when the fault is removed. If I disable ISR then the ACLK does not restore when the fault is removed.

This is of course the desired behavior but I don't understand how the ISR is doing this, and why it does not move on past the CSCTL5 &= ~LFXTOFFG; instruction if the CS is locked?

Thanks!

-P 

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW | WDTHOLD;

// GPIO Setup
P1OUT = 0;
P1DIR = BIT0; // For LED

P2DIR |= BIT0;
P2SEL0 |= BIT0; // Output ACLK
P2SEL1 |= BIT0;

P3DIR |= BIT4;
P3SEL1 |= BIT4; // Output SMCLK

PJSEL0 = BIT4 | BIT5; // For XT1

// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;

// Clock System Setup
CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
CSCTL4 &= ~LFXTOFF;
do
{
CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1&OFIFG); // Test oscillator fault flag

//CSCTL0_H = 0x00; // Lock CS module (use byte mode to upper byte)

// Now that osc is running enable fault interrupt
SFRIE1 |= OFIE;

__bis_SR_register(LPM0_bits); // Wait in LPM0 for fault flag
}

#pragma vector=UNMI_VECTOR
__interrupt void UNMI_ISR(void)
{
do
{
// set a breakpoint on the line below to observe XT1 operating from VLO
// when the breakpoint is hit during a crystal fault
CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
P1OUT |= BIT0;
__delay_cycles(25000); // time for flag to get set again
}while (SFRIFG1&OFIFG); // Test oscillator fault flag

P1OUT &= ~BIT0;
}

  • This 'LFXTOFFG' indicates only the source of the fault and can only be cleared when CS is unlocked (add this in your ISR).

    As-long 'OFIFG' is set the CLK's will be sourced from the default clock, this bit can always be cleared by software and re-enables the user settings.

  • Thanks for the reply Leo.

    Something doesn't add up though. If LFXOFFG never clears, it would mean that the source of fault is still present and OFIFG should immediately get set again, and it should get stuck in the ISR.

    I added a few variables to watch the CSCTL5 & LFXTOFFG and it appears to have been cleared even when CS is locked. The ISR stops at Break Point 1 and temp0 is indeed 1 at that point. Execution is then resumed. The ISR does not want to stop at a Break Point 2, and instruction P1OUT |= BIT0 never gets executed (LED does not blink, and any break point set there never stops the debugger).

    The ISR is exited somehow, bypassing the rest of the code. When the program returns to the main loop the last check in the main loop indicates that LFXTOFFG had been cleared since pausing the program stops it in the main loop and temp2 is indeed zero.

    Code is below.

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  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.
     *
     * *  Neither the name of Texas Instruments Incorporated 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 OWNER 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.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   MSP430FR59xx Demo - Output 32768Hz crystal on XT1 and observe failsafe
    //
    //   Description: Configure ACLK = LFXT1 and enter LPM3.
    //   To observe failsafe behavior short the crystal briefly on the target board.
    //   This will cause an NMI to occur. P1.0 is toggled inside the NMI ISR.
    //   Once the fault flag is cleared XT1 operation continues from 32768Hz crystal
    //   Otherwise ACLK defaults to LFMODCLK (~37.5KHz).
    //   ACLK = LFXT1 = 32kHz, MCLK = SMCLK = 1MHz
    //
    //           MSP430FR59x
    //         ---------------
    //     /|\|            XIN|-
    //      | |               | 32KHz Crystal
    //      --|RST        XOUT|-
    //        |               |
    //        |           P2.0|---> ACLK = 32.768kHz (or 37.5kHz during LFXTOFFG)
    //        |           P3.4|---> SMCLK = MCLK = 1MHz
    //        |           P1.0|---> LED
    //
    //   P. Thanigai
    //   Texas Instruments Inc.
    //   August 2012
    //   Built with Code Composer Studio V5.5
    //******************************************************************************
    #include <msp430.h>
    
    volatile unsigned int temp0 = 0;
    volatile unsigned int temp1 = 0;
    volatile unsigned int temp2 = 0;
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;
    
      // GPIO Setup
      P1OUT = 0;
      P1DIR = BIT0;                             // For LED
    
      P2DIR |= BIT0;
      P2SEL0 |= BIT0;                           // Output ACLK
      P2SEL1 |= BIT0;
    
      P3DIR |= BIT4;
      P3SEL1 |= BIT4;                           // Output SMCLK
    
      PJSEL0 = BIT4 | BIT5;                     // For XT1
    
      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;
    
      // Clock System Setup
      CSCTL0_H = CSKEY >> 8;                    // Unlock CS registers
      CSCTL1 = DCOFSEL_0;                       // Set DCO to 1MHz
      CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
      CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;     // Set all dividers
      CSCTL4 &= ~LFXTOFF;
      do
      {
        CSCTL5 &= ~LFXTOFFG;                    // Clear XT1 fault flag
        SFRIFG1 &= ~OFIFG;
      }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
    
      CSCTL0_H = 0x00;	// Lock CS module (use byte mode to upper byte)
    
      // Now that osc is running enable fault interrupt
      SFRIE1 |= OFIE;
    
    //  __bis_SR_register(LPM0_bits);             // Wait in LPM0 for fault flag
        __enable_interrupt();
    
      while (1) {
    	    temp2 = CSCTL5 & LFXTOFFG;
      }
    }
    
    #pragma vector=UNMI_VECTOR
    __interrupt void UNMI_ISR(void)
    {
      do
      {
        // set a breakpoint on the line below to observe XT1 operating from VLO
        // when the breakpoint is hit during a crystal fault
    	temp0 |= CSCTL5 & LFXTOFFG;
        CSCTL5 &= ~LFXTOFFG; // Break point 1
    	temp1 |= CSCTL5 & LFXTOFFG;
        SFRIFG1 &= ~OFIFG; // Break point 2
        P1OUT |= BIT0;
        __delay_cycles(25000);                  // time for flag to get set again
      } while (SFRIFG1 & OFIFG);                   // Test oscillator fault flag
    
      P1OUT &= ~BIT0;
    }
    

**Attention** This is a public forum