iwdg.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include "iwdg.h"
  2. #include "stm32f2xx_iwdg.h"
  3. void IWDG_Configuration(uint16_t ms)
  4. {
  5. /* Enable write access to IWDG_PR and IWDG_RLR registers */
  6. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  7. //Prescaler_4 Min timeout:0.125ms Max timeout :512
  8. //Prescaler_8 Min timeout:0.25ms Max timeout :1024
  9. //Prescaler_16 Min timeout:0.5ms Max timeout :2048
  10. //Prescaler_32 Min timeout:1ms Max timeout :4096
  11. //Prescaler_64 Min timeout:2ms Max timeout :8192
  12. //Prescaler_128 Min timeout:4ms Max timeout :16384
  13. //Prescaler_256 Min timeout:8ms Max timeout :32768
  14. IWDG_SetPrescaler(IWDG_Prescaler_64);
  15. /* Set counter reload value to obtain 1000ms IWDG TimeOut.
  16. Counter Reload Value = 1000ms/IWDG counter clock period
  17. = 1000ms / (LSI/64)
  18. = 1s / (32 KHz /64)
  19. = 2
  20. */
  21. IWDG_SetReload(ms/2); // ms
  22. /* Enable IWDG (LSI oscillator will be enabled by hardware) */
  23. IWDG_Enable();
  24. /* Reload IWDG counter */
  25. IWDG_ReloadCounter();
  26. }
  27. void IWDG_feed()
  28. {
  29. /* Reload IWDG counter */
  30. IWDG_ReloadCounter();
  31. }