IWDG on Nucleo F401RE

For Independant Watchdog IWDG See http://www.st.com/web/en/resource/technical/document/reference_manual/DM00096844.pdf#415

#include "stm32f4xx_hal_iwdg.h"

  wd.Instance = IWDG;
  wd.Init.Prescaler = IWDG_PRESCALER_256; //About 32s
  wd.Init.Reload = 0x0FFF;
  HAL_IWDG_Init(&wd);
  HAL_IWDG_Start(&wd);
  
  //Call to reset watchdog
  HAL_IWDG_Refresh(&wd);//NVIC_SystemReset();

To Check reset reason

#include "stm32f4xx_hal_rcc.h"

   printf("\r\n\r\nSystemCoreClock = %d Hz   Reset reason: ", SystemCoreClock);
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST)) printf("Independant Watchdog \r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)) printf("Window Watchdog \r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST)) printf("Low Power Reset \r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)) printf("Software Reset \r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST)) printf("Power On/Down Reset \r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) printf("Reset pin\r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST)) printf("Brownout\r\n");
   if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY)) printf("Low speed internal clock ready\r\n");
   __HAL_RCC_CLEAR_RESET_FLAGS();
  printf("\r\n"); 


Please log in to post comments.