cancel
Showing results for 
Search instead for 
Did you mean: 

Windowed watchdog unable to initialize

RSHAR.1
Associate II

I'm trying to initialize windowed watchdog and get to work done in STM32F4 discovery board. I've a couple of doubts,

  1. my system is not getting reset because of timeout
  2. when I'm trying to use debugger to debug it get stuck in an infinite loop.
  3. My printf statement is also not working

Below is my code:

/**

 ******************************************************************************

 * @file  main.c

 * @author Ac6

 * @version V1.0

 * @date  01-December-2013

 * @brief  Default main function.

 ******************************************************************************

*/

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

#include "stm32f4xx.h"

#include "stm32f4_discovery.h"

#include "stm32f4xx_hal.h"

#include "stdio.h"

extern void initialise_monitor_handles();

WWDG_HandleTypeDef hWWDG;

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_WWDG_Init(void);

int main(void)

{

// For printf we need to call this initialize function

initialise_monitor_handles();

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_WWDG_Init();

// If watchdog is running then led will turn on

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)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))

{

while(1);

}

// HAL_WWDG_Refresh(&hWWDG);

HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);

HAL_Delay(1000);

HAL_WWDG_Refresh(&hWWDG);

}

}

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

uint32_t PCLK1_fre = 0;

__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;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

RCC_OscInitStruct.PLL.PLLM = 16;

RCC_OscInitStruct.PLL.PLLN = 336;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;

RCC_OscInitStruct.PLL.PLLQ = 7;

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_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

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);

PCLK1_fre = HAL_RCC_GetPCLK1Freq();

printf("PCLK frequency is: ");

printf(PCLK1_fre);

}

void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct,GPIO_ButtonStruct;

__GPIOD_CLK_ENABLE();

__GPIOA_CLK_ENABLE();

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);

GPIO_InitStruct.Pin = GPIO_PIN_12;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

// used pin 13 for watchdog clocked indication

GPIO_InitStruct.Pin = GPIO_PIN_13;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

// for watchdog initialization confirmation

GPIO_InitStruct.Pin = GPIO_PIN_15;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

GPIO_ButtonStruct.Pin = GPIO_PIN_0;

GPIO_ButtonStruct.Mode = GPIO_MODE_IT_RISING;

GPIO_ButtonStruct.Pull = GPIO_NOPULL;

GPIO_ButtonStruct.Speed = GPIO_SPEED_LOW;

GPIO_ButtonStruct.Pin = GPIO_PIN_0;

HAL_GPIO_Init(GPIOA,&GPIO_ButtonStruct);

}

static void MX_WWDG_Init(void)

{

WWDG_InitTypeDef WWDG_InitStruct;

// HAL_StatusTypeDef catchvariable;

hWWDG.Instance = WWDG;

// hWWDG.Init = WWDG_InitStruct;

WWDG_InitStruct.Prescaler = WWDG_PRESCALER_8;

WWDG_InitStruct.Window = 95;

WWDG_InitStruct.Counter = 127;

WWDG_InitStruct.EWIMode = WWDG_EWI_ENABLE;

if(HAL_WWDG_Init(&hWWDG) == HAL_OK)

{

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);

HAL_Delay(2000);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);

}else

{

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);

}

}

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

When I tried to debug using watchpoints i found, inside SystemClock_Config() function after __PWR_CLK_ENABLE() it redirected to startup_stm32f407xx.s and there is a inifinte loop code where it get trapped.

Below is the exact code:

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

/**

 * @brief This is the code that gets called when the processor receives an 

 *     unexpected interrupt. This simply enters an infinite loop, preserving

 *     the system state for examination by a debugger.

 * @param None   

 * @retval None    

*/

  .section .text.Default_Handler,"ax",%progbits

Default_Handler:

Infinite_Loop:

 b Infinite_Loop

 .size Default_Handler, .-Default_Handler

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

4 REPLIES 4
TDK
Guru
PCLK1_fre = HAL_RCC_GetPCLK1Freq();
printf("PCLK frequency is: ");
printf(PCLK1_fre);

That last printf statement won't work. PCLK1_fre is not a string.

Look at the SCB register to figure out which interrupt is active. VECTACTIVE bits.

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

Thanks for answer. It's going to infinite loop because of that printf statement, I resolve it by including "%d" in printf statement. But my watchdog is not getting reset. Can u suggest me where I'm doing wrong.

TDK
Guru

> But my watchdog is not getting reset.

Looks like your main loop calls HAL_WWDG_Refresh repeatedly. Why would the chip reset?

> GPIO_ButtonStruct.Mode = GPIO_MODE_IT_RISING;

Why not GPIO_MODE_INPUT?

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

I check with input mode also

GPIO_ButtonStruct.Mode = GPIO_MODE_INPUT

But it didn't work.

I used switch so that I can redirect cpu into an infinite loop and it worked but system is not getting reset. I tried with increasing time delay but that also not worked means system is not getting reset. I think there is problem in windowed watchdog initialization. Can u help me out where I'm making mistake?