cancel
Showing results for 
Search instead for 
Did you mean: 

While initializing window watchdog it redirects to reset handler

RSHAR.1
Associate II

I'm trying to test the window watchdog timer but when I'm calling HAL_WWDG_Init(), it redirects to reset handler and whole system restarts. Below is my code, I'm showing here only important lines.

/******************************************/

WWDG_HandleTypeDef  hWWDG;                  // In the global
 
int main()
{
        HAL_Init();
	SystemClock_Config();
	MX_GPIO_Init();
	MX_WWDG_Init();
 
	HAL_Delay(20);
	HAL_WWDG_Refresh(&hWWDG);
 
	if( __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) == SET)
	 {
	      HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
	      __HAL_RCC_CLEAR_RESET_FLAGS();
	 }
	else
	{
	    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
	}
 
	while (1)
	{
//	   HAL_WWDG_Refresh(&hWWDG);
	   HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
	   HAL_Delay(42);
	   HAL_WWDG_Refresh(&hWWDG);
 
	}
 
}
 
}

Below is the code for clock initialization

void SystemClock_Config(void)
{
	RCC_OscInitTypeDef	RCC_OscInitStruct;
	RCC_ClkInitTypeDef	RCC_ClkInitStruct;
 
	__PWR_CLK_ENABLE();
 
	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
 
	RCC_OscInitStruct.OscillatorType		=	RCC_OSCILLATORTYPE_HSI;
	RCC_OscInitStruct.HSIState				=	RCC_HSI_ON;
	RCC_OscInitStruct.HSICalibrationValue	=	16;
	RCC_OscInitStruct.PLL.PLLState			=	RCC_PLL_ON;
 
	HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
	RCC_ClkInitStruct.ClockType				=	RCC_CLOCKTYPE_HCLK | 
 RCC_CLOCKTYPE_PCLK1 |RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_SYSCLK;
 
	RCC_ClkInitStruct.SYSCLKSource			=	RCC_SYSCLKSOURCE_HSI;
	RCC_ClkInitStruct.AHBCLKDivider			=	RCC_SYSCLK_DIV1;		
	RCC_ClkInitStruct.APB1CLKDivider		=	RCC_HCLK_DIV1;			
	RCC_ClkInitStruct.APB2CLKDivider		=	RCC_HCLK_DIV1;			
 
	HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
 
	HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
	HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
	HAL_NVIC_SetPriority(SysTick_IRQn,0,0);
 
}

window watchdog initialization code

static void MX_WWDG_Init(void)
{
	__HAL_RCC_WWDG_CLK_ENABLE();
 
	WWDG_InitTypeDef	WWDG_InitStruct;
 
	hWWDG.Instance			=	WWDG;
	WWDG_InitStruct.Prescaler	=	WWDG_PRESCALER_8;
	WWDG_InitStruct.Window		=	80;
	WWDG_InitStruct.Counter		=	127;					
	WWDG_InitStruct.EWIMode		=	WWDG_EWI_ENABLE;
 
	 __HAL_WWDG_ENABLE(&hWWDG);
	if(HAL_WWDG_Init(&hWWDG) == HAL_OK)
	{
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
	}else
	{
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
	}
}

can someone suggest what is the cause for getting reset. Don't look at values for counter and window they are randomly taken.

4 REPLIES 4
Jack Peacock_2
Senior III

If you enable the WWDG while the counter is outside the window you'll force a watchdog reset. You can't use random numbers for window and counter. The counter must be larger than the lower window at 0x40 and less than the upper window value. Either an early or late counter load causes a reset.

Jack Peacock

RSHAR.1
Associate II

I removed HAL_WWDG_ENABLE() macro but still it causing reset while calling HAL_WWDG_Init(&hWWDG) function. once initialization done I can think about the delays. counter and window are taken from example there it used to work but in this board I've not tested that's why I called it as random. But I think the main problem is initialization. Can you be more specific what else should I do?

TDK
Guru

Always include your chip part number in your post.

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru
	hWWDG.Instance			=	WWDG;
	WWDG_InitStruct.Prescaler	=	WWDG_PRESCALER_8;
	WWDG_InitStruct.Window		=	80;
	WWDG_InitStruct.Counter		=	127;					
	WWDG_InitStruct.EWIMode		=	WWDG_EWI_ENABLE;
 
	 __HAL_WWDG_ENABLE(&hWWDG);
	if(HAL_WWDG_Init(&hWWDG) == HAL_OK)

the top line assigns to hWWDG. The other lines assign to WWDG_InitStruct.

Then you enable it without initializing first.

Then you call initialization on hWWDG, which doesn't use any of the values you've assigned to WWDG_InitStruct.

So, multiple issues.

If you feel a post has answered your question, please click "Accept as Solution".