apm32e10x_rcm.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*!
  2. * @file apm32e10x_rcm.h
  3. *
  4. * @brief This file contains all the functions prototypes for the RCM firmware library
  5. *
  6. * @version V1.0.2
  7. *
  8. * @date 2022-12-31
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2021-2023 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 __APM32E10X_RCM_H
  27. #define __APM32E10X_RCM_H
  28. /* Includes */
  29. #include "apm32e10x.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** @addtogroup APM32E10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup 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, /*!< CLOSE HSE */
  48. RCM_HSE_OPEN, /*!< OPEN HSE */
  49. RCM_HSE_BYPASS, /*!< HSE BYPASS */
  50. } RCM_HSE_T;
  51. /**
  52. * @brief PLL multiplication factor
  53. */
  54. typedef enum
  55. {
  56. RCM_PLLMF_2,
  57. RCM_PLLMF_3,
  58. RCM_PLLMF_4,
  59. RCM_PLLMF_5,
  60. RCM_PLLMF_6,
  61. RCM_PLLMF_7,
  62. RCM_PLLMF_8,
  63. RCM_PLLMF_9,
  64. RCM_PLLMF_10,
  65. RCM_PLLMF_11,
  66. RCM_PLLMF_12,
  67. RCM_PLLMF_13,
  68. RCM_PLLMF_14,
  69. RCM_PLLMF_15,
  70. RCM_PLLMF_16
  71. } RCM_PLLMF_T;
  72. /**
  73. * @brief System clock select
  74. */
  75. typedef enum
  76. {
  77. RCM_SYSCLK_SEL_HSI,
  78. RCM_SYSCLK_SEL_HSE,
  79. RCM_SYSCLK_SEL_PLL
  80. } RCM_SYSCLK_SEL_T;
  81. /**
  82. * @brief AHB divider Number
  83. */
  84. typedef enum
  85. {
  86. RCM_AHB_DIV_1 = 7,
  87. RCM_AHB_DIV_2,
  88. RCM_AHB_DIV_4,
  89. RCM_AHB_DIV_8,
  90. RCM_AHB_DIV_16,
  91. RCM_AHB_DIV_64,
  92. RCM_AHB_DIV_128,
  93. RCM_AHB_DIV_256,
  94. RCM_AHB_DIV_512
  95. } RCM_AHB_DIV_T;
  96. /**
  97. * @brief APB divider Number
  98. */
  99. typedef enum
  100. {
  101. RCM_APB_DIV_1 = 3,
  102. RCM_APB_DIV_2,
  103. RCM_APB_DIV_4,
  104. RCM_APB_DIV_8,
  105. RCM_APB_DIV_16
  106. } RCM_APB_DIV_T;
  107. /**
  108. * @brief USB divider Number
  109. */
  110. typedef enum
  111. {
  112. RCM_USB_DIV_1_5,
  113. RCM_USB_DIV_1,
  114. RCM_USB_DIV_2,
  115. RCM_USB_DIV_2_5
  116. } RCM_USB_DIV_T;
  117. /**
  118. * @brief FPU divider Number
  119. */
  120. typedef enum
  121. {
  122. RCM_FPU_DIV_1,
  123. RCM_FPU_DIV_2
  124. } RCM_FPU_DIV_T;
  125. /**
  126. * @brief ADC divider Number
  127. */
  128. typedef enum
  129. {
  130. RCM_PCLK2_DIV_2,
  131. RCM_PCLK2_DIV_4,
  132. RCM_PCLK2_DIV_6,
  133. RCM_PCLK2_DIV_8
  134. } RCM_PCLK2_DIV_T;
  135. /**
  136. * @brief LSE State
  137. */
  138. typedef enum
  139. {
  140. RCM_LSE_CLOSE,
  141. RCM_LSE_OPEN,
  142. RCM_LSE_BYPASS
  143. } RCM_LSE_T;
  144. /**
  145. * @brief RTC clock select
  146. */
  147. typedef enum
  148. {
  149. RCM_RTCCLK_LSE = 1,
  150. RCM_RTCCLK_LSI,
  151. RCM_RTCCLK_HSE_DIV_128
  152. } RCM_RTCCLK_T;
  153. /**
  154. * @brief Clock output control
  155. */
  156. typedef enum
  157. {
  158. RCM_MCOCLK_NO_CLOCK = 3,
  159. RCM_MCOCLK_SYSCLK,
  160. RCM_MCOCLK_HSI,
  161. RCM_MCOCLK_HSE,
  162. RCM_MCOCLK_PLLCLK_DIV_2
  163. } RCM_MCOCLK_T;
  164. /**
  165. * @brief PLL entry clock select
  166. */
  167. typedef enum
  168. {
  169. RCM_PLLSEL_HSI_DIV_2 = 0,
  170. RCM_PLLSEL_HSE = 1,
  171. RCM_PLLSEL_HSE_DIV2 = 3,
  172. } RCM_PLLSEL_T;
  173. /**
  174. * @brief RCM Interrupt Source
  175. */
  176. typedef enum
  177. {
  178. RCM_INT_LSIRDY = BIT0, /*!< LSI ready interrupt */
  179. RCM_INT_LSERDY = BIT1, /*!< LSE ready interrupt */
  180. RCM_INT_HSIRDY = BIT2, /*!< HSI ready interrupt */
  181. RCM_INT_HSERDY = BIT3, /*!< HSE ready interrupt */
  182. RCM_INT_PLLRDY = BIT4, /*!< PLL ready interrupt */
  183. RCM_INT_CSS = BIT7 /*!< Clock security system interrupt */
  184. } RCM_INT_T;
  185. /**
  186. * @brief AHB peripheral
  187. */
  188. typedef enum
  189. {
  190. RCM_AHB_PERIPH_DMA1 = BIT0,
  191. RCM_AHB_PERIPH_DMA2 = BIT1,
  192. RCM_AHB_PERIPH_SRAM = BIT2,
  193. RCM_AHB_PERIPH_FPU = BIT3,
  194. RCM_AHB_PERIPH_FMC = BIT4,
  195. RCM_AHB_PERIPH_QSPI = BIT5,
  196. RCM_AHB_PERIPH_CRC = BIT6,
  197. RCM_AHB_PERIPH_SMC = BIT8,
  198. RCM_AHB_PERIPH_SDIO = BIT10
  199. } RCM_AHB_PERIPH_T;
  200. /**
  201. * @brief AHB2 peripheral
  202. */
  203. typedef enum
  204. {
  205. RCM_APB2_PERIPH_AFIO = BIT0,
  206. RCM_APB2_PERIPH_GPIOA = BIT2,
  207. RCM_APB2_PERIPH_GPIOB = BIT3,
  208. RCM_APB2_PERIPH_GPIOC = BIT4,
  209. RCM_APB2_PERIPH_GPIOD = BIT5,
  210. RCM_APB2_PERIPH_GPIOE = BIT6,
  211. RCM_APB2_PERIPH_GPIOF = BIT7,
  212. RCM_APB2_PERIPH_GPIOG = BIT8,
  213. RCM_APB2_PERIPH_ADC1 = BIT9,
  214. RCM_APB2_PERIPH_ADC2 = BIT10,
  215. RCM_APB2_PERIPH_TMR1 = BIT11,
  216. RCM_APB2_PERIPH_SPI1 = BIT12,
  217. RCM_APB2_PERIPH_TMR8 = BIT13,
  218. RCM_APB2_PERIPH_USART1 = BIT14,
  219. RCM_APB2_PERIPH_ADC3 = BIT15
  220. } RCM_APB2_PERIPH_T;
  221. /**
  222. * @brief AHB1 peripheral
  223. */
  224. typedef enum
  225. {
  226. RCM_APB1_PERIPH_TMR2 = BIT0,
  227. RCM_APB1_PERIPH_TMR3 = BIT1,
  228. RCM_APB1_PERIPH_TMR4 = BIT2,
  229. RCM_APB1_PERIPH_TMR5 = BIT3,
  230. RCM_APB1_PERIPH_TMR6 = BIT4,
  231. RCM_APB1_PERIPH_TMR7 = BIT5,
  232. RCM_APB1_PERIPH_WWDT = BIT11,
  233. RCM_APB1_PERIPH_SPI2 = BIT14,
  234. RCM_APB1_PERIPH_SPI3 = BIT15,
  235. RCM_APB1_PERIPH_USART2 = BIT17,
  236. RCM_APB1_PERIPH_USART3 = BIT18,
  237. RCM_APB1_PERIPH_UART4 = BIT19,
  238. RCM_APB1_PERIPH_UART5 = BIT20,
  239. RCM_APB1_PERIPH_I2C1 = BIT21,
  240. RCM_APB1_PERIPH_I2C2 = BIT22,
  241. RCM_APB1_PERIPH_USB = BIT23,
  242. RCM_APB1_PERIPH_CAN1 = BIT25,
  243. RCM_APB1_PERIPH_CAN2 = BIT26,
  244. RCM_APB1_PERIPH_BAKR = BIT27,
  245. RCM_APB1_PERIPH_PMU = BIT28,
  246. RCM_APB1_PERIPH_DAC = BIT29
  247. } RCM_APB1_PERIPH_T;
  248. /**
  249. * @brief RCM FLAG define
  250. */
  251. typedef enum
  252. {
  253. RCM_FLAG_HSIRDY = 0x001, /*!< HSI Ready Flag */
  254. RCM_FLAG_HSERDY = 0x011, /*!< HSE Ready Flag */
  255. RCM_FLAG_PLLRDY = 0x019, /*!< PLL Ready Flag */
  256. RCM_FLAG_LSERDY = 0x101, /*!< LSE Ready Flag */
  257. RCM_FLAG_LSIRDY = 0x201, /*!< LSI Ready Flag */
  258. RCM_FLAG_PINRST = 0x21A, /*!< PIN reset flag */
  259. RCM_FLAG_PORRST = 0x21B, /*!< POR/PDR reset flag */
  260. RCM_FLAG_SWRST = 0x21C, /*!< Software reset flag */
  261. RCM_FLAG_IWDTRST = 0x21D, /*!< Independent watchdog reset flag */
  262. RCM_FLAG_WWDTRST = 0x21E, /*!< Window watchdog reset flag */
  263. RCM_FLAG_LPRRST = 0x21F /*!< Low-power reset flag */
  264. } RCM_FLAG_T;
  265. /**@} end of group RCM_Enumerations */
  266. /** @defgroup RCM_Functions Functions
  267. @{
  268. */
  269. /* Function description */
  270. /* RCM Reset */
  271. void RCM_Reset(void);
  272. /* HSE clock */
  273. void RCM_ConfigHSE(RCM_HSE_T state);
  274. uint8_t RCM_WaitHSEReady(void);
  275. /* HSI clock */
  276. void RCM_ConfigHSITrim(uint8_t HSITrim);
  277. void RCM_EnableHSI(void);
  278. void RCM_DisableHSI(void);
  279. /* LSE and LSI clock */
  280. void RCM_ConfigLSE(RCM_LSE_T state);
  281. void RCM_EnableLSI(void);
  282. void RCM_DisableLSI(void);
  283. /* PLL clock */
  284. void RCM_ConfigPLL(RCM_PLLSEL_T pllSelect, RCM_PLLMF_T pllMf);
  285. void RCM_EnablePLL(void);
  286. void RCM_DisablePLL(void);
  287. /* Clock Security System */
  288. void RCM_EnableCSS(void);
  289. void RCM_DisableCSS(void);
  290. void RCM_ConfigMCO(RCM_MCOCLK_T mcoClock);
  291. void RCM_ConfigSYSCLK(RCM_SYSCLK_SEL_T sysClkSelect);
  292. RCM_SYSCLK_SEL_T RCM_ReadSYSCLKSource(void);
  293. /* Config clock prescaler of AHB, APB1, APB2, USB and ADC */
  294. void RCM_ConfigAHB(RCM_AHB_DIV_T AHBDiv);
  295. void RCM_ConfigAPB1(RCM_APB_DIV_T APB1Div);
  296. void RCM_ConfigAPB2(RCM_APB_DIV_T APB2Div);
  297. void RCM_ConfigUSBCLK(RCM_USB_DIV_T USBDiv);
  298. void RCM_ConfigFPUCLK(RCM_FPU_DIV_T FPUDiv);
  299. void RCM_ConfigADCCLK(RCM_PCLK2_DIV_T ADCDiv);
  300. /* RTC clock */
  301. void RCM_ConfigRTCCLK(RCM_RTCCLK_T rtcClkSelect);
  302. void RCM_EnableRTCCLK(void);
  303. void RCM_DisableRTCCLK(void);
  304. /* Reads the clock frequency */
  305. uint32_t RCM_ReadSYSCLKFreq(void);
  306. uint32_t RCM_ReadHCLKFreq(void);
  307. void RCM_ReadPCLKFreq(uint32_t* PCLK1, uint32_t* PCLK2);
  308. uint32_t RCM_ReadADCCLKFreq(void);
  309. /* Enable or disable Periph Clock */
  310. void RCM_EnableAHBPeriphClock(uint32_t AHBPeriph);
  311. void RCM_DisableAHBPeriphClock(uint32_t AHBPeriph);
  312. void RCM_EnableAPB2PeriphClock(uint32_t APB2Periph);
  313. void RCM_DisableAPB2PeriphClock(uint32_t APB2Periph);
  314. void RCM_EnableAPB1PeriphClock(uint32_t APB1Periph);
  315. void RCM_DisableAPB1PeriphClock(uint32_t APB1Periph);
  316. /* Enable or disable Periph Reset */
  317. void RCM_EnableAPB2PeriphReset(uint32_t APB2Periph);
  318. void RCM_DisableAPB2PeriphReset(uint32_t APB2Periph);
  319. void RCM_EnableAPB1PeriphReset(uint32_t APB1Periph);
  320. void RCM_DisableAPB1PeriphReset(uint32_t APB1Periph);
  321. /* Backup domain reset */
  322. void RCM_EnableBackupReset(void);
  323. void RCM_DisableBackupReset(void);
  324. /* Interrupts and flags */
  325. void RCM_EnableInterrupt(uint32_t interrupt);
  326. void RCM_DisableInterrupt(uint32_t interrupt);
  327. uint8_t RCM_ReadStatusFlag(RCM_FLAG_T flag);
  328. void RCM_ClearStatusFlag(void);
  329. uint8_t RCM_ReadIntFlag(RCM_INT_T flag);
  330. void RCM_ClearIntFlag(uint32_t flag);
  331. /**@} end of group RCM_Functions */
  332. /**@} end of group RCM_Driver */
  333. /**@} end of group APM32E10x_StdPeriphDriver*/
  334. #ifdef __cplusplus
  335. }
  336. #endif
  337. #endif /* __APM32E10X_RCM_H */