main.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. \file main.c
  3. \brief wwdgt delay feed demo
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #include "gd32f3x0.h"
  10. #include "systick.h"
  11. #include <stdio.h>
  12. #include "gd32f3x0_eval.h"
  13. /*!
  14. \brief main function
  15. \param[in] none
  16. \param[out] none
  17. \retval none
  18. */
  19. int main(void)
  20. {
  21. gd_eval_led_init(LED1);
  22. gd_eval_led_init(LED2);
  23. gd_eval_led_on(LED1);
  24. gd_eval_led_on(LED2);
  25. systick_config();
  26. /* check if the system has resumed from WWDGT reset */
  27. if (RESET != rcu_flag_get(RCU_FLAG_WWDGTRST)){
  28. /* WWDGTRST flag set */
  29. gd_eval_led_on(LED1);
  30. rcu_all_reset_flag_clear();
  31. while(1);
  32. }else{
  33. delay_1ms(150);
  34. gd_eval_led_off(LED1);
  35. }
  36. /* enable WWDGT clock */
  37. rcu_periph_clock_enable(RCU_WWDGT);
  38. /* enable WWDGT and set counter value to 127, WWDGT timeout = ~607 us * 64 = 38.8 ms.
  39. in this case the refresh window is: ~607 * (127-80)= 28.5ms < refresh window < ~607 * 64 =38.8ms.
  40. set window value to 80; WWDGT counter should be refreshed only when the counter
  41. is below 80 (and greater than 64) otherwise a reset will be generated.
  42. WWDGT clock counter = (PCLK1 (54MHz)/4096)/8 = 1647Hz (~607 us) */
  43. wwdgt_config(127,80,WWDGT_CFG_PSC_DIV8);
  44. wwdgt_enable();
  45. while (1){
  46. gd_eval_led_toggle(LED2);
  47. /* insert 30 ms delay */
  48. delay_1ms(30);
  49. /* update WWDGT counter */
  50. wwdgt_counter_update(127);
  51. }
  52. }