apm32f10x_rcm.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*!
  2. * @file apm32f10x_rcm.h
  3. *
  4. * @brief This file contains all the functions prototypes for the RCM firmware library
  5. *
  6. * @version V1.0.4
  7. *
  8. * @date 2022-12-01
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F10X_RCM_H
  27. #define __APM32F10X_RCM_H
  28. /* Includes */
  29. #include "apm32f10x.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** @addtogroup APM32F10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup RCM_Driver RCM Driver
  37. @{
  38. */
  39. /** @defgroup RCM_Enumerations Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief HSE state
  44. */
  45. typedef enum
  46. {
  47. RCM_HSE_CLOSE,
  48. RCM_HSE_OPEN,
  49. RCM_HSE_BYPASS
  50. } RCM_HSE_T;
  51. /**
  52. * @brief PLL multiplication factor
  53. */
  54. typedef enum
  55. {
  56. #if defined(APM32F10X_CL)
  57. RCM_PLLMF_4 = 2,
  58. RCM_PLLMF_5,
  59. RCM_PLLMF_6,
  60. RCM_PLLMF_7,
  61. RCM_PLLMF_8,
  62. RCM_PLLMF_9,
  63. RCM_PLLMF_6_5 = 13,
  64. #else
  65. RCM_PLLMF_2,
  66. RCM_PLLMF_3,
  67. RCM_PLLMF_4,
  68. RCM_PLLMF_5,
  69. RCM_PLLMF_6,
  70. RCM_PLLMF_7,
  71. RCM_PLLMF_8,
  72. RCM_PLLMF_9,
  73. RCM_PLLMF_10,
  74. RCM_PLLMF_11,
  75. RCM_PLLMF_12,
  76. RCM_PLLMF_13,
  77. RCM_PLLMF_14,
  78. RCM_PLLMF_15,
  79. RCM_PLLMF_16
  80. #endif
  81. } RCM_PLLMF_T;
  82. /**
  83. * @brief PLL2 multiplication factor
  84. */
  85. typedef enum
  86. {
  87. RCM_PLL2MF_8 = 6,
  88. RCM_PLL2MF_9 = 7,
  89. RCM_PLL2MF_10 = 8,
  90. RCM_PLL2MF_11 = 9,
  91. RCM_PLL2MF_12 = 10,
  92. RCM_PLL2MF_13 = 11,
  93. RCM_PLL2MF_14 = 12,
  94. RCM_PLL2MF_16 = 14,
  95. RCM_PLL2MF_20 = 15
  96. } RCM_PLL2MF_T;
  97. /**
  98. * @brief PLL3 multiplication factor
  99. */
  100. typedef enum
  101. {
  102. RCM_PLL3MF_8 = 6,
  103. RCM_PLL3MF_9 = 7,
  104. RCM_PLL3MF_10 = 8,
  105. RCM_PLL3MF_11 = 9,
  106. RCM_PLL3MF_12 = 10,
  107. RCM_PLL3MF_13 = 11,
  108. RCM_PLL3MF_14 = 12,
  109. RCM_PLL3MF_16 = 14,
  110. RCM_PLL3MF_20 = 15
  111. } RCM_PLL3MF_T;
  112. /**
  113. * @brief System clock select
  114. */
  115. typedef enum
  116. {
  117. RCM_SYSCLK_SEL_HSI,
  118. RCM_SYSCLK_SEL_HSE,
  119. RCM_SYSCLK_SEL_PLL
  120. } RCM_SYSCLK_SEL_T;
  121. #if defined(APM32F10X_CL)
  122. /**
  123. * @brief PLLPSC1 Source
  124. */
  125. typedef enum
  126. {
  127. RCM_PLLPSC1_SRC_HSE,
  128. RCM_PLLPSC1_SRC_PLL2
  129. } RCM_PLLPSC1_SRC_T;
  130. /**
  131. * @brief PLLPSC1 divider Number
  132. */
  133. typedef enum
  134. {
  135. RCM_PLLPSC1_DIV_1,
  136. RCM_PLLPSC1_DIV_2,
  137. RCM_PLLPSC1_DIV_3,
  138. RCM_PLLPSC1_DIV_4,
  139. RCM_PLLPSC1_DIV_5,
  140. RCM_PLLPSC1_DIV_6,
  141. RCM_PLLPSC1_DIV_7,
  142. RCM_PLLPSC1_DIV_8,
  143. RCM_PLLPSC1_DIV_9,
  144. RCM_PLLPSC1_DIV_10,
  145. RCM_PLLPSC1_DIV_11,
  146. RCM_PLLPSC1_DIV_12,
  147. RCM_PLLPSC1_DIV_13,
  148. RCM_PLLPSC1_DIV_14,
  149. RCM_PLLPSC1_DIV_15,
  150. RCM_PLLPSC1_DIV_16
  151. } RCM_PLLPSC1_DIV_T;
  152. /**
  153. * @brief PLLPSC2 divider Number
  154. */
  155. typedef enum
  156. {
  157. RCM_PLLPSC2_DIV_1,
  158. RCM_PLLPSC2_DIV_2,
  159. RCM_PLLPSC2_DIV_3,
  160. RCM_PLLPSC2_DIV_4,
  161. RCM_PLLPSC2_DIV_5,
  162. RCM_PLLPSC2_DIV_6,
  163. RCM_PLLPSC2_DIV_7,
  164. RCM_PLLPSC2_DIV_8,
  165. RCM_PLLPSC2_DIV_9,
  166. RCM_PLLPSC2_DIV_10,
  167. RCM_PLLPSC2_DIV_11,
  168. RCM_PLLPSC2_DIV_12,
  169. RCM_PLLPSC2_DIV_13,
  170. RCM_PLLPSC2_DIV_14,
  171. RCM_PLLPSC2_DIV_15,
  172. RCM_PLLPSC2_DIV_16
  173. } RCM_PLLPSC2_DIV_T;
  174. #endif
  175. /**
  176. * @brief AHB divider Number
  177. */
  178. typedef enum
  179. {
  180. RCM_AHB_DIV_1 = 7,
  181. RCM_AHB_DIV_2,
  182. RCM_AHB_DIV_4,
  183. RCM_AHB_DIV_8,
  184. RCM_AHB_DIV_16,
  185. RCM_AHB_DIV_64,
  186. RCM_AHB_DIV_128,
  187. RCM_AHB_DIV_256,
  188. RCM_AHB_DIV_512
  189. } RCM_AHB_DIV_T;
  190. /**
  191. * @brief APB divider Number
  192. */
  193. typedef enum
  194. {
  195. RCM_APB_DIV_1 = 3,
  196. RCM_APB_DIV_2,
  197. RCM_APB_DIV_4,
  198. RCM_APB_DIV_8,
  199. RCM_APB_DIV_16
  200. } RCM_APB_DIV_T;
  201. /**
  202. * @brief USB divider Number
  203. */
  204. typedef enum
  205. {
  206. RCM_USB_DIV_1_5,
  207. RCM_USB_DIV_1,
  208. RCM_USB_DIV_2,
  209. RCM_USB_DIV_2_5 /*!< (Only for High-density devices for APM32F103xx) */
  210. } RCM_USB_DIV_T;
  211. /**
  212. * @brief OTG FS divider Number
  213. */
  214. typedef enum
  215. {
  216. RCM_OTGFS_DIV_1_5,
  217. RCM_OTGFS_DIV_1
  218. } RCM_OTGFS_DIV_T;
  219. /**
  220. * @brief FPU divider Number
  221. */
  222. typedef enum
  223. {
  224. RCM_FPU_DIV_1,
  225. RCM_FPU_DIV_2
  226. } RCM_FPU_DIV_T;
  227. /**
  228. * @brief ADC divider Number
  229. */
  230. typedef enum
  231. {
  232. RCM_PCLK2_DIV_2,
  233. RCM_PCLK2_DIV_4,
  234. RCM_PCLK2_DIV_6,
  235. RCM_PCLK2_DIV_8
  236. } RCM_PCLK2_DIV_T;
  237. /**
  238. * @brief LSE State
  239. */
  240. typedef enum
  241. {
  242. RCM_LSE_CLOSE,
  243. RCM_LSE_OPEN,
  244. RCM_LSE_BYPASS
  245. } RCM_LSE_T;
  246. /**
  247. * @brief I2S2 clock select
  248. */
  249. typedef enum
  250. {
  251. RCM_I2S2CLK_SYSCLK,
  252. RCM_I2S2CLK_DOUBLE_PLL3
  253. } RCM_I2S2CLK_T;
  254. /**
  255. * @brief I2S3 clock select
  256. */
  257. typedef enum
  258. {
  259. RCM_I2S3CLK_SYSCLK,
  260. RCM_I2S3CLK_DOUBLE_PLL3
  261. } RCM_I2S3CLK_T;
  262. /**
  263. * @brief RTC clock select
  264. */
  265. typedef enum
  266. {
  267. RCM_RTCCLK_LSE = 1,
  268. RCM_RTCCLK_LSI,
  269. RCM_RTCCLK_HSE_DIV_128
  270. } RCM_RTCCLK_T;
  271. /**
  272. * @brief Clock output control
  273. */
  274. typedef enum
  275. {
  276. RCM_MCOCLK_NO_CLOCK = 3,
  277. RCM_MCOCLK_SYSCLK,
  278. RCM_MCOCLK_HSI,
  279. RCM_MCOCLK_HSE,
  280. RCM_MCOCLK_PLLCLK_DIV_2,
  281. #if defined(APM32F10X_CL)
  282. RCM_MCOCLK_PLL2CLK = 8,
  283. RCM_MCOCLK_PLL3CLK_DIV_2,
  284. RCM_MCOCLK_OSCCLK,
  285. RCM_MCOCLK_PLL3CLK
  286. #endif
  287. } RCM_MCOCLK_T;
  288. /**
  289. * @brief PLL entry clock select
  290. */
  291. typedef enum
  292. {
  293. RCM_PLLSEL_HSI_DIV_2 = 0,
  294. #if defined(APM32F10X_CL)
  295. RCM_PLLSEL_PREDIV1 = 1,
  296. #else
  297. RCM_PLLSEL_HSE = 1,
  298. RCM_PLLSEL_HSE_DIV2 = 3,
  299. #endif /* APM32F10X_CL */
  300. } RCM_PLLSEL_T;
  301. /**
  302. * @brief RCM Interrupt Source
  303. */
  304. typedef enum
  305. {
  306. RCM_INT_LSIRDY = BIT0, /*!< LSI ready interrupt */
  307. RCM_INT_LSERDY = BIT1, /*!< LSE ready interrupt */
  308. RCM_INT_HSIRDY = BIT2, /*!< HSI ready interrupt */
  309. RCM_INT_HSERDY = BIT3, /*!< HSE ready interrupt */
  310. RCM_INT_PLLRDY = BIT4, /*!< PLL ready interrupt */
  311. RCM_INT_PLL2RDY = BIT5, /*!< PLL2 ready interrupt */
  312. RCM_INT_PLL3RDY = BIT6, /*!< PLL3 ready interrupt */
  313. RCM_INT_CSS = BIT7 /*!< Clock security system interrupt */
  314. } RCM_INT_T;
  315. /**
  316. * @brief AHB peripheral
  317. */
  318. typedef enum
  319. {
  320. RCM_AHB_PERIPH_DMA1 = BIT0,
  321. RCM_AHB_PERIPH_DMA2 = BIT1,
  322. RCM_AHB_PERIPH_SRAM = BIT2,
  323. RCM_AHB_PERIPH_FPU = BIT3,
  324. RCM_AHB_PERIPH_FMC = BIT4,
  325. RCM_AHB_PERIPH_QSPI = BIT5,
  326. RCM_AHB_PERIPH_CRC = BIT6,
  327. RCM_AHB_PERIPH_EMMC = BIT8,
  328. RCM_AHB_PERIPH_SDIO = BIT10,
  329. RCM_AHB_PERIPH_OTG_FS = BIT12,
  330. RCM_AHB_PERIPH_ETH_MAC = BIT14,
  331. RCM_AHB_PERIPH_ETH_MAC_TX = BIT15,
  332. RCM_AHB_PERIPH_ETH_MAC_RX = BIT16
  333. } RCM_AHB_PERIPH_T;
  334. /**
  335. * @brief AHB2 peripheral
  336. */
  337. typedef enum
  338. {
  339. RCM_APB2_PERIPH_AFIO = BIT0,
  340. RCM_APB2_PERIPH_GPIOA = BIT2,
  341. RCM_APB2_PERIPH_GPIOB = BIT3,
  342. RCM_APB2_PERIPH_GPIOC = BIT4,
  343. RCM_APB2_PERIPH_GPIOD = BIT5,
  344. RCM_APB2_PERIPH_GPIOE = BIT6,
  345. RCM_APB2_PERIPH_GPIOF = BIT7,
  346. RCM_APB2_PERIPH_GPIOG = BIT8,
  347. RCM_APB2_PERIPH_ADC1 = BIT9,
  348. RCM_APB2_PERIPH_ADC2 = BIT10,
  349. RCM_APB2_PERIPH_TMR1 = BIT11,
  350. RCM_APB2_PERIPH_SPI1 = BIT12,
  351. RCM_APB2_PERIPH_TMR8 = BIT13,
  352. RCM_APB2_PERIPH_USART1 = BIT14,
  353. RCM_APB2_PERIPH_ADC3 = BIT15
  354. } RCM_APB2_PERIPH_T;
  355. /**
  356. * @brief AHB1 peripheral
  357. */
  358. typedef enum
  359. {
  360. RCM_APB1_PERIPH_TMR2 = BIT0,
  361. RCM_APB1_PERIPH_TMR3 = BIT1,
  362. RCM_APB1_PERIPH_TMR4 = BIT2,
  363. RCM_APB1_PERIPH_TMR5 = BIT3,
  364. RCM_APB1_PERIPH_TMR6 = BIT4,
  365. RCM_APB1_PERIPH_TMR7 = BIT5,
  366. RCM_APB1_PERIPH_WWDT = BIT11,
  367. RCM_APB1_PERIPH_SPI2 = BIT14,
  368. RCM_APB1_PERIPH_SPI3 = BIT15,
  369. RCM_APB1_PERIPH_USART2 = BIT17,
  370. RCM_APB1_PERIPH_USART3 = BIT18,
  371. RCM_APB1_PERIPH_UART4 = BIT19,
  372. RCM_APB1_PERIPH_UART5 = BIT20,
  373. RCM_APB1_PERIPH_I2C1 = BIT21,
  374. RCM_APB1_PERIPH_I2C2 = BIT22,
  375. RCM_APB1_PERIPH_USB = BIT23,
  376. RCM_APB1_PERIPH_CAN1 = BIT25,
  377. RCM_APB1_PERIPH_CAN2 = BIT26,
  378. RCM_APB1_PERIPH_BAKR = BIT27,
  379. RCM_APB1_PERIPH_PMU = BIT28,
  380. RCM_APB1_PERIPH_DAC = BIT29
  381. } RCM_APB1_PERIPH_T;
  382. /**
  383. * @brief RCM FLAG define
  384. */
  385. typedef enum
  386. {
  387. RCM_FLAG_HSIRDY = 0x001, /*!< HSI Ready Flag */
  388. RCM_FLAG_HSERDY = 0x011, /*!< HSE Ready Flag */
  389. RCM_FLAG_PLLRDY = 0x019, /*!< PLL Ready Flag */
  390. RCM_FLAG_PLL2RDY = 0x01B, /*!< PLL2 Ready Flag */
  391. RCM_FLAG_PLL3RDY = 0x01D, /*!< PLL3 Ready Flag */
  392. RCM_FLAG_LSERDY = 0x101, /*!< LSE Ready Flag */
  393. RCM_FLAG_LSIRDY = 0x201, /*!< LSI Ready Flag */
  394. RCM_FLAG_PINRST = 0x21A, /*!< PIN reset flag */
  395. RCM_FLAG_PORRST = 0x21B, /*!< POR/PDR reset flag */
  396. RCM_FLAG_SWRST = 0x21C, /*!< Software reset flag */
  397. RCM_FLAG_IWDTRST = 0x21D, /*!< Independent watchdog reset flag */
  398. RCM_FLAG_WWDTRST = 0x21E, /*!< Window watchdog reset flag */
  399. RCM_FLAG_LPRRST = 0x21F /*!< Low-power reset flag */
  400. } RCM_FLAG_T;
  401. /**@} end of group RCM_Enumerations */
  402. /** @defgroup RCM_Functions Functions
  403. @{
  404. */
  405. /* Function description */
  406. /* RCM Reset */
  407. void RCM_Reset(void);
  408. /* HSE clock */
  409. void RCM_ConfigHSE(RCM_HSE_T state);
  410. uint8_t RCM_WaitHSEReady(void);
  411. /* HSI clock */
  412. void RCM_ConfigHSITrim(uint8_t HSITrim);
  413. void RCM_EnableHSI(void);
  414. void RCM_DisableHSI(void);
  415. /* LSE and LSI clock */
  416. void RCM_ConfigLSE(RCM_LSE_T state);
  417. void RCM_EnableLSI(void);
  418. void RCM_DisableLSI(void);
  419. /* PLL clock */
  420. void RCM_ConfigPLL(RCM_PLLSEL_T pllSelect, RCM_PLLMF_T pllMf);
  421. void RCM_EnablePLL(void);
  422. void RCM_DisablePLL(void);
  423. #if defined(APM32F10X_CL)
  424. void RCM_EnablePLL2(void);
  425. void RCM_DisablePLL2(void);
  426. void RCM_EnablePLL3(void);
  427. void RCM_DisablePLL3(void);
  428. void RCM_ConfigPLLPSC1(RCM_PLLPSC1_SRC_T pllPsc1Src, RCM_PLLPSC1_DIV_T pllPsc1);
  429. void RCM_ConfigPLLPSC2(RCM_PLLPSC2_DIV_T pllpsc2);
  430. void RCM_ConfigPLL2(RCM_PLL2MF_T pll2Mf);
  431. void RCM_ConfigPLL3(RCM_PLL3MF_T pll3Mf);
  432. #endif
  433. /* Clock Security System */
  434. void RCM_EnableCSS(void);
  435. void RCM_DisableCSS(void);
  436. void RCM_ConfigMCO(RCM_MCOCLK_T mcoClock);
  437. void RCM_ConfigSYSCLK(RCM_SYSCLK_SEL_T sysClkSelect);
  438. RCM_SYSCLK_SEL_T RCM_ReadSYSCLKSource(void);
  439. /* Config clock prescaler of AHB, APB1, APB2, USB and ADC */
  440. void RCM_ConfigAHB(RCM_AHB_DIV_T AHBDiv);
  441. void RCM_ConfigAPB1(RCM_APB_DIV_T APB1Div);
  442. void RCM_ConfigAPB2(RCM_APB_DIV_T APB2Div);
  443. #if defined(APM32F10X_CL)
  444. void RCM_ConfigI2S2CLK(RCM_I2S2CLK_T i2s2ClkSelect);
  445. void RCM_ConfigI2S3CLK(RCM_I2S2CLK_T i2s3ClkSelect);
  446. void RCM_ConfigOTGFSCLK(RCM_OTGFS_DIV_T OTGDiv);
  447. #else
  448. void RCM_ConfigUSBCLK(RCM_USB_DIV_T USBDiv);
  449. void RCM_ConfigFPUCLK(RCM_FPU_DIV_T FPUDiv);
  450. #endif
  451. void RCM_ConfigADCCLK(RCM_PCLK2_DIV_T ADCDiv);
  452. /* RTC clock */
  453. void RCM_ConfigRTCCLK(RCM_RTCCLK_T rtcClkSelect);
  454. void RCM_EnableRTCCLK(void);
  455. void RCM_DisableRTCCLK(void);
  456. /* Reads the clock frequency */
  457. uint32_t RCM_ReadSYSCLKFreq(void);
  458. uint32_t RCM_ReadHCLKFreq(void);
  459. void RCM_ReadPCLKFreq(uint32_t* PCLK1, uint32_t* PCLK2);
  460. uint32_t RCM_ReadADCCLKFreq(void);
  461. /* Enable or disable Periph Clock */
  462. void RCM_EnableAHBPeriphClock(uint32_t AHBPeriph);
  463. void RCM_DisableAHBPeriphClock(uint32_t AHBPeriph);
  464. void RCM_EnableAPB2PeriphClock(uint32_t APB2Periph);
  465. void RCM_DisableAPB2PeriphClock(uint32_t APB2Periph);
  466. void RCM_EnableAPB1PeriphClock(uint32_t APB1Periph);
  467. void RCM_DisableAPB1PeriphClock(uint32_t APB1Periph);
  468. /* Enable or disable Periph Reset */
  469. #if defined(APM32F10X_CL)
  470. void RCM_EnableAHBPeriphReset(uint32_t AHBPeriph);
  471. void RCM_DisableAHBPeriphReset(uint32_t AHBPeriph);
  472. #endif
  473. void RCM_EnableAPB2PeriphReset(uint32_t APB2Periph);
  474. void RCM_DisableAPB2PeriphReset(uint32_t APB2Periph);
  475. void RCM_EnableAPB1PeriphReset(uint32_t APB1Periph);
  476. void RCM_DisableAPB1PeriphReset(uint32_t APB1Periph);
  477. /* Backup domain reset */
  478. void RCM_EnableBackupReset(void);
  479. void RCM_DisableBackupReset(void);
  480. /* Interrupts and flags */
  481. void RCM_EnableInterrupt(uint32_t interrupt);
  482. void RCM_DisableInterrupt(uint32_t interrupt);
  483. uint8_t RCM_ReadStatusFlag(RCM_FLAG_T flag);
  484. void RCM_ClearStatusFlag(void);
  485. uint8_t RCM_ReadIntFlag(RCM_INT_T flag);
  486. void RCM_ClearIntFlag(uint32_t flag);
  487. /**@} end of group RCM_Functions */
  488. /**@} end of group RCM_Driver */
  489. /**@} end of group APM32F10x_StdPeriphDriver */
  490. #ifdef __cplusplus
  491. }
  492. #endif
  493. #endif /* __APM32F10X_RCM_H */