MSPM0C1104: WDT

Part Number: MSPM0C1104

Tool/software:

I'm trying to write firmware code for the MSPM0C1104 MCU.

Watchdog timer (WDT) function is a fundamental requirement on my code.

The MSPM0_sdk provides a "wwdt_window_mode_periodic_reset" example code.

I've slightly rewritten this example code, as shown in the attachment.

I've slightly rewritten this sample code, as shown in the attachment.

I've noticed that the main loop only executes before the first IRQ routine.

As the result, the program only executes the IRQ routine and never returns to the main loop.

Could any expert provide some advise?

Many thanks.

wwdt_window_mode_periodic_reset.c

/**
 * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
 * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
 * @cliArgs --device "MSPM0C110X" --part "Default" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.04.00.06"
 * @v2CliArgs --device "MSPM0C1104" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.04.00.06"
 * @versions {"tool":"1.22.0+3893"}
 */

/**
 * Import the modules used in this configuration.
 */
const Board  = scripting.addModule("/ti/driverlib/Board");
const GPIO   = scripting.addModule("/ti/driverlib/GPIO", {}, false);
const GPIO1  = GPIO.addInstance();
const SYSCTL = scripting.addModule("/ti/driverlib/SYSCTL");
const TIMER  = scripting.addModule("/ti/driverlib/TIMER", {}, false);
const TIMER1 = TIMER.addInstance();
const WWDT   = scripting.addModule("/ti/driverlib/WWDT", {}, false);
const WWDT1  = WWDT.addInstance();

/**
 * Write custom configuration values to the imported modules.
 */
Board.configureUnused             = true;
Board.peripheral.$assign          = "DEBUGSS";
Board.peripheral.swclkPin.$assign = "PA20";
Board.peripheral.swdioPin.$assign = "PA19";

GPIO1.$name                          = "GPIO_LEDS";
GPIO1.associatedPins.create(2);
GPIO1.associatedPins[0].$name        = "USER_LED_1";
GPIO1.associatedPins[0].initialValue = "SET";
GPIO1.associatedPins[0].assignedPin  = "22";
GPIO1.associatedPins[1].$name        = "USER_TEST";
GPIO1.associatedPins[1].assignedPin  = "2";
GPIO1.associatedPins[1].initialValue = "SET";

SYSCTL.validateClkStatus = true;
SYSCTL.powerPolicy       = "STANDBY0";
SYSCTL.MFCLKEn           = true;

TIMER1.$name              = "TIMER_0";
TIMER1.timerMode          = "PERIODIC";
TIMER1.interrupts         = ["ZERO"];
TIMER1.timerClkSrc        = "LFCLK";
TIMER1.timerPeriod        = "300 ms";
TIMER1.timerClkPrescale   = 33;
TIMER1.peripheral.$assign = "TIMG14";

WWDT1.$name               = "WWDT0";
WWDT1.sleepMode           = true;
WWDT1.window0ClosedPeriod = "25";
WWDT1.peripheral.$assign  = "WWDT0";

/**
 * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
 * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
 * re-solve from scratch.
 */
GPIO1.associatedPins[0].pin.$suggestSolution = "PA22";
GPIO1.associatedPins[1].pin.$suggestSolution = "PA2";
SYSCTL.peripheral.$suggestSolution           = "SYSCTL";

   

wwdt_window_mode_periodic_reset.scfg

/*
 * Copyright (c) 2023, 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.
 */

#include "ti_msp_dl_config.h"

int main(void)
{
    SYSCFG_DL_init();

    /* Enable TimerG interrupts on device */
    NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);

    /* Enable sleep on exit */
    DL_SYSCTL_enableSleepOnExit();

    /* Set LED to indicate Timer counter enable */
    DL_GPIO_clearPins(
        GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_TEST_PIN);

    /*
     * Configures timer to be halted if CPU is halted. This ensures
     * that timer is always aligned with the WWDT so it is never serviced
     * too late or too early.
     */
    DL_Timer_setCoreHaltBehavior(TIMER_0_INST, DL_TIMER_CORE_HALT_IMMEDIATE);

    /* Start TimerG counter */
    DL_TimerG_startCounter(TIMER_0_INST);

    while (1) {
        //__WFI();
        DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_TEST_PIN);
        delay_cycles(1000);
        DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_TEST_PIN); 
        delay_cycles(1000);     
        //DL_WWDT_restart(WWDT0_INST);   
    }
}

void TIMER_0_INST_IRQHandler(void)
{
    switch (DL_TimerG_getPendingInterrupt(TIMER_0_INST)) {
        case DL_TIMER_IIDX_ZERO:
            /* Restart WWDT timer */
            DL_WWDT_restart(WWDT0_INST);

            /* Toggle LED to indicate WWDT reset */
            DL_GPIO_togglePins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
            break;
        default:
            break;
    }
}