main.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*!
  2. \file main.c
  3. \brief fwdgt key 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. void irc40k_config(void);
  14. /*!
  15. \brief main function
  16. \param[in] none
  17. \param[out] none
  18. \retval none
  19. */
  20. int main(void)
  21. {
  22. /* system clocks configuration */
  23. irc40k_config();
  24. systick_config();
  25. gd_eval_led_init(LED2);
  26. gd_eval_key_init(KEY_TAMPER,KEY_MODE_EXTI);
  27. delay_1ms(50);
  28. /* enable write access to FWDGT_PSC and FWDGT_RLD registers.
  29. FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
  30. fwdgt_config(625,FWDGT_PSC_DIV64);
  31. fwdgt_enable();
  32. /* check if the system has resumed from FWDGT reset */
  33. if (RESET != rcu_flag_get(RCU_FLAG_FWDGTRST)){
  34. gd_eval_led_on(LED2);
  35. rcu_all_reset_flag_clear();
  36. while(1);
  37. }else{
  38. gd_eval_led_off(LED2);
  39. }
  40. while (1);
  41. }
  42. /*!
  43. \brief IRC40K configuration function
  44. \param[in] none
  45. \param[out] none
  46. \retval none
  47. */
  48. void irc40k_config(void)
  49. {
  50. /* enable IRC40K */
  51. rcu_osci_on(RCU_IRC40K);
  52. /* wait till IRC40K is ready */
  53. rcu_osci_stab_wait(RCU_IRC40K);
  54. }