Ver código fonte

init commmit.

Anson Zhao 6 anos atrás
commit
caf1cb2360
100 arquivos alterados com 5887 adições e 0 exclusões
  1. 132 0
      Examples/ADC/ADC_analog_watchdog/gd32f3x0_it.c
  2. 41 0
      Examples/ADC/ADC_analog_watchdog/gd32f3x0_it.h
  3. 42 0
      Examples/ADC/ADC_analog_watchdog/gd32f3x0_libopt.h
  4. 137 0
      Examples/ADC/ADC_analog_watchdog/main.c
  5. 18 0
      Examples/ADC/ADC_analog_watchdog/main.h
  6. 24 0
      Examples/ADC/ADC_analog_watchdog/readme.txt
  7. 58 0
      Examples/ADC/ADC_analog_watchdog/systick.c
  8. 24 0
      Examples/ADC/ADC_analog_watchdog/systick.h
  9. 114 0
      Examples/ADC/Oversample_shift/gd32f3x0_it.c
  10. 37 0
      Examples/ADC/Oversample_shift/gd32f3x0_it.h
  11. 42 0
      Examples/ADC/Oversample_shift/gd32f3x0_libopt.h
  12. 143 0
      Examples/ADC/Oversample_shift/main.c
  13. 18 0
      Examples/ADC/Oversample_shift/main.h
  14. 19 0
      Examples/ADC/Oversample_shift/readme.txt
  15. 58 0
      Examples/ADC/Oversample_shift/systick.c
  16. 24 0
      Examples/ADC/Oversample_shift/systick.h
  17. 114 0
      Examples/ADC/Regular_channel_discontinuous_mode/gd32f3x0_it.c
  18. 37 0
      Examples/ADC/Regular_channel_discontinuous_mode/gd32f3x0_it.h
  19. 42 0
      Examples/ADC/Regular_channel_discontinuous_mode/gd32f3x0_libopt.h
  20. 155 0
      Examples/ADC/Regular_channel_discontinuous_mode/main.c
  21. 18 0
      Examples/ADC/Regular_channel_discontinuous_mode/main.h
  22. 17 0
      Examples/ADC/Regular_channel_discontinuous_mode/readme.txt
  23. 58 0
      Examples/ADC/Regular_channel_discontinuous_mode/systick.c
  24. 24 0
      Examples/ADC/Regular_channel_discontinuous_mode/systick.h
  25. 114 0
      Examples/ADC/Regular_channel_with_DMA/gd32f3x0_it.c
  26. 37 0
      Examples/ADC/Regular_channel_with_DMA/gd32f3x0_it.h
  27. 42 0
      Examples/ADC/Regular_channel_with_DMA/gd32f3x0_libopt.h
  28. 146 0
      Examples/ADC/Regular_channel_with_DMA/main.c
  29. 18 0
      Examples/ADC/Regular_channel_with_DMA/main.h
  30. 21 0
      Examples/ADC/Regular_channel_with_DMA/readme.txt
  31. 58 0
      Examples/ADC/Regular_channel_with_DMA/systick.c
  32. 24 0
      Examples/ADC/Regular_channel_with_DMA/systick.h
  33. 114 0
      Examples/ADC/Resolution/gd32f3x0_it.c
  34. 37 0
      Examples/ADC/Resolution/gd32f3x0_it.h
  35. 42 0
      Examples/ADC/Resolution/gd32f3x0_libopt.h
  36. 142 0
      Examples/ADC/Resolution/main.c
  37. 18 0
      Examples/ADC/Resolution/main.h
  38. 18 0
      Examples/ADC/Resolution/readme.txt
  39. 58 0
      Examples/ADC/Resolution/systick.c
  40. 24 0
      Examples/ADC/Resolution/systick.h
  41. 114 0
      Examples/ADC/TIMER_trigger_inserted_channel/gd32f3x0_it.c
  42. 37 0
      Examples/ADC/TIMER_trigger_inserted_channel/gd32f3x0_it.h
  43. 42 0
      Examples/ADC/TIMER_trigger_inserted_channel/gd32f3x0_libopt.h
  44. 142 0
      Examples/ADC/TIMER_trigger_inserted_channel/main.c
  45. 18 0
      Examples/ADC/TIMER_trigger_inserted_channel/main.h
  46. 15 0
      Examples/ADC/TIMER_trigger_inserted_channel/readme.txt
  47. 58 0
      Examples/ADC/TIMER_trigger_inserted_channel/systick.c
  48. 24 0
      Examples/ADC/TIMER_trigger_inserted_channel/systick.h
  49. 114 0
      Examples/ADC/Temperature_Vref/gd32f3x0_it.c
  50. 37 0
      Examples/ADC/Temperature_Vref/gd32f3x0_it.h
  51. 42 0
      Examples/ADC/Temperature_Vref/gd32f3x0_libopt.h
  52. 115 0
      Examples/ADC/Temperature_Vref/main.c
  53. 18 0
      Examples/ADC/Temperature_Vref/main.h
  54. 20 0
      Examples/ADC/Temperature_Vref/readme.txt
  55. 58 0
      Examples/ADC/Temperature_Vref/systick.c
  56. 24 0
      Examples/ADC/Temperature_Vref/systick.h
  57. 219 0
      Examples/CEC/Intercommunication/gd32f3x0_it.c
  58. 42 0
      Examples/CEC/Intercommunication/gd32f3x0_it.h
  59. 42 0
      Examples/CEC/Intercommunication/gd32f3x0_libopt.h
  60. 116 0
      Examples/CEC/Intercommunication/main.c
  61. 17 0
      Examples/CEC/Intercommunication/readme.txt
  62. 58 0
      Examples/CEC/Intercommunication/systick.c
  63. 24 0
      Examples/CEC/Intercommunication/systick.h
  64. 124 0
      Examples/CMP/Interrupt/gd32f3x0_it.c
  65. 42 0
      Examples/CMP/Interrupt/gd32f3x0_it.h
  66. 42 0
      Examples/CMP/Interrupt/gd32f3x0_libopt.h
  67. 64 0
      Examples/CMP/Interrupt/main.c
  68. 18 0
      Examples/CMP/Interrupt/readme.txt
  69. 42 0
      Examples/CMP/PWM_signal_control/gd32f3x0_libopt.h
  70. 121 0
      Examples/CMP/PWM_signal_control/main.c
  71. 23 0
      Examples/CMP/PWM_signal_control/readme.txt
  72. 42 0
      Examples/CMP/Port_output/gd32f3x0_libopt.h
  73. 83 0
      Examples/CMP/Port_output/main.c
  74. 16 0
      Examples/CMP/Port_output/readme.txt
  75. 42 0
      Examples/CMP/Switch/gd32f3x0_libopt.h
  76. 103 0
      Examples/CMP/Switch/main.c
  77. 17 0
      Examples/CMP/Switch/readme.txt
  78. 125 0
      Examples/CMP/Timer1_CH3IC/gd32f3x0_it.c
  79. 41 0
      Examples/CMP/Timer1_CH3IC/gd32f3x0_it.h
  80. 42 0
      Examples/CMP/Timer1_CH3IC/gd32f3x0_libopt.h
  81. 109 0
      Examples/CMP/Timer1_CH3IC/main.c
  82. 18 0
      Examples/CMP/Timer1_CH3IC/readme.txt
  83. 128 0
      Examples/CMP/Window/gd32f3x0_it.c
  84. 43 0
      Examples/CMP/Window/gd32f3x0_it.h
  85. 42 0
      Examples/CMP/Window/gd32f3x0_libopt.h
  86. 181 0
      Examples/CMP/Window/main.c
  87. 24 0
      Examples/CMP/Window/main.h
  88. 24 0
      Examples/CMP/Window/readme.txt
  89. 110 0
      Examples/CRC/Calculate_demo/gd32f3x0_it.c
  90. 38 0
      Examples/CRC/Calculate_demo/gd32f3x0_it.h
  91. 42 0
      Examples/CRC/Calculate_demo/gd32f3x0_libopt.h
  92. 77 0
      Examples/CRC/Calculate_demo/main.c
  93. 16 0
      Examples/CRC/Calculate_demo/readme.txt
  94. 58 0
      Examples/CRC/Calculate_demo/systick.c
  95. 24 0
      Examples/CRC/Calculate_demo/systick.h
  96. 42 0
      Examples/CTC/CTC_gpio/gd32f3x0_libopt.h
  97. 77 0
      Examples/CTC/CTC_gpio/main.c
  98. 18 0
      Examples/CTC/CTC_gpio/readme.txt
  99. 42 0
      Examples/CTC/CTC_lxtal/gd32f3x0_libopt.h
  100. 82 0
      Examples/CTC/CTC_lxtal/main.c

+ 132 - 0
Examples/ADC/ADC_analog_watchdog/gd32f3x0_it.c

@@ -0,0 +1,132 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+extern uint8_t data;
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}
+
+/*!
+    \brief      this function handles ADC exception 
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void ADC_CMP_IRQHandler(void)
+{
+    /* clear the ADC interrupt or status flag */
+    adc_interrupt_flag_clear(ADC_INT_WDE);
+
+    /* turn on LED2 */
+    gd_eval_led_on(LED2);
+    data = 1;
+}

+ 41 - 0
Examples/ADC/ADC_analog_watchdog/gd32f3x0_it.h

@@ -0,0 +1,41 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+/* this function handles ADC exception */
+void ADC_CMP_IRQHandler(void);
+
+#endif /* GD32F3X0_IT_H */
+
+

+ 42 - 0
Examples/ADC/ADC_analog_watchdog/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 137 - 0
Examples/ADC/ADC_analog_watchdog/main.c

@@ -0,0 +1,137 @@
+/*!
+    \file  main.c
+    \brief ADC analog watchdog demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+#define BOARD_ADC_CHANNEL          ADC_CHANNEL_11
+#define ADC_GPIO_PORT              GPIOC
+#define ADC_GPIO_PIN               GPIO_PIN_1
+
+uint16_t adc_value;
+uint8_t data;
+
+void rcu_config(void);
+void gpio_config(void);
+void nvic_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+
+int main(void)
+{
+    /* system clocks configuration */
+    rcu_config();
+    /* systick configuration */
+    systick_config();  
+    /* GPIO configuration */
+    gpio_config();
+    /* NVIC configuration */
+    nvic_config();
+    /* ADC configuration */
+    adc_config();
+
+    while(1){
+        if(1 == data){
+            data = 0;
+            delay_1ms(3000);
+            gd_eval_led_off(LED2);
+        }
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOC clock */
+    rcu_periph_clock_enable(RCU_GPIOC);
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the GPIO peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* configure led GPIO */
+    gd_eval_led_init(LED2);
+    /* config the GPIO as analog mode */
+    gpio_mode_set(ADC_GPIO_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC_GPIO_PIN);
+}
+
+/*!
+    \brief      configure interrupt priority
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void nvic_config(void)
+{
+    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
+    nvic_irq_enable(ADC_CMP_IRQn, 0, 0);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC contineous function enable */
+    adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE); 
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_REGULAR_CHANNEL, 1);
+ 
+    /* ADC regular channel config */
+    adc_regular_channel_config(0, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
+    adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
+    
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+
+    /* ADC analog watchdog threshold config */
+    adc_watchdog_threshold_config(0x0400, 0x0A00);
+    /* ADC analog watchdog single channel config */
+    adc_watchdog_single_channel_enable(BOARD_ADC_CHANNEL);
+    /* ADC interrupt config */
+    adc_interrupt_enable(ADC_INT_WDE);
+
+    /* ADC software trigger enable */
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+}

+ 18 - 0
Examples/ADC/ADC_analog_watchdog/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 24 - 0
Examples/ADC/ADC_analog_watchdog/readme.txt

@@ -0,0 +1,24 @@
+/*!
+    \file  readme.txt
+    \brief description of the ADC analog watchdog demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to
+use the ADC analog watchdog to guard continuously an ADC channel.
+The ADC is configured in continuous mode, PC1 is chosen as analog
+input pin.
+
+  Change the VR1 on the GD32350R-EVAL board, when the channel11 
+converted value is over the programmed analog watchdog high threshold
+(value 0x0A00) or below the analog watchdog low threshold(value 0x0400),
+an WDE interrupt will occur, and LED2 will turn on. When the channel11
+converted value is in safe range(among 0x0400 and 0x0A00), the LED2 will
+be off.
+
+  The analog input pin should be configured to AIN mode.

+ 58 - 0
Examples/ADC/ADC_analog_watchdog/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/ADC_analog_watchdog/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 114 - 0
Examples/ADC/Oversample_shift/gd32f3x0_it.c

@@ -0,0 +1,114 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}

+ 37 - 0
Examples/ADC/Oversample_shift/gd32f3x0_it.h

@@ -0,0 +1,37 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/ADC/Oversample_shift/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 143 - 0
Examples/ADC/Oversample_shift/main.c

@@ -0,0 +1,143 @@
+/*!
+    \file  main.c
+    \brief ADC oversample and shift 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+#define BOARD_ADC_CHANNEL          ADC_CHANNEL_11
+#define ADC_GPIO_PORT              GPIOC
+#define ADC_GPIO_PIN               GPIO_PIN_1
+
+uint16_t adc_value = 0;
+
+void rcu_config(void);
+void gpio_config(void);
+void nvic_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+
+int main(void)
+{
+    /* system clocks configuration */
+    rcu_config();
+    /* systick configuration */
+    systick_config();  
+    /* GPIO configuration */
+    gpio_config();
+    /* NVIC configuration */
+    nvic_config();
+    /* ADC configuration */
+    adc_config();
+    /* configures COM port */
+    gd_eval_com_init(EVAL_COM1); 
+  
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+
+    while(1){
+        adc_flag_clear(ADC_FLAG_EOC);
+        while(SET != adc_flag_get(ADC_FLAG_EOC)){
+        }
+        
+        adc_value = ADC_RDATA;
+        printf("16 times sample, 4 bits shift: 0x%x\r\n", adc_value);
+        delay_1ms(1000);
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOC clock */
+    rcu_periph_clock_enable(RCU_GPIOC);
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the GPIO peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* config the GPIO as analog mode */
+    gpio_mode_set(ADC_GPIO_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC_GPIO_PIN);
+}
+
+/*!
+    \brief      configure interrupt priority
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void nvic_config(void)
+{
+    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
+    nvic_irq_enable(ADC_CMP_IRQn, 0, 0);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC contineous function enable */
+    adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);  
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE); 
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_REGULAR_CHANNEL, 1);
+ 
+    /* ADC regular channel config */
+    adc_regular_channel_config(0, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
+    adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
+
+    /* 16 times sample, 4 bits shift */
+    adc_oversample_mode_config(ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_4B, ADC_OVERSAMPLING_RATIO_MUL16);
+    adc_oversample_mode_enable();
+    
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+}
+
+/* retarget the C library printf function to the USART */
+int fputc(int ch, FILE *f)
+{
+    usart_data_transmit(EVAL_COM1, (uint8_t)ch);
+    while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
+
+    return ch;
+}

+ 18 - 0
Examples/ADC/Oversample_shift/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 19 - 0
Examples/ADC/Oversample_shift/readme.txt

@@ -0,0 +1,19 @@
+/*!
+    \file  readme.txt
+    \brief description of the ADC oversample shift example
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to use
+the function of oversample and shift. In this demo, 16 times ratio of
+oversample and 4 bits shift are configured. PC1(channel11) is chosen as
+analog input pin. The ADC conversion begins by software, the converted 
+data is printed by USART.
+
+  The analog input pin should configured to analog mode.
+  Jump the JP13 to USART.

+ 58 - 0
Examples/ADC/Oversample_shift/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/Oversample_shift/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 114 - 0
Examples/ADC/Regular_channel_discontinuous_mode/gd32f3x0_it.c

@@ -0,0 +1,114 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}

+ 37 - 0
Examples/ADC/Regular_channel_discontinuous_mode/gd32f3x0_it.h

@@ -0,0 +1,37 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/ADC/Regular_channel_discontinuous_mode/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 155 - 0
Examples/ADC/Regular_channel_discontinuous_mode/main.c

@@ -0,0 +1,155 @@
+/*!
+    \file  main.c
+    \brief ADC discontinuous mode for regular channel 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+uint16_t adc_value[16];
+
+void rcu_config(void);
+void gpio_config(void);
+void dma_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+
+int main(void)
+{
+    /* system clocks configuration */
+    rcu_config();
+    /* systick configuration */
+    systick_config();  
+    /* GPIO configuration */
+    gpio_config();
+    /* DMA configuration */
+    dma_config();
+    /* ADC configuration */
+    adc_config();
+  
+    while(1){
+        /* delay 1s */
+        delay_1ms(1000);
+        /* ADC software trigger enable */
+        adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOC clock */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* enable DMA clock */
+    rcu_periph_clock_enable(RCU_DMA);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the GPIO peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* config the GPIO as analog mode */ 
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
+}
+
+/*!
+    \brief      configure the DMA peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void dma_config(void)
+{
+    /* ADC_DMA_channel configuration */
+    dma_parameter_struct dma_data_parameter;
+    
+    /* ADC DMA_channel configuration */
+    dma_deinit(DMA_CH0);
+    
+    /* initialize DMA single data mode */
+    dma_data_parameter.periph_addr  = (uint32_t)(&ADC_RDATA);
+    dma_data_parameter.periph_inc   = DMA_PERIPH_INCREASE_DISABLE;
+    dma_data_parameter.memory_addr  = (uint32_t)(&adc_value);
+    dma_data_parameter.memory_inc   = DMA_MEMORY_INCREASE_ENABLE;
+    dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
+    dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;  
+    dma_data_parameter.direction    = DMA_PERIPHERAL_TO_MEMORY;
+    dma_data_parameter.number       = 16;
+    dma_data_parameter.priority     = DMA_PRIORITY_HIGH;
+    dma_init(DMA_CH0, dma_data_parameter);
+
+    dma_circulation_enable(DMA_CH0);
+  
+    /* enable DMA channel */
+    dma_channel_enable(DMA_CH0);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE); 
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_REGULAR_CHANNEL, 8);
+
+    /* ADC regular channel config */
+    adc_regular_channel_config(0, ADC_CHANNEL_0, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(1, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(2, ADC_CHANNEL_2, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(3, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(4, ADC_CHANNEL_4, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(5, ADC_CHANNEL_5, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(6, ADC_CHANNEL_6, ADC_SAMPLETIME_55POINT5);
+    adc_regular_channel_config(7, ADC_CHANNEL_7, ADC_SAMPLETIME_55POINT5);
+
+    adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
+
+    /* ADC discontinuous mode */
+    adc_discontinuous_mode_config(ADC_REGULAR_CHANNEL, 3);
+
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+
+    /* ADC DMA function enable */
+    adc_dma_mode_enable();
+}

+ 18 - 0
Examples/ADC/Regular_channel_discontinuous_mode/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 17 - 0
Examples/ADC/Regular_channel_discontinuous_mode/readme.txt

@@ -0,0 +1,17 @@
+/*!
+    \file  readme.txt
+    \brief description of the ADC discontinuous mode example
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to use the
+ADC discontinuous mode. The ADC is configured in discontinuous mode, group
+length is 8, conversion length is 3, using software trigger. Every trigger 
+converts 3 channels.
+
+  You can use the watch window to see the conversion result.

+ 58 - 0
Examples/ADC/Regular_channel_discontinuous_mode/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/Regular_channel_discontinuous_mode/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 114 - 0
Examples/ADC/Regular_channel_with_DMA/gd32f3x0_it.c

@@ -0,0 +1,114 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}

+ 37 - 0
Examples/ADC/Regular_channel_with_DMA/gd32f3x0_it.h

@@ -0,0 +1,37 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/ADC/Regular_channel_with_DMA/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 146 - 0
Examples/ADC/Regular_channel_with_DMA/main.c

@@ -0,0 +1,146 @@
+/*!
+    \file  main.c
+    \brief ADC regular channel with DMA 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+#define BOARD_ADC_CHANNEL          ADC_CHANNEL_11
+#define ADC_GPIO_PORT              GPIOC
+#define ADC_GPIO_PIN               GPIO_PIN_1
+
+uint16_t adc_value;
+
+void rcu_config(void);
+void gpio_config(void);
+void dma_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+
+int main(void)
+{
+    /* system clocks configuration */
+    rcu_config();
+    /* systick configuration */
+    systick_config();  
+    /* GPIO configuration */
+    gpio_config();
+    /* DMA configuration */
+    dma_config();
+    /* ADC configuration */
+    adc_config();
+  
+    while(1){
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOC clock */
+    rcu_periph_clock_enable(RCU_GPIOC);
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* enable DMA clock */
+    rcu_periph_clock_enable(RCU_DMA);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the GPIO peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* config the GPIO as analog mode */
+    gpio_mode_set(ADC_GPIO_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC_GPIO_PIN);
+}
+
+/*!
+    \brief      configure the DMA peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void dma_config(void)
+{
+    /* ADC_DMA_channel configuration */
+    dma_parameter_struct dma_data_parameter;
+    
+    /* ADC DMA_channel configuration */
+    dma_deinit(DMA_CH0);
+    
+    /* initialize DMA single data mode */
+    dma_data_parameter.periph_addr  = (uint32_t)(&ADC_RDATA);
+    dma_data_parameter.periph_inc   = DMA_PERIPH_INCREASE_DISABLE;
+    dma_data_parameter.memory_addr  = (uint32_t)(&adc_value);
+    dma_data_parameter.memory_inc   = DMA_MEMORY_INCREASE_DISABLE;
+    dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
+    dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;  
+    dma_data_parameter.direction    = DMA_PERIPHERAL_TO_MEMORY;
+    dma_data_parameter.number       = 1;
+    dma_data_parameter.priority     = DMA_PRIORITY_HIGH;
+    dma_init(DMA_CH0, dma_data_parameter);
+
+    dma_circulation_enable(DMA_CH0);
+  
+    /* enable DMA channel */
+    dma_channel_enable(DMA_CH0);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC contineous function enable */
+    adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE); 
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_REGULAR_CHANNEL, 1);
+ 
+    /* ADC regular channel config */
+    adc_regular_channel_config(0, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
+    adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
+
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+
+    /* ADC DMA function enable */
+    adc_dma_mode_enable();
+    /* ADC software trigger enable */
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+}

+ 18 - 0
Examples/ADC/Regular_channel_with_DMA/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 21 - 0
Examples/ADC/Regular_channel_with_DMA/readme.txt

@@ -0,0 +1,21 @@
+/*!
+    \file  readme.txt
+    \brief description of the ADC regular channel with DMA
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to use the ADC 
+to convert analog signal to digital data through DMA. The ADC is configured
+in continuous mode, PC1 is chosen as analog input pin.
+  
+  As the ADC convertion begins by software, the converted data from ADC_RDATA 
+register to SRAM begins continuously. Users can change the VR1 on the GD32350R-EVAL
+board, measure TP1 pad board, and check if its value matches the converted 
+data through the watch window.
+
+  The analog input pin should configured to AIN mode.

+ 58 - 0
Examples/ADC/Regular_channel_with_DMA/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/Regular_channel_with_DMA/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 114 - 0
Examples/ADC/Resolution/gd32f3x0_it.c

@@ -0,0 +1,114 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}

+ 37 - 0
Examples/ADC/Resolution/gd32f3x0_it.h

@@ -0,0 +1,37 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/ADC/Resolution/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 142 - 0
Examples/ADC/Resolution/main.c

@@ -0,0 +1,142 @@
+/*!
+    \file  main.c
+    \brief ADC resolution demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+#define BOARD_ADC_CHANNEL          ADC_CHANNEL_11
+#define ADC_GPIO_PORT              GPIOC
+#define ADC_GPIO_PIN               GPIO_PIN_1
+
+uint16_t adc_value;
+
+void rcu_config(void);
+void gpio_config(void);
+void nvic_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* system clocks configuration */
+    rcu_config();
+    /* systick configuration */
+    systick_config();  
+    /* GPIO configuration */
+    gpio_config();
+    /* NVIC configuration */
+    nvic_config();
+    /* configures COM port */
+    gd_eval_com_init(EVAL_COM1); 
+    
+    /* ADC configuration */
+    adc_config();
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+  
+    while(1){
+        adc_flag_clear(ADC_FLAG_EOC);
+        while(SET != adc_flag_get(ADC_FLAG_EOC)){
+        }
+
+        adc_value = ADC_RDATA;
+        printf("6B: 0x%x\r\n", adc_value);
+        delay_1ms(500);
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOC clock */
+    rcu_periph_clock_enable(RCU_GPIOC);
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the GPIO peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* config the GPIO as analog mode */
+    gpio_mode_set(ADC_GPIO_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC_GPIO_PIN);
+}
+
+/*!
+    \brief      configure interrupt priority
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void nvic_config(void)
+{
+    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
+    nvic_irq_enable(ADC_CMP_IRQn, 0, 0);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC contineous function enable */
+    adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE); 
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_REGULAR_CHANNEL, 1);
+ 
+    /* ADC regular channel config */
+    adc_regular_channel_config(0, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
+    adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
+
+    /* ADC resolusion 6B */
+    printf("\r\nresolusion 6B:\r\n");
+    adc_resolution_config(ADC_RESOLUTION_6B);
+    
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+}
+
+/* retarget the C library printf function to the USART */
+int fputc(int ch, FILE *f)
+{
+    usart_data_transmit(EVAL_COM1, (uint8_t)ch);
+    while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
+
+    return ch;
+}

+ 18 - 0
Examples/ADC/Resolution/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 18 - 0
Examples/ADC/Resolution/readme.txt

@@ -0,0 +1,18 @@
+/*!
+    \file  readme.txt
+    \brief description of the ADC resolution demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to use 
+the function of programmble resolusion. In this demo, 6B resolusion 
+is configured. PC1(channel11) is chosen as analog input pin. The ADC 
+conversion begins by software, the converted data is printed by USART.
+
+  The analog input pin should configured to analog mode.
+  Jump the JP13 to USART.

+ 58 - 0
Examples/ADC/Resolution/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/Resolution/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 114 - 0
Examples/ADC/TIMER_trigger_inserted_channel/gd32f3x0_it.c

@@ -0,0 +1,114 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}

+ 37 - 0
Examples/ADC/TIMER_trigger_inserted_channel/gd32f3x0_it.h

@@ -0,0 +1,37 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/ADC/TIMER_trigger_inserted_channel/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 142 - 0
Examples/ADC/TIMER_trigger_inserted_channel/main.c

@@ -0,0 +1,142 @@
+/*!
+    \file  main.c
+    \brief TIMER trigger injected channel of ADC demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+void rcu_config(void);
+void gpio_config(void);
+void timer_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+
+int main(void)
+{
+    /* system clocks configuration */
+    rcu_config();
+    /* systick configuration */
+    systick_config();  
+    /* GPIO configuration */
+    gpio_config();
+    /* TIMER configuration */
+    timer_config();
+    /* ADC configuration */
+    adc_config();
+
+    /* enable TIMER1 */
+    timer_enable(TIMER1);
+  
+    while(1){ 
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOC clock */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* enable timer1 clock */
+    rcu_periph_clock_enable(RCU_TIMER1);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the GPIO peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* config the GPIO as analog mode */
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
+}
+
+
+/*!
+    \brief      configure the TIMER peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void timer_config(void)
+{
+    timer_oc_parameter_struct timer_ocintpara;
+    timer_parameter_struct timer_initpara;
+
+    /* TIMER1 configuration */
+    timer_initpara.prescaler         = 8399;
+    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
+    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
+    timer_initpara.period            = 9999;
+    timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
+    timer_initpara.repetitioncounter = 0;
+    timer_init(TIMER1,&timer_initpara);
+
+    /* CH0 configuration in PWM mode1 */
+    timer_ocintpara.ocpolarity  = TIMER_OC_POLARITY_HIGH;
+    timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
+    timer_channel_output_config(TIMER1, TIMER_CH_0, &timer_ocintpara);
+
+    timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_0, 3999);
+    timer_channel_output_mode_config(TIMER1, TIMER_CH_0, TIMER_OC_MODE_PWM1);
+    timer_channel_output_shadow_config(TIMER1, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC continous function enable */
+    adc_special_function_config(ADC_SCAN_MODE, ENABLE);
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_INSERTED_CHANNEL, ADC_EXTTRIG_INSERTED_T1_CH0); 
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_INSERTED_CHANNEL, 4);
+ 
+    /* ADC inserted channel config */
+    adc_inserted_channel_config(0, ADC_CHANNEL_0, ADC_SAMPLETIME_55POINT5);
+    adc_inserted_channel_config(1, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
+    adc_inserted_channel_config(2, ADC_CHANNEL_2, ADC_SAMPLETIME_55POINT5);
+    adc_inserted_channel_config(3, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
+
+    /* ADC external trigger enable */
+    adc_external_trigger_config(ADC_INSERTED_CHANNEL, ENABLE);
+
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+}

+ 18 - 0
Examples/ADC/TIMER_trigger_inserted_channel/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 15 - 0
Examples/ADC/TIMER_trigger_inserted_channel/readme.txt

@@ -0,0 +1,15 @@
+/*!
+    \file  readme.txt
+    \brief description of TIMER trigger inserted channel of ADC demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to convert 
+ADC inserted group channels continuously using TIMER1 external trigger. 
+The inserted group length is 4, the scan mode is set, every compare event 
+will trigger ADC to convert all the channels in the inserted group.

+ 58 - 0
Examples/ADC/TIMER_trigger_inserted_channel/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/TIMER_trigger_inserted_channel/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 114 - 0
Examples/ADC/Temperature_Vref/gd32f3x0_it.c

@@ -0,0 +1,114 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "main.h"
+#include "systick.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    delay_decrement();
+}

+ 37 - 0
Examples/ADC/Temperature_Vref/gd32f3x0_it.h

@@ -0,0 +1,37 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/ADC/Temperature_Vref/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 115 - 0
Examples/ADC/Temperature_Vref/main.c

@@ -0,0 +1,115 @@
+/*!
+    \file  main.c
+    \brief ADC channel of temperature and Vref demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "main.h"
+#include "gd32f3x0_eval.h"
+
+float temperature;
+float vref_value;
+
+void rcu_config(void);
+void adc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+
+int main(void)
+{
+    /* configure systick */
+    systick_config();  
+    /* system clocks configuration */
+    rcu_config();
+    /* ADC configuration */
+    adc_config();
+    /* USART configuration */
+    gd_eval_com_init(EVAL_COM1);
+
+    while(1){
+        /* ADC software trigger enable */
+        adc_software_trigger_enable(ADC_INSERTED_CHANNEL);
+        /* delay a time in milliseconds */
+        delay_1ms(2000);
+
+        /* value convert */
+        temperature = (1.43 - ADC_IDATA0 * 3.3/4096) * 1000 / 4.3 + 25;
+        vref_value = (ADC_IDATA1 * 3.3 / 4096);
+
+        /* value print */
+        printf(" the temperature data is %2.0f degrees Celsius\r\n", temperature);
+        printf(" the reference voltage data is %5.3fV \r\n", vref_value);
+        printf(" \r\n");
+    }
+}
+
+/*!
+    \brief      configure the different system clocks
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable ADC clock */
+    rcu_periph_clock_enable(RCU_ADC);
+    /* config ADC clock */
+    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
+}
+
+/*!
+    \brief      configure the ADC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void adc_config(void)
+{
+    /* ADC channel length config */
+    adc_channel_length_config(ADC_INSERTED_CHANNEL, 2);
+
+    /* ADC temperature sensor channel config */
+    adc_inserted_channel_config(0, ADC_CHANNEL_16, ADC_SAMPLETIME_239POINT5);
+    /* ADC internal reference voltage channel config */
+    adc_inserted_channel_config(1, ADC_CHANNEL_17, ADC_SAMPLETIME_239POINT5);
+
+    /* ADC trigger config */
+    adc_external_trigger_source_config(ADC_INSERTED_CHANNEL, ADC_EXTTRIG_INSERTED_NONE);
+    /* ADC data alignment config */
+    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
+    /* ADC SCAN function enable */
+    adc_special_function_config(ADC_SCAN_MODE, ENABLE);
+    /* ADC temperature and Vrefint enable */
+    adc_tempsensor_vrefint_enable();
+
+    adc_external_trigger_config(ADC_INSERTED_CHANNEL, ENABLE);
+
+    /* enable ADC interface */
+    adc_enable();
+    delay_1ms(1);
+    
+    /* ADC calibration and reset calibration */
+    adc_calibration_enable();
+}
+
+/* retarget the C library printf function to the USART */
+int fputc(int ch, FILE *f)
+{
+    usart_data_transmit(EVAL_COM1, (uint8_t)ch);
+    while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
+
+    return ch;
+}

+ 18 - 0
Examples/ADC/Temperature_Vref/main.h

@@ -0,0 +1,18 @@
+/*!
+    \file  main.h
+    \brief the header file of main 
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef __MAIN_H
+#define __MAIN_H
+
+/* led spark function */
+void led_spark(void);
+
+#endif /* __MAIN_H */

+ 20 - 0
Examples/ADC/Temperature_Vref/readme.txt

@@ -0,0 +1,20 @@
+/*!
+    \file  readme.txt
+    \brief description of ADC channel of temperature and Vref demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to use the
+ADC to convert analog signal to digital data. The ADC is configured in
+dependent mode, inner channel 16(temperature sensor channel) and channel 
+17(VREF channel) are chosen as analog input pin.
+
+  As the ADC convertion begins by software, the converted data in the 
+ADC_IDATAx register,where the x is 0 to 1.
+
+  Jump the JP13 to USART.

+ 58 - 0
Examples/ADC/Temperature_Vref/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){
+        delay--;
+    }
+}

+ 24 - 0
Examples/ADC/Temperature_Vref/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 219 - 0
Examples/CEC/Intercommunication/gd32f3x0_it.c

@@ -0,0 +1,219 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "gd32f3x0_eval.h"
+#include "systick.h"
+
+/* array1 transmission */
+uint8_t senddata1[2] = {0xA5,0x5A};
+/* array2 transmission */
+uint8_t senddata2[2] = {0x5A,0xA5};
+/* receive array buffer  */
+uint8_t rcvdata[10];
+/* sent data pointer */
+uint8_t *transdata;
+__IO uint8_t rcvstatus = 0U;
+__IO uint8_t send_inc = 0U, rcv_inc = 0U;
+uint16_t senderrorcode = 0U;
+uint16_t rcverrorcode = 0U;
+__IO uint8_t bytenum = 0U;
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+        delay_decrement();
+}
+
+/*!
+    \brief      this function handles EXTI0_1 interrupt request
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void EXTI0_1_IRQHandler(void)
+{
+    if(RESET != exti_flag_get(WAKEUP_KEY_EXTI_LINE)){
+        /* Tamper key press */
+        bytenum = 2U;
+        /* send CEC address */
+        cec_data_send(0x12U);
+        /* start transmission */
+        transdata = senddata1;
+        /* start transmission */
+        cec_transmission_start();
+        exti_flag_clear(WAKEUP_KEY_EXTI_LINE);
+    }
+}
+
+/*!
+    \brief      this function handles EXTI4_15 interrupt request
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void EXTI4_15_IRQHandler(void)
+{
+    if(RESET != exti_flag_get(TAMPER_KEY_EXTI_LINE)){
+        /* Tamper key press */
+        bytenum = 2U;
+        /* send CEC address */
+        cec_data_send(0x12U);
+        /* start transmission */
+        transdata = senddata2;
+        /* start transmission */
+        cec_transmission_start();
+        exti_flag_clear(TAMPER_KEY_EXTI_LINE);
+    }
+}
+
+/*!
+    \brief      this function handles CEC interrupt request
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void CEC_IRQHandler(void)
+{
+    /* check if a reception error occured */
+    if(cec_interrupt_flag_get(CEC_INTF_RO | CEC_INTF_BRE | CEC_INTF_BPSE | CEC_INTF_BPLE | CEC_INTF_RAE)){
+        rcverrorcode = CEC_INTF;
+        cec_interrupt_flag_clear(CEC_INTF_RO | CEC_INTF_BRE | CEC_INTF_BPSE | CEC_INTF_BPLE | CEC_INTF_RAE);
+        rcvstatus  = 2U;
+    }
+    /* receive data */
+    if(cec_interrupt_flag_get(CEC_INTF_BR)){
+        rcvdata[rcv_inc] = cec_data_receive();
+        rcv_inc++;
+        cec_interrupt_flag_clear(CEC_INTF_BR);
+    }
+    /* check if the byte received is the last one of the message */
+    if(cec_interrupt_flag_get(CEC_INTF_REND)){
+        rcvstatus = 1U;
+        rcv_inc = 0U;
+        cec_interrupt_flag_clear(CEC_INTF_REND);
+    }
+
+    /* check if a transmission error occurred */
+    if(cec_interrupt_flag_get(CEC_INTF_ARBF | CEC_INTF_TU | CEC_INTF_TERR | CEC_INTF_TAERR)){
+        senderrorcode = CEC_INTF;
+        cec_interrupt_flag_clear(CEC_INTF_ARBF | CEC_INTF_TU | CEC_INTF_TERR | CEC_INTF_TAERR);
+    }
+  
+    /* check if end of message bit is set in the data to be transmitted */
+    if(cec_interrupt_flag_get(CEC_INTF_TEND)){
+        cec_interrupt_flag_clear(CEC_INTF_TEND| CEC_INTF_TBR);
+        send_inc = 0U;
+    }else if(cec_interrupt_flag_get(CEC_INTF_TBR)){
+        /* set EOM bit if the byte to be transmitted is the last one of the senddata */
+        if(send_inc++ == (bytenum - 1U)){
+            cec_transmission_end();
+            cec_data_send(*transdata++);
+        }else{
+            /* send the byte in the transdata */
+            cec_data_send(*transdata++);
+        }
+        cec_interrupt_flag_clear(CEC_INTF_TBR);
+    }
+}

+ 42 - 0
Examples/CEC/Intercommunication/gd32f3x0_it.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* NMI handle function */
+void NMI_Handler(void);
+/* HardFault handle function */
+void HardFault_Handler(void);
+/* MemManage handle function */
+void MemManage_Handler(void);
+/* BusFault handle function */
+void BusFault_Handler(void);
+/* UsageFault handle function */
+void UsageFault_Handler(void);
+/* SVC handle function */
+void SVC_Handler(void);
+/* DebugMon handle function */
+void DebugMon_Handler(void);
+/* PendSV handle function */
+void PendSV_Handler(void);
+/* SysTick handle function */
+void SysTick_Handler(void);
+/* EXTI4_15 handle function */
+void EXTI4_15_IRQHandler(void);
+/* CEC handle function */
+void CEC_IRQHandler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/CEC/Intercommunication/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 116 - 0
Examples/CEC/Intercommunication/main.c

@@ -0,0 +1,116 @@
+/*!
+    \file  main.c
+    \brief CEC intercommunication
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+#include "systick.h"
+
+void cec_config(void);
+
+extern uint8_t rcvdata[10];
+extern __IO uint8_t rcvstatus;
+extern uint8_t rcv_inc;
+extern uint8_t bytenum;
+__IO uint8_t NUM=0U;
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* GPIO clock enable */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    rcu_periph_clock_enable(RCU_GPIOB);
+    rcu_periph_clock_enable(RCU_GPIOC);
+    rcu_periph_clock_enable(RCU_GPIOF);
+
+    /* delay time initialize */
+    systick_config();
+
+    /* configure the CEC peripheral */
+    cec_config();
+
+    /* configure the EXTI */
+    gd_eval_key_init(KEY_TAMPER, KEY_MODE_EXTI);
+    
+    gd_eval_key_init(KEY_WAKEUP, KEY_MODE_EXTI);
+
+    /* LED1 LED2 initialize */
+    gd_eval_led_init(LED1);
+    gd_eval_led_init(LED2);
+    gd_eval_led_off(LED1);
+    gd_eval_led_off(LED2);
+
+    /* main loop */
+    while(1){
+        /* wait receive data */
+        while(rcvstatus==0U);
+
+        if(rcvstatus == 1U){
+            if((rcvdata[1]==0xA5U)&&(rcvdata[2]==0x5AU)){
+                gd_eval_led_on(LED1);
+                delay_1ms(50U);
+                gd_eval_led_off(LED1);
+            }
+            if((rcvdata[1]==0x5AU)&&(rcvdata[2]==0xA5U)){
+                gd_eval_led_on(LED2);
+                delay_1ms(50U);
+                gd_eval_led_off(LED2);
+            }
+        }
+        /* a reception error occured */
+        rcvstatus = 0U;
+    }
+}
+
+/*!
+    \brief      configure the CEC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void cec_config(void)
+{
+    /* enable clocks */
+    rcu_periph_clock_enable(RCU_GPIOB);
+    rcu_periph_clock_enable(RCU_CEC);
+
+    /* configure CEC_LINE_GPIO as output open drain */
+    gpio_mode_set(GPIOB,GPIO_MODE_AF,GPIO_PUPD_NONE,GPIO_PIN_8);
+    gpio_output_options_set(GPIOB,GPIO_OTYPE_OD,GPIO_OSPEED_50MHZ,GPIO_PIN_8);
+    gpio_af_set(GPIOB,GPIO_AF_0,GPIO_PIN_8);
+
+    /* configure priority group */
+    nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
+
+    /* enable the CEC global interrupt (with higher priority) */
+    nvic_irq_enable(CEC_IRQn,0U,0U);
+
+    /* configure CEC */
+    cec_init(CEC_SFT_START_STAOM,CEC_SFT_1POINT5_PERIOD,CEC_OWN_ADDRESS2);
+    cec_error_config(CEC_BROADCAST_ERROR_BIT_OFF,CEC_LONG_PERIOD_ERROR_BIT_OFF,CEC_RISING_PERIOD_ERROR_BIT_OFF,CEC_STOP_RISING_ERROR_BIT_OFF);
+    cec_reception_tolerance_disable();
+
+    /* activate CEC interrupts associated to the set of TX and RX flags */
+    cec_interrupt_enable(CEC_INTEN_TENDIE | CEC_INTEN_TBRIE | CEC_INTEN_RENDIE | CEC_INTEN_BRIE);
+
+    /* activate CEC interrupts associated to the set of TX and RX error */
+    cec_interrupt_enable(CEC_INTEN_ROIE | CEC_INTEN_BREIE | CEC_INTEN_BPSEIE | CEC_INTEN_BPLEIE 
+    | CEC_INTEN_RAEIE | CEC_INTEN_ARBFIE | CEC_INTEN_TUIE | CEC_INTEN_TERRIE | CEC_INTEN_TAERRIE );
+
+    /* enable CEC */
+    cec_enable();
+}

+ 17 - 0
Examples/CEC/Intercommunication/readme.txt

@@ -0,0 +1,17 @@
+/*!
+    \file  readme.txt
+    \brief description of CEC intercommunication
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This example is based on the GD32350R-EVAL board, it shows how to 
+configure and use the CEC peripheral to receive and transmit messages. In this 
+demo, the same program is loaded to two GD32350R-EVAL boards, 
+then they are communicated through connecting respective CEC line(PB8) and GND.
+When press the buttons(K3 or K4) on one board, LED1 and LED2 will blink once.
+  Connect two GD32350R-EVAL boards through CEC line(PB8) and GND.

+ 58 - 0
Examples/CEC/Intercommunication/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000U)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00U);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0U != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0U != delay){ 
+        delay--;
+    }
+}

+ 24 - 0
Examples/CEC/Intercommunication/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 124 - 0
Examples/CMP/Interrupt/gd32f3x0_it.c

@@ -0,0 +1,124 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles External lines 21 and 22 interrupt exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void ADC_CMP_IRQHandler(void)
+{
+    if(RESET != exti_interrupt_flag_get(EXTI_21)){
+        gd_eval_led_on(LED2);
+        exti_interrupt_flag_clear(EXTI_21);
+    }
+}

+ 42 - 0
Examples/CMP/Interrupt/gd32f3x0_it.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+#include "gd32f3x0_eval.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+/* ADC CMP handle function */
+void ADC_CMP_IRQHandler(void);
+
+#endif /* GD32F3X0_IT_H */
+
+

+ 42 - 0
Examples/CMP/Interrupt/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 64 - 0
Examples/CMP/Interrupt/main.c

@@ -0,0 +1,64 @@
+/*!
+    \file  main.c
+    \brief CMP trigger interrupt using an external interrupt line
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+
+void led_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* configure leds */
+    led_config();
+    
+    /* enable GPIOA clock */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    
+    /* configure PA1 as comparator input */
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_1);
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_PULLUP, GPIO_PIN_1);
+    
+    /* enable comparator clock */
+    rcu_periph_clock_enable(RCU_CFGCMP);
+    
+    /* configure comparator channel0 */
+    cmp_mode_init(CMP0, CMP_VERYLOWSPEED, CMP_1_4VREFINT, CMP_HYSTERESIS_NO);
+    cmp_output_init(CMP0, CMP_OUTPUT_NONE, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* initialize exti line21 */
+    exti_init(EXTI_21, EXTI_INTERRUPT, EXTI_TRIG_RISING);
+    
+    /* configure ADC_CMP NVIC */
+    nvic_irq_enable(ADC_CMP_IRQn, 0, 0);
+    
+    /* enable comparator channel0 */
+    cmp_enable(CMP0);
+    
+    while(1);
+}
+
+/*!
+    \brief      configure the leds
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void led_config(void)
+{
+    gd_eval_led_init (LED2);
+}

+ 18 - 0
Examples/CMP/Interrupt/readme.txt

@@ -0,0 +1,18 @@
+/*!
+    \file  readme.txt
+    \brief description of the comparator interrupt demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to configure the
+comparator trigger interrupt using an external interrupt line. In this demo,input
+3.3V to PA1, EXTI line 21 is configured to generate an interrupt on rising edge 
+of the output signal. After system start-up, enable comparator and trigger interrupt,
+then LED2 is on. 
+
+  Connect PA1 to +3V3.

+ 42 - 0
Examples/CMP/PWM_signal_control/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 121 - 0
Examples/CMP/PWM_signal_control/main.c

@@ -0,0 +1,121 @@
+/*!
+    \file  main.c
+    \brief PWM output by using comparator output
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdio.h>
+
+uint16_t period = 65535;
+
+void rcu_config(void);
+void gpio_config(void);
+void timer_config(void);
+void cmp_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* configure RCU */
+    rcu_config();
+    
+    /* configure GPIO */
+    gpio_config();
+    
+    /* configure TIMER */
+    timer_config();
+    
+    /* configure comparator */
+    cmp_config();
+    
+    while(1);
+}
+
+/*!
+    \brief      configure RCU
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    rcu_periph_clock_enable(RCU_GPIOA);
+    rcu_periph_clock_enable(RCU_GPIOB);
+    rcu_periph_clock_enable(RCU_TIMER1);
+    rcu_periph_clock_enable(RCU_CFGCMP);
+}
+
+/*!
+    \brief      configure GPIO
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* configure PB3 as PWM output */
+    gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
+    gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3);
+    gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_3);
+    
+    /* configure PA1 as comparator input */
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_1);
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_PULLUP, GPIO_PIN_1);
+    
+}
+
+/*!
+    \brief      configure TIMER
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void timer_config(void)
+{
+    /* initialize TIMER1 */
+    timer_parameter_struct timer_init_parameter;
+    timer_init_parameter.prescaler = 71;
+    timer_init_parameter.counterdirection = TIMER_COUNTER_UP;
+    timer_init_parameter.period = 65535;
+    timer_init_parameter.clockdivision = TIMER_CKDIV_DIV1;
+    
+    timer_init(TIMER1, &timer_init_parameter);
+
+    /* PWM1 mode configure channel1 in PWM1 mode */
+    timer_channel_output_mode_config(TIMER1, TIMER_CH_1, TIMER_OC_MODE_PWM1);
+    timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_1, (period/2) + 1);
+    timer_channel_output_state_config(TIMER1,TIMER_CH_1, TIMER_CCX_ENABLE);
+    /* select OCREFCLR as source for clearing OC2REF */
+    timer_channel_output_clear_config(TIMER1, TIMER_CH_1, TIMER_OC_CLEAR_ENABLE);
+    timer_ocpre_clear_source_config(TIMER1, TIMER_OCPRE_CLEAR_SOURCE_CLR);
+
+    /* enable TIMER1 counter */
+    timer_enable(TIMER1);
+}
+
+/*!
+    \brief      configure comparator
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void cmp_config(void)
+{
+    /* configure comparator channel0 */
+    cmp_mode_init(CMP0, CMP_HIGHSPEED, CMP_VREFINT, CMP_HYSTERESIS_NO);
+    cmp_output_init(CMP0, CMP_OUTPUT_TIMER1OCPRECLR, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* enable comparator channel0 */
+    cmp_enable(CMP0);
+}

+ 23 - 0
Examples/CMP/PWM_signal_control/readme.txt

@@ -0,0 +1,23 @@
+/*!
+    \file  readme.txt
+    \brief description of the comparator pwm signal control demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to control PWM 
+  output by using comparator output
+
+  - CMP channel0 is configured as following:
+  - Inverting input is internally connected to VREFINT = 1.22V
+  - Non Inverting input is connected to PC1
+  - Output is internally connected to TIMER1 OCREFCLR (output compare reference clear)
+
+  - While PC1/PC0 is lower than VREFINT (1.22V), PWM signal is displayed on PB3 
+  - While PC1/PC0 is higher than VREFINT, PB3 is displayed in low level.
+
+  Connect PA1 to PC1.

+ 42 - 0
Examples/CMP/Port_output/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 83 - 0
Examples/CMP/Port_output/main.c

@@ -0,0 +1,83 @@
+/*!
+    \file  main.c
+    \brief CMP port output
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+
+void rcu_config(void);
+void gpio_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    int i;
+    /* configure RCU */
+    rcu_config();
+    
+    /* configure GPIO */
+    gpio_config();
+    
+    gd_eval_led_init(LED2);
+    
+    /* configure comparator channel0 */
+    cmp_mode_init(CMP0, CMP_VERYLOWSPEED, CMP_1_4VREFINT, CMP_HYSTERESIS_NO);
+    cmp_output_init(CMP0, CMP_OUTPUT_NONE, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* enable comparator channel0 */
+    cmp_enable(CMP0);
+    
+    for( i=0; i<100; i++);
+    
+    /* get the output level */
+    if(CMP_OUTPUTLEVEL_HIGH == cmp_output_level_get(CMP0)){
+        gd_eval_led_on(LED2);
+    }else{
+        gd_eval_led_off(LED2);
+    }
+    
+    while (1);
+}
+
+/*!
+    \brief      configure RCU 
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    /* enable GPIOA clock */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    /* enable comparator clock */
+    rcu_periph_clock_enable(RCU_CFGCMP);
+}
+
+/*!
+    \brief      configure GPIO
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_1);
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_PULLUP, GPIO_PIN_1);
+
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
+    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_6);
+    gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_6);
+}

+ 16 - 0
Examples/CMP/Port_output/readme.txt

@@ -0,0 +1,16 @@
+/*!
+    \file  readme.txt
+    \brief description of the comparator port output demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to configure 
+the comparator portoutput. In this demo, input 3.3V to PA1. After system 
+start-up,enable comparator ,then LED2 is on.
+
+  Connect PA1 to +3V3. 

+ 42 - 0
Examples/CMP/Switch/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 103 - 0
Examples/CMP/Switch/main.c

@@ -0,0 +1,103 @@
+/*!
+    \file  main.c
+    \brief CMP switch
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+
+void rcu_config(void);
+void gpio_config(void);
+void dac_config(void);
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    gd_eval_led_init(LED1);
+    /* configure RCU */
+    rcu_config();
+    
+    /* configure GPIO */
+    gpio_config();
+    
+    /* configure DAC */
+    dac_config();
+    
+    /* set data for DAC0 */
+    dac_data_set(DAC_ALIGN_12B_R, 0x7FF);
+    
+    dac_software_trigger_enable();
+    
+    /* configure comparator channel0 */
+    cmp_mode_init(CMP0, CMP_VERYLOWSPEED, CMP_1_4VREFINT, CMP_HYSTERESIS_NO);
+    cmp_output_init(CMP0, CMP_OUTPUT_NONE, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* enable channel0 switch */
+    cmp_switch_enable();
+    
+    /* enable comparator channel0 */
+    cmp_enable(CMP0);
+    
+    while(1)
+    {
+        if(cmp_output_level_get(CMP0) == CMP_OUTPUTLEVEL_HIGH)
+        {
+            gd_eval_led_on(LED1);
+        }
+
+    }
+}
+
+/*!
+    \brief      configure RCU
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    rcu_periph_clock_enable(RCU_GPIOA);
+    rcu_periph_clock_enable(RCU_DAC);
+    rcu_periph_clock_enable(RCU_CFGCMP);
+}
+
+/*!
+    \brief      configure GPIO
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* configure PA4 */
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_4);
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_PULLUP, GPIO_PIN_4);
+    /* configure PA6 */
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
+    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_6);
+    gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_6);
+}
+
+/*!
+    \brief      dac TIMER
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void dac_config(void)
+{
+    dac_trigger_source_config(DAC_TRIGGER_SOFTWARE);
+    dac_output_buffer_enable();
+    dac_enable();
+}

+ 17 - 0
Examples/CMP/Switch/readme.txt

@@ -0,0 +1,17 @@
+/*!
+    \file  readme.txt
+    \brief description of the comparator switch demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to configure the
+comparator input switch. In this demo, input 3.3V to PA4 ,turn on comparator 
+input switch,then PA4 will be connected to CMP1_IP.After system start-up, enable
+comparator,then LED2 is on.
+
+  Connect PA4 to +3V3.   

+ 125 - 0
Examples/CMP/Timer1_CH3IC/gd32f3x0_it.c

@@ -0,0 +1,125 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+#include "gd32f3x0_eval.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles timer1 handle exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void TIMER1_IRQHandler(void)
+{
+    if(SET == timer_interrupt_flag_get(TIMER1, TIMER_INT_CH3)){
+        gd_eval_led_on(LED3);
+        timer_interrupt_flag_clear(TIMER1, TIMER_INT_CH3);
+    }
+}

+ 41 - 0
Examples/CMP/Timer1_CH3IC/gd32f3x0_it.h

@@ -0,0 +1,41 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* NMI handle function */
+void NMI_Handler(void);
+/* HardFault handle function */
+void HardFault_Handler(void);
+/* MemManage handle function */
+void MemManage_Handler(void);
+/* BusFault handle function */
+void BusFault_Handler(void);
+/* UsageFault handle function */
+void UsageFault_Handler(void);
+/* SVC handle function */
+void SVC_Handler(void);
+/* DebugMon handle function */
+void DebugMon_Handler(void);
+/* PendSV handle function */
+void PendSV_Handler(void);
+/* SysTick handle function */
+void SysTick_Handler(void);
+/* ADC CMP handle function */
+void ADC_CMP_IRQHandler(void);
+
+#endif /* GD32F3X0_IT_H */
+
+

+ 42 - 0
Examples/CMP/Timer1_CH3IC/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 109 - 0
Examples/CMP/Timer1_CH3IC/main.c

@@ -0,0 +1,109 @@
+/*!
+    \file  main.c
+    \brief CMP output timer input capture
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+
+void rcu_config(void);
+void gpio_config(void);
+void timer_config(void);
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* configure RCU */
+    rcu_config();
+    
+    /* configure GPIO */
+    gpio_config();
+    
+    /* configure leds */
+    gd_eval_led_init(LED3);
+    
+    /* configure comparator channel0 */
+    cmp_mode_init(CMP0, CMP_VERYLOWSPEED, CMP_1_4VREFINT, CMP_HYSTERESIS_NO);
+    cmp_output_init(CMP0, CMP_OUTPUT_TIMER1IC3, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* configure TIMER */
+    timer_config();
+    
+    /* enable comparator channel0 */
+    cmp_enable(CMP0);
+    while(1);
+}
+
+/*!
+    \brief      configure RCU
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void rcu_config(void)
+{
+    rcu_periph_clock_enable(RCU_GPIOA);
+    rcu_periph_clock_enable(RCU_GPIOB);
+    rcu_periph_clock_enable(RCU_GPIOC);
+    rcu_periph_clock_enable(RCU_TIMER1);
+    rcu_periph_clock_enable(RCU_CFGCMP);
+}
+
+/*!
+    \brief      configure GPIO
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void gpio_config(void)
+{
+    /* configure PB11 */
+    gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_11) ;
+    gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_11);
+    gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_11);
+
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_1) ;
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_PULLUP, GPIO_PIN_1);
+}
+
+/*!
+    \brief      configure TIMER
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void timer_config(void)
+{
+    /* initialize TIMER1 */
+    timer_parameter_struct timer_init_parameter;
+    timer_init_parameter.prescaler = 0;
+    timer_init_parameter.counterdirection = TIMER_COUNTER_UP;
+    timer_init_parameter.period = 65535;
+    timer_init_parameter.clockdivision = TIMER_CKDIV_DIV1;
+    
+    timer_init(TIMER1, &timer_init_parameter);
+    
+    /* clear flag */
+    timer_flag_clear(TIMER1, TIMER_FLAG_UP);
+    
+    nvic_irq_enable(TIMER1_IRQn, 0, 0);
+    
+    /* reset TIMER1 interrupt flag register */
+    TIMER_INTF(TIMER1) = 0;
+    
+    timer_interrupt_enable(TIMER1, TIMER_INT_CH3);
+    
+    /* enable TIMER1 counter */
+    timer_enable(TIMER1);
+}

+ 18 - 0
Examples/CMP/Timer1_CH3IC/readme.txt

@@ -0,0 +1,18 @@
+/*!
+    \file  readme.txt
+    \brief description of the comparator output timer input capture demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+    This demo is based on the GD32350R-EVAL board, it shows how to configure the
+  comparator trigger timer 1 channel 3 input capture event, which is configured 
+  to generate an interrupt on both rising and falling edge of the output signal.
+  In this demo, input 3.3V to CMP0_IP. After system start-up, enable comparator 
+  and trigger interrupt,then LED3 is on.  
+
+    Connect PA1 to +3V3.   

+ 128 - 0
Examples/CMP/Window/gd32f3x0_it.c

@@ -0,0 +1,128 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt service routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+
+extern uint32_t delayms;
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+    if(delayms){
+        delayms--;
+    }
+}
+
+void ADC_CMP_IRQHandler(void)
+{
+    if((RESET != exti_interrupt_flag_get(EXTI_21)) || RESET != (exti_interrupt_flag_get(EXTI_22))){
+        /* recover the system clock to 72MHz */
+        SystemInit();
+        check_state();
+        /* clear EXTI line21 bit */
+        exti_interrupt_flag_clear(EXTI_21);
+        /* clear EXTI line22 bit */
+        exti_interrupt_flag_clear(EXTI_22);
+    }
+}

+ 43 - 0
Examples/CMP/Window/gd32f3x0_it.h

@@ -0,0 +1,43 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+#include "gd32f3x0_eval.h"
+#include "main.h"
+
+/* function declarations */
+/* this function handles NMI exception */
+void NMI_Handler(void);
+/* this function handles HardFault exception */
+void HardFault_Handler(void);
+/* this function handles MemManage exception */
+void MemManage_Handler(void);
+/* this function handles BusFault exception */
+void BusFault_Handler(void);
+/* this function handles UsageFault exception */
+void UsageFault_Handler(void);
+/* this function handles SVC exception */
+void SVC_Handler(void);
+/* this function handles DebugMon exception */
+void DebugMon_Handler(void);
+/* this function handles PendSV exception */
+void PendSV_Handler(void);
+/* this function handles SysTick exception */
+void SysTick_Handler(void);
+/* ADC CMP handle function */
+void ADC_CMP_IRQHandler(void);
+
+#endif /* GD32F3X0_IT_H */
+
+

+ 42 - 0
Examples/CMP/Window/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 181 - 0
Examples/CMP/Window/main.c

@@ -0,0 +1,181 @@
+/*!
+    \file  main.c
+    \brief CMP watchdog window
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+#include "main.h"
+
+uint32_t delayms;
+void led_config(void);
+void deepsleep_mode_config(void);
+void cmp_config(void);
+void delay_ms(uint32_t time);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    SysTick_Config(72000000/1000);
+    
+    /* configure leds */
+    led_config();
+
+    /* configure CMP0 and CMP1 */
+    cmp_config();
+    
+    /* configure CMP0 and CMP1 */
+    check_state();
+    
+    while(1)
+    {
+        /* input voltage is over the thresholds: higher and lower thresholds */
+        if(STATE_OVER_THRESHOLD == check_state()){
+            gd_eval_led_on(LED1);
+            gd_eval_led_off(LED2);
+            gd_eval_led_on(LED3);
+            gd_eval_led_off(LED4);
+        }
+        /* input voltage is within the thresholds: higher and lower thresholds */
+        if(STATE_WITHIN_THRESHOLD == check_state()){
+            delay_ms(500);
+            if(STATE_WITHIN_THRESHOLD == check_state()){
+                gd_eval_led_off(LED1);
+                gd_eval_led_off(LED2);
+                gd_eval_led_off(LED3);
+                gd_eval_led_off(LED4);
+                /* enter deepsleep mode */
+                deepsleep_mode_config();
+            }
+        }
+        /* input voltage is under the thresholds: higher and lower thresholds */
+        if(STATE_UNDER_THRESHOLD == check_state()){
+            gd_eval_led_off(LED1);
+            gd_eval_led_on(LED2);
+            gd_eval_led_off(LED3);
+            gd_eval_led_on(LED4);
+        }
+    }
+}
+
+/*!
+    \brief      configure comparator
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void cmp_config(void)
+{
+    /* enable GPIOA clock */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    
+    /* configure PA1 as comparator input */
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_1);
+    gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_PULLUP, GPIO_PIN_1);
+    
+    /* enable comparator clock */
+    rcu_periph_clock_enable(RCU_CFGCMP);
+    
+    /* configure comparator channel0 */
+    cmp_mode_init(CMP0, CMP_LOWSPEED, CMP_VREFINT, CMP_HYSTERESIS_HIGH);
+    cmp_output_init(CMP0, CMP_OUTPUT_NONE, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* configure comparator channel1 */
+    cmp_mode_init(CMP1, CMP_LOWSPEED, CMP_1_2VREFINT, CMP_HYSTERESIS_HIGH);
+    cmp_output_init(CMP1, CMP_OUTPUT_NONE, CMP_OUTPUT_POLARITY_NOINVERTED);
+    
+    /* configure exti line */
+    exti_init(EXTI_21, EXTI_INTERRUPT, EXTI_TRIG_BOTH);
+    exti_init(EXTI_22, EXTI_INTERRUPT, EXTI_TRIG_BOTH);
+    
+    /* configure ADC_CMP nvic */
+    nvic_irq_enable(ADC_CMP_IRQn, 0, 0);
+    
+    /* enable comparator window */
+    cmp_window_enable();
+    
+    /* enable comparator channels */
+    cmp_enable(CMP0);
+    cmp_enable(CMP1);
+}
+
+/*!
+    \brief      configure deepsleep mode
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void deepsleep_mode_config(void)  
+{
+    /* enable pmu clock */
+    rcu_periph_clock_enable(RCU_PMU);
+
+   /* enter to deepsleep mode */
+    pmu_to_deepsleepmode(PMU_LDO_LOWPOWER, WFI_CMD);  
+}
+
+/*!
+    \brief      check comparator output state
+    \param[in]  none
+    \param[out] none
+    \retval     cmp_state
+*/
+cmp_state_enum check_state(void)
+{
+    cmp_state_enum state;
+
+    /* check if cmp0 output level is high and cmp1 output level is high */
+    if ((cmp_output_level_get(CMP0) == CMP_OUTPUTLEVEL_HIGH)
+    && (cmp_output_level_get(CMP1) == CMP_OUTPUTLEVEL_HIGH)){
+        state = STATE_OVER_THRESHOLD;
+    }
+    /* check if cmp0 output level is low and cmp1 output level is high */
+    if ((cmp_output_level_get(CMP0) == CMP_OUTPUTLEVEL_LOW) 
+    && (cmp_output_level_get(CMP1) == CMP_OUTPUTLEVEL_HIGH)){
+        state = STATE_WITHIN_THRESHOLD;
+    }
+    /* check if cmp0 output level is low and cmp1 output level is low */
+    if ((cmp_output_level_get(CMP0) == CMP_OUTPUTLEVEL_LOW)
+    && (cmp_output_level_get(CMP1) == CMP_OUTPUTLEVEL_LOW)){
+        state = STATE_UNDER_THRESHOLD;
+    }
+    return state;
+}
+
+/*!
+    \brief      delay function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_ms(uint32_t time)
+{
+    delayms = time;
+    while(delayms);
+}
+
+/*!
+    \brief      configure the leds
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void led_config(void)
+{
+    gd_eval_led_init (LED1);
+    gd_eval_led_init (LED2);
+    gd_eval_led_init (LED3);
+    gd_eval_led_init (LED4);
+}

+ 24 - 0
Examples/CMP/Window/main.h

@@ -0,0 +1,24 @@
+/*!
+    \file  main.c
+    \brief the header file of the main
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef MAIN_H
+#define MAIN_H
+
+typedef enum
+{
+    STATE_OVER_THRESHOLD ,
+    STATE_WITHIN_THRESHOLD, 
+    STATE_UNDER_THRESHOLD 
+} cmp_state_enum;
+
+cmp_state_enum check_state(void);
+
+#endif /* MAIN_H */

+ 24 - 0
Examples/CMP/Window/readme.txt

@@ -0,0 +1,24 @@
+/*!
+    \file  readme.txt
+    \brief description of the comparator window demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This demo is based on the GD32350R-EVAL board, it shows how to make an analog 
+  watchdog by using comparator 
+  peripherals in window mode:
+  - The upper threshold is set to VREFINT = 1.22V
+  - The lower threshold is set to VREFINT / 2 = 1.22V = 0.610V
+  - The input voltage is configured to be connected to PC1
+
+  If the input voltage is above the higher threshold, LED1 and LED3 are turned on.
+  If the input voltage is under the lower threshold, LED2 and LED4 are turned on.
+  If the input voltage is within the thresholds, the MCU remains in deepsleep mode
+  and all leds are turned off.
+
+  Connect PA1 to PC1.   

+ 110 - 0
Examples/CRC/Calculate_demo/gd32f3x0_it.c

@@ -0,0 +1,110 @@
+/*!
+    \file  gd32f3x0_it.c
+    \brief interrupt Service Routines
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0_it.h"
+
+/*!
+    \brief      this function handles NMI exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void NMI_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles HardFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void HardFault_Handler(void)
+{
+    /* if Hard Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles MemManage exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void MemManage_Handler(void)
+{
+    /* if Memory Manage exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles BusFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void BusFault_Handler(void)
+{
+    /* if Bus Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles UsageFault exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void UsageFault_Handler(void)
+{
+    /* if Usage Fault exception occurs, go to infinite loop */
+    while (1);
+}
+
+/*!
+    \brief      this function handles SVC exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SVC_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles DebugMon exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void DebugMon_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles PendSV exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void PendSV_Handler(void)
+{
+}
+
+/*!
+    \brief      this function handles SysTick exception
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void SysTick_Handler(void)
+{
+}

+ 38 - 0
Examples/CRC/Calculate_demo/gd32f3x0_it.h

@@ -0,0 +1,38 @@
+/*!
+    \file  gd32f3x0_it.h
+    \brief the header file of the ISR
+
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_IT_H
+#define GD32F3X0_IT_H
+
+#include "gd32f3x0.h"
+
+/* function declarations */
+/* NMI handle function */
+void NMI_Handler(void);
+/* HardFault handle function */
+void HardFault_Handler(void);
+/* MemManage handle function */
+void MemManage_Handler(void);
+/* BusFault handle function */
+void BusFault_Handler(void);
+/* UsageFault handle function */
+void UsageFault_Handler(void);
+/* SVC handle function */
+void SVC_Handler(void);
+/* DebugMon handle function */
+void DebugMon_Handler(void);
+/* PendSV handle function */
+void PendSV_Handler(void);
+/* SysTick handle function */
+void SysTick_Handler(void);
+
+#endif /* GD32F3X0_IT_H */

+ 42 - 0
Examples/CRC/Calculate_demo/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 77 - 0
Examples/CRC/Calculate_demo/main.c

@@ -0,0 +1,77 @@
+/*!
+    \file  main.c
+    \brief CRC calculate demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+#include <stdio.h>
+#include "gd32f3x0_eval.h"
+
+uint32_t vab1 = 0, success_flag = 0;
+uint32_t read32_1, read32_2, read32_3, read32_4, read32_5, read32_6, read32_7, read32_8;
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    gd_eval_led_init(LED1);
+
+    vab1 = (uint32_t)0xabcd1234;
+    rcu_periph_clock_enable(RCU_CRC);
+    
+    crc_deinit();
+    read32_1 = crc_single_data_calculate(vab1);
+
+    /* input reverse */
+    crc_deinit();
+    crc_input_data_reverse_config(CRC_INPUT_DATA_BYTE);
+    read32_2 = crc_single_data_calculate(vab1);
+
+    crc_deinit();
+    crc_input_data_reverse_config(CRC_INPUT_DATA_HALFWORD);
+    read32_3 = crc_single_data_calculate(vab1);
+
+    crc_deinit();
+    crc_input_data_reverse_config(CRC_INPUT_DATA_WORD);
+    read32_4 = crc_single_data_calculate(vab1);
+
+    /* output reverse */
+    crc_deinit();
+    crc_reverse_output_data_enable();
+    read32_5 = crc_single_data_calculate(vab1);
+
+    crc_deinit();
+    crc_input_data_reverse_config(CRC_INPUT_DATA_BYTE);
+    crc_reverse_output_data_enable();
+    read32_6 = crc_single_data_calculate(vab1);
+
+    crc_deinit();
+    crc_input_data_reverse_config(CRC_INPUT_DATA_HALFWORD);
+    crc_reverse_output_data_enable();
+    read32_7 = crc_single_data_calculate(vab1);
+
+    crc_deinit();
+    crc_input_data_reverse_config(CRC_INPUT_DATA_WORD);
+    crc_reverse_output_data_enable();
+    read32_8 = crc_single_data_calculate(vab1);
+
+    /* check the caculation result */
+    if((read32_1 == 0xf7018a40U)&&(read32_2 == 0x49fc6721U)&&(read32_3 == 0x606444e3U)&&(read32_4 == 0x16d70081U)
+        &&(read32_5 == 0x025180efU)&&(read32_6 == 0x84e63f92U)&&(read32_7 == 0xc7222606U)&&(read32_8 == 0x8100eb68U)){
+        success_flag = 0x1U;
+        gd_eval_led_on(LED1);
+    }
+
+    while (1);
+}

+ 16 - 0
Examples/CRC/Calculate_demo/readme.txt

@@ -0,0 +1,16 @@
+/*!
+    \file  readme.txt
+    \brief description of the CRC calculate demo
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This example is based on the GD32350R-EVAL board, it shows how to 
+configure the CRC module. In this demo, 8 CRC codes are calculated for a 32-bit
+data by configuring various control bits in the CRC control register.
+
+  If the test passes, the success_flag variable equals 0x1 and turn on the LED1.

+ 58 - 0
Examples/CRC/Calculate_demo/systick.c

@@ -0,0 +1,58 @@
+/*!
+    \file  systick.c
+    \brief the systick configuration file
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "systick.h"
+
+static uint32_t delay;
+
+/*!
+    \brief      configure systick
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void systick_config(void)
+{
+    /* setup systick timer for 1000Hz interrupts */
+    if (SysTick_Config(SystemCoreClock / 1000)){
+        /* capture error */
+        while (1);
+    }
+    /* configure the systick handler priority */
+    NVIC_SetPriority(SysTick_IRQn, 0x00);
+}
+
+/*!
+    \brief      delay a time in milliseconds
+    \param[in]  count: count in milliseconds
+    \param[out] none
+    \retval     none
+*/
+void delay_1ms(uint32_t count)
+{
+    delay = count;
+
+    while(0 != delay);
+}
+
+/*!
+    \brief      delay decrement
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void delay_decrement(void)
+{
+    if (0 != delay){ 
+        delay--;
+    }
+}

+ 24 - 0
Examples/CRC/Calculate_demo/systick.h

@@ -0,0 +1,24 @@
+/*!
+    \file  systick.h
+    \brief the header file of systick
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef SYS_TICK_H
+#define SYS_TICK_H
+
+#include <stdint.h>
+
+/* configure systick */
+void systick_config(void);
+/* delay a time in milliseconds */
+void delay_1ms(uint32_t count);
+/* delay decrement */
+void delay_decrement(void);
+
+#endif /* SYS_TICK_H */

+ 42 - 0
Examples/CTC/CTC_gpio/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 77 - 0
Examples/CTC/CTC_gpio/main.c

@@ -0,0 +1,77 @@
+/*!
+    \file  main.c
+    \brief CTC is used to trim internal 48MHz RC oscillator with GPIO
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "gd32f3x0_eval.h"
+
+void ctc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* init led1*/
+    gd_eval_led_init(LED1);
+    /* enable IRC48M clock */
+    rcu_osci_on(RCU_IRC48M);
+    /* wait till IRC48M is ready */
+    rcu_osci_stab_wait(RCU_IRC48M);
+
+    /* configure PA8 as external reference signal source input with 32khz */
+    rcu_periph_clock_enable(RCU_GPIOA);
+    gpio_af_set(GPIOA, GPIO_AF_6 ,GPIO_PIN_8);
+    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLDOWN, GPIO_PIN_8);
+    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_8);
+
+    /* CTC peripheral clock enable */
+    rcu_periph_clock_enable(RCU_CTC);
+    /* CTC config */
+    ctc_config();
+
+    while(1){
+        /* if the clock trim is OK */
+        if(RESET != ctc_flag_get(CTC_FLAG_CKOK)){
+            gd_eval_led_on(LED1);
+        }else{
+            gd_eval_led_off(LED1);
+        }
+    }
+}
+
+/*!
+    \brief      configure the CTC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void ctc_config(void)
+{
+    /* config CTC reference signal source prescaler */
+    ctc_refsource_prescaler_config(CTC_REFSOURCE_PSC_DIV32);
+    /* select reference signal source */
+    ctc_refsource_signal_select(CTC_REFSOURCE_GPIO);
+    /* select reference signal source polarity */
+    ctc_refsource_polarity_config(CTC_REFSOURCE_POLARITY_RISING);
+    /* config hardware automatically trim mode */
+    ctc_hardware_trim_mode_config(CTC_HARDWARE_TRIM_MODE_ENABLE);
+    
+    /* config CTC counter reload value, Fclock/Fref-1 */
+    ctc_counter_reload_value_config(0xBB7F);
+    /* config clock trim base limit value, Fclock/Fref*0.0012/2 */
+    ctc_clock_limit_value_config(0x1D);
+
+    /* CTC counter enable */
+    ctc_counter_enable();
+}

+ 18 - 0
Examples/CTC/CTC_gpio/readme.txt

@@ -0,0 +1,18 @@
+/*!
+    \file  readme.txt
+    \brief description of the CTC trim internal 48MHz RC oscillator with GPIO
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+  This example is based on the GD32350R-EVAL board, it shows CTC is used to trim internal
+48MHz RC oscillator with GPIO.
+
+  Connect the PA8 pin with the 32kHz square wave(the amplitude is 3.3V and the offset is 
+1.65V).
+
+  When the clock trim is OK, led1 will be on.

+ 42 - 0
Examples/CTC/CTC_lxtal/gd32f3x0_libopt.h

@@ -0,0 +1,42 @@
+/*!
+    \file  gd32f3x0_libopt.h
+    \brief library optional for gd32f3x0
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#ifndef GD32F3X0_LIBOPT_H
+#define GD32F3X0_LIBOPT_H
+
+#include "gd32f3x0_adc.h"
+#include "gd32f3x0_crc.h"
+#include "gd32f3x0_ctc.h"
+#include "gd32f3x0_dbg.h"
+#include "gd32f3x0_dma.h"
+#include "gd32f3x0_exti.h"
+#include "gd32f3x0_fmc.h"
+#include "gd32f3x0_gpio.h"
+#include "gd32f3x0_syscfg.h"
+#include "gd32f3x0_i2c.h"
+#include "gd32f3x0_fwdgt.h"
+#include "gd32f3x0_pmu.h"
+#include "gd32f3x0_rcu.h"
+#include "gd32f3x0_rtc.h"
+#include "gd32f3x0_spi.h"
+#include "gd32f3x0_timer.h"
+#include "gd32f3x0_usart.h"
+#include "gd32f3x0_wwdgt.h"
+#include "gd32f3x0_misc.h"
+#include "gd32f3x0_tsi.h"
+
+#ifdef GD32F350
+#include "gd32f3x0_cec.h"
+#include "gd32f3x0_cmp.h"
+#include "gd32f3x0_dac.h"
+#endif /* GD32F350 */
+
+#endif /* GD32F3X0_LIBOPT_H */

+ 82 - 0
Examples/CTC/CTC_lxtal/main.c

@@ -0,0 +1,82 @@
+/*!
+    \file  main.c
+    \brief CTC is used to trim internal 48MHz RC oscillator with LXTAL clock
+*/
+
+/*
+    Copyright (C) 2017 GigaDevice
+
+    2017-06-06, V1.0.0, firmware for GD32F3x0
+*/
+
+#include "gd32f3x0.h"
+#include "gd32f3x0_eval.h"
+
+void ctc_config(void);
+
+/*!
+    \brief      main function
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+int main(void)
+{
+    /* init led1*/
+    gd_eval_led_init(LED1);
+
+    /* enable IRC48M clock */
+    rcu_osci_on(RCU_IRC48M);
+    /* wait till IRC48M is ready */
+    rcu_osci_stab_wait(RCU_IRC48M);
+
+    /* LXTAL clock config */
+    rcu_periph_clock_enable(RCU_PMU);
+    pmu_backup_write_enable();
+
+    /* enable LXTAL clock */
+    rcu_osci_on(RCU_LXTAL);
+    /* wait till LXTAL is ready */
+    rcu_osci_stab_wait(RCU_LXTAL);
+    
+
+    /* CTC peripheral clock enable */
+    rcu_periph_clock_enable(RCU_CTC);
+    /* CTC config */
+    ctc_config();
+
+    while(1){
+        /* if the clock trim is OK */
+        if(ctc_flag_get(CTC_FLAG_CKOK) != RESET){
+            gd_eval_led_on(LED1);
+        }else{
+            gd_eval_led_off(LED1);
+        }
+    }
+}
+
+/*!
+    \brief      configure the CTC peripheral
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+void ctc_config(void)
+{
+    /* config CTC reference signal source prescaler */
+    ctc_refsource_prescaler_config(CTC_REFSOURCE_PSC_OFF);
+    /* select reference signal source */
+    ctc_refsource_signal_select(CTC_REFSOURCE_LXTAL);
+    /* select reference signal source polarity */
+    ctc_refsource_polarity_config(CTC_REFSOURCE_POLARITY_RISING);
+    /* config hardware automatically trim mode */
+    ctc_hardware_trim_mode_config(CTC_HARDWARE_TRIM_MODE_ENABLE);
+    
+    /* config CTC counter reload value, Fclock/Fref-1 */
+    ctc_counter_reload_value_config(0x05B8);
+    /* config clock trim base limit value, Fclock/Fref*0.0012/2 */
+    ctc_clock_limit_value_config(0x0002);
+
+    /* CTC counter enable */
+    ctc_counter_enable();
+}

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff