AnsweredAssumed Answered

K64 KSDK2.1 watchdog fires when disabled

Question asked by manfredschnell on Mar 13, 2017
Latest reply on Mar 24, 2017 by manfredschnell

Hi,

 

we use K64 with KSDK2.1 and IAR Workbench.

I use KSDK2.1 lib funtions.

I use the K64 internal watchdog in my application. After using the watchdog in my application, I want to disable the watchdog again.

--> the disabled watchdog resets the system

 

I wrote a little demo:

- Setup GPIO A5 for debug purpose

- enable watchdog with 2 seconds + IRQ

- wait a short time

- disable watchdog

- wait forever

 

When waiting "forever" the disabled watchdog resets my system after 2 seconds. It looks, like the watchdog is still enabled!

 

Can anyone look at this, and tell me what goes wrong??

Best regards

Manfred

 

// GPIO
#define BOARD_TP37_GPIO                       GPIOA
#define BOARD_TP37_PORT                       PORTA
#define BOARD_TP37_PIN                        5
#define BOARD_TP37_PIN_MASK                   (1L<<BOARD_TP37_PIN)

#define BOARD_WDOG_IRQ_PRIO                   0
#define BOARD_WDOG_IRQ                        WDOG_EWM_IRQn


void Watchdog_IRQHandler(void)  {
  WDOG_ClearStatusFlags(WDOG, kWDOG_TimeoutFlag);
  // signal on A5 (TP37)
  GPIO_SetPinsOutput(GPIOA, BOARD_TP37_PIN_MASK);
  GPIO_ClearPinsOutput(GPIOA, BOARD_TP37_PIN_MASK);
  GPIO_SetPinsOutput(GPIOA, BOARD_TP37_PIN_MASK);
return;
}

void main (void)  {
  uint32_t wait;
  wdog_config_t config;
  const port_pin_config_t pin_port_config = {
    .pullSelect = kPORT_PullDisable,
    .slewRate = kPORT_SlowSlewRate,
    .passiveFilterEnable = kPORT_PassiveFilterDisable,
    .openDrainEnable = kPORT_OpenDrainDisable,
    .driveStrength = kPORT_LowDriveStrength,
    .mux = kPORT_MuxAsGpio,
    .lockRegister = kPORT_UnlockRegister
  };   
  const gpio_pin_config_t pin_gpio_config = { kGPIO_DigitalOutput, 0 };
 
    // prepare GPIO A5 for signaling watchdog IRQ
    CLOCK_EnableClock(kCLOCK_PortA);
    PORT_SetPinConfig(BOARD_TP37_PORT, BOARD_TP37_PIN, &pin_port_config);
    GPIO_PinInit(BOARD_TP37_GPIO, BOARD_TP37_PIN, &pin_gpio_config);

    // reset GPIO A5
    GPIO_ClearPinsOutput(GPIOA, BOARD_TP37_PIN_MASK);

   
    WDOG_GetDefaultConfig(&config); 
   
    // enable watchdog with ~2sec
    config.enableWdog = true;
    config.timeoutValue = 2000/8;
    config.enableInterrupt = true;
    config.prescaler = kWDOG_ClockPrescalerDivide8;
    config.clockSource = kWDOG_LpoClockSource;
    config.workMode.enableDebug = false;
    WDOG_Init(WDOG, &config);
    WDOG_Refresh(WDOG);
   
   
    // set priority and enable Watchdog IRQ
    NVIC_SetPriority(BOARD_WDOG_IRQ, BOARD_WDOG_IRQ_PRIO);
    EnableIRQ(BOARD_WDOG_IRQ);
   
    // global interupts enable
    __enable_interrupt();

    // wait a short time
    wait = 0x10000;
    while(--wait);
   
    // disable the watchdog again.
    WDOG_GetDefaultConfig(&config); 
    config.enableWdog = false;
    WDOG_Init(WDOG, &config);

    // wait, for nothing to happen, because the watchdog is disabled!!!
    for(;;);
}

Outcomes