apm32s10x_rcm.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*!
  2. * @file apm32s10x_rcm.h
  3. *
  4. * @brief This file contains all the functions prototypes for the RCM firmware library
  5. *
  6. * @version V1.0.1
  7. *
  8. * @date 2022-12-31
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2022-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 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. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32S10X_RCM_H
  27. #define __APM32S10X_RCM_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32s10x.h"
  33. /** @addtogroup APM32S10x_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. 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_T;
  116. /**
  117. * @brief FPU divider Number
  118. */
  119. typedef enum
  120. {
  121. RCM_FPU_DIV_1,
  122. RCM_FPU_DIV_2
  123. } RCM_FPU_DIV_T;
  124. /**
  125. * @brief ADC divider Number
  126. */
  127. typedef enum
  128. {
  129. RCM_PCLK2_DIV_2,
  130. RCM_PCLK2_DIV_4,
  131. RCM_PCLK2_DIV_6,
  132. RCM_PCLK2_DIV_8
  133. } RCM_PCLK2_DIV_T;
  134. /**
  135. * @brief LSE State
  136. */
  137. typedef enum
  138. {
  139. RCM_LSE_CLOSE,
  140. RCM_LSE_OPEN,
  141. RCM_LSE_BYPASS
  142. } RCM_LSE_T;
  143. /**
  144. * @brief RTC clock select
  145. */
  146. typedef enum
  147. {
  148. RCM_RTCCLK_LSE = 1,
  149. RCM_RTCCLK_LSI,
  150. RCM_RTCCLK_HSE_DIV_128
  151. } RCM_RTCCLK_T;
  152. /**
  153. * @brief Clock output control
  154. */
  155. typedef enum
  156. {
  157. RCM_MCOCLK_NO_CLOCK = 3,
  158. RCM_MCOCLK_SYSCLK,
  159. RCM_MCOCLK_HSI,
  160. RCM_MCOCLK_HSE,
  161. RCM_MCOCLK_PLLCLK_DIV_2
  162. } RCM_MCOCLK_T;
  163. /**
  164. * @brief PLL entry clock select
  165. */
  166. typedef enum
  167. {
  168. RCM_PLLSEL_HSI_DIV_2 = 0,
  169. RCM_PLLSEL_HSE = 1,
  170. RCM_PLLSEL_HSE_DIV2 = 3,
  171. } RCM_PLLSEL_T;
  172. /**
  173. * @brief RCM Interrupt Source
  174. */
  175. typedef enum
  176. {
  177. RCM_INT_LSIRDY = BIT0, /*!< LSI ready interrupt */
  178. RCM_INT_LSERDY = BIT1, /*!< LSE ready interrupt */
  179. RCM_INT_HSIRDY = BIT2, /*!< HSI ready interrupt */
  180. RCM_INT_HSERDY = BIT3, /*!< HSE ready interrupt */
  181. RCM_INT_PLLRDY = BIT4, /*!< PLL ready interrupt */
  182. RCM_INT_CSS = BIT7 /*!< Clock security system interrupt */
  183. } RCM_INT_T;
  184. /**
  185. * @brief AHB peripheral
  186. */
  187. typedef enum
  188. {
  189. RCM_AHB_PERIPH_DMA1 = BIT0,
  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_T;
  196. /**
  197. * @brief AHB2 peripheral
  198. */
  199. typedef enum
  200. {
  201. RCM_APB2_PERIPH_AFIO = BIT0,
  202. RCM_APB2_PERIPH_GPIOA = BIT2,
  203. RCM_APB2_PERIPH_GPIOB = BIT3,
  204. RCM_APB2_PERIPH_GPIOC = BIT4,
  205. RCM_APB2_PERIPH_GPIOD = BIT5,
  206. RCM_APB2_PERIPH_GPIOE = BIT6,
  207. RCM_APB2_PERIPH_ADC1 = BIT9,
  208. RCM_APB2_PERIPH_ADC2 = BIT10,
  209. RCM_APB2_PERIPH_TMR1 = BIT11,
  210. RCM_APB2_PERIPH_SPI1 = BIT12,
  211. RCM_APB2_PERIPH_USART1 = BIT14
  212. } RCM_APB2_PERIPH_T;
  213. /**
  214. * @brief AHB1 peripheral
  215. */
  216. typedef enum
  217. {
  218. RCM_APB1_PERIPH_TMR2 = BIT0,
  219. RCM_APB1_PERIPH_TMR3 = BIT1,
  220. RCM_APB1_PERIPH_TMR4 = BIT2,
  221. RCM_APB1_PERIPH_WWDT = BIT11,
  222. RCM_APB1_PERIPH_SPI2 = BIT14,
  223. RCM_APB1_PERIPH_USART2 = BIT17,
  224. RCM_APB1_PERIPH_USART3 = BIT18,
  225. RCM_APB1_PERIPH_I2C1 = BIT21,
  226. RCM_APB1_PERIPH_I2C2 = BIT22,
  227. RCM_APB1_PERIPH_USB = BIT23,
  228. RCM_APB1_PERIPH_CAN1 = BIT25,
  229. RCM_APB1_PERIPH_CAN2 = BIT26,
  230. RCM_APB1_PERIPH_BAKR = BIT27,
  231. RCM_APB1_PERIPH_PMU = BIT28
  232. } RCM_APB1_PERIPH_T;
  233. /**
  234. * @brief RCM FLAG define
  235. */
  236. typedef enum
  237. {
  238. RCM_FLAG_HSIRDY = 0x001, /*!< HSI Ready Flag */
  239. RCM_FLAG_HSERDY = 0x011, /*!< HSE Ready Flag */
  240. RCM_FLAG_PLLRDY = 0x019, /*!< PLL Ready Flag */
  241. RCM_FLAG_LSERDY = 0x101, /*!< LSE Ready Flag */
  242. RCM_FLAG_LSIRDY = 0x201, /*!< LSI Ready Flag */
  243. RCM_FLAG_PINRST = 0x21A, /*!< PIN reset flag */
  244. RCM_FLAG_PORRST = 0x21B, /*!< POR/PDR reset flag */
  245. RCM_FLAG_SWRST = 0x21C, /*!< Software reset flag */
  246. RCM_FLAG_IWDTRST = 0x21D, /*!< Independent watchdog reset flag */
  247. RCM_FLAG_WWDTRST = 0x21E, /*!< Window watchdog reset flag */
  248. RCM_FLAG_LPRRST = 0x21F /*!< Low-power reset flag */
  249. } RCM_FLAG_T;
  250. /**@} end of group RCM_Enumerations */
  251. /** @defgroup RCM_Functions Functions
  252. @{
  253. */
  254. /* Function description */
  255. /* RCM Reset */
  256. void RCM_Reset(void);
  257. /* HSE clock */
  258. void RCM_ConfigHSE(RCM_HSE_T state);
  259. uint8_t RCM_WaitHSEReady(void);
  260. /* HSI clock */
  261. void RCM_ConfigHSITrim(uint8_t HSITrim);
  262. void RCM_EnableHSI(void);
  263. void RCM_DisableHSI(void);
  264. /* LSE and LSI clock */
  265. void RCM_ConfigLSE(RCM_LSE_T state);
  266. void RCM_EnableLSI(void);
  267. void RCM_DisableLSI(void);
  268. /* PLL clock */
  269. void RCM_ConfigPLL(RCM_PLLSEL_T pllSelect, RCM_PLLMF_T pllMf);
  270. void RCM_EnablePLL(void);
  271. void RCM_DisablePLL(void);
  272. /* Clock Security System */
  273. void RCM_EnableCSS(void);
  274. void RCM_DisableCSS(void);
  275. void RCM_ConfigMCO(RCM_MCOCLK_T mcoClock);
  276. void RCM_ConfigSYSCLK(RCM_SYSCLK_SEL_T sysClkSelect);
  277. RCM_SYSCLK_SEL_T RCM_ReadSYSCLKSource(void);
  278. /* Config clock prescaler of AHB, APB1, APB2, USB and ADC */
  279. void RCM_ConfigAHB(RCM_AHB_DIV_T AHBDiv);
  280. void RCM_ConfigAPB1(RCM_APB_DIV_T APB1Div);
  281. void RCM_ConfigAPB2(RCM_APB_DIV_T APB2Div);
  282. void RCM_ConfigUSBCLK(RCM_USB_DIV_T USBDiv);
  283. void RCM_ConfigFPUCLK(RCM_FPU_DIV_T FPUDiv);
  284. void RCM_ConfigADCCLK(RCM_PCLK2_DIV_T ADCDiv);
  285. /* RTC clock */
  286. void RCM_ConfigRTCCLK(RCM_RTCCLK_T rtcClkSelect);
  287. void RCM_EnableRTCCLK(void);
  288. void RCM_DisableRTCCLK(void);
  289. /* Reads the clock frequency */
  290. uint32_t RCM_ReadSYSCLKFreq(void);
  291. uint32_t RCM_ReadHCLKFreq(void);
  292. void RCM_ReadPCLKFreq(uint32_t* PCLK1, uint32_t* PCLK2);
  293. uint32_t RCM_ReadADCCLKFreq(void);
  294. /* Enable or disable Periph Clock */
  295. void RCM_EnableAHBPeriphClock(uint32_t AHBPeriph);
  296. void RCM_DisableAHBPeriphClock(uint32_t AHBPeriph);
  297. void RCM_EnableAPB2PeriphClock(uint32_t APB2Periph);
  298. void RCM_DisableAPB2PeriphClock(uint32_t APB2Periph);
  299. void RCM_EnableAPB1PeriphClock(uint32_t APB1Periph);
  300. void RCM_DisableAPB1PeriphClock(uint32_t APB1Periph);
  301. /* Enable or disable Periph Reset */
  302. void RCM_EnableAPB2PeriphReset(uint32_t APB2Periph);
  303. void RCM_DisableAPB2PeriphReset(uint32_t APB2Periph);
  304. void RCM_EnableAPB1PeriphReset(uint32_t APB1Periph);
  305. void RCM_DisableAPB1PeriphReset(uint32_t APB1Periph);
  306. /* Backup domain reset */
  307. void RCM_EnableBackupReset(void);
  308. void RCM_DisableBackupReset(void);
  309. /* Interrupts and flags */
  310. void RCM_EnableInterrupt(uint32_t interrupt);
  311. void RCM_DisableInterrupt(uint32_t interrupt);
  312. uint8_t RCM_ReadStatusFlag(RCM_FLAG_T flag);
  313. void RCM_ClearStatusFlag(void);
  314. uint8_t RCM_ReadIntFlag(RCM_INT_T flag);
  315. void RCM_ClearIntFlag(uint32_t flag);
  316. /**@} end of group RCM_Functions */
  317. /**@} end of group RCM_Driver */
  318. /**@} end of group APM32S10x_StdPeriphDriver */
  319. #ifdef __cplusplus
  320. }
  321. #endif
  322. #endif /* __APM32S10X_RCM_H */