at32f421_crm.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /**
  2. **************************************************************************
  3. * @file at32f421_crm.h
  4. * @brief at32f421 crm 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. /* define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F421_CRM_H
  26. #define __AT32F421_CRM_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* includes ------------------------------------------------------------------*/
  31. #include "at32f421.h"
  32. /** @addtogroup AT32F421_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup CRM
  36. * @{
  37. */
  38. #define CRM_REG(value) PERIPH_REG(CRM_BASE, value)
  39. #define CRM_REG_BIT(value) PERIPH_REG_BIT(value)
  40. /** @defgroup CRM_flags_definition
  41. * @brief crm flag
  42. * @{
  43. */
  44. #define CRM_HICK_STABLE_FLAG MAKE_VALUE(0x00, 1) /*!< high speed internal clock stable flag */
  45. #define CRM_HEXT_STABLE_FLAG MAKE_VALUE(0x00, 17) /*!< high speed external crystal stable flag */
  46. #define CRM_PLL_STABLE_FLAG MAKE_VALUE(0x00, 25) /*!< phase locking loop stable flag */
  47. #define CRM_LEXT_STABLE_FLAG MAKE_VALUE(0x20, 1) /*!< low speed external crystal stable flag */
  48. #define CRM_LICK_STABLE_FLAG MAKE_VALUE(0x24, 1) /*!< low speed internal clock stable flag */
  49. #define CRM_ALL_RESET_FLAG MAKE_VALUE(0x24, 24) /*!< all reset flag */
  50. #define CRM_NRST_RESET_FLAG MAKE_VALUE(0x24, 26) /*!< nrst pin reset flag */
  51. #define CRM_POR_RESET_FLAG MAKE_VALUE(0x24, 27) /*!< power on reset flag */
  52. #define CRM_SW_RESET_FLAG MAKE_VALUE(0x24, 28) /*!< software reset flag */
  53. #define CRM_WDT_RESET_FLAG MAKE_VALUE(0x24, 29) /*!< watchdog timer reset flag */
  54. #define CRM_WWDT_RESET_FLAG MAKE_VALUE(0x24, 30) /*!< window watchdog timer reset flag */
  55. #define CRM_LOWPOWER_RESET_FLAG MAKE_VALUE(0x24, 31) /*!< low-power reset flag */
  56. #define CRM_LICK_READY_INT_FLAG MAKE_VALUE(0x08, 0) /*!< low speed internal clock stable interrupt ready flag */
  57. #define CRM_LEXT_READY_INT_FLAG MAKE_VALUE(0x08, 1) /*!< low speed external crystal stable interrupt ready flag */
  58. #define CRM_HICK_READY_INT_FLAG MAKE_VALUE(0x08, 2) /*!< high speed internal clock stable interrupt ready flag */
  59. #define CRM_HEXT_READY_INT_FLAG MAKE_VALUE(0x08, 3) /*!< high speed external crystal stable interrupt ready flag */
  60. #define CRM_PLL_READY_INT_FLAG MAKE_VALUE(0x08, 4) /*!< phase locking loop stable interrupt ready flag */
  61. #define CRM_CLOCK_FAILURE_INT_FLAG MAKE_VALUE(0x08, 7) /*!< clock failure interrupt ready flag */
  62. /**
  63. * @}
  64. */
  65. /** @defgroup CRM_interrupts_definition
  66. * @brief crm interrupt
  67. * @{
  68. */
  69. #define CRM_LICK_STABLE_INT ((uint32_t)0x00000100) /*!< low speed internal clock stable interrupt */
  70. #define CRM_LEXT_STABLE_INT ((uint32_t)0x00000200) /*!< low speed external crystal stable interrupt */
  71. #define CRM_HICK_STABLE_INT ((uint32_t)0x00000400) /*!< high speed internal clock stable interrupt */
  72. #define CRM_HEXT_STABLE_INT ((uint32_t)0x00000800) /*!< high speed external crystal stable interrupt */
  73. #define CRM_PLL_STABLE_INT ((uint32_t)0x00001000) /*!< phase locking loop stable interrupt */
  74. #define CRM_CLOCK_FAILURE_INT ((uint32_t)0x00800000) /*!< clock failure interrupt */
  75. /**
  76. * @}
  77. */
  78. /** @defgroup CRM_exported_types
  79. * @{
  80. */
  81. /**
  82. * @brief crm periph clock
  83. */
  84. typedef enum
  85. {
  86. /* ahb periph */
  87. CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x14, 0), /*!< dma1 periph clock */
  88. CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x14, 6), /*!< crc periph clock */
  89. CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x14, 17), /*!< gpioa periph clock */
  90. CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x14, 18), /*!< gpiob periph clock */
  91. CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x14, 19), /*!< gpioc periph clock */
  92. CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x14, 22), /*!< gpiof periph clock */
  93. /* apb2 periph */
  94. CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x18, 0), /*!< scfg periph clock */
  95. CRM_CMP_PERIPH_CLOCK = MAKE_VALUE(0x18, 0), /*!< comparator periph clock */
  96. CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x18, 9), /*!< adc1 periph clock */
  97. CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x18, 11), /*!< tmr1 periph clock */
  98. CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x18, 12), /*!< spi1 periph clock */
  99. CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x18, 14), /*!< usart1 periph clock */
  100. CRM_TMR15_PERIPH_CLOCK = MAKE_VALUE(0x18, 16), /*!< tmr15 periph clock */
  101. CRM_TMR16_PERIPH_CLOCK = MAKE_VALUE(0x18, 17), /*!< tmr16 periph clock */
  102. CRM_TMR17_PERIPH_CLOCK = MAKE_VALUE(0x18, 18), /*!< tmr17 periph clock */
  103. /* apb1 periph */
  104. CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x1C, 1), /*!< tmr3 periph clock */
  105. CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x1C, 4), /*!< tmr6 periph clock */
  106. CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x1C, 8), /*!< tmr14 periph clock */
  107. CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x1C, 11), /*!< wwdt periph clock */
  108. CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x1C, 14), /*!< spi2 periph clock */
  109. CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x1C, 17), /*!< usart2 periph clock */
  110. CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x1C, 21), /*!< i2c1 periph clock */
  111. CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x1C, 22), /*!< i2c2 periph clock */
  112. CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x1C, 28), /*!< pwc periph clock */
  113. } crm_periph_clock_type;
  114. /**
  115. * @brief crm periph reset
  116. */
  117. typedef enum
  118. {
  119. /* ahb periph */
  120. CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x28, 17), /*!< gpioa periph reset */
  121. CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x28, 18), /*!< gpiob periph reset */
  122. CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x28, 19), /*!< gpioc periph reset */
  123. CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x28, 22), /*!< gpiof periph reset */
  124. /* apb2 periph */
  125. CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x0C, 0), /*!< scfg periph reset */
  126. CRM_CMP_PERIPH_RESET = MAKE_VALUE(0x0C, 0), /*!< comparator periph reset */
  127. CRM_EXINT_PERIPH_RESET = MAKE_VALUE(0x0C, 1), /*!< exint periph reset */
  128. CRM_ADC1_PERIPH_RESET = MAKE_VALUE(0x0C, 9), /*!< adc1 periph reset */
  129. CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x0C, 11), /*!< tmr1 periph reset */
  130. CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x0C, 12), /*!< spi2 periph reset */
  131. CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x0C, 14), /*!< usart1 periph reset */
  132. CRM_TMR15_PERIPH_RESET = MAKE_VALUE(0x0C, 16), /*!< tmr15 periph reset */
  133. CRM_TMR16_PERIPH_RESET = MAKE_VALUE(0x0C, 17), /*!< tmr16 periph reset */
  134. CRM_TMR17_PERIPH_RESET = MAKE_VALUE(0x0C, 18), /*!< tmr17 periph reset */
  135. /* apb1 periph */
  136. CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< tmr3 periph reset */
  137. CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< tmr6 periph reset */
  138. CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x10, 8), /*!< tmr14 periph reset */
  139. CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x10, 11), /*!< wwdt periph reset */
  140. CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x10, 14), /*!< spi2 periph reset */
  141. CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x10, 17), /*!< usart2 periph reset */
  142. CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< i2c1 periph reset */
  143. CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< i2c2 periph reset */
  144. CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x10, 28), /*!< pwc periph reset */
  145. } crm_periph_reset_type;
  146. /**
  147. * @brief crm periph clock in sleep mode
  148. */
  149. typedef enum
  150. {
  151. /* ahb periph */
  152. CRM_SRAM_PERIPH_CLOCK_SLEEP_MODE = MAKE_VALUE(0x14, 2), /*!< sram sleep mode periph clock */
  153. CRM_FLASH_PERIPH_CLOCK_SLEEP_MODE = MAKE_VALUE(0x14, 4) /*!< flash sleep mode periph clock */
  154. } crm_periph_clock_sleepmd_type;
  155. /**
  156. * @brief crm pll mult_x
  157. */
  158. typedef enum
  159. {
  160. CRM_PLL_MULT_2 = 0, /*!< pll multiplication factor 2 */
  161. CRM_PLL_MULT_3 = 1, /*!< pll multiplication factor 3 */
  162. CRM_PLL_MULT_4 = 2, /*!< pll multiplication factor 4 */
  163. CRM_PLL_MULT_5 = 3, /*!< pll multiplication factor 5 */
  164. CRM_PLL_MULT_6 = 4, /*!< pll multiplication factor 6 */
  165. CRM_PLL_MULT_7 = 5, /*!< pll multiplication factor 7 */
  166. CRM_PLL_MULT_8 = 6, /*!< pll multiplication factor 8 */
  167. CRM_PLL_MULT_9 = 7, /*!< pll multiplication factor 9 */
  168. CRM_PLL_MULT_10 = 8, /*!< pll multiplication factor 10 */
  169. CRM_PLL_MULT_11 = 9, /*!< pll multiplication factor 11 */
  170. CRM_PLL_MULT_12 = 10, /*!< pll multiplication factor 12 */
  171. CRM_PLL_MULT_13 = 11, /*!< pll multiplication factor 13 */
  172. CRM_PLL_MULT_14 = 12, /*!< pll multiplication factor 14 */
  173. CRM_PLL_MULT_15 = 13, /*!< pll multiplication factor 15 */
  174. CRM_PLL_MULT_16 = 15, /*!< pll multiplication factor 16 */
  175. CRM_PLL_MULT_17 = 16, /*!< pll multiplication factor 17 */
  176. CRM_PLL_MULT_18 = 17, /*!< pll multiplication factor 18 */
  177. CRM_PLL_MULT_19 = 18, /*!< pll multiplication factor 19 */
  178. CRM_PLL_MULT_20 = 19, /*!< pll multiplication factor 20 */
  179. CRM_PLL_MULT_21 = 20, /*!< pll multiplication factor 21 */
  180. CRM_PLL_MULT_22 = 21, /*!< pll multiplication factor 22 */
  181. CRM_PLL_MULT_23 = 22, /*!< pll multiplication factor 23 */
  182. CRM_PLL_MULT_24 = 23, /*!< pll multiplication factor 24 */
  183. CRM_PLL_MULT_25 = 24, /*!< pll multiplication factor 25 */
  184. CRM_PLL_MULT_26 = 25, /*!< pll multiplication factor 26 */
  185. CRM_PLL_MULT_27 = 26, /*!< pll multiplication factor 27 */
  186. CRM_PLL_MULT_28 = 27, /*!< pll multiplication factor 28 */
  187. CRM_PLL_MULT_29 = 28, /*!< pll multiplication factor 29 */
  188. CRM_PLL_MULT_30 = 29, /*!< pll multiplication factor 30 */
  189. CRM_PLL_MULT_31 = 30, /*!< pll multiplication factor 31 */
  190. CRM_PLL_MULT_32 = 31, /*!< pll multiplication factor 32 */
  191. CRM_PLL_MULT_33 = 32, /*!< pll multiplication factor 33 */
  192. CRM_PLL_MULT_34 = 33, /*!< pll multiplication factor 34 */
  193. CRM_PLL_MULT_35 = 34, /*!< pll multiplication factor 35 */
  194. CRM_PLL_MULT_36 = 35, /*!< pll multiplication factor 36 */
  195. CRM_PLL_MULT_37 = 36, /*!< pll multiplication factor 37 */
  196. CRM_PLL_MULT_38 = 37, /*!< pll multiplication factor 38 */
  197. CRM_PLL_MULT_39 = 38, /*!< pll multiplication factor 39 */
  198. CRM_PLL_MULT_40 = 39, /*!< pll multiplication factor 40 */
  199. CRM_PLL_MULT_41 = 40, /*!< pll multiplication factor 41 */
  200. CRM_PLL_MULT_42 = 41, /*!< pll multiplication factor 42 */
  201. CRM_PLL_MULT_43 = 42, /*!< pll multiplication factor 43 */
  202. CRM_PLL_MULT_44 = 43, /*!< pll multiplication factor 44 */
  203. CRM_PLL_MULT_45 = 44, /*!< pll multiplication factor 45 */
  204. CRM_PLL_MULT_46 = 45, /*!< pll multiplication factor 46 */
  205. CRM_PLL_MULT_47 = 46, /*!< pll multiplication factor 47 */
  206. CRM_PLL_MULT_48 = 47, /*!< pll multiplication factor 48 */
  207. CRM_PLL_MULT_49 = 48, /*!< pll multiplication factor 49 */
  208. CRM_PLL_MULT_50 = 49, /*!< pll multiplication factor 50 */
  209. CRM_PLL_MULT_51 = 50, /*!< pll multiplication factor 51 */
  210. CRM_PLL_MULT_52 = 51, /*!< pll multiplication factor 52 */
  211. CRM_PLL_MULT_53 = 52, /*!< pll multiplication factor 53 */
  212. CRM_PLL_MULT_54 = 53, /*!< pll multiplication factor 54 */
  213. CRM_PLL_MULT_55 = 54, /*!< pll multiplication factor 55 */
  214. CRM_PLL_MULT_56 = 55, /*!< pll multiplication factor 56 */
  215. CRM_PLL_MULT_57 = 56, /*!< pll multiplication factor 57 */
  216. CRM_PLL_MULT_58 = 57, /*!< pll multiplication factor 58 */
  217. CRM_PLL_MULT_59 = 58, /*!< pll multiplication factor 59 */
  218. CRM_PLL_MULT_60 = 59, /*!< pll multiplication factor 60 */
  219. CRM_PLL_MULT_61 = 60, /*!< pll multiplication factor 61 */
  220. CRM_PLL_MULT_62 = 61, /*!< pll multiplication factor 62 */
  221. CRM_PLL_MULT_63 = 62, /*!< pll multiplication factor 63 */
  222. CRM_PLL_MULT_64 = 63 /*!< pll multiplication factor 64 */
  223. } crm_pll_mult_type;
  224. /**
  225. * @brief crm pll fref_x
  226. */
  227. typedef enum
  228. {
  229. CRM_PLL_FREF_4M = 0, /*!< pll refrence clock between 3.9 mhz and 5 mhz */
  230. CRM_PLL_FREF_6M = 1, /*!< pll refrence clock between 5.2 mhz and 6.25 mhz */
  231. CRM_PLL_FREF_8M = 2, /*!< pll refrence clock between 7.8125 mhz and 8.33 mhz */
  232. CRM_PLL_FREF_12M = 3, /*!< pll refrence clock between 8.33 mhz and 12.5 mhz */
  233. CRM_PLL_FREF_16M = 4, /*!< pll refrence clock between 15.625 mhz and 20.83 mhz */
  234. CRM_PLL_FREF_25M = 5, /*!< pll refrence clock between 20.83 mhz and 31.255 mhz */
  235. } crm_pll_fref_type;
  236. /**
  237. * @brief crm pll clock source
  238. */
  239. typedef enum
  240. {
  241. CRM_PLL_SOURCE_HICK = 0x00, /*!< high speed internal clock as pll reference clock source */
  242. CRM_PLL_SOURCE_HEXT = 0x01, /*!< high speed external crystal as pll reference clock source */
  243. CRM_PLL_SOURCE_HEXT_DIV = 0x02 /*!< high speed external crystal div as pll reference clock source */
  244. } crm_pll_clock_source_type;
  245. /**
  246. * @brief crm pll fr
  247. */
  248. typedef enum
  249. {
  250. CRM_PLL_FR_1 = 0x00, /*!< pll post-division div1 */
  251. CRM_PLL_FR_2 = 0x01, /*!< pll post-division div2 */
  252. CRM_PLL_FR_4 = 0x02, /*!< pll post-division div4 */
  253. CRM_PLL_FR_8 = 0x03, /*!< pll post-division div8 */
  254. CRM_PLL_FR_16 = 0x04, /*!< pll post-division div16 */
  255. CRM_PLL_FR_32 = 0x05 /*!< pll post-division div32 */
  256. } crm_pll_fr_type;
  257. /**
  258. * @brief crm clock source
  259. */
  260. typedef enum
  261. {
  262. CRM_CLOCK_SOURCE_HICK = 0x00, /*!< high speed internal clock */
  263. CRM_CLOCK_SOURCE_HEXT = 0x01, /*!< high speed external crystal */
  264. CRM_CLOCK_SOURCE_PLL = 0x02, /*!< phase locking loop */
  265. CRM_CLOCK_SOURCE_LEXT = 0x03, /*!< low speed external crystal */
  266. CRM_CLOCK_SOURCE_LICK = 0x04 /*!< low speed internal clock */
  267. } crm_clock_source_type;
  268. /**
  269. * @brief crm ahb division
  270. */
  271. typedef enum
  272. {
  273. CRM_AHB_DIV_1 = 0x00, /*!< sclk div1 to ahbclk */
  274. CRM_AHB_DIV_2 = 0x08, /*!< sclk div2 to ahbclk */
  275. CRM_AHB_DIV_4 = 0x09, /*!< sclk div4 to ahbclk */
  276. CRM_AHB_DIV_8 = 0x0A, /*!< sclk div8 to ahbclk */
  277. CRM_AHB_DIV_16 = 0x0B, /*!< sclk div16 to ahbclk */
  278. CRM_AHB_DIV_64 = 0x0C, /*!< sclk div64 to ahbclk */
  279. CRM_AHB_DIV_128 = 0x0D, /*!< sclk div128 to ahbclk */
  280. CRM_AHB_DIV_256 = 0x0E, /*!< sclk div256 to ahbclk */
  281. CRM_AHB_DIV_512 = 0x0F /*!< sclk div512 to ahbclk */
  282. } crm_ahb_div_type;
  283. /**
  284. * @brief crm apb1 division
  285. */
  286. typedef enum
  287. {
  288. CRM_APB1_DIV_1 = 0x00, /*!< ahbclk div1 to apb1clk */
  289. CRM_APB1_DIV_2 = 0x04, /*!< ahbclk div2 to apb1clk */
  290. CRM_APB1_DIV_4 = 0x05, /*!< ahbclk div4 to apb1clk */
  291. CRM_APB1_DIV_8 = 0x06, /*!< ahbclk div8 to apb1clk */
  292. CRM_APB1_DIV_16 = 0x07 /*!< ahbclk div16 to apb1clk */
  293. } crm_apb1_div_type;
  294. /**
  295. * @brief crm apb2 division
  296. */
  297. typedef enum
  298. {
  299. CRM_APB2_DIV_1 = 0x00, /*!< ahbclk div1 to apb2clk */
  300. CRM_APB2_DIV_2 = 0x04, /*!< ahbclk div2 to apb2clk */
  301. CRM_APB2_DIV_4 = 0x05, /*!< ahbclk div4 to apb2clk */
  302. CRM_APB2_DIV_8 = 0x06, /*!< ahbclk div8 to apb2clk */
  303. CRM_APB2_DIV_16 = 0x07 /*!< ahbclk div16 to apb2clk */
  304. } crm_apb2_div_type;
  305. /**
  306. * @brief crm adc division
  307. */
  308. typedef enum
  309. {
  310. CRM_ADC_DIV_2 = 0x00, /*!< apb2clk div2 to adcclk */
  311. CRM_ADC_DIV_4 = 0x01, /*!< apb2clk div4 to adcclk */
  312. CRM_ADC_DIV_6 = 0x02, /*!< apb2clk div6 to adcclk */
  313. CRM_ADC_DIV_8 = 0x03, /*!< apb2clk div8 to adcclk */
  314. CRM_ADC_DIV_12 = 0x05, /*!< apb2clk div12 to adcclk */
  315. CRM_ADC_DIV_16 = 0x07 /*!< apb2clk div16 to adcclk */
  316. } crm_adc_div_type;
  317. /**
  318. * @brief crm ertc clock
  319. */
  320. typedef enum
  321. {
  322. CRM_ERTC_CLOCK_NOCLK = 0x00, /*!< no clock as ertc clock source */
  323. CRM_ERTC_CLOCK_LEXT = 0x01, /*!< low speed external crystal as ertc clock source */
  324. CRM_ERTC_CLOCK_LICK = 0x02, /*!< low speed internal clock as ertc clock source */
  325. CRM_ERTC_CLOCK_HEXT_DIV = 0x03 /*!< high speed external crystal div as ertc clock source */
  326. } crm_ertc_clock_type;
  327. /**
  328. * @brief crm hick 48mhz division
  329. */
  330. typedef enum
  331. {
  332. CRM_HICK48_DIV6 = 0x00, /*!< high speed internal clock (48 mhz) div6 */
  333. CRM_HICK48_NODIV = 0x01 /*!< high speed internal clock (48 mhz) no div */
  334. } crm_hick_div_6_type;
  335. /**
  336. * @brief crm sclk select
  337. */
  338. typedef enum
  339. {
  340. CRM_SCLK_HICK = 0x00, /*!< select high speed internal clock as sclk */
  341. CRM_SCLK_HEXT = 0x01, /*!< select high speed external crystal as sclk */
  342. CRM_SCLK_PLL = 0x02 /*!< select phase locking loop clock as sclk */
  343. } crm_sclk_type;
  344. /**
  345. * @brief crm clkout select
  346. */
  347. typedef enum
  348. {
  349. CRM_CLKOUT_NOCLK = 0x00, /*!< output no clock to clkout pin */
  350. CRM_CLKOUT_LICK = 0x02, /*!< output low speed internal clock to clkout pin */
  351. CRM_CLKOUT_LEXT = 0x03, /*!< output low speed external crystal to clkout pin */
  352. CRM_CLKOUT_SCLK = 0x04, /*!< output system clock to clkout pin */
  353. CRM_CLKOUT_HICK = 0x05, /*!< output high speed internal clock to clkout pin */
  354. CRM_CLKOUT_HEXT = 0x06, /*!< output high speed external crystal to clkout pin */
  355. CRM_CLKOUT_PLL_DIV_2 = 0x07, /*!< output phase locking loop clock div2 to clkout pin */
  356. CRM_CLKOUT_PLL_DIV_4 = 0x0C, /*!< output phase locking loop clock div4 to clkout pin */
  357. CRM_CLKOUT_ADC = 0x0E /*!< output adcclk to clkout pin */
  358. } crm_clkout_select_type;
  359. /**
  360. * @brief crm clkout division
  361. */
  362. typedef enum
  363. {
  364. CRM_CLKOUT_DIV_1 = 0x00, /*!< clkout div1 */
  365. CRM_CLKOUT_DIV_2 = 0x08, /*!< clkout div2 */
  366. CRM_CLKOUT_DIV_4 = 0x09, /*!< clkout div4 */
  367. CRM_CLKOUT_DIV_8 = 0x0A, /*!< clkout div8 */
  368. CRM_CLKOUT_DIV_16 = 0x0B, /*!< clkout div16 */
  369. CRM_CLKOUT_DIV_64 = 0x0C, /*!< clkout div64 */
  370. CRM_CLKOUT_DIV_128 = 0x0D, /*!< clkout div128 */
  371. CRM_CLKOUT_DIV_256 = 0x0E, /*!< clkout div256 */
  372. CRM_CLKOUT_DIV_512 = 0x0F /*!< clkout div512 */
  373. } crm_clkout_div_type;
  374. /**
  375. * @brief crm auto step mode
  376. */
  377. typedef enum
  378. {
  379. CRM_AUTO_STEP_MODE_DISABLE = 0x00, /*!< disable auto step mode */
  380. CRM_AUTO_STEP_MODE_ENABLE = 0x03 /*!< enable auto step mode */
  381. } crm_auto_step_mode_type;
  382. /**
  383. * @brief crm hick as system clock frequency select
  384. */
  385. typedef enum
  386. {
  387. CRM_HICK_SCLK_8MHZ = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */
  388. CRM_HICK_SCLK_48MHZ = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */
  389. } crm_hick_sclk_frequency_type;
  390. /**
  391. * @brief crm clocks freqency structure
  392. */
  393. typedef struct
  394. {
  395. uint32_t sclk_freq; /*!< system clock frequency */
  396. uint32_t ahb_freq; /*!< ahb bus clock frequency */
  397. uint32_t apb2_freq; /*!< apb2 bus clock frequency */
  398. uint32_t apb1_freq; /*!< apb1 bus clock frequency */
  399. uint32_t adc_freq; /*!< adc clock frequency */
  400. } crm_clocks_freq_type;
  401. /**
  402. * @brief type define crm register all
  403. */
  404. typedef struct
  405. {
  406. /**
  407. * @brief crm ctrl register, offset:0x00
  408. */
  409. union
  410. {
  411. __IO uint32_t ctrl;
  412. struct
  413. {
  414. __IO uint32_t hicken : 1; /* [0] */
  415. __IO uint32_t hickstbl : 1; /* [1] */
  416. __IO uint32_t hicktrim : 6; /* [7:2] */
  417. __IO uint32_t hickcal : 8; /* [15:8] */
  418. __IO uint32_t hexten : 1; /* [16] */
  419. __IO uint32_t hextstbl : 1; /* [17] */
  420. __IO uint32_t hextbyps : 1; /* [18] */
  421. __IO uint32_t cfden : 1; /* [19] */
  422. __IO uint32_t reserved1 : 4; /* [23:20] */
  423. __IO uint32_t pllen : 1; /* [24] */
  424. __IO uint32_t pllstbl : 1; /* [25] */
  425. __IO uint32_t reserved2 : 6; /* [31:26] */
  426. } ctrl_bit;
  427. };
  428. /**
  429. * @brief crm cfg register, offset:0x04
  430. */
  431. union
  432. {
  433. __IO uint32_t cfg;
  434. struct
  435. {
  436. __IO uint32_t sclksel : 2; /* [1:0] */
  437. __IO uint32_t sclksts : 2; /* [3:2] */
  438. __IO uint32_t ahbdiv : 4; /* [7:4] */
  439. __IO uint32_t apb1div : 3; /* [10:8] */
  440. __IO uint32_t apb2div : 3; /* [13:11] */
  441. __IO uint32_t adcdiv_l : 2; /* [15:14] */
  442. __IO uint32_t pllrcs : 1; /* [16] */
  443. __IO uint32_t pllhextdiv : 1; /* [17] */
  444. __IO uint32_t pllmult_l : 4; /* [21:18] */
  445. __IO uint32_t reserved1 : 2; /* [23:22] */
  446. __IO uint32_t clkout_sel : 3; /* [26:24] */
  447. __IO uint32_t reserved2 : 1; /* [27] */
  448. __IO uint32_t adcdiv_h : 1; /* [28] */
  449. __IO uint32_t pllmult_h : 2; /* [30:29] */
  450. __IO uint32_t reserved3 : 1; /* [31] */
  451. } cfg_bit;
  452. };
  453. /**
  454. * @brief crm clkint register, offset:0x08
  455. */
  456. union
  457. {
  458. __IO uint32_t clkint;
  459. struct
  460. {
  461. __IO uint32_t lickstblf : 1; /* [0] */
  462. __IO uint32_t lextstblf : 1; /* [1] */
  463. __IO uint32_t hickstblf : 1; /* [2] */
  464. __IO uint32_t hextstblf : 1; /* [3] */
  465. __IO uint32_t pllstblf : 1; /* [4] */
  466. __IO uint32_t reserved1 : 2; /* [6:5] */
  467. __IO uint32_t cfdf : 1; /* [7] */
  468. __IO uint32_t lickstblien : 1; /* [8] */
  469. __IO uint32_t lextstblien : 1; /* [9] */
  470. __IO uint32_t hickstblien : 1; /* [10] */
  471. __IO uint32_t hextstblien : 1; /* [11] */
  472. __IO uint32_t pllstblien : 1; /* [12] */
  473. __IO uint32_t reserved2 : 3; /* [15:13] */
  474. __IO uint32_t lickstblfc : 1; /* [16] */
  475. __IO uint32_t lextstblfc : 1; /* [17] */
  476. __IO uint32_t hickstblfc : 1; /* [18] */
  477. __IO uint32_t hextstblfc : 1; /* [19] */
  478. __IO uint32_t pllstblfc : 1; /* [20] */
  479. __IO uint32_t reserved3 : 2; /* [22:21] */
  480. __IO uint32_t cfdfc : 1; /* [23] */
  481. __IO uint32_t reserved4 : 8; /* [31:24] */
  482. } clkint_bit;
  483. };
  484. /**
  485. * @brief crm apb2rst register, offset:0x0C
  486. */
  487. union
  488. {
  489. __IO uint32_t apb2rst;
  490. struct
  491. {
  492. __IO uint32_t scfgcmprst : 1; /* [0] */
  493. __IO uint32_t exintrst : 1; /* [1] */
  494. __IO uint32_t reserved1 : 7; /* [8:2] */
  495. __IO uint32_t adc1rst : 1; /* [9] */
  496. __IO uint32_t reserved2 : 1; /* [10] */
  497. __IO uint32_t tmr1rst : 1; /* [11] */
  498. __IO uint32_t spi1rst : 1; /* [12] */
  499. __IO uint32_t reserved3 : 1; /* [13] */
  500. __IO uint32_t usart1rst : 1; /* [14] */
  501. __IO uint32_t reserved4 : 1; /* [15] */
  502. __IO uint32_t tmr15rst : 1; /* [16] */
  503. __IO uint32_t tmr16rst : 1; /* [17] */
  504. __IO uint32_t tmr17rst : 1; /* [18] */
  505. __IO uint32_t reserved5 : 13;/* [31:19] */
  506. } apb2rst_bit;
  507. };
  508. /**
  509. * @brief crm apb1rst register, offset:0x10
  510. */
  511. union
  512. {
  513. __IO uint32_t apb1rst;
  514. struct
  515. {
  516. __IO uint32_t reserved1 : 1; /* [0] */
  517. __IO uint32_t tmr3rst : 1; /* [1] */
  518. __IO uint32_t reserved2 : 2; /* [3:2] */
  519. __IO uint32_t tmr6rst : 1; /* [4] */
  520. __IO uint32_t reserved3 : 3; /* [7:5] */
  521. __IO uint32_t tmr14rst : 1; /* [8] */
  522. __IO uint32_t reserved4 : 2; /* [10:9] */
  523. __IO uint32_t wwdtrst : 1; /* [11] */
  524. __IO uint32_t reserved5 : 2; /* [13:12] */
  525. __IO uint32_t spi2rst : 1; /* [14] */
  526. __IO uint32_t reserved6 : 2; /* [16:15] */
  527. __IO uint32_t usart2rst : 1; /* [17] */
  528. __IO uint32_t reserved7 : 3; /* [20:18] */
  529. __IO uint32_t i2c1rst : 1; /* [21] */
  530. __IO uint32_t i2c2rst : 1; /* [22] */
  531. __IO uint32_t reserved8 : 5; /* [27:23] */
  532. __IO uint32_t pwcrst : 1; /* [28] */
  533. __IO uint32_t reserved9 : 3; /* [31:29] */
  534. } apb1rst_bit;
  535. };
  536. /**
  537. * @brief crm ahben register, offset:0x14
  538. */
  539. union
  540. {
  541. __IO uint32_t ahben;
  542. struct
  543. {
  544. __IO uint32_t dma1en : 1; /* [0] */
  545. __IO uint32_t reserved1 : 1; /* [1] */
  546. __IO uint32_t sramen : 1; /* [2] */
  547. __IO uint32_t reserved2 : 1; /* [3] */
  548. __IO uint32_t flashen : 1; /* [4] */
  549. __IO uint32_t reserved3 : 1; /* [5] */
  550. __IO uint32_t crcen : 1; /* [6] */
  551. __IO uint32_t reserved4 : 10;/* [16:7] */
  552. __IO uint32_t gpioaen : 1; /* [17] */
  553. __IO uint32_t gpioben : 1; /* [18] */
  554. __IO uint32_t gpiocen : 1; /* [19] */
  555. __IO uint32_t reserved5 : 2; /* [21:20] */
  556. __IO uint32_t gpiofen : 1; /* [22] */
  557. __IO uint32_t reserved6 : 9; /* [31:23] */
  558. } ahben_bit;
  559. };
  560. /**
  561. * @brief crm apb2en register, offset:0x18
  562. */
  563. union
  564. {
  565. __IO uint32_t apb2en;
  566. struct
  567. {
  568. __IO uint32_t scfgcmpen : 1; /* [0] */
  569. __IO uint32_t reserved1 : 8; /* [8:1] */
  570. __IO uint32_t adc1en : 1; /* [9] */
  571. __IO uint32_t reserved2 : 1; /* [10] */
  572. __IO uint32_t tmr1en : 1; /* [11] */
  573. __IO uint32_t spi1en : 1; /* [12] */
  574. __IO uint32_t reserved3 : 1; /* [13] */
  575. __IO uint32_t usart1en : 1; /* [14] */
  576. __IO uint32_t reserved4 : 1; /* [15] */
  577. __IO uint32_t tmr15en : 1; /* [16] */
  578. __IO uint32_t tmr16en : 1; /* [17] */
  579. __IO uint32_t tmr17en : 1; /* [18] */
  580. __IO uint32_t reserved5 : 13;/* [31:19] */
  581. } apb2en_bit;
  582. };
  583. /**
  584. * @brief crm apb1en register, offset:0x1C
  585. */
  586. union
  587. {
  588. __IO uint32_t apb1en;
  589. struct
  590. {
  591. __IO uint32_t reserved1 : 1; /* [0] */
  592. __IO uint32_t tmr3en : 1; /* [1] */
  593. __IO uint32_t reserved2 : 2; /* [3:2] */
  594. __IO uint32_t tmr6en : 1; /* [4] */
  595. __IO uint32_t reserved3 : 3; /* [7:5] */
  596. __IO uint32_t tmr14en : 1; /* [8] */
  597. __IO uint32_t reserved4 : 2; /* [10:9] */
  598. __IO uint32_t wwdten : 1; /* [11] */
  599. __IO uint32_t reserved5 : 2; /* [13:12] */
  600. __IO uint32_t spi2en : 1; /* [14] */
  601. __IO uint32_t reserved6 : 2; /* [16:15] */
  602. __IO uint32_t usart2en : 1; /* [17] */
  603. __IO uint32_t reserved7 : 3; /* [20:18] */
  604. __IO uint32_t i2c1en : 1; /* [21] */
  605. __IO uint32_t i2c2en : 1; /* [22] */
  606. __IO uint32_t reserved8 : 5; /* [27:23] */
  607. __IO uint32_t pwcen : 1; /* [28] */
  608. __IO uint32_t reserved9 : 3; /* [31:29] */
  609. } apb1en_bit;
  610. };
  611. /**
  612. * @brief crm bpdc register, offset:0x20
  613. */
  614. union
  615. {
  616. __IO uint32_t bpdc;
  617. struct
  618. {
  619. __IO uint32_t lexten : 1; /* [0] */
  620. __IO uint32_t lextstbl : 1; /* [1] */
  621. __IO uint32_t lextbyps : 1; /* [2] */
  622. __IO uint32_t reserved1 : 5; /* [7:3] */
  623. __IO uint32_t ertcsel : 2; /* [9:8] */
  624. __IO uint32_t reserved2 : 5; /* [14:10] */
  625. __IO uint32_t ertcen : 1; /* [15] */
  626. __IO uint32_t bpdrst : 1; /* [16] */
  627. __IO uint32_t reserved3 : 15;/* [31:17] */
  628. } bpdc_bit;
  629. };
  630. /**
  631. * @brief crm ctrlsts register, offset:0x24
  632. */
  633. union
  634. {
  635. __IO uint32_t ctrlsts;
  636. struct
  637. {
  638. __IO uint32_t licken : 1; /* [0] */
  639. __IO uint32_t lickstbl : 1; /* [1] */
  640. __IO uint32_t reserved1 : 22;/* [23:2] */
  641. __IO uint32_t rstfc : 1; /* [24] */
  642. __IO uint32_t reserved2 : 1; /* [25] */
  643. __IO uint32_t nrstf : 1; /* [26] */
  644. __IO uint32_t porrstf : 1; /* [27] */
  645. __IO uint32_t swrstf : 1; /* [28] */
  646. __IO uint32_t wdtrstf : 1; /* [29] */
  647. __IO uint32_t wwdtrstf : 1; /* [30] */
  648. __IO uint32_t lprstf : 1; /* [31] */
  649. } ctrlsts_bit;
  650. };
  651. /**
  652. * @brief crm ahbrst register, offset:0x28
  653. */
  654. union
  655. {
  656. __IO uint32_t ahbrst;
  657. struct
  658. {
  659. __IO uint32_t reserved1 : 17;/* [16:0] */
  660. __IO uint32_t gpioarst : 1; /* [17] */
  661. __IO uint32_t gpiobrst : 1; /* [18] */
  662. __IO uint32_t gpiocrst : 1; /* [19] */
  663. __IO uint32_t reserved2 : 2; /* [21:20] */
  664. __IO uint32_t gpiofrst : 1; /* [22] */
  665. __IO uint32_t reserved3 : 9; /* [31:23] */
  666. } ahbrst_bit;
  667. };
  668. /**
  669. * @brief crm pll register, offset:0x2C
  670. */
  671. union
  672. {
  673. __IO uint32_t pll;
  674. struct
  675. {
  676. __IO uint32_t pllfr : 3; /* [2:0] */
  677. __IO uint32_t reserved1 : 1; /* [3] */
  678. __IO uint32_t pllms : 4; /* [7:4] */
  679. __IO uint32_t pllns : 9; /* [16:8] */
  680. __IO uint32_t reserved2 : 7; /* [23:17] */
  681. __IO uint32_t pllfref : 3; /* [26:24] */
  682. __IO uint32_t reserved3 : 4; /* [30:27] */
  683. __IO uint32_t pllcfgen : 1; /* [31] */
  684. } pll_bit;
  685. };
  686. /**
  687. * @brief crm misc1 register, offset:0x30
  688. */
  689. union
  690. {
  691. __IO uint32_t misc1;
  692. struct
  693. {
  694. __IO uint32_t hickcal_key : 8; /* [7:0] */
  695. __IO uint32_t reserved1 : 8; /* [15:8] */
  696. __IO uint32_t clkout_sel : 1; /* [16] */
  697. __IO uint32_t reserved2 : 3; /* [19:17] */
  698. __IO uint32_t clkflashsrc : 1; /* [20] */
  699. __IO uint32_t reserved3 : 4; /* [24:21] */
  700. __IO uint32_t hickdiv : 1; /* [25] */
  701. __IO uint32_t reserved4 : 2; /* [27:26] */
  702. __IO uint32_t clkoutdiv : 4; /* [31:28] */
  703. } misc1_bit;
  704. };
  705. /**
  706. * @brief crm reserved2 register, offset:0x50~0x34
  707. */
  708. __IO uint32_t reserved2[8];
  709. /**
  710. * @brief crm misc2 register, offset:0x54
  711. */
  712. union
  713. {
  714. __IO uint32_t misc2;
  715. struct
  716. {
  717. __IO uint32_t reserved1 : 4; /* [3:0] */
  718. __IO uint32_t auto_step_en : 2; /* [5:4] */
  719. __IO uint32_t reserved2 : 3; /* [8:6] */
  720. __IO uint32_t hick_to_sclk : 1; /* [9] */
  721. __IO uint32_t reserved3 : 22;/* [31:10] */
  722. } misc2_bit;
  723. };
  724. } crm_type;
  725. /**
  726. * @}
  727. */
  728. #define CRM ((crm_type *) CRM_BASE)
  729. /** @defgroup CRM_exported_functions
  730. * @{
  731. */
  732. void crm_reset(void);
  733. void crm_lext_bypass(confirm_state new_state);
  734. void crm_hext_bypass(confirm_state new_state);
  735. flag_status crm_flag_get(uint32_t flag);
  736. error_status crm_hext_stable_wait(void);
  737. void crm_hick_clock_trimming_set(uint8_t trim_value);
  738. void crm_hick_clock_calibration_set(uint8_t cali_value);
  739. void crm_periph_clock_enable(crm_periph_clock_type value, confirm_state new_state);
  740. void crm_periph_reset(crm_periph_reset_type value, confirm_state new_state);
  741. void crm_periph_sleep_mode_clock_enable(crm_periph_clock_sleepmd_type value, confirm_state new_state);
  742. void crm_clock_source_enable(crm_clock_source_type source, confirm_state new_state);
  743. void crm_flag_clear(uint32_t flag);
  744. void crm_ertc_clock_select(crm_ertc_clock_type value);
  745. void crm_ertc_clock_enable(confirm_state new_state);
  746. void crm_ahb_div_set(crm_ahb_div_type value);
  747. void crm_apb1_div_set(crm_apb1_div_type value);
  748. void crm_apb2_div_set(crm_apb2_div_type value);
  749. void crm_adc_clock_div_set(crm_adc_div_type div_value);
  750. void crm_clock_failure_detection_enable(confirm_state new_state);
  751. void crm_battery_powered_domain_reset(confirm_state new_state);
  752. void crm_pll_config(crm_pll_clock_source_type clock_source, crm_pll_mult_type mult_value);
  753. void crm_pll_config2(crm_pll_clock_source_type clock_source, uint16_t pll_ns, uint16_t pll_ms, crm_pll_fr_type pll_fr);
  754. void crm_sysclk_switch(crm_sclk_type value);
  755. crm_sclk_type crm_sysclk_switch_status_get(void);
  756. void crm_clocks_freq_get(crm_clocks_freq_type *clocks_struct);
  757. void crm_clock_out_set(crm_clkout_select_type clkout);
  758. void crm_interrupt_enable(uint32_t crm_int, confirm_state new_state);
  759. void crm_auto_step_mode_enable(confirm_state new_state);
  760. void crm_hick_divider_select(crm_hick_div_6_type value);
  761. void crm_hick_sclk_frequency_select(crm_hick_sclk_frequency_type value);
  762. void crm_clkout_div_set(crm_clkout_div_type clkout_div);
  763. /**
  764. * @}
  765. */
  766. /**
  767. * @}
  768. */
  769. /**
  770. * @}
  771. */
  772. #ifdef __cplusplus
  773. }
  774. #endif
  775. #endif