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.

TMS320F28075: Missing Clock Detection no work

Part Number: TMS320F28075
Other Parts Discussed in Thread: C2000WARE

Hi,experts

      I'm using C2000ware example project to test MCD.But it doesnot work.

      My mcu is TMS320F28075PZPS(100 pin),the example project is from C2000ware,see the picture below,is the route of the project.

     I tested flash ECC logic ,it was ok.

     I use a GPIO set to 0 to switch on a led if MCD test passed,but till now ,the MCD function is still not work.

     Please ,help.

Regards!

yang jingping

  • Yang,

    You seem to using really old version of C2000Ware code. This code seems to be deprecated in subsequent revisions of C2000Ware and I don't have access to this code.

    Also, we don't have an example for MCD in F2807x device. But, we have similar example in F2838x which can be adapted to F2807x.

    Path:<C2000Ware>\driverlib\f2838x\examples\c28x\sysctl\

    Project: sysctl_ex1_missing_clock_detection

    Regards,

    Manoj

  • One more example code which you can refer is for F28004x

    Path: <C2000Ware>\driverlib\f28004x\examples\sysctl

    Project: sysctl_ex1_missing_clock_detection

  • Hi,expert,

         According to your suggestion,I have tested both project,but the problem is still there,CLKFAIL NMI not triggered.

         I monitored the register, the OSCOFF was 1 , but the program was suspended on  "while(nmiISRFlag != true", 

         

         nmiISRFlag is set in nmi_isr,so it seems there is no NMI triggered.

         

         

         

         I tried to force a CLKFAIL,the interrput code was ok. See the picture below.

         

         the problem now is ,how to trigger the CLKFAIL NMI .

    Regards!

    yang jingping

  • Let me test this on silicon and get back with you in next couple of business days.

  • Yang,

    I tried below missing clock code (slightly modified from F28004x) and was able to get missing clock detect trigger NMI.

    //#############################################################################
    //
    // FILE:   sysctl_ex1_missing_clock_detection.c
    //
    // TITLE:  Missing clock detection
    //
    //! \addtogroup driver_example_list
    //! <h1> Missing clock detection (MCD) </h1>
    //!
    //! This example demonstrates the missing clock detection functionality and
    //! the way to handle it.
    //! Once the MCD is simulated by disconnecting the OSCCLK to the MCD module
    //! an NMI would be generated. This NMI determines that an MCD was generated
    //! due to a clock failure which is handled in the ISR.
    //!
    //! Before an MCD the clock frequency would be as per device initialization (100Mhz).
    //! Post MCD the frequency would move to 10Mhz or INTOSC1.
    //!
    //! The example also shows how we can lock the PLL after missing clock,
    //! detection, by first explicitly switching the clock source to INTOSC1,
    //!  resetting the missing clock detect circuit and then re-locking the PLL.
    //! Post a re-lock the clock frequency would be 100Mhz but using the INTOSC1 as
    //! clock source.
    //!
    //! \b External \b Connections \n
    //!  - None.
    //!
    //! \b Watch \b Variables \n
    //!  - \b fail - Indicates that a missing clock was either not detected or was
    //!       not handled correctly.
    //!  - \b mcd_clkfail_isr - Indicates that the missing clock failure caused an
    //!       NMI to be triggered and called an the ISR to handle it.
    //!  - \b mcd_detect - Indicates that a missing clock was detected.
    //!  - \b result - Status of a successful handling of missing clock detection
    //!
    //
    //#############################################################################
    // $Copyright:
    // Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com/
    //
    // 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.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Globals
    //
    bool mcd_detect;
    uint16_t nmistatus = 0;
    uint32_t mcd_clkfail_isr = 0;
    
    //
    // Defines
    //
    #define PASS 0
    #define FAIL 1
    
    uint32_t result = FAIL;
    
    
    //
    // Define to pass to SysCtl_setClock(). Will configure the clock as follows:
    // PLLSYSCLK = 10MHz (INT_OSC1) * 40 (IMULT) * 1 (FMULT) / 2 (PLLCLK_BY_2)
    //
    #define DEVICE_SETCLOCK_INTOSC      (SYSCTL_OSCSRC_OSC1 | SYSCTL_IMULT(40) |  \
                                         SYSCTL_FMULT_NONE | SYSCTL_SYSDIV(2) |   \
                                         SYSCTL_PLL_ENABLE)
    
    
    
    //
    // Function Prototypes
    //
    __interrupt void nmi_isr(void);
    
    //
    // Main
    //
    void main(void)
    {
        uint32_t fail = 0;
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Re-map NMI signal to call the ISR function in this
        // example
        //
        SysCtl_clearAllNMIFlags();
        Interrupt_register(INT_NMI, &nmi_isr);
    
        //
        // Enabling the NMI global interrupt
        //
        SysCtl_enableNMIGlobalInterrupt();
    
        Interrupt_enable(INT_NMI);
    
        //
        // Enable Global Interrupt (INTM) and Real Time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Check the PLL System clock before the Missing clock detection
        // is simulated. It should be same as that set by Device_init().
        //
        if(SysCtl_getClock(DEVICE_OSCSRC_FREQ) != DEVICE_SYSCLK_FREQ)
            fail++;
    
        //
        // Enable the missing clock detection (MCD) Logic as a precaution.
        // The is continuously active, unless the MCD was disabled previously
        //
        SysCtl_enableMCD();
    
        //
        // Simulate a missing clock detection
        //
        SysCtl_disconnectMCDClockSource();
    
        //
        // Wait till the NMI is fired on clock failure
        //
        while(mcd_clkfail_isr != 0x1U);
    
        //
        // A missing clock was detected
        //
        if(mcd_detect != true)
            fail++;
    
        //
        // Check if the NMI triggered was due to a clock failure
        //
        if((nmistatus & SYSCTL_NMI_CLOCKFAIL) != SYSCTL_NMI_CLOCKFAIL)
            fail++;
    
        //
        // Check the PLL System clock after the Missing clock detection
        // is simulated. It should be equal to INTOSC1(10Mhz).
        //
        if(SysCtl_getClock(DEVICE_OSCSRC_FREQ) != SYSCTL_DEFAULT_OSC_FREQ)
            fail++;
    
        //
        // To lock the PLL after missing clock detection, we first explicitly
        // switch the clock source to INTOSC1, reset the missing clock detect
        // circuit and then re-lock the PLL.
        //
        // Configure oscillator source to INTOSC1
        //
        SysCtl_selectOscSource(SYSCTL_OSCSRC_OSC1);
    
        //
        // Re-connect missing clock detection clock source to stop simulating clock
        // failure
        //
        SysCtl_connectMCDClockSource();
    
        //
        // Reset the missing clock detection logic after clock failure
        //
        SysCtl_resetMCD();
    
        //
        // Set up PLL control and clock dividers using INTOSC1 as clock source
        //
        SysCtl_setClock(DEVICE_SETCLOCK_INTOSC);
    
        //
        // Check the PLL System clock after the Missing clock detection
        // is cleared and handled using INTOSC1 as clock source.
        //
        if(SysCtl_getClock(SYSCTL_DEFAULT_OSC_FREQ) != DEVICE_SYSCLK_FREQ)
            fail++;
    
        //
        // Status of a successful handling of missing clock detection
        //
        if (fail)
        {
            result = FAIL;
        }
        else
        {
            result = PASS;
    
        }
        while(1);
    }
    
    //
    // NMI ISR - The interrupt service routine called when the NMI
    //           is generated on clock failure detection
    //
    __interrupt void nmi_isr(void)
    {
        mcd_clkfail_isr = 0x1U;
        mcd_detect = SysCtl_isMCDClockFailureDetected();
        nmistatus = SysCtl_getNMIFlagStatus();
        SysCtl_clearAllNMIFlags();
    }
    
    
    //
    // End of File
    //
    

    - Check whether NMIFLG.CLOCKFAIL is set to 1 ?

    - Check whether NMIFLG.NMIINT is set to 1 ?

    - Check whether NMICFG.NMIE is set to 1?

    Regards,

    Manoj

  • Hi,expert

         

         

        

    //#############################################################################
    //
    // FILE:  sta_main.c
    //
    // TITLE: Self Test Application Main source
    //
    //#############################################################################
    // $TI Release: F2807x Diagnostic Library v1.00.02.00 $
    // $Release Date: Mon Dec 18 17:00:32 CST 2017 $
    // $Copyright:
    // Copyright (C) 2016-2017 Texas Instruments Incorporated - http://www.ti.com/
    //
    // 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.
    // $
    //#############################################################################
    
    //
    // Included files for device configuration
    //
    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include "driverlib.h"
    #include "device.h"
    #include "F2807x_device.h"
    #include "F021_F2837xD_C28x.h"
    
    //
    // Included files for test-infrastructure.
    //
    #include "sta_timer.h"
    #include "sta_tests.h"
    #include "sta_comm.h"
    
    //
    // Globals
    //
    int16_t enableErrorInject;
    int16_t enableReset;
    volatile bool nmiISRFlag = false;
    uint16_t nmiStatus = 0U;
    bool mcdDetect = false;
    uint32_t result = 1;
    uint32_t fail = 0U;
    
    //
    // Prototypes
    //
    void STA_Main_configXCLKOut(void);
    Fapi_StatusType STA_Main_initFlashAPI(void);
    
    
    
    #ifdef _FLASH
    // These are defined by the linker (see device linker command file)
    extern uint16_t RamfuncsLoadStart;
    extern uint16_t RamfuncsLoadSize;
    extern uint16_t RamfuncsRunStart;
    
    extern uint16_t HwbistLoadStart;
    extern uint16_t HwbistLoadSize;
    extern uint16_t HwbistRunStart;
    #endif
    
    //
    // Function Prototypes
    //
    __interrupt void nmi_isr(void);
    
    //
    // Main
    //
    void main(void)
    {
    
    #ifdef _FLASH
        memcpy(&HwbistRunStart, &HwbistLoadStart, (size_t)&HwbistLoadSize);
    #endif
    
        unsigned char *msg;
        uint16_t testIndex = 0;
        Fapi_StatusType statusFlashAPI =  Fapi_Status_Success;
    
        enableErrorInject = 0;
        uint16_t nmiWatchdogPeriod = 0x1000;
        //
        // Configure PLL, disable WD, enable peripheral clocks.
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pull-ups.
        //
        Device_initGPIO();
    
        //***********************************
        //added by yang for debug
        GPIO_setPinConfig(GPIO_43_GPIO43);
        GPIO_setDirectionMode(43,GPIO_DIR_MODE_OUT);
        GPIO_setPadConfig(43,GPIO_PIN_TYPE_STD);
        GPIO_writePin(43,1);
        //************************************
        //
        // Put watchdog in interrupt mode.
        //
        SysCtl_setWatchdogMode(SYSCTL_WD_MODE_INTERRUPT);
    
     //   statusFlashAPI = STA_Main_initFlashAPI();
    
     //   if(statusFlashAPI != Fapi_Status_Success)
     //   {
     //       ESTOP0;
     //   }
    
        //
        // Disable global interrupts.
        //
      //  DINT;
    
        //
        // Initialize interrupt controller and vector table.
        //
        Interrupt_initModule();
        Interrupt_initVectorTable();
    
        SysCtl_clearAllNMIFlags();
        Interrupt_register(INT_NMI, &nmi_isr);
        SysCtl_setNMIWatchdogPeriod(nmiWatchdogPeriod);
        //
        // Enabling the NMI global interrupt (typically already enabled by boot ROM
        // or GEL file).
        //
        EALLOW;
        HWREGH(NMI_BASE + NMI_O_CFG) |= NMI_CFG_NMIE;
        EDIS;
        Interrupt_enable(INT_NMI);
        EINT;
        ERTM;
    
        if(SysCtl_getClock(DEVICE_OSCSRC_FREQ) != DEVICE_SYSCLK_FREQ)
        {
           fail++;
        }
        SysCtl_enableMCD();
        SysCtl_disconnectMCDClockSource();
    
        fail=3;
        while(nmiISRFlag != true)
        {
            fail++;
        }
        fail=5;
        // A missing clock was detected.
        //
        if(mcdDetect != true)
        {
            fail++;
        }
    
        // Check if the NMI triggered was due to a clock failure.
        //
        if((nmiStatus & SYSCTL_NMI_CLOCKFAIL) != SYSCTL_NMI_CLOCKFAIL)
        {
            fail++;
        }
    
        // Check the PLL System clock after the Missing clock detection
        // is simulated. It should be equal to INTOSC1(10Mhz).
        //
        if(SysCtl_getClock(DEVICE_OSCSRC_FREQ) != SYSCTL_DEFAULT_OSC_FREQ)
        {
            fail++;
        }
        // To lock the PLL after missing clock detection, we first explicitly
            // switch the clock source to INTOSC1, reset the missing clock detect
            // circuit, and then re-lock the PLL.
            //
            // Configure oscillator source to INTOSC1.
            //
        SysCtl_selectOscSource(SYSCTL_OSCSRC_OSC1);
        SysCtl_connectMCDClockSource();
        // Reset the missing clock detection logic after clock failure.
        //
        SysCtl_resetMCD();
        // Set up PLL control and clock dividers using the original clock source.
        //
        SysCtl_setClock(DEVICE_SETCLOCK_CFG);
        // Check the system clock after the missing clock detection is cleared
        // and handled using INTOSC1 as clock source.
        //
        if(SysCtl_getClock(DEVICE_OSCSRC_FREQ) != DEVICE_SYSCLK_FREQ)
        {
           fail++;
        }
        // Status of a successful handling of missing clock detection.
        //
        if(fail != 0U)
        {
           result = 1;    //fail
        //   GPIO_writePin(43,0);
        }
        else
        {
           result = 0;   //pass
        //   GPIO_writePin(43,0);
        }
        while(1);
        //
        // Debug
        //
       // STA_Main_configXCLKOut();
    
        //
        // Configure SCI A as the main communication port
        //
      //  STA_Comm_configSCIA();
    
        //
        // Configure Timer 0 as the main time-out timer
        //
      //  STA_Timer_config(4000U);
    
    //#if STA_UTIL_PROFILE
    //    STA_Util_configProfiler(CPUTIMER1_BASE);
    //#endif
    
        //
        // Enable Global Interrupt (INTM) and real time interrupt (DBGM)
        //
    //    EINT;
    //    ERTM;
    
        //
        // Send starting message.
        //
     //   msg = "\r\n\n\nBegin Test\0";
    //    STA_Comm_transmitData(msg);
    
     /*   for(;;)
        {
    
            if(STA_Timer_isTimedOut())
            {
    
                if(enableErrorInject)
                {
                    STA_Tests_injectErrorEnable();
                }
                else
                {
                    STA_Tests_injectErrorDisable();
                }
    
                if(enableReset)
                {
                    STA_Tests_enableReset();
                }
                else
                {
                    STA_Tests_disableReset();
                }
    
                STA_Comm_transmitData(
                         STA_Tests_testDevice(STA_Tests_testArray[testIndex++]));
    
                if(testIndex >= STA_TESTS_NUMBERS)
                {
                    testIndex = 0U;
                }
                STA_Timer_restart();
            }
        }  */
    }
    
    //
    // STA_Main_configXCLKOut(void)
    //
    void STA_Main_configXCLKOut(void)
    {
        // Configure GPIO 73 as SYSCLK out
        GPIO_setPadConfig(73,GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_73_XCLKOUT);
        // Clock source is SYSCLK
        SysCtl_selectClockOutSource(SYSCTL_CLOCKOUT_SYSCLK);
        EALLOW;
        // XCLOCK out = clock source /8
        HWREG(CLKCFG_BASE + SYSCTL_O_XCLKOUTDIVSEL) = 3U;
        EDIS;
    }
    
    //
    // STA_Main_initFlashAPI(void)
    //
    #pragma CODE_SECTION(STA_Main_initFlashAPI, ".TI.ramfunc");
    Fapi_StatusType STA_Main_initFlashAPI(void)
    {
        Fapi_StatusType returnStatus;
        //
        // Disable ECC when initializing the Flash API
        //
        Flash_disableECC(FLASH0ECC_BASE);
    
        EALLOW;
    
        //
        // This function is required to initialize the Flash API based on System
        // frequency before any other Flash API operation can be performed
        //
        returnStatus = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS,
                                          DEVICE_SYSCLK_FREQ / 1000000U);
    
        EDIS;
    
        return(returnStatus);
    }
    
    //
    // nmiISR -  The interrupt service routine called when the NMI
    //           is generated on clock failure detection.
    //
    __interrupt void nmi_isr(void)
    {
        nmiISRFlag = true;
        mcdDetect = SysCtl_isMCDClockFailureDetected();
        nmiStatus = SysCtl_getNMIFlagStatus();
        SysCtl_clearAllNMIFlags();
        GPIO_writePin(43,0);
    }
    
    //
    // End of File
    //

        this is my source code.

        Could you provide me your tested project by mail.

    Regards!

    yang jingping

  • What is your input clock? INTOSC1 / INTOSC2, X1 (or) XTAL?

    I don't see even missing clock condition created. MCDCR.MCLKSTS is not set to 1.

    Can you try another device? I wondering whether you have a defective device.

  • It is XTAL,20MHz.

    I don't see even missing clock condition created. MCDCR.MCLKSTS is not set to 1.

    Yes,it looks missing clock condition not created.

  • As mentioned before, I was able to generate missing clock condition is code attached in my previous post and it was able to generate NMI interrupt on CLOCKFAIL condition.

    I would encourage you to try this experiment on different device. It is likely that you might be working on defective device (may be ESD failure)

  • Hi,expert,

       I have got the NMI,see the picture below,

       

      But you can see,it entered the default NMI_ISR,not the interrupt function I defined.                    Interrupt_register(INT_NMI,STL_MCD_missingClockNMIISR);       

      

    //###########################################################################
    //
    // FILE:  stl_mcd.c
    //
    // TITLE: Diagnostic Library Missing Clock Detect software module source
    //
    //###########################################################################
    // $TI Release: F2807x Diagnostic Library v1.00.02.00 $
    // $Release Date: Mon Dec 18 17:00:32 CST 2017 $
    // $Copyright:
    // Copyright (C) 2016-2017 Texas Instruments Incorporated - http://www.ti.com/
    //
    // 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.
    // $
    //###########################################################################
    
    //
    // Includes
    //
    #include "stl_mcd.h"
    #include "stl_util.h"
    #include "sysctl.h"
    #include "interrupt.h"
    
    //
    // Defines
    //
    #define STL_MCD_PIE_NMI_OFFSET      0x0024U
    
    //
    // Globals
    //
    volatile static bool STL_MCD_missingClockDetectedFlag = false;
    
    //*****************************************************************************
    //
    // STL_MCD_missingClockNMIISR(void)
    // DID_07_16
    //*****************************************************************************
    __interrupt void STL_MCD_missingClockNMIISR(void)
    {
        uint16_t watchdogCount1;
        uint16_t watchdogCount2;
    
        //
        // Get the MCD status.
        // DID_07_17
        //
        STL_MCD_missingClockDetectedFlag = SysCtl_isMCDClockFailureDetected();
    
        //
        // DID_07_19
        //
    
        //
        // Read WDCNT.
        //
        watchdogCount1 = SysCtl_getNMIWatchdogCounter();
    
        NOP;
        NOP;
    
        //
        // Read WDCNT.
        //
        watchdogCount2 = SysCtl_getNMIWatchdogCounter();
    
        //
        // Ensure the WDCNT has decreased.
        // DID_07_20
        //
        if(watchdogCount1 >= watchdogCount2)
        {
            //
            // Set the global error flag.
            //
            STL_Util_setErrorFlag(STL_UTIL_NMIWD);
        }
    
        //
        // Clear the NMI CLOCKFAIL flag and NMIINT flag if it is
        // the only flag left.
        // DID_07_18
        //
        SysCtl_clearNMIStatus(SYSCTL_NMI_CLOCKFAIL);
    }
    
    //*****************************************************************************
    //
    // STL_MCD_detect(const uint16_t nmiWatchdogPeriod, const uint16_t delay)
    // DID_07_03, DID_07_04
    //*****************************************************************************
    uint16_t STL_MCD_detect(const uint16_t nmiWatchdogPeriod,
                            const uint16_t delay)
    {
        /*LDRA_INSPECTED 8 D MR:R.2.2 Comment_8D*/
        uint16_t testStatus;
        uint32_t previousNMIVector;
    
        //
        // Reset the global missing clock detected flag.
        //
        STL_MCD_missingClockDetectedFlag = false;
    
        //
        // Clear any pending NMI flags.
        // DID_07_05
        //
        SysCtl_clearAllNMIFlags();
    
        //
        // Set the input NMI watchdog period.
        // DID_07_07
        //
        SysCtl_setNMIWatchdogPeriod(nmiWatchdogPeriod);
    
        //
        // DID_07_06, DID_07_08
        //
    
        //
        // Save previous NMI.
        //
        previousNMIVector = HWREG(PIEVECTTABLE_BASE + STL_MCD_PIE_NMI_OFFSET);
    
        //
        // Register the test NMI ISR.
        //
        Interrupt_register(INT_NMI, STL_MCD_missingClockNMIISR);
    
        //
        // Enable missing clock detection logic.
        // DID_07_21
        //
        SysCtl_enableMCD();
    
        //
        // Connect OSCCLK to missing clock detection logic.
        //
        SysCtl_connectMCDClockSource();
    
        //
        // Disable PLL. Ensure the PLL is out of our clock tree.
        //
        EALLOW;
        HWREGH(CLKCFG_BASE + SYSCTL_O_SYSPLLCTL1) &= ~(SYSCTL_SYSPLLCTL1_PLLCLKEN |
                                                       SYSCTL_SYSPLLCTL1_PLLEN);
        EDIS;
    
        //
        // Force a missing clock.
        // DID_07_09, DID_07_10
        //
    //    EALLOW;
    //    HWREGH(CLKCFG_BASE + SYSCTL_O_CLKSRCCTL1) |= SYSCTL_CLKSRCCTL1_INTOSC2OFF |
    //                                                 SYSCTL_CLKSRCCTL1_XTALOFF;
    //    EDIS;
    
        SysCtl_disconnectMCDClockSource();   //yang
        //
        // Need a short delay here (depending on SYSCLK) if disconnecting the clock
        // source does not generate an immediate interrupt.
        // DID_07_11
        //
        SysCtl_delay(delay);
        //
        // DID_07_12
        //
        if(STL_MCD_missingClockDetectedFlag && !((bool)SysCtl_getNMIFlagStatus()))
        {
            //
            // DID_07_14
            //
            testStatus = STL_MCD_PASS;
        }
        else
        {
            //
            // DID_07_13
            //
    
            //
            // Set the global error flag.
            //
            STL_Util_setErrorFlag(STL_UTIL_MCD);
    
            testStatus = STL_MCD_FAIL;
        }
    
        //
        // Restore and reset the clock.
        // DID_07_15
        //
        EALLOW;
        HWREGH(CLKCFG_BASE + SYSCTL_O_CLKSRCCTL1) &=
                       ~(SYSCTL_CLKSRCCTL1_INTOSC2OFF | SYSCTL_CLKSRCCTL1_XTALOFF);
        EDIS;
    
        //
        // Reset missing clock detection mechanism.
        //
        SysCtl_resetMCD();
    
        //
        // Restore NMI.
        // DID_07_06
        //
        Interrupt_register(INT_NMI, (void (*)(void))previousNMIVector);
    
        return(testStatus);
    }
    
    //
    // End of File
    //

      from the source code ,I defined the NMI interrupt     __interrupt void STL_MCD_missingClockNMIISR(void)

      and registered  the interrupt      Interrupt_register(INT_NMI, STL_MCD_missingClockNMIISR);

       Is there somewhere to configure the NMI ?

  • You need to pass the address of your NMI subroutine as shown below

     Interrupt_register(INT_NMI, &STL_MCD_missingClockNMIISR);

  • Hi,expert,

          Problem solved. Thanks for your support.

    Regards,

    yang jingping

  • Closing this thread