gd32f3x0.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*!
  2. \file gd32f3x0.h
  3. \brief general definitions for gd32f3x0
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #ifndef GD32F3X0_H
  10. #define GD32F3X0_H
  11. #ifdef cplusplus
  12. extern "C" {
  13. #endif
  14. /* define GD32F3x0 */
  15. #if !defined (GD32F3x0)
  16. #define GD32F3x0
  17. #endif /* define GD32F3x0 */
  18. #if !defined (GD32F3x0)
  19. #error "Please select the target GD32F3x0 device used in your application (in gd32f3x0.h file)"
  20. #endif /* undefine GD32F3x0 tip */
  21. /* define GD32F3x0 device category */
  22. #if (!defined (GD32F330))&&(!defined (GD32F350))
  23. #error "Please select GD32F3x0 device category( GD32F330 or GD32F350 )"
  24. #endif /* undefine GD32F330 or GD32F350 tip */
  25. #if (defined (GD32F330))&&(defined (GD32F350))
  26. #error "Please select one GD32F3x0 device category( GD32F330 or GD32F350 )"
  27. #endif /* define GD32F330 and GD32F350 tip */
  28. /* define value of high speed crystal oscillator (HXTAL) in Hz */
  29. #if !defined (HXTAL_VALUE)
  30. #define HXTAL_VALUE ((uint32_t)8000000)
  31. #endif /* high speed crystal oscillator value */
  32. /* define startup timeout value of high speed crystal oscillator (HXTAL) */
  33. #if !defined (HXTAL_STARTUP_TIMEOUT)
  34. #define HXTAL_STARTUP_TIMEOUT ((uint16_t)0x0800)
  35. #endif /* high speed crystal oscillator startup timeout */
  36. /* define value of internal 8MHz RC oscillator (IRC8M) in Hz */
  37. #if !defined (IRC8M_VALUE)
  38. #define IRC8M_VALUE ((uint32_t)8000000)
  39. #endif /* internal 8MHz RC oscillator value */
  40. /* define startup timeout value of internal 8MHz RC oscillator (IRC8M) */
  41. #if !defined (IRC8M_STARTUP_TIMEOUT)
  42. #define IRC8M_STARTUP_TIMEOUT ((uint16_t)0x0500)
  43. #endif /* internal 8MHz RC oscillator startup timeout */
  44. /* define value of internal RC oscillator for ADC in Hz */
  45. #if !defined (IRC28M_VALUE)
  46. #define IRC28M_VALUE ((uint32_t)28000000)
  47. #endif /* IRC28M_VALUE */
  48. #if !defined (IRC48M_VALUE)
  49. #define IRC48M_VALUE ((uint32_t)48000000)
  50. #endif /* IRC48M_VALUE */
  51. /* define value of internal 40KHz RC oscillator(IRC40K) in Hz */
  52. #if !defined (IRC40K_VALUE)
  53. #define IRC40K_VALUE ((uint32_t)40000)
  54. #endif /* internal 40KHz RC oscillator value */
  55. /* define value of low speed crystal oscillator (LXTAL)in Hz */
  56. #if !defined (LXTAL_VALUE)
  57. #define LXTAL_VALUE ((uint32_t)32768)
  58. #endif /* low speed crystal oscillator value */
  59. /* GD32F3x0 firmware library version number V1.0 */
  60. #define __GD32F3x0_STDPERIPH_VERSION_MAIN (0x01) /*!< [31:24] main version */
  61. #define __GD32F3x0_STDPERIPH_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
  62. #define __GD32F3x0_STDPERIPH_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
  63. #define __GD32F3x0_STDPERIPH_VERSION_RC (0x00) /*!< [7:0] release candidate */
  64. #define __GD32F3x0_STDPERIPH_VERSION ((__GD32F3x0_STDPERIPH_VERSION_MAIN << 24)\
  65. |(__GD32F3x0_STDPERIPH_VERSION_SUB1 << 16)\
  66. |(__GD32F3x0_STDPERIPH_VERSION_SUB2 << 8)\
  67. |(__GD32F3x0_STDPERIPH_VERSION_RC))
  68. /* configuration of the Cortex-M4 processor and core peripherals */
  69. #define __CM4_REV 0x0001 /*!< Core revision r0p1 */
  70. #define __MPU_PRESENT 1 /*!< GD32F3x0 do not provide MPU */
  71. #define __NVIC_PRIO_BITS 4 /*!< GD32F3x0 uses 4 bits for the priority levels */
  72. #define __Vendor_SysTickConfig 0 /*!< set to 1 if different sysTick config is used */
  73. /* define interrupt number */
  74. typedef enum IRQn
  75. {
  76. /* Cortex-M4 processor exceptions numbers */
  77. NonMaskableInt_IRQn = -14, /*!< 2 non maskable interrupt */
  78. MemoryManagement_IRQn = -12, /*!< 4 Cortex-M4 memory management interrupt */
  79. BusFault_IRQn = -11, /*!< 5 Cortex-M4 bus fault interrupt */
  80. UsageFault_IRQn = -10, /*!< 6 Cortex-M4 usage fault interrupt */
  81. SVCall_IRQn = -5, /*!< 11 Cortex-M4 SV call interrupt */
  82. DebugMonitor_IRQn = -4, /*!< 12 Cortex-M4 debug monitor interrupt */
  83. PendSV_IRQn = -2, /*!< 14 Cortex-M4 pend SV interrupt */
  84. SysTick_IRQn = -1, /*!< 15 Cortex-M4 system tick interrupt */
  85. /* interruput numbers */
  86. WWDGT_IRQn = 0, /*!< window watchdog timer interrupt */
  87. LVD_IRQn = 1, /*!< LVD through EXTI line detect interrupt */
  88. RTC_IRQn = 2, /*!< RTC through EXTI line interrupt */
  89. FMC_IRQn = 3, /*!< FMC interrupt */
  90. RCU_IRQn = 4, /*!< RCU interrupt */
  91. EXTI0_1_IRQn = 5, /*!< EXTI line 0 and 1 interrupts */
  92. EXTI2_3_IRQn = 6, /*!< EXTI line 2 and 3 interrupts */
  93. EXTI4_15_IRQn = 7, /*!< EXTI line 4 to 15 interrupts */
  94. TSI_IRQn = 8, /*!< TSI Interrupt */
  95. DMA_Channel0_IRQn = 9, /*!< DMA channel 0 interrupt */
  96. DMA_Channel1_2_IRQn = 10, /*!< DMA channel 1 and channel 2 interrupts */
  97. DMA_Channel3_4_IRQn = 11, /*!< DMA channel 3 and channel 4 interrupts */
  98. ADC_CMP_IRQn = 12, /*!< ADC, CMP0 and CMP1 interrupts */
  99. TIMER0_BRK_UP_TRG_COM_IRQn = 13, /*!< TIMER0 break, update, trigger and commutation interrupts */
  100. TIMER0_CC_IRQn = 14, /*!< TIMER0 capture compare interrupt */
  101. TIMER1_IRQn = 15, /*!< TIMER1 interrupt */
  102. TIMER2_IRQn = 16, /*!< TIMER2 interrupt */
  103. #ifdef GD32F350
  104. TIMER5_DAC_IRQn = 17, /*!< TIMER5 and DAC interrupts */
  105. #endif /* GD32F350 */
  106. TIMER13_IRQn = 19, /*!< TIMER13 interrupt */
  107. TIMER14_IRQn = 20, /*!< TIMER14 interrupt */
  108. TIMER15_IRQn = 21, /*!< TIMER15 interrupt */
  109. TIMER16_IRQn = 22, /*!< TIMER16 interrupt */
  110. I2C0_EV_IRQn = 23, /*!< I2C0 event interrupt */
  111. I2C1_EV_IRQn = 24, /*!< I2C1 event interrupt */
  112. SPI0_IRQn = 25, /*!< SPI0 interrupt */
  113. SPI1_IRQn = 26, /*!< SPI1 interrupt */
  114. USART0_IRQn = 27, /*!< USART0 interrupt */
  115. USART1_IRQn = 28, /*!< USART1 interrupt */
  116. #ifdef GD32F350
  117. CEC_IRQn = 30, /*!< CEC interrupt */
  118. #endif /* GD32F350 */
  119. I2C0_ER_IRQn = 32, /*!< I2C0 error interrupt */
  120. I2C1_ER_IRQn = 34, /*!< I2C1 error interrupt */
  121. I2C2_EV_IRQn = 35, /*!< I2C2 event interrupt */
  122. I2C2_ER_IRQn = 36, /*!< I2C2 error interrupt */
  123. DMA_Channel5_6_IRQn = 48, /*!< DMA1 channel 5 and channel 6 interrupts */
  124. #ifdef GD32F350
  125. USBFS_WKUP_IRQn = 42, /*!< USBFS wakeup interrupt */
  126. #endif /* GD32F350 */
  127. SPI2_IRQn = 51, /*!< SPI2 global interrupt */
  128. #ifdef GD32F350
  129. USBFS_IRQn = 67, /*!< USBFS global interrupt */
  130. #endif /* GD32F350 */
  131. } IRQn_Type;
  132. /* includes */
  133. #include "core_cm4.h"
  134. #include "system_gd32f3x0.h"
  135. #include <stdint.h>
  136. /* enum definitions */
  137. typedef enum {DISABLE = 0, ENABLE = !DISABLE} EventStatus, ControlStatus;
  138. typedef enum {FALSE = 0, TRUE = !FALSE} bool;
  139. typedef enum {RESET = 0, SET = !RESET} FlagStatus;
  140. typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
  141. /* bit operations */
  142. #define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
  143. #define REG16(addr) (*(volatile uint16_t *)(uint32_t)(addr))
  144. #define REG8(addr) (*(volatile uint8_t *)(uint32_t)(addr))
  145. #define BIT(x) ((uint32_t)((uint32_t)0x01U<<(x)))
  146. #define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
  147. #define GET_BITS(regval, start, end) (((regval) & BITS((start),(end))) >> (start))
  148. /* main flash and SRAM memory map */
  149. #define FLASH_BASE ((uint32_t)0x08000000U) /*!< main FLASH base address */
  150. #define SRAM_BASE ((uint32_t)0x20000000U) /*!< SRAM base address */
  151. /* SRAM and peripheral base bit-band region */
  152. #define SRAM_BB_BASE ((uint32_t)0x22000000U) /*!< SRAM bit-band base address */
  153. #define PERIPH_BB_BASE ((uint32_t)0x42000000U) /*!< peripheral bit-band base address */
  154. /* peripheral memory map */
  155. #define APB1_BUS_BASE ((uint32_t)0x40000000U) /*!< apb1 base address */
  156. #define APB2_BUS_BASE ((uint32_t)0x40010000U) /*!< apb2 base address */
  157. #define AHB1_BUS_BASE ((uint32_t)0x40020000U) /*!< ahb1 base address */
  158. #define AHB2_BUS_BASE ((uint32_t)0x48000000U) /*!< ahb2 base address */
  159. /* advanced peripheral bus 1 memory map */
  160. #define TIMER_BASE (APB1_BUS_BASE + 0x00000000U) /*!< TIMER base address */
  161. #define RTC_BASE (APB1_BUS_BASE + 0x00002800U) /*!< RTC base address */
  162. #define WWDGT_BASE (APB1_BUS_BASE + 0x00002C00U) /*!< WWDGT base address */
  163. #define FWDGT_BASE (APB1_BUS_BASE + 0x00003000U) /*!< FWDGT base address */
  164. #define SPI_BASE (APB1_BUS_BASE + 0x00003800U) /*!< SPI base address */
  165. #define USART_BASE (APB1_BUS_BASE + 0x00004400U) /*!< USART base address */
  166. #define I2C_BASE (APB1_BUS_BASE + 0x00005400U) /*!< I2C base address */
  167. #define PMU_BASE (APB1_BUS_BASE + 0x00007000U) /*!< PMU base address */
  168. #define DAC_BASE (APB1_BUS_BASE + 0x00007400U) /*!< DAC base address */
  169. #define CEC_BASE (APB1_BUS_BASE + 0x00007800U) /*!< CEC base address */
  170. #define CTC_BASE (APB1_BUS_BASE + 0x0000C800U) /*!< CTC base address */
  171. /* advanced peripheral bus 2 memory map */
  172. #define SYSCFG_BASE (APB2_BUS_BASE + 0x00000000U) /*!< SYSCFG base address */
  173. #define CMP_BASE (APB2_BUS_BASE + 0x0000001CU) /*!< CMP base address */
  174. #define EXTI_BASE (APB2_BUS_BASE + 0x00000400U) /*!< EXTI base address */
  175. #define ADC_BASE (APB2_BUS_BASE + 0x00002400U) /*!< ADC base address */
  176. /* advanced high performance bus 1 memory map */
  177. #define DMA_BASE (AHB1_BUS_BASE + 0x00000000U) /*!< DMA base address */
  178. #define DMA_CHANNEL_BASE (DMA_BASE + 0x00000008U) /*!< DMA channel base address */
  179. #define RCU_BASE (AHB1_BUS_BASE + 0x00001000U) /*!< RCU base address */
  180. #define FMC_BASE (AHB1_BUS_BASE + 0x00002000U) /*!< FMC base address */
  181. #define CRC_BASE (AHB1_BUS_BASE + 0x00003000U) /*!< CRC base address */
  182. #define TSI_BASE (AHB1_BUS_BASE + 0x00004000U) /*!< TSI base address */
  183. #define USBFS_BASE (AHB1_BUS_BASE + 0x0FFE0000U) /*!< USBFS base address */
  184. /* advanced high performance bus 2 memory map */
  185. #define GPIO_BASE (AHB2_BUS_BASE + 0x00000000U) /*!< GPIO base address */
  186. /* option byte and debug memory map */
  187. #define OB_BASE ((uint32_t)0x1FFFF800U) /*!< OB base address */
  188. #define DBG_BASE ((uint32_t)0xE0042000U) /*!< DBG base address */
  189. /* define marco USE_STDPERIPH_DRIVER */
  190. #if !defined USE_STDPERIPH_DRIVER
  191. #define USE_STDPERIPH_DRIVER
  192. #endif
  193. #ifdef USE_STDPERIPH_DRIVER
  194. #include "gd32f3x0_libopt.h"
  195. #endif /* USE_STDPERIPH_DRIVER */
  196. #ifdef cplusplus
  197. }
  198. #endif
  199. #endif