cancel
Showing results for 
Search instead for 
Did you mean: 

WWDG

lucas23
Associate II
Posted on July 17, 2015 at 16:18

Hi,

I am having problems to run the WWDG in a STM32F405.

I am using the HAL Drivers from Cube MX.

The process is the following:

{

__HAL_RCC_WWDG_CLK_ENABLE();

MX_WWDG_Init();

HAL_WWDG_Start(&hwwdg);

HAL_WWDG_Refresh(&hwwdg,127);

}

Where:

void MX_WWDG_Init(void)

{

  hwwdg.Instance = WWDG;

  hwwdg.Init.Prescaler = WWDG_PRESCALER_1;

  hwwdg.Init.Window = 80;

  hwwdg.Init.Counter = 127;

  HAL_WWDG_Init(&hwwdg);

}

The problem is that the program never reaches the refresh function. It resets the micro in the line showed below:

HAL_StatusTypeDef HAL_WWDG_Start(WWDG_HandleTypeDef *hwwdg)

{

  /* Process Locked */

  __HAL_LOCK(hwwdg); 

  

  /* Change WWDG peripheral state */  

  hwwdg->State = HAL_WWDG_STATE_BUSY;

  /* Enable the peripheral */

  __HAL_WWDG_ENABLE(hwwdg);  // THE MICRO RESETS AFTER CALLING THAT FUNCTION!

  

  /* Change WWDG peripheral state */    

  hwwdg->State = HAL_WWDG_STATE_READY; 

  

  /* Process Unlocked */

  __HAL_UNLOCK(hwwdg);

  

  /* Return function status */

  return HAL_OK;

}

Any clues?

#stm32f1-wwdg-iwdg
5 REPLIES 5
nesrine
Senior
Posted on July 17, 2015 at 18:46

Hi,

I suggest you to start from one example of WWDG from the STM32cubeF4 package

-Syrine-

jpeacock
Associate III
Posted on July 17, 2015 at 19:19

Before you enable the WWDG you have to make sure the timer is inside the window.  Enabling WWDG if the counter is outside the window forces a reset.

I poll WWDG->CR register until it is well above the min threshold, about half way in the window, before turning it on.  I don't use the HAL so no idea if there's any support for making sure the WWDG is in a good place before enabling.

  Jack Peacock

lucas23
Associate II
Posted on July 20, 2015 at 21:14

The Cube example is presented below. The code is basicly the same as mine. Still not working!

/*##-2- Configure the WWDG peripheral ######################################*/

  /* WWDG clock counter = (PCLK1 (42MHz)/4096)/8) = 1281 Hz (~780 us) 

     WWDG Window value = 80 means that the WWDG counter should be refreshed only 

     when the counter is below 80 (and greater than 64) otherwise a reset will 

     be generated. 

     WWDG Counter value = 127, WWDG timeout = ~780 us * 64 = 49.9 ms */

  WwdgHandle.Instance = WWDG;

  WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8;

  WwdgHandle.Init.Window    = 80;

  WwdgHandle.Init.Counter   = 127;

  if(HAL_WWDG_Init(&WwdgHandle) != HAL_OK)

  {

    /* Initialization Error */

    Error_Handler();

  }

  

  /*##-5- Start the WWDG #####################################################*/ 

  if(HAL_WWDG_Start(&WwdgHandle) != HAL_OK)

  {

    Error_Handler();

  }

  

  /* Infinite loop */ 

  while (1)

  {

    /* Toggle LED2 */

    BSP_LED_Toggle(LED2);

    

    /* Insert 40 ms delay */

    HAL_Delay(40);

    

    /* Refresh WWDG: update counter value to 127, the refresh window is: 

    ~780 * (127-80) = 36.6ms < refresh window < ~780 * 64 = 49.9ms */  

    

    if(HAL_WWDG_Refresh(&WwdgHandle, 127) != HAL_OK)

    {

      Error_Handler();

    }

  }

Vprabhu
Associate II
Posted on November 20, 2015 at 11:08

Hi All,

Here is my code for WWDG in STM32F429

void BSP::WATCHDOG_Intialization (void)

 {

HAL_WWDG_DeInit(&Watchdog);

__WWDG_CLK_ENABLE();             //Enable WAtch dog timer clock

 

  __HAL_FREEZE_WWDG_DBGMCU();    //Stop WWDG during Debugging

  Watchdog.Instance=WWDG;

     //WWDG clock counter = (PCLK1 (42MHz)/4096)/8) = 1281 Hz (~780 us) PCLK1 = AHB clock/4=168Mhz/4=42MHz

  Watchdog.Init.Counter = 127;

  Watchdog.Init.Prescaler = WWDG_PRESCALER_8;

  Watchdog.Init.Window = 80;

 HAL_WWDG_Init(&Watchdog);                 //Intialize the Watchdog with configuration

 }

 void BSP::WATCHDOG_start(void)                //Starts the Watchdog timer with initial counter value to downcount

 {

 HAL_WWDG_Start(&Watchdog);

 }

 void BSP::WATCHDOG_Refresh(void)               //Refreshes the Watchdog timer counter for every to prevent the counter being underflowing

 {

  HAL_GPIO_TogglePin(LED1_PORT, LED1_PIN);  //Just for the purpose of knowing it does refreshment

  HAL_WWDG_Refresh(&Watchdog, 127);         //reload the watchdog timer with initial count value

 }

The  BSP::WATCHDOG_Refresh( ) ; function is called in 40 msec loop in some other file.but my problem here is the MCU gets reset even after i do counter refresh in 40 msec loop .the windows threshold is 36.6 msec to 49.9 msec where as i do refresh in 40 msec.but still the problem persists...Could any one help me in this soon?

baycan
Associate
Posted on August 31, 2016 at 16:26

Hi,

Did you find any solution about this issue with using HAL libs ?

Best Regards