main.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. \file main.c
  3. \brief led spark with systick, USART print and key example
  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 "main.h"
  13. #include "gd32f3x0_eval.h"
  14. /*!
  15. \brief toggle the led every 500ms
  16. \param[in] none
  17. \param[out] none
  18. \retval none
  19. */
  20. void led_spark(void)
  21. {
  22. static __IO uint32_t timingdelaylocal = 0U;
  23. if(timingdelaylocal){
  24. if(timingdelaylocal < 500U){
  25. gd_eval_led_on(LED1);
  26. }else{
  27. gd_eval_led_off(LED1);
  28. }
  29. timingdelaylocal--;
  30. }else{
  31. timingdelaylocal = 1000U;
  32. }
  33. }
  34. /*!
  35. \brief main function
  36. \param[in] none
  37. \param[out] none
  38. \retval none
  39. */
  40. int main(void)
  41. {
  42. /* configure systick */
  43. systick_config();
  44. /* initilize the LEDs, USART and key */
  45. gd_eval_led_init(LED1);
  46. gd_eval_led_init(LED2);
  47. gd_eval_led_init(LED3);
  48. gd_eval_com_init(EVAL_COM1);
  49. gd_eval_key_init(KEY_WAKEUP, KEY_MODE_GPIO);
  50. /* print out the clock frequency of system, AHB, APB1 and APB2 */
  51. printf("\r\nCK_SYS is %d", rcu_clock_freq_get(CK_SYS));
  52. printf("\r\nCK_AHB is %d", rcu_clock_freq_get(CK_AHB));
  53. printf("\r\nCK_APB1 is %d", rcu_clock_freq_get(CK_APB1));
  54. printf("\r\nCK_APB2 is %d", rcu_clock_freq_get(CK_APB2));
  55. rcu_ckout_config(RCU_CKOUTSRC_CKSYS, RCU_CKOUT_DIV1);
  56. while (1){
  57. if(RESET == gd_eval_key_state_get(KEY_WAKEUP)){
  58. gd_eval_led_on(LED2);
  59. delay_1ms(500);
  60. gd_eval_led_off(LED2);
  61. gd_eval_led_toggle(LED3);
  62. }
  63. }
  64. }
  65. /* retarget the C library printf function to the USART */
  66. int fputc(int ch, FILE *f)
  67. {
  68. usart_data_transmit(EVAL_COM1, (uint8_t)ch);
  69. while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
  70. return ch;
  71. }