at32f413.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /**
  2. **************************************************************************
  3. * @file at32f413.h
  4. * @brief at32f413 header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #ifndef __AT32F413_H
  25. #define __AT32F413_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #if defined (__CC_ARM)
  30. #pragma anon_unions
  31. #endif
  32. /** @addtogroup CMSIS
  33. * @{
  34. */
  35. /** @addtogroup AT32F413
  36. * @{
  37. */
  38. /** @addtogroup Library_configuration_section
  39. * @{
  40. */
  41. /**
  42. * tip: to avoid modifying this file each time you need to switch between these
  43. * devices, you can define the device in your toolchain compiler preprocessor.
  44. */
  45. #if !defined (AT32F413KBU7_4) && !defined (AT32F413KCU7_4) && !defined (AT32F413CBU7) && \
  46. !defined (AT32F413CCU7) && !defined (AT32F413C8T7) && !defined (AT32F413CBT7) && \
  47. !defined (AT32F413CCT7) && !defined (AT32F413RBT7) && !defined (AT32F413RCT7) && \
  48. !defined (AT32FEBKC8T7) && !defined (AT32F413TBU7)
  49. #error "Please select first the target device used in your application (in at32f413.h file)"
  50. #endif
  51. #if defined (AT32F413KBU7_4) || defined (AT32F413KCU7_4) || defined (AT32F413CBU7) || \
  52. defined (AT32F413CCU7) || defined (AT32F413C8T7) || defined (AT32F413CBT7) || \
  53. defined (AT32F413CCT7) || defined (AT32F413RBT7) || defined (AT32F413RCT7) || \
  54. defined (AT32FEBKC8T7) || defined (AT32F413TBU7)
  55. #define AT32F413xx
  56. #endif
  57. /**
  58. * define with package
  59. */
  60. #if defined (AT32F413RBT7) || defined (AT32F413RCT7)
  61. #define AT32F413Rx
  62. #endif
  63. #if defined (AT32F413CBU7) || defined (AT32F413CCU7) || defined (AT32F413C8T7) || \
  64. defined (AT32F413CBT7) || defined (AT32F413CCT7)
  65. #define AT32F413Cx
  66. #endif
  67. #if defined (AT32F413KBU7_4) || defined (AT32F413KCU7_4)
  68. #define AT32F413Kx
  69. #endif
  70. /**
  71. * define with memory density
  72. */
  73. #if defined (AT32F413C8T7) || defined (AT32FEBKC8T7)
  74. #define AT32F413x8
  75. #endif
  76. #if defined (AT32F413KBU7_4) || defined (AT32F413CBU7) || defined (AT32F413CBT7) || \
  77. defined (AT32F413RBT7) || defined (AT32F413TBU7)
  78. #define AT32F413xB
  79. #endif
  80. #if defined (AT32F413KCU7_4) || defined (AT32F413CCU7) || defined (AT32F413CCT7) || \
  81. defined (AT32F413RCT7)
  82. #define AT32F413xC
  83. #endif
  84. #ifndef USE_STDPERIPH_DRIVER
  85. /**
  86. * @brief comment the line below if you will not use the peripherals drivers.
  87. * in this case, these drivers will not be included and the application code will
  88. * be based on direct access to peripherals registers
  89. */
  90. #ifdef _RTE_
  91. #include "RTE_Components.h"
  92. #ifdef RTE_DEVICE_STDPERIPH_FRAMEWORK
  93. #define USE_STDPERIPH_DRIVER
  94. #endif
  95. #endif
  96. #endif
  97. /**
  98. * @brief at32f413 standard peripheral library version number
  99. */
  100. #define __AT32F413_LIBRARY_VERSION_MAJOR (0x02) /*!< [31:24] major version */
  101. #define __AT32F413_LIBRARY_VERSION_MIDDLE (0x01) /*!< [23:16] middle version */
  102. #define __AT32F413_LIBRARY_VERSION_MINOR (0x03) /*!< [15:8] minor version */
  103. #define __AT32F413_LIBRARY_VERSION_RC (0x00) /*!< [7:0] release candidate */
  104. #define __AT32F413_LIBRARY_VERSION ((__AT32F413_LIBRARY_VERSION_MAJOR << 24) | \
  105. (__AT32F413_LIBRARY_VERSION_MIDDLE << 16) | \
  106. (__AT32F413_LIBRARY_VERSION_MINOR << 8) | \
  107. (__AT32F413_LIBRARY_VERSION_RC))
  108. /**
  109. * @}
  110. */
  111. /** @addtogroup Configuration_section_for_CMSIS
  112. * @{
  113. */
  114. /**
  115. * @brief configuration of the cortex-m4 processor and core peripherals
  116. */
  117. #define __CM4_REV 0x0001U /*!< core revision r0p1 */
  118. #define __MPU_PRESENT 1 /*!< mpu present */
  119. #define __NVIC_PRIO_BITS 4 /*!< at32 uses 4 bits for the priority levels */
  120. #define __Vendor_SysTickConfig 0 /*!< set to 1 if different systick config is used */
  121. #define __FPU_PRESENT 1U /*!< fpu present */
  122. /**
  123. * @brief at32f413 interrupt number definition, according to the selected device
  124. * in @ref Library_configuration_section
  125. */
  126. typedef enum IRQn
  127. {
  128. /****** cortex-m4 processor exceptions numbers ***************************************************/
  129. Reset_IRQn = -15, /*!< 1 reset vector, invoked on power up and warm reset */
  130. NonMaskableInt_IRQn = -14, /*!< 2 non maskable interrupt */
  131. HardFault_IRQn = -13, /*!< 3 hard fault, all classes of fault */
  132. MemoryManagement_IRQn = -12, /*!< 4 cortex-m4 memory management interrupt */
  133. BusFault_IRQn = -11, /*!< 5 cortex-m4 bus fault interrupt */
  134. UsageFault_IRQn = -10, /*!< 6 cortex-m4 usage fault interrupt */
  135. SVCall_IRQn = -5, /*!< 11 cortex-m4 sv call interrupt */
  136. DebugMonitor_IRQn = -4, /*!< 12 cortex-m4 debug monitor interrupt */
  137. PendSV_IRQn = -2, /*!< 14 cortex-m4 pend sv interrupt */
  138. SysTick_IRQn = -1, /*!< 15 cortex-m4 system tick interrupt */
  139. /****** at32 specific interrupt numbers *********************************************************/
  140. WWDT_IRQn = 0, /*!< window watchdog timer interrupt */
  141. PVM_IRQn = 1, /*!< pvm through exint line detection interrupt */
  142. TAMPER_IRQn = 2, /*!< tamper interrupt */
  143. RTC_IRQn = 3, /*!< rtc global interrupt */
  144. FLASH_IRQn = 4, /*!< flash global interrupt */
  145. CRM_IRQn = 5, /*!< crm global interrupt */
  146. EXINT0_IRQn = 6, /*!< external line0 interrupt */
  147. EXINT1_IRQn = 7, /*!< external line1 interrupt */
  148. EXINT2_IRQn = 8, /*!< external line2 interrupt */
  149. EXINT3_IRQn = 9, /*!< external line3 interrupt */
  150. EXINT4_IRQn = 10, /*!< external line4 interrupt */
  151. DMA1_Channel1_IRQn = 11, /*!< dma1 channel 1 global interrupt */
  152. DMA1_Channel2_IRQn = 12, /*!< dma1 channel 2 global interrupt */
  153. DMA1_Channel3_IRQn = 13, /*!< dma1 channel 3 global interrupt */
  154. DMA1_Channel4_IRQn = 14, /*!< dma1 channel 4 global interrupt */
  155. DMA1_Channel5_IRQn = 15, /*!< dma1 channel 5 global interrupt */
  156. DMA1_Channel6_IRQn = 16, /*!< dma1 channel 6 global interrupt */
  157. DMA1_Channel7_IRQn = 17, /*!< dma1 channel 7 global interrupt */
  158. ADC1_2_IRQn = 18, /*!< adc1 and adc2 global interrupt */
  159. USBFS_H_CAN1_TX_IRQn = 19, /*!< usb device high priority or can1 tx interrupts */
  160. USBFS_L_CAN1_RX0_IRQn = 20, /*!< usb device low priority or can1 rx0 interrupts */
  161. CAN1_RX1_IRQn = 21, /*!< can1 rx1 interrupt */
  162. CAN1_SE_IRQn = 22, /*!< can1 se interrupt */
  163. EXINT9_5_IRQn = 23, /*!< external line[9:5] interrupts */
  164. TMR1_BRK_TMR9_IRQn = 24, /*!< tmr1 brake interrupt */
  165. TMR1_OVF_TMR10_IRQn = 25, /*!< tmr1 overflow interrupt */
  166. TMR1_TRG_HALL_TMR11_IRQn = 26, /*!< tmr1 trigger and hall interrupt */
  167. TMR1_CH_IRQn = 27, /*!< tmr1 channel interrupt */
  168. TMR2_GLOBAL_IRQn = 28, /*!< tmr2 global interrupt */
  169. TMR3_GLOBAL_IRQn = 29, /*!< tmr3 global interrupt */
  170. TMR4_GLOBAL_IRQn = 30, /*!< tmr4 global interrupt */
  171. I2C1_EVT_IRQn = 31, /*!< i2c1 event interrupt */
  172. I2C1_ERR_IRQn = 32, /*!< i2c1 error interrupt */
  173. I2C2_EVT_IRQn = 33, /*!< i2c2 event interrupt */
  174. I2C2_ERR_IRQn = 34, /*!< i2c2 error interrupt */
  175. SPI1_IRQn = 35, /*!< spi1 global interrupt */
  176. SPI2_IRQn = 36, /*!< spi2 global interrupt */
  177. USART1_IRQn = 37, /*!< usart1 global interrupt */
  178. USART2_IRQn = 38, /*!< usart2 global interrupt */
  179. USART3_IRQn = 39, /*!< usart3 global interrupt */
  180. EXINT15_10_IRQn = 40, /*!< external line[15:10] interrupts */
  181. RTCAlarm_IRQn = 41, /*!< rtc alarm through exint line interrupt */
  182. USBFSWakeUp_IRQn = 42, /*!< usb device wakeup from suspend through exint line interrupt */
  183. TMR8_BRK_IRQn = 43, /*!< tmr8 brake interrupt */
  184. TMR8_OVF_IRQn = 44, /*!< tmr8 overflow interrupt */
  185. TMR8_TRG_HALL_IRQn = 45, /*!< tmr8 trigger and hall interrupt */
  186. TMR8_CH_IRQn = 46, /*!< tmr8 channel interrupt */
  187. SDIO1_IRQn = 49, /*!< sdio1 global interrupt */
  188. TMR5_GLOBAL_IRQn = 50, /*!< tmr5 global interrupt */
  189. UART4_IRQn = 52, /*!< uart4 global interrupt */
  190. UART5_IRQn = 53, /*!< uart5 global interrupt */
  191. DMA2_Channel1_IRQn = 56, /*!< dma2 channel 1 global interrupt */
  192. DMA2_Channel2_IRQn = 57, /*!< dma2 channel 2 global interrupt */
  193. DMA2_Channel3_IRQn = 58, /*!< dma2 channel 3 global interrupt */
  194. DMA2_Channel4_5_IRQn = 59, /*!< dma2 channel 4 and channel 5 global interrupt */
  195. CAN2_TX_IRQn = 68, /*!< can2 tx interrupt */
  196. CAN2_RX0_IRQn = 69, /*!< can2 rx0 interrupt */
  197. CAN2_RX1_IRQn = 70, /*!< can2 rx1 interrupt */
  198. CAN2_SE_IRQn = 71, /*!< can2 se interrupt */
  199. ACC_IRQn = 72, /*!< acc interrupt */
  200. USBFS_MAPH_IRQn = 73, /*!< usb map hp interrupt */
  201. USBFS_MAPL_IRQn = 74, /*!< usb map lp interrupt */
  202. DMA2_Channel6_7_IRQn = 75 /*!< dma2 channel 6 and channel 7 global interrupt */
  203. } IRQn_Type;
  204. /**
  205. * @}
  206. */
  207. #include "core_cm4.h"
  208. #include "system_at32f413.h"
  209. #include <stdint.h>
  210. /** @addtogroup Exported_types
  211. * @{
  212. */
  213. typedef int32_t INT32;
  214. typedef int16_t INT16;
  215. typedef int8_t INT8;
  216. typedef uint32_t UINT32;
  217. typedef uint16_t UINT16;
  218. typedef uint8_t UINT8;
  219. typedef int32_t s32;
  220. typedef int16_t s16;
  221. typedef int8_t s8;
  222. typedef const int32_t sc32; /*!< read only */
  223. typedef const int16_t sc16; /*!< read only */
  224. typedef const int8_t sc8; /*!< read only */
  225. typedef __IO int32_t vs32;
  226. typedef __IO int16_t vs16;
  227. typedef __IO int8_t vs8;
  228. typedef __I int32_t vsc32; /*!< read only */
  229. typedef __I int16_t vsc16; /*!< read only */
  230. typedef __I int8_t vsc8; /*!< read only */
  231. typedef uint32_t u32;
  232. typedef uint16_t u16;
  233. typedef uint8_t u8;
  234. typedef const uint32_t uc32; /*!< read only */
  235. typedef const uint16_t uc16; /*!< read only */
  236. typedef const uint8_t uc8; /*!< read only */
  237. typedef __IO uint32_t vu32;
  238. typedef __IO uint16_t vu16;
  239. typedef __IO uint8_t vu8;
  240. typedef __I uint32_t vuc32; /*!< read only */
  241. typedef __I uint16_t vuc16; /*!< read only */
  242. typedef __I uint8_t vuc8; /*!< read only */
  243. /**
  244. * @brief flag status
  245. */
  246. typedef enum {RESET = 0, SET = !RESET} flag_status;
  247. /**
  248. * @brief confirm state
  249. */
  250. typedef enum {FALSE = 0, TRUE = !FALSE} confirm_state;
  251. /**
  252. * @brief error status
  253. */
  254. typedef enum {ERROR = 0, SUCCESS = !ERROR} error_status;
  255. /**
  256. * @}
  257. */
  258. /** @addtogroup Exported_macro
  259. * @{
  260. */
  261. #define REG8(addr) *(volatile uint8_t *)(addr)
  262. #define REG16(addr) *(volatile uint16_t *)(addr)
  263. #define REG32(addr) *(volatile uint32_t *)(addr)
  264. #define MAKE_VALUE(reg_offset, bit_num) (uint32_t)(((reg_offset) << 16) | (bit_num & 0x1F))
  265. #define PERIPH_REG(periph_base, value) REG32((periph_base + (value >> 16)))
  266. #define PERIPH_REG_BIT(value) (0x1U << (value & 0x1F))
  267. /**
  268. * @}
  269. */
  270. /** @addtogroup Peripheral_memory_map
  271. * @{
  272. */
  273. #define FLASH_BASE ((uint32_t)0x08000000)
  274. #define SPIM_FLASH_BASE ((uint32_t)0x08400000)
  275. #define USD_BASE ((uint32_t)0x1FFFF800)
  276. #define SRAM_BASE ((uint32_t)0x20000000)
  277. #define PERIPH_BASE ((uint32_t)0x40000000)
  278. #define XMC_REG_BASE ((uint32_t)0xA0000000)
  279. #define DEBUG_BASE ((uint32_t)0xE0042000)
  280. #define APB1PERIPH_BASE (PERIPH_BASE + 0x00000)
  281. #define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
  282. #define AHBPERIPH_BASE (PERIPH_BASE + 0x20000)
  283. /* apb1 bus base address */
  284. #define TMR2_BASE (APB1PERIPH_BASE + 0x0000)
  285. #define TMR3_BASE (APB1PERIPH_BASE + 0x0400)
  286. #define TMR4_BASE (APB1PERIPH_BASE + 0x0800)
  287. #define TMR5_BASE (APB1PERIPH_BASE + 0x0C00)
  288. #define RTC_BASE (APB1PERIPH_BASE + 0x2800)
  289. #define WWDT_BASE (APB1PERIPH_BASE + 0x2C00)
  290. #define WDT_BASE (APB1PERIPH_BASE + 0x3000)
  291. #define SPI2_BASE (APB1PERIPH_BASE + 0x3800)
  292. #define USART2_BASE (APB1PERIPH_BASE + 0x4400)
  293. #define USART3_BASE (APB1PERIPH_BASE + 0x4800)
  294. #define UART4_BASE (APB1PERIPH_BASE + 0x4C00)
  295. #define UART5_BASE (APB1PERIPH_BASE + 0x5000)
  296. #define I2C1_BASE (APB1PERIPH_BASE + 0x5400)
  297. #define I2C2_BASE (APB1PERIPH_BASE + 0x5800)
  298. #define USBFS_BASE (APB1PERIPH_BASE + 0x5C00)
  299. #define CAN1_BASE (APB1PERIPH_BASE + 0x6400)
  300. #define CAN2_BASE (APB1PERIPH_BASE + 0x6800)
  301. #define BPR_BASE (APB1PERIPH_BASE + 0x6C00)
  302. #define PWC_BASE (APB1PERIPH_BASE + 0x7000)
  303. /* apb2 bus base address */
  304. #define IOMUX_BASE (APB2PERIPH_BASE + 0x0000)
  305. #define EXINT_BASE (APB2PERIPH_BASE + 0x0400)
  306. #define GPIOA_BASE (APB2PERIPH_BASE + 0x0800)
  307. #define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)
  308. #define GPIOC_BASE (APB2PERIPH_BASE + 0x1000)
  309. #define GPIOD_BASE (APB2PERIPH_BASE + 0x1400)
  310. #define GPIOF_BASE (APB2PERIPH_BASE + 0x1C00)
  311. #define ADC1_BASE (APB2PERIPH_BASE + 0x2400)
  312. #define ADC2_BASE (APB2PERIPH_BASE + 0x2800)
  313. #define TMR1_BASE (APB2PERIPH_BASE + 0x2C00)
  314. #define SPI1_BASE (APB2PERIPH_BASE + 0x3000)
  315. #define TMR8_BASE (APB2PERIPH_BASE + 0x3400)
  316. #define USART1_BASE (APB2PERIPH_BASE + 0x3800)
  317. #define TMR9_BASE (APB2PERIPH_BASE + 0x4C00)
  318. #define TMR10_BASE (APB2PERIPH_BASE + 0x5000)
  319. #define TMR11_BASE (APB2PERIPH_BASE + 0x5400)
  320. #define ACC_BASE (APB2PERIPH_BASE + 0x5800)
  321. #define SDIO1_BASE (APB2PERIPH_BASE + 0x8000)
  322. /* ahb bus base address */
  323. #define DMA1_BASE (AHBPERIPH_BASE + 0x0000)
  324. #define DMA1_CHANNEL1_BASE (AHBPERIPH_BASE + 0x0008)
  325. #define DMA1_CHANNEL2_BASE (AHBPERIPH_BASE + 0x001C)
  326. #define DMA1_CHANNEL3_BASE (AHBPERIPH_BASE + 0x0030)
  327. #define DMA1_CHANNEL4_BASE (AHBPERIPH_BASE + 0x0044)
  328. #define DMA1_CHANNEL5_BASE (AHBPERIPH_BASE + 0x0058)
  329. #define DMA1_CHANNEL6_BASE (AHBPERIPH_BASE + 0x006C)
  330. #define DMA1_CHANNEL7_BASE (AHBPERIPH_BASE + 0x0080)
  331. #define DMA2_BASE (AHBPERIPH_BASE + 0x0400)
  332. #define DMA2_CHANNEL1_BASE (AHBPERIPH_BASE + 0x0408)
  333. #define DMA2_CHANNEL2_BASE (AHBPERIPH_BASE + 0x041C)
  334. #define DMA2_CHANNEL3_BASE (AHBPERIPH_BASE + 0x0430)
  335. #define DMA2_CHANNEL4_BASE (AHBPERIPH_BASE + 0x0444)
  336. #define DMA2_CHANNEL5_BASE (AHBPERIPH_BASE + 0x0458)
  337. #define DMA2_CHANNEL6_BASE (AHBPERIPH_BASE + 0x046C)
  338. #define DMA2_CHANNEL7_BASE (AHBPERIPH_BASE + 0x0480)
  339. #define CRM_BASE (AHBPERIPH_BASE + 0x1000)
  340. #define FLASH_REG_BASE (AHBPERIPH_BASE + 0x2000)
  341. #define CRC_BASE (AHBPERIPH_BASE + 0x3000)
  342. /**
  343. * @}
  344. */
  345. /**
  346. * @}
  347. */
  348. /**
  349. * @}
  350. */
  351. #include "at32f413_def.h"
  352. #include "at32f413_conf.h"
  353. #ifdef __cplusplus
  354. }
  355. #endif
  356. #endif