#include "iwdg.h" #include "stm32f2xx_iwdg.h" void IWDG_Configuration(uint16_t ms) { /* Enable write access to IWDG_PR and IWDG_RLR registers */ IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Prescaler_4 Min timeout:0.125ms Max timeout :512 //Prescaler_8 Min timeout:0.25ms Max timeout :1024 //Prescaler_16 Min timeout:0.5ms Max timeout :2048 //Prescaler_32 Min timeout:1ms Max timeout :4096 //Prescaler_64 Min timeout:2ms Max timeout :8192 //Prescaler_128 Min timeout:4ms Max timeout :16384 //Prescaler_256 Min timeout:8ms Max timeout :32768 IWDG_SetPrescaler(IWDG_Prescaler_64); /* Set counter reload value to obtain 1000ms IWDG TimeOut. Counter Reload Value = 1000ms/IWDG counter clock period = 1000ms / (LSI/64) = 1s / (32 KHz /64) = 2 */ IWDG_SetReload(ms/2); // ms /* Enable IWDG (LSI oscillator will be enabled by hardware) */ IWDG_Enable(); /* Reload IWDG counter */ IWDG_ReloadCounter(); } void IWDG_feed() { /* Reload IWDG counter */ IWDG_ReloadCounter(); }