main.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*!
  2. \file main.c
  3. \brief WWDGT delay feed demo
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #include "gd32f30x.h"
  33. #include "systick.h"
  34. #include "gd32f307c_eval.h"
  35. /*!
  36. \brief main function
  37. \param[in] none
  38. \param[out] none
  39. \retval none
  40. */
  41. int main(void)
  42. {
  43. /* configure systick */
  44. systick_config();
  45. /* configure LED2 and LED3 */
  46. gd_eval_led_init(LED2);
  47. gd_eval_led_init(LED3);
  48. /* turn off LED2 and LED3 */
  49. gd_eval_led_off(LED2);
  50. gd_eval_led_off(LED3);
  51. /* delay */
  52. delay_1ms(150);
  53. /* check if the system has resumed from WWDGT reset */
  54. if(RESET != rcu_flag_get(RCU_FLAG_WWDGTRST)) {
  55. /* WWDGTRST flag set */
  56. gd_eval_led_on(LED2);
  57. /* clear the WWDGTRST flag */
  58. rcu_all_reset_flag_clear();
  59. while(1);
  60. }
  61. /* enable WWDGT clock */
  62. rcu_periph_clock_enable(RCU_WWDGT);
  63. /*
  64. * set WWDGT clock = (PCLK1 (60MHz)/4096)/8 = 1831Hz (~546 us)
  65. * set counter value to 127
  66. * set window value to 80
  67. * refresh window is: ~546 * (127-80)= 25.6ms < refresh window < ~546 * (127-63) =34.9ms.
  68. */
  69. wwdgt_config(127, 80, WWDGT_CFG_PSC_DIV8);
  70. wwdgt_enable();
  71. while(1) {
  72. /* toggle LED3 */
  73. gd_eval_led_toggle(LED3);
  74. /* insert 26 ms delay */
  75. delay_1ms(26);
  76. /* update WWDGT counter */
  77. wwdgt_counter_update(127);
  78. }
  79. }