apm32f10x_rcm.h 8.6 KB

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