py32f002b_hal_rcc.h 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal_rcc.h
  4. * @author MCU Application Team
  5. * @brief Header file of RCC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F002B_HAL_RCC_H
  32. #define __PY32F002B_HAL_RCC_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f002b_hal_def.h"
  38. /** @addtogroup PY32F002B_HAL_Driver
  39. * @{
  40. */
  41. /** @addtogroup RCC
  42. * @{
  43. */
  44. /* Private constants ---------------------------------------------------------*/
  45. /** @addtogroup RCC_Private_Constants
  46. * @{
  47. */
  48. /* Defines used for Flags */
  49. #define CR_REG_INDEX 1U
  50. #define BDCR_REG_INDEX 2U
  51. #define CSR_REG_INDEX 3U
  52. #define RCC_FLAG_MASK 0x1FU
  53. /* Define used for IS_RCC_CLOCKTYPE() */
  54. #define RCC_CLOCKTYPE_ALL (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1) /*!< All clocktype to configure */
  55. /**
  56. * @}
  57. */
  58. /* Private macros ------------------------------------------------------------*/
  59. /** @defgroup RCC_Private_Macros RCC Private Macros
  60. * @{
  61. */
  62. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  63. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  64. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  65. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  66. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE))
  67. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_BYPASS_ENABLE) || ((__HSE__) == RCC_HSE_BYPASS_DISABLE))
  68. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  69. ((__LSE__) == RCC_LSE_BYPASS))
  70. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  71. #if defined(RCC_HSI48M_SUPPORT)
  72. #define IS_RCC_HSI_CALIBRATION_VALUE(__VALUE__) (((__VALUE__) == RCC_HSICALIBRATION_24MHz) || \
  73. ((__VALUE__) == RCC_HSICALIBRATION_48MHz))
  74. #else
  75. #define IS_RCC_HSI_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) == RCC_HSICALIBRATION_24MHz)
  76. #endif
  77. #define IS_RCC_HSIDIV(__DIV__) (((__DIV__) == RCC_HSI_DIV1) || ((__DIV__) == RCC_HSI_DIV2) || \
  78. ((__DIV__) == RCC_HSI_DIV4) || ((__DIV__) == RCC_HSI_DIV8) || \
  79. ((__DIV__) == RCC_HSI_DIV16) || ((__DIV__) == RCC_HSI_DIV32)|| \
  80. ((__DIV__) == RCC_HSI_DIV64) || ((__DIV__) == RCC_HSI_DIV128))
  81. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  82. #define IS_RCC_CLOCKTYPE(__CLK__) ((((__CLK__) & RCC_CLOCKTYPE_ALL) != 0x00UL) && (((__CLK__) & ~RCC_CLOCKTYPE_ALL) == 0x00UL))
  83. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSISYS) || \
  84. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  85. ((__SOURCE__) == RCC_SYSCLKSOURCE_LSE) || \
  86. ((__SOURCE__) == RCC_SYSCLKSOURCE_LSI))
  87. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  88. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  89. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  90. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  91. ((__HCLK__) == RCC_SYSCLK_DIV512))
  92. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  93. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  94. ((__PCLK__) == RCC_HCLK_DIV16))
  95. #define IS_RCC_MCO(__MCOX__) (((__MCOX__) == RCC_MCO1) || ((__MCOX__) == RCC_MCO2))
  96. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCOSOURCE_NOCLOCK) || \
  97. ((__SOURCE__) == RCC_MCOSOURCE_SYSCLK) || \
  98. ((__SOURCE__) == RCC_MCOSOURCE_HSI) || \
  99. ((__SOURCE__) == RCC_MCOSOURCE_HSE) || \
  100. ((__SOURCE__) == RCC_MCOSOURCE_LSI) || \
  101. ((__SOURCE__) == RCC_MCOSOURCE_LSE))
  102. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1) || ((__DIV__) == RCC_MCODIV_2) || \
  103. ((__DIV__) == RCC_MCODIV_4) || ((__DIV__) == RCC_MCODIV_8) || \
  104. ((__DIV__) == RCC_MCODIV_16)|| ((__DIV__) == RCC_MCODIV_32) || \
  105. ((__DIV__) == RCC_MCODIV_64)|| ((__DIV__) == RCC_MCODIV_128))
  106. #define IS_RCC_LSE_DRIVE(__DRIVE__) (((__DRIVE__) == RCC_LSEDRIVE_LOWEST) || \
  107. ((__DRIVE__) == RCC_LSEDRIVE_LOW) || \
  108. ((__DRIVE__) == RCC_LSEDRIVE_MEDIUM) || \
  109. ((__DRIVE__) == RCC_LSEDRIVE_HIGH))
  110. /**
  111. * @}
  112. */
  113. /* Exported types ------------------------------------------------------------*/
  114. /** @defgroup RCC_Exported_Types RCC Exported Types
  115. * @{
  116. */
  117. /**
  118. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  119. */
  120. typedef struct
  121. {
  122. uint32_t OscillatorType; /*!< The oscillators to be configured.
  123. This parameter can be a value of @ref RCC_Oscillator_Type */
  124. uint32_t HSEState; /*!< The new state of the HSE.
  125. This parameter can be a value of @ref RCC_HSE_Config */
  126. uint32_t LSEState; /*!< The new state of the LSE.
  127. This parameter can be a value of @ref RCC_LSE_Config */
  128. uint32_t LSEDriver; /*!< The driver factor of the LSE.
  129. This parameter can be a value of @ref RCC_LSE_Driver */
  130. uint32_t HSIState; /*!< The new state of the HSI.
  131. This parameter can be a value of @ref RCC_HSI_Config */
  132. uint32_t HSIDiv; /*!< The division factor of the HSI.
  133. This parameter can be a value of @ref RCC_HSI_Div */
  134. uint32_t HSICalibrationValue; /*!< The calibration trimming value.
  135. This parameter can be a value of @ref RCC_HSI_Calibration */
  136. uint32_t LSIState; /*!< The new state of the LSI.
  137. This parameter can be a value of @ref RCC_LSI_Config */
  138. uint32_t LSICalibrationValue; /*!< The calibration trimming value.
  139. This parameter can be a value of @ref RCC_LSI_Calibration */
  140. } RCC_OscInitTypeDef;
  141. /**
  142. * @brief RCC System, AHB and APB busses clock configuration structure definition
  143. */
  144. typedef struct
  145. {
  146. uint32_t ClockType; /*!< The clock to be configured.
  147. This parameter can be a combination of @ref RCC_System_Clock_Type */
  148. uint32_t SYSCLKSource; /*!< The clock source used as system clock (SYSCLK).
  149. This parameter can be a value of @ref RCC_System_Clock_Source */
  150. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  151. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  152. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  153. This parameter can be a value of @ref RCC_APB1_Clock_Source */
  154. } RCC_ClkInitTypeDef;
  155. /**
  156. * @}
  157. */
  158. /* Exported constants --------------------------------------------------------*/
  159. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  160. * @{
  161. */
  162. /** @defgroup RCC_Timeout_Value Timeout Values
  163. * @{
  164. */
  165. #define RCC_DBP_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
  166. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT /* LSE timeout in ms */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup RCC_Oscillator_Type Oscillator Type
  171. * @{
  172. */
  173. #define RCC_OSCILLATORTYPE_NONE 0x00000000U /*!< Oscillator configuration unchanged */
  174. #define RCC_OSCILLATORTYPE_HSE 0x00000001U /*!< HSE to configure */
  175. #define RCC_OSCILLATORTYPE_HSI 0x00000002U /*!< HSI to configure */
  176. #define RCC_OSCILLATORTYPE_LSE 0x00000004U /*!< LSE to configure */
  177. #define RCC_OSCILLATORTYPE_LSI 0x00000008U /*!< LSI to configure */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup RCC_HSE_Config HSE Config
  182. * @{
  183. */
  184. #define RCC_HSE_BYPASS_DISABLE 0x00000000U /*!< Disable external clock source for HSE clock */
  185. #define RCC_HSE_BYPASS_ENABLE ((uint32_t)(RCC_CR_HSEEN)) /*!< Enable external clock source for HSE clock */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup RCC_LSE_Config LSE Config
  190. * @{
  191. */
  192. #define RCC_LSE_OFF 0x00000000U /*!< LSE clock deactivation */
  193. #define RCC_LSE_ON RCC_BDCR_LSEON /*!< LSE clock activation */
  194. #define RCC_LSE_BYPASS ((uint32_t)(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON)) /*!< External clock source for LSE clock */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup RCC_LSE_Driver LSE Config
  199. * @{
  200. */
  201. #define RCC_LSEDRIVE_LOWEST 0x00000000 /*!< LSE lowest driving capability */
  202. #define RCC_LSEDRIVE_LOW RCC_ECSCR_LSE_DRIVER_0 /*!< LSE low drive capability */
  203. #define RCC_LSEDRIVE_MEDIUM RCC_ECSCR_LSE_DRIVER_1 /*!< LSE medium drive capability */
  204. #define RCC_LSEDRIVE_HIGH (RCC_ECSCR_LSE_DRIVER_0 | RCC_ECSCR_LSE_DRIVER_1) /*!< LSE high drive capability */
  205. /**
  206. * @}
  207. */
  208. /** @defgroup RCC_LSE_STARTUP LSE settling time Config
  209. * @{
  210. */
  211. #define RCC_LSE_STARTUP_NONE (RCC_ECSCR_LSE_STARTUP_1 | RCC_ECSCR_LSE_STARTUP_0)
  212. #define RCC_LSE_STARTUP_LOW RCC_ECSCR_LSE_STARTUP_0
  213. #define RCC_LSE_STARTUP_MEDIUM 0x00000000U
  214. #define RCC_LSE_STARTUP_HIGH RCC_ECSCR_LSE_STARTUP_1
  215. /**
  216. * @}
  217. */
  218. /** @defgroup RCC_HSI_Config HSI Config
  219. * @{
  220. */
  221. #define RCC_HSI_OFF 0x00000000U /*!< HSI clock deactivation */
  222. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  223. /**
  224. * @}
  225. */
  226. /** @defgroup RCC_HSI_Calibration HSI Calibration
  227. * @{
  228. */
  229. #define RCC_HSICALIBRATION_24MHz ((*(uint32_t *)(0x1FFF0100)) & 0xFFFF) /*!< 24MHz HSI calibration trimming value */
  230. #if defined(RCC_HSI48M_SUPPORT)
  231. #define RCC_HSICALIBRATION_48MHz ((*(uint32_t *)(0x1FFF0104)) & 0xFFFF) /*!< 48MHz HSI calibration trimming value */
  232. #endif
  233. /**
  234. * @}
  235. */
  236. /** @defgroup RCC_HSI_Div HSI Div
  237. * @{
  238. */
  239. #define RCC_HSI_DIV1 0x00000000U /*!< HSI clock is not divided */
  240. #define RCC_HSI_DIV2 RCC_CR_HSIDIV_0 /*!< HSI clock is divided by 2 */
  241. #define RCC_HSI_DIV4 RCC_CR_HSIDIV_1 /*!< HSI clock is divided by 4 */
  242. #define RCC_HSI_DIV8 (RCC_CR_HSIDIV_1|RCC_CR_HSIDIV_0) /*!< HSI clock is divided by 8 */
  243. #define RCC_HSI_DIV16 RCC_CR_HSIDIV_2 /*!< HSI clock is divided by 16 */
  244. #define RCC_HSI_DIV32 (RCC_CR_HSIDIV_2|RCC_CR_HSIDIV_0) /*!< HSI clock is divided by 32 */
  245. #define RCC_HSI_DIV64 (RCC_CR_HSIDIV_2|RCC_CR_HSIDIV_1) /*!< HSI clock is divided by 64 */
  246. #define RCC_HSI_DIV128 (RCC_CR_HSIDIV_2|RCC_CR_HSIDIV_1|RCC_CR_HSIDIV_0) /*!< HSI clock is divided by 128 */
  247. /**
  248. * @}
  249. */
  250. /** @defgroup RCC_LSI_Config LSI Config
  251. * @{
  252. */
  253. #define RCC_LSI_OFF 0x00000000U /*!< LSI clock deactivation */
  254. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  255. /**
  256. * @}
  257. */
  258. /** @defgroup RCC_LSI_Calibration LSI Calibration
  259. * @{
  260. */
  261. #define RCC_LSICALIBRATION_32768Hz ((*(uint32_t *)(0x1FFF0144)) & 0x1FF) /*!< 32.768KHz LSI calibration trimming value */
  262. #define RCC_LSICALIBRATION_38400Hz ((*(uint32_t *)(0x1FFF0148)) & 0x1FF) /*!< 38.4KHz LSI calibration trimming value */
  263. /**
  264. * @}
  265. */
  266. /** @defgroup RCC_System_Clock_Type System Clock Type
  267. * @{
  268. */
  269. #define RCC_CLOCKTYPE_SYSCLK 0x00000001U /*!< SYSCLK to configure */
  270. #define RCC_CLOCKTYPE_HCLK 0x00000002U /*!< HCLK to configure */
  271. #define RCC_CLOCKTYPE_PCLK1 0x00000004U /*!< PCLK1 to configure */
  272. /**
  273. * @}
  274. */
  275. /** @defgroup RCC_System_Clock_Source System Clock Source
  276. * @{
  277. */
  278. #define RCC_SYSCLKSOURCE_HSISYS 0x00000000U /*!< HSISYS selection as system clock */
  279. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_0 /*!< HSE selection as system clock */
  280. #define RCC_SYSCLKSOURCE_LSI (RCC_CFGR_SW_1 | RCC_CFGR_SW_0) /*!< LSI selection as system clock */
  281. #define RCC_SYSCLKSOURCE_LSE RCC_CFGR_SW_2 /*!< LSE selection as system clock */
  282. /**
  283. * @}
  284. */
  285. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  286. * @{
  287. */
  288. #define RCC_SYSCLKSOURCE_STATUS_HSISYS 0x00000000U /*!< HSISYS used as system clock */
  289. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_0 /*!< HSE used as system clock */
  290. #define RCC_SYSCLKSOURCE_STATUS_LSI (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0) /*!< LSI used as system clock */
  291. #define RCC_SYSCLKSOURCE_STATUS_LSE RCC_CFGR_SWS_2 /*!< LSE used as system clock */
  292. /**
  293. * @}
  294. */
  295. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  296. * @{
  297. */
  298. #define RCC_SYSCLK_DIV1 0x00000000U /*!< SYSCLK not divided */
  299. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_3 /*!< SYSCLK divided by 2 */
  300. #define RCC_SYSCLK_DIV4 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 4 */
  301. #define RCC_SYSCLK_DIV8 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_1) /*!< SYSCLK divided by 8 */
  302. #define RCC_SYSCLK_DIV16 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_1 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 16 */
  303. #define RCC_SYSCLK_DIV64 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2) /*!< SYSCLK divided by 64 */
  304. #define RCC_SYSCLK_DIV128 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 128 */
  305. #define RCC_SYSCLK_DIV256 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2 | RCC_CFGR_HPRE_1) /*!< SYSCLK divided by 256 */
  306. #define RCC_SYSCLK_DIV512 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2 | RCC_CFGR_HPRE_1 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 512 */
  307. /**
  308. * @}
  309. */
  310. /** @defgroup RCC_APB1_Clock_Source APB Clock Source
  311. * @{
  312. */
  313. #define RCC_HCLK_DIV1 0x00000000U /*!< HCLK not divided */
  314. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE_2 /*!< HCLK divided by 2 */
  315. #define RCC_HCLK_DIV4 (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_0) /*!< HCLK divided by 4 */
  316. #define RCC_HCLK_DIV8 (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_1) /*!< HCLK divided by 8 */
  317. #define RCC_HCLK_DIV16 (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_1 | RCC_CFGR_PPRE_0) /*!< HCLK divided by 16 */
  318. /**
  319. * @}
  320. */
  321. /** @defgroup RCC_MCO_Index MCO Index
  322. * @{
  323. */
  324. #define RCC_MCO 0x00000000U
  325. #define RCC_MCO1 RCC_MCO /*!< Configure PA07 as the clock output.*/
  326. #define RCC_MCO2 0x00000001U /*!< Configure PB01 as the clock output. */
  327. /**
  328. * @}
  329. */
  330. /** @defgroup RCC_MCO_Clock_Source MCO Clock Source
  331. * @{
  332. */
  333. #define RCC_MCOSOURCE_NOCLOCK 0x00000000U /*!< MCO output disabled, no clock on MCO */
  334. #define RCC_MCOSOURCE_SYSCLK RCC_CFGR_MCOSEL_0 /*!< SYSCLK selection as MCO source */
  335. #define RCC_MCOSOURCE_HSI (RCC_CFGR_MCOSEL_0| RCC_CFGR_MCOSEL_1) /*!< HSI selection as MCO source */
  336. #define RCC_MCOSOURCE_HSE RCC_CFGR_MCOSEL_2 /*!< HSE selection as MCO source */
  337. #define RCC_MCOSOURCE_LSI (RCC_CFGR_MCOSEL_1|RCC_CFGR_MCOSEL_2) /*!< LSI selection as MCO source */
  338. #define RCC_MCOSOURCE_LSE (RCC_CFGR_MCOSEL_0|RCC_CFGR_MCOSEL_1|RCC_CFGR_MCOSEL_2) /*!< LSE selection as MCO source */
  339. /**
  340. * @}
  341. */
  342. /** @defgroup RCC_MCOx_Clock_Prescaler MCO1 Clock Prescaler
  343. * @{
  344. */
  345. #define RCC_MCODIV_1 0x00000000U /*!< MCO not divided */
  346. #define RCC_MCODIV_2 RCC_CFGR_MCOPRE_0 /*!< MCO divided by 2 */
  347. #define RCC_MCODIV_4 RCC_CFGR_MCOPRE_1 /*!< MCO divided by 4 */
  348. #define RCC_MCODIV_8 (RCC_CFGR_MCOPRE_1 | RCC_CFGR_MCOPRE_0) /*!< MCO divided by 8 */
  349. #define RCC_MCODIV_16 RCC_CFGR_MCOPRE_2 /*!< MCO divided by 16 */
  350. #define RCC_MCODIV_32 (RCC_CFGR_MCOPRE_2 | RCC_CFGR_MCOPRE_0) /*!< MCO divided by 32 */
  351. #define RCC_MCODIV_64 (RCC_CFGR_MCOPRE_2 | RCC_CFGR_MCOPRE_1) /*!< MCO divided by 64 */
  352. #define RCC_MCODIV_128 (RCC_CFGR_MCOPRE_2 | RCC_CFGR_MCOPRE_1 | RCC_CFGR_MCOPRE_0) /*!< MCO divided by 128 */
  353. /**
  354. * @}
  355. */
  356. /** @defgroup RCC_Interrupt Interrupts
  357. * @{
  358. */
  359. #define RCC_IT_LSIRDY RCC_CIFR_LSIRDYF /*!< LSI Ready Interrupt flag */
  360. #define RCC_IT_LSERDY RCC_CIFR_LSERDYF /*!< LSE Ready Interrupt flag */
  361. #define RCC_IT_LSECSS RCC_CIFR_LSECSSF /*!< LSE Clock Security System Interrupt flag */
  362. #define RCC_IT_HSIRDY RCC_CIFR_HSIRDYF /*!< HSI Ready Interrupt flag */
  363. /**
  364. * @}
  365. */
  366. /** @defgroup RCC_Flag Flags
  367. * Elements values convention: XXXYYYYYb
  368. * - YYYYY : Flag position in the register
  369. * - XXX : Register index
  370. * - 001: CR register
  371. * - 010: BDCR register
  372. * - 011: CSR register
  373. * @{
  374. */
  375. /* Flags in the CR register */
  376. #define RCC_FLAG_HSIRDY ((CR_REG_INDEX << 5U) | RCC_CR_HSIRDY_Pos) /*!< HSI Ready flag */
  377. /* Flags in the BDCR register */
  378. #define RCC_FLAG_LSERDY ((BDCR_REG_INDEX << 5U) | RCC_BDCR_LSERDY_Pos) /*!< LSE Ready flag */
  379. /* Flags in the CSR register */
  380. #define RCC_FLAG_LSIRDY ((CSR_REG_INDEX << 5U) | RCC_CSR_LSIRDY_Pos) /*!< LSI Ready flag */
  381. #define RCC_FLAG_OBLRST ((CSR_REG_INDEX << 5U) | RCC_CSR_OBLRSTF_Pos) /*!< Option Byte Loader reset flag */
  382. #define RCC_FLAG_PINRST ((CSR_REG_INDEX << 5U) | RCC_CSR_PINRSTF_Pos) /*!< PIN reset flag */
  383. #define RCC_FLAG_PWRRST ((CSR_REG_INDEX << 5U) | RCC_CSR_PWRRSTF_Pos) /*!< BOR or POR/PDR reset flag */
  384. #define RCC_FLAG_SFTRST ((CSR_REG_INDEX << 5U) | RCC_CSR_SFTRSTF_Pos) /*!< Software Reset flag */
  385. #define RCC_FLAG_IWDGRST ((CSR_REG_INDEX << 5U) | RCC_CSR_IWDGRSTF_Pos) /*!< Independent Watchdog reset flag */
  386. /**
  387. * @}
  388. */
  389. /**
  390. * @}
  391. */
  392. /* Exported macros -----------------------------------------------------------*/
  393. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  394. * @{
  395. */
  396. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable AHB Peripheral Clock Enable Disable
  397. * @brief Enable or disable the AHB peripheral clock.
  398. * @note After reset, the peripheral clock (used for registers read/write access)
  399. * is disabled and the application software has to enable this clock before
  400. * using it.
  401. * @{
  402. */
  403. #define __HAL_RCC_FLASH_CLK_ENABLE() do { \
  404. __IO uint32_t tmpreg; \
  405. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN); \
  406. /* Delay after an RCC peripheral clock enabling */ \
  407. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN); \
  408. UNUSED(tmpreg); \
  409. } while(0U)
  410. #define __HAL_RCC_SRAM_CLK_ENABLE() do { \
  411. __IO uint32_t tmpreg; \
  412. SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN); \
  413. /* Delay after an RCC peripheral clock enabling */ \
  414. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN); \
  415. UNUSED(tmpreg); \
  416. } while(0U)
  417. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  418. __IO uint32_t tmpreg; \
  419. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN); \
  420. /* Delay after an RCC peripheral clock enabling */ \
  421. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN); \
  422. UNUSED(tmpreg); \
  423. } while(0U)
  424. #define __HAL_RCC_FLASH_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN)
  425. #define __HAL_RCC_SRAM_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN)
  426. #define __HAL_RCC_CRC_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN)
  427. /**
  428. * @}
  429. */
  430. /** @defgroup RCC_IOPORT_Clock_Enable_Disable IOPORT Clock Enable Disable
  431. * @brief Enable or disable the IO Ports clock.
  432. * @note After reset, the IO ports clock (used for registers read/write access)
  433. * is disabled and the application software has to enable this clock before
  434. * using it.
  435. * @{
  436. */
  437. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  438. __IO uint32_t tmpreg; \
  439. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN); \
  440. /* Delay after an RCC peripheral clock enabling */ \
  441. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN); \
  442. UNUSED(tmpreg); \
  443. } while(0U)
  444. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  445. __IO uint32_t tmpreg; \
  446. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN); \
  447. /* Delay after an RCC peripheral clock enabling */ \
  448. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN); \
  449. UNUSED(tmpreg); \
  450. } while(0U)
  451. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  452. __IO uint32_t tmpreg; \
  453. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN); \
  454. /* Delay after an RCC peripheral clock enabling */ \
  455. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN); \
  456. UNUSED(tmpreg); \
  457. } while(0U)
  458. #define __HAL_RCC_GPIOA_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN)
  459. #define __HAL_RCC_GPIOB_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN)
  460. #define __HAL_RCC_GPIOC_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN)
  461. /**
  462. * @}
  463. */
  464. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Peripheral Clock Enable Disable
  465. * @brief Enable or disable the APB1 peripheral clock.
  466. * @note After reset, the peripheral clock (used for registers read/write access)
  467. * is disabled and the application software has to enable this clock before
  468. * using it.
  469. * @{
  470. */
  471. #define __HAL_RCC_I2C_CLK_ENABLE() do { \
  472. __IO uint32_t tmpreg; \
  473. SET_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN); \
  474. /* Delay after an RCC peripheral clock enabling */ \
  475. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN); \
  476. UNUSED(tmpreg); \
  477. } while(0U)
  478. #define __HAL_RCC_DBGMCU_CLK_ENABLE() do { \
  479. __IO uint32_t tmpreg; \
  480. SET_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN); \
  481. /* Delay after an RCC peripheral clock enabling */ \
  482. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN); \
  483. UNUSED(tmpreg); \
  484. } while(0U)
  485. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  486. __IO uint32_t tmpreg; \
  487. SET_BIT(RCC->APBENR1, RCC_APBENR1_PWREN); \
  488. /* Delay after an RCC peripheral clock enabling */ \
  489. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_PWREN); \
  490. UNUSED(tmpreg); \
  491. } while(0U)
  492. #define __HAL_RCC_LPTIM_CLK_ENABLE() do { \
  493. __IO uint32_t tmpreg; \
  494. SET_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN); \
  495. /* Delay after an RCC peripheral clock enabling */ \
  496. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN); \
  497. UNUSED(tmpreg); \
  498. } while(0U)
  499. /**
  500. * @}
  501. */
  502. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Peripheral Clock Enable Disable
  503. * @brief Enable or disable the APB2 peripheral clock.
  504. * @note After reset, the peripheral clock (used for registers read/write access)
  505. * is disabled and the application software has to enable this clock before
  506. * using it.
  507. * @{
  508. */
  509. #define __HAL_RCC_SYSCFG_CLK_ENABLE() do { \
  510. __IO uint32_t tmpreg; \
  511. SET_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN); \
  512. /* Delay after an RCC peripheral clock enabling */ \
  513. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN); \
  514. UNUSED(tmpreg); \
  515. } while(0U)
  516. #define __HAL_RCC_TIM1_CLK_ENABLE() do { \
  517. __IO uint32_t tmpreg; \
  518. SET_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN); \
  519. /* Delay after an RCC peripheral clock enabling */ \
  520. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN); \
  521. UNUSED(tmpreg); \
  522. } while(0U)
  523. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  524. __IO uint32_t tmpreg; \
  525. SET_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN); \
  526. /* Delay after an RCC peripheral clock enabling */ \
  527. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN); \
  528. UNUSED(tmpreg); \
  529. } while(0U)
  530. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  531. __IO uint32_t tmpreg; \
  532. SET_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN); \
  533. /* Delay after an RCC peripheral clock enabling */ \
  534. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN); \
  535. UNUSED(tmpreg); \
  536. } while(0U)
  537. #define __HAL_RCC_TIM14_CLK_ENABLE() do { \
  538. __IO uint32_t tmpreg; \
  539. SET_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN); \
  540. /* Delay after an RCC peripheral clock enabling */ \
  541. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN); \
  542. UNUSED(tmpreg); \
  543. } while(0U)
  544. #define __HAL_RCC_ADC_CLK_ENABLE() do { \
  545. __IO uint32_t tmpreg; \
  546. SET_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN); \
  547. /* Delay after an RCC peripheral clock enabling */ \
  548. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN); \
  549. UNUSED(tmpreg); \
  550. } while(0U)
  551. #if defined(COMP1)
  552. #define __HAL_RCC_COMP1_CLK_ENABLE() do { \
  553. __IO uint32_t tmpreg; \
  554. SET_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN); \
  555. /* Delay after an RCC peripheral clock enabling */ \
  556. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN); \
  557. UNUSED(tmpreg); \
  558. } while(0U)
  559. #endif
  560. #if defined(COMP2)
  561. #define __HAL_RCC_COMP2_CLK_ENABLE() do { \
  562. __IO uint32_t tmpreg; \
  563. SET_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN); \
  564. /* Delay after an RCC peripheral clock enabling */ \
  565. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN); \
  566. UNUSED(tmpreg); \
  567. } while(0U)
  568. #endif
  569. #define __HAL_RCC_I2C_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN)
  570. #define __HAL_RCC_DBGMCU_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN)
  571. #define __HAL_RCC_PWR_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_PWREN)
  572. #define __HAL_RCC_LPTIM_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN)
  573. #define __HAL_RCC_SYSCFG_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN)
  574. #define __HAL_RCC_TIM1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN)
  575. #define __HAL_RCC_SPI1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN)
  576. #define __HAL_RCC_USART1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN)
  577. #if defined(TIM14)
  578. #define __HAL_RCC_TIM14_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN)
  579. #endif
  580. #define __HAL_RCC_ADC_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN)
  581. #if defined(COMP1)
  582. #define __HAL_RCC_COMP1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN)
  583. #endif
  584. #if defined(COMP2)
  585. #define __HAL_RCC_COMP2_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN)
  586. #endif
  587. /**
  588. * @}
  589. */
  590. /** @defgroup RCC_AHB_Peripheral_Clock_Enabled_Disabled_Status AHB Peripheral Clock Enabled or Disabled Status
  591. * @brief Check whether the AHB peripheral clock is enabled or not.
  592. * @note After reset, the peripheral clock (used for registers read/write access)
  593. * is disabled and the application software has to enable this clock before
  594. * using it.
  595. * @{
  596. */
  597. #define __HAL_RCC_FLASH_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN) != RESET)
  598. #define __HAL_RCC_CRC_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) != RESET)
  599. #define __HAL_RCC_FLASH_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN) == RESET)
  600. #define __HAL_RCC_CRC_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) == RESET)
  601. /**
  602. * @}
  603. */
  604. /** @defgroup RCC_IOPORT_Clock_Enabled_Disabled_Status IOPORT Clock Enabled or Disabled Status
  605. * @brief Check whether the IO Port clock is enabled or not.
  606. * @note After reset, the peripheral clock (used for registers read/write access)
  607. * is disabled and the application software has to enable this clock before
  608. * using it.
  609. * @{
  610. */
  611. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) != RESET)
  612. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) != RESET)
  613. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN) != RESET)
  614. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) == RESET)
  615. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) == RESET)
  616. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN) == RESET)
  617. /**
  618. * @}
  619. */
  620. /** @defgroup RCC_APB1_Clock_Enabled_Disabled_Status APB1 Peripheral Clock Enabled or Disabled Status
  621. * @brief Check whether the APB1 peripheral clock is enabled or not.
  622. * @note After reset, the peripheral clock (used for registers read/write access)
  623. * is disabled and the application software has to enable this clock before
  624. * using it.
  625. * @{
  626. */
  627. #define __HAL_RCC_I2C_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN) != 0U)
  628. #define __HAL_RCC_DBGMCU_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN) != 0U)
  629. #define __HAL_RCC_PWR_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_PWREN) != 0U)
  630. #define __HAL_RCC_LPTIM_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN) != 0U)
  631. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN) == 0U)
  632. #define __HAL_RCC_DBGMCU_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN) == 0U)
  633. #define __HAL_RCC_PWR_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_PWREN) == 0U)
  634. #define __HAL_RCC_LPTIM_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN) == 0U)
  635. /**
  636. * @}
  637. */
  638. /** @defgroup RCC_APB2_Clock_Enabled_Disabled_Status APB2 Peripheral Clock Enabled or Disabled Status
  639. * @brief Check whether the APB2 peripheral clock is enabled or not.
  640. * @note After reset, the peripheral clock (used for registers read/write access)
  641. * is disabled and the application software has to enable this clock before
  642. * using it.
  643. * @{
  644. */
  645. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN) != 0U)
  646. #define __HAL_RCC_TIM1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN) != 0U)
  647. #define __HAL_RCC_SPI1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN) != 0U)
  648. #define __HAL_RCC_USART1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN) != 0U)
  649. #if defined(TIM14)
  650. #define __HAL_RCC_TIM14_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN) != 0U)
  651. #endif
  652. #define __HAL_RCC_ADC_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN) != 0U)
  653. #if defined(COMP1)
  654. #define __HAL_RCC_COMP1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN) != 0U)
  655. #endif
  656. #if defined(COMP2)
  657. #define __HAL_RCC_COMP2_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN) != 0U)
  658. #endif
  659. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN) == 0U)
  660. #define __HAL_RCC_TIM1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN) == 0U)
  661. #define __HAL_RCC_SPI1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN) == 0U)
  662. #define __HAL_RCC_USART1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN) == 0U)
  663. #if defined(TIM14)
  664. #define __HAL_RCC_TIM14_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN) == 0U)
  665. #endif
  666. #define __HAL_RCC_ADC_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN) == 0U)
  667. #if defined(COMP1)
  668. #define __HAL_RCC_COMP1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN) == 0U)
  669. #endif
  670. #if defined(COMP2)
  671. #define __HAL_RCC_COMP2_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN) == 0U)
  672. #endif
  673. /**
  674. * @}
  675. */
  676. /** @defgroup RCC_AHB_Force_Release_Reset AHB Peripheral Force Release Reset
  677. * @brief Force or release AHB1 peripheral reset.
  678. * @{
  679. */
  680. #define __HAL_RCC_AHB_FORCE_RESET() WRITE_REG(RCC->AHBRSTR, 0xFFFFFFFFU)
  681. #define __HAL_RCC_FLASH_FORCE_RESET() SET_BIT(RCC->AHBRSTR, RCC_AHBRSTR_FLASHRST)
  682. #define __HAL_RCC_CRC_FORCE_RESET() SET_BIT(RCC->AHBRSTR, RCC_AHBRSTR_CRCRST)
  683. #define __HAL_RCC_AHB_RELEASE_RESET() WRITE_REG(RCC->AHBRSTR, 0x00000000U)
  684. #define __HAL_RCC_FLASH_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, RCC_AHBRSTR_FLASHRST)
  685. #define __HAL_RCC_CRC_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, RCC_AHBRSTR_CRCRST)
  686. /**
  687. * @}
  688. */
  689. /** @defgroup RCC_IOPORT_Force_Release_Reset IOPORT Force Release Reset
  690. * @brief Force or release IO Port reset.
  691. * @{
  692. */
  693. #define __HAL_RCC_IOP_FORCE_RESET() WRITE_REG(RCC->IOPRSTR, 0xFFFFFFFFU)
  694. #define __HAL_RCC_GPIOA_FORCE_RESET() SET_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOARST)
  695. #define __HAL_RCC_GPIOB_FORCE_RESET() SET_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOBRST)
  696. #define __HAL_RCC_GPIOC_FORCE_RESET() SET_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOCRST)
  697. #define __HAL_RCC_IOP_RELEASE_RESET() WRITE_REG(RCC->IOPRSTR, 0x00000000U)
  698. #define __HAL_RCC_GPIOA_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOARST)
  699. #define __HAL_RCC_GPIOB_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOBRST)
  700. #define __HAL_RCC_GPIOC_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOCRST)
  701. /**
  702. * @}
  703. */
  704. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Peripheral Force Release Reset
  705. * @brief Force or release APB1 peripheral reset.
  706. * @{
  707. */
  708. #define __HAL_RCC_APB1_FORCE_RESET() WRITE_REG(RCC->APBRSTR1, 0xFFFFFFFFU)
  709. #define __HAL_RCC_I2C_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_I2CRST)
  710. #define __HAL_RCC_DBGMCU_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_DBGRST)
  711. #define __HAL_RCC_PWR_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_PWRRST)
  712. #define __HAL_RCC_LPTIM_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_LPTIMRST)
  713. #define __HAL_RCC_APB1_RELEASE_RESET() WRITE_REG(RCC->APBRSTR1, 0x00000000U)
  714. #define __HAL_RCC_I2C_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_I2CRST)
  715. #define __HAL_RCC_DBGMCU_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_DBGRST)
  716. #define __HAL_RCC_PWR_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_PWRRST)
  717. #define __HAL_RCC_LPTIM_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_LPTIMRST)
  718. /**
  719. * @}
  720. */
  721. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Peripheral Force Release Reset
  722. * @brief Force or release APB2 peripheral reset.
  723. * @{
  724. */
  725. #define __HAL_RCC_APB2_FORCE_RESET() WRITE_REG(RCC->APBRSTR2, 0xFFFFFFFFU)
  726. #define __HAL_RCC_SYSCFG_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SYSCFGRST)
  727. #define __HAL_RCC_TIM1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM1RST)
  728. #define __HAL_RCC_SPI1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SPI1RST)
  729. #define __HAL_RCC_USART1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_USART1RST)
  730. #define __HAL_RCC_TIM14_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM14RST)
  731. #define __HAL_RCC_ADC_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_ADCRST)
  732. #if defined(COMP1)
  733. #define __HAL_RCC_COMP1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP1RST)
  734. #endif
  735. #if defined(COMP2)
  736. #define __HAL_RCC_COMP2_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP2RST)
  737. #endif
  738. #define __HAL_RCC_APB2_RELEASE_RESET() WRITE_REG(RCC->APBRSTR2, 0x00U)
  739. #define __HAL_RCC_SYSCFG_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SYSCFGRST)
  740. #define __HAL_RCC_TIM1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM1RST)
  741. #define __HAL_RCC_SPI1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SPI1RST)
  742. #define __HAL_RCC_USART1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_USART1RST)
  743. #define __HAL_RCC_TIM14_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM14RST)
  744. #define __HAL_RCC_ADC_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_ADCRST)
  745. #if defined(COMP1)
  746. #define __HAL_RCC_COMP1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP1RST)
  747. #endif
  748. #if defined(COMP2)
  749. #define __HAL_RCC_COMP2_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP2RST)
  750. #endif
  751. /**
  752. * @}
  753. */
  754. /** @defgroup RCC_Clock_Configuration RCC Clock Configuration
  755. * @{
  756. */
  757. /** @brief Macros to enable the Internal High Speed oscillator (HSI).
  758. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  759. * It is used (enabled by hardware) as system clock source after startup
  760. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  761. * of the HSE used directly or indirectly as system clock (if the Clock
  762. * Security System CSS is enabled).
  763. * @note After enabling the HSI, the application software should wait on HSIRDY
  764. * flag to be set indicating that HSI clock is stable and can be used as
  765. * system clock source.
  766. * This parameter can be: ENABLE or DISABLE.
  767. * @retval None
  768. */
  769. #define __HAL_RCC_HSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_HSION)
  770. /** @brief Macros to disable the Internal High Speed oscillator (HSI).
  771. * @note HSI can not be stopped if it is used as system clock source. In this case,
  772. * you have to select another source of the system clock then stop the HSI.
  773. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  774. * clock cycles.
  775. * @retval None
  776. */
  777. #define __HAL_RCC_HSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_HSION)
  778. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  779. * @note The calibration is used to compensate for the variations in voltage
  780. * and temperature that influence the frequency of the internal HSI RC.
  781. * @param __HSICALIBRATIONVALUE__ specifies the calibration trimming value
  782. * (default is RCC_HSICALIBRATION_DEFAULT).
  783. * This parameter must be a number between 0 and 127.
  784. * @retval None
  785. */
  786. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(__HSICALIBRATIONVALUE__) \
  787. MODIFY_REG(RCC->ICSCR, (RCC_ICSCR_HSI_FS_Msk|RCC_ICSCR_HSI_TRIM), (uint32_t)(__HSICALIBRATIONVALUE__) << RCC_ICSCR_HSI_TRIM_Pos)
  788. /** @brief Macro to configure the HSISYS clock.
  789. * @param __HSIDIV__ specifies the HSI division factor.
  790. * This parameter can be one of the following values:
  791. * @arg @ref RCC_HSI_DIV1 HSI clock source is divided by 1
  792. * @arg @ref RCC_HSI_DIV2 HSI clock source is divided by 2
  793. * @arg @ref RCC_HSI_DIV4 HSI clock source is divided by 4
  794. * @arg @ref RCC_HSI_DIV8 HSI clock source is divided by 8
  795. * @arg @ref RCC_HSI_DIV16 HSI clock source is divided by 16
  796. * @arg @ref RCC_HSI_DIV32 HSI clock source is divided by 32
  797. * @arg @ref RCC_HSI_DIV64 HSI clock source is divided by 64
  798. * @arg @ref RCC_HSI_DIV128 HSI clock source is divided by 128
  799. */
  800. #define __HAL_RCC_HSI_CONFIG(__HSIDIV__) \
  801. MODIFY_REG(RCC->CR, RCC_CR_HSIDIV, (__HSIDIV__))
  802. /** @brief Macros to enable or disable the Internal Low Speed oscillator (LSI).
  803. * @note After enabling the LSI, the application software should wait on
  804. * LSIRDY flag to be set indicating that LSI clock is stable and can
  805. * be used to clock the IWDG.
  806. * @note LSI can not be disabled if the IWDG is running.
  807. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  808. * clock cycles.
  809. * @retval None
  810. */
  811. #define __HAL_RCC_LSI_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_LSION)
  812. #define __HAL_RCC_LSI_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_LSION)
  813. /** @brief Macro to adjust the Internal Low Speed oscillator (LSI) calibration value.
  814. * @param __LSICALIBRATIONVALUE__ specifies the calibration trimming value.
  815. * This parameter can be one of the following values:
  816. * @arg @ref RCC_LSICALIBRATION_32768Hz
  817. * @arg @ref RCC_LSICALIBRATION_38400Hz
  818. * @retval None
  819. */
  820. #define __HAL_RCC_LSI_CALIBRATIONVALUE_ADJUST(__LSICALIBRATIONVALUE__) \
  821. MODIFY_REG(RCC->ICSCR, RCC_ICSCR_LSI_TRIM, (__LSICALIBRATIONVALUE__ << RCC_ICSCR_LSI_TRIM_Pos))
  822. /**
  823. * @brief Macro to configure the External High Speed oscillator (HSE).
  824. * @param __STATE__ specifies the new state of the HSE.
  825. * This parameter can be one of the following values:
  826. * @arg @ref RCC_HSE_BYPASS_DISABLE Disable HSE oscillator bypassed with external clock.
  827. * @arg @ref RCC_HSE_BYPASS_ENABLE Enable HSE oscillator bypassed with external clock.
  828. * @retval None
  829. */
  830. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  831. do { \
  832. if((__STATE__) == RCC_HSE_BYPASS_ENABLE) \
  833. { \
  834. SET_BIT(RCC->CR, RCC_CR_HSEEN); \
  835. } \
  836. else \
  837. { \
  838. CLEAR_BIT(RCC->CR, RCC_CR_HSEEN); \
  839. } \
  840. } while(0U)
  841. /**
  842. * @brief Macro to configure the External Low Speed oscillator (LSE).
  843. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not
  844. * supported by this macro. User should request a transition to LSE Off
  845. * first and then LSE On or LSE Bypass.
  846. * @note As the LSE is in the Backup domain and write access is denied to
  847. * this domain after reset, you have to enable write access using
  848. * HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  849. * (to be done once after reset).
  850. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  851. * software should wait on LSERDY flag to be set indicating that LSE clock
  852. * is stable.
  853. * @param __STATE__ specifies the new state of the LSE.
  854. * This parameter can be one of the following values:
  855. * @arg @ref RCC_LSE_OFF Turn OFF the LSE oscillator, LSERDY flag goes low after
  856. * 6 LSE oscillator clock cycles.
  857. * @arg @ref RCC_LSE_ON Turn ON the LSE oscillator.
  858. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  859. * @retval None
  860. */
  861. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  862. do { \
  863. if((__STATE__) == RCC_LSE_ON) \
  864. { \
  865. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  866. } \
  867. else if((__STATE__) == RCC_LSE_BYPASS) \
  868. { \
  869. SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  870. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  871. } \
  872. else \
  873. { \
  874. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  875. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  876. } \
  877. } while(0U)
  878. /** @brief Macro to configure the LSE settling time.
  879. * @param __TIME__ specifies the LSE settling time.
  880. * This parameter can be one of the following values:
  881. * @arg @ref RCC_LSE_STARTUP_NONE Direct output regardless of stabilization time.
  882. * @arg @ref RCC_LSE_STARTUP_LOW It is output after 2048 LSE clock cycles.
  883. If LSEBYP is set, it is output after 1024 clock cycles.
  884. * @arg @ref RCC_LSE_STARTUP_MEDIUM It is output after 4096 LSE clock cycles.
  885. If LSEBYP is set, it is output after 2048 clock cycles.
  886. * @arg @ref RCC_LSE_STARTUP_HIGH It is output after 8192 LSE clock cycles.
  887. If LSEBYP is set, it is output after 4096 clock cycles.
  888. */
  889. #define __HAL_RCC_LSE_STARTUP_DELAY(__TIME__) MODIFY_REG(RCC->ECSCR, RCC_ECSCR_LSE_STARTUP ,(__TIME__))
  890. /**
  891. * @brief Macro to configure the system clock source.
  892. * @param __SYSCLKSOURCE__ specifies the system clock source.
  893. * This parameter can be one of the following values:
  894. * @arg @ref RCC_SYSCLKSOURCE_HSISYS HSISYS oscillator is used as system clock source.
  895. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  896. * @arg @ref RCC_SYSCLKSOURCE_LSI LSI oscillator is used as system clock source.
  897. * @arg @ref RCC_SYSCLKSOURCE_LSE LSE oscillator is used as system clock source.
  898. * @note Depending on devices and packages, some clocks may not be available.
  899. * Refer to device datasheet for clocks availability.
  900. * @retval None
  901. */
  902. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  903. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  904. /** @brief Macro to get the clock source used as system clock.
  905. * @retval The clock source used as system clock. The returned value can be one
  906. * of the following:
  907. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSISYS HSISYS used as system clock.
  908. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock.
  909. * @arg @ref RCC_SYSCLKSOURCE_STATUS_LSI LSI used as system clock source.
  910. * @arg @ref RCC_SYSCLKSOURCE_STATUS_LSE LSE used as system clock source.
  911. * @note Depending on devices and packages, some clocks may not be available.
  912. * Refer to device datasheet for clocks availability.
  913. */
  914. #define __HAL_RCC_GET_SYSCLK_SOURCE() (RCC->CFGR & RCC_CFGR_SWS)
  915. /**
  916. * @brief Macro to configure the External Low Speed oscillator (LSE) drive capability.
  917. * @note As the LSE is in the Backup domain and write access is denied to
  918. * this domain after reset, you have to enable write access using
  919. * HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  920. * (to be done once after reset).
  921. * @param __LSEDRIVE__ specifies the new state of the LSE drive capability.
  922. * This parameter can be one of the following values:
  923. * @arg @ref RCC_LSEDRIVE_LOWEST LSE oscillator lowest drive capability.
  924. * @arg @ref RCC_LSEDRIVE_LOW LSE oscillator low drive capability.
  925. * @arg @ref RCC_LSEDRIVE_MEDIUM LSE oscillator medium low drive capability.
  926. * @arg @ref RCC_LSEDRIVE_HIGH LSE oscillator high drive capability.
  927. * @retval None
  928. */
  929. #define __HAL_RCC_LSEDRIVE_CONFIG(__LSEDRIVE__) \
  930. MODIFY_REG(RCC->ECSCR, RCC_ECSCR_LSE_DRIVER, (uint32_t)(__LSEDRIVE__))
  931. /** @brief Macro to configure the MCO clock.
  932. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  933. * This parameter can be one of the following values:
  934. * @arg @ref RCC_MCOSOURCE_NOCLOCK MCO output disabled
  935. * @arg @ref RCC_MCOSOURCE_SYSCLK System clock selected as MCO source
  936. * @arg @ref RCC_MCOSOURCE_HSI HSI clock selected as MCO source
  937. * @arg @ref RCC_MCOSOURCE_HSE HSE clock selected as MCO sourcee
  938. * @arg @ref RCC_MCOSOURCE_LSI LSI clock selected as MCO source
  939. * @arg @ref RCC_MCOSOURCE_LSE LSE clock selected as MCO source
  940. * @note Depending on devices and packages, some clocks may not be available.
  941. * Refer to device datasheet for clocks availability.
  942. * @param __MCODIV__ specifies the MCO clock prescaler.
  943. * This parameter can be one of the following values:
  944. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  945. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  946. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  947. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  948. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  949. * @arg @ref RCC_MCODIV_32 MCO clock source is divided by 32
  950. * @arg @ref RCC_MCODIV_64 MCO clock source is divided by 64
  951. * @arg @ref RCC_MCODIV_128 MCO clock source is divided by 128
  952. */
  953. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  954. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCOSEL | RCC_CFGR_MCOPRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  955. /**
  956. * @}
  957. */
  958. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  959. * @brief macros to manage the specified RCC Flags and interrupts.
  960. * @{
  961. */
  962. /** @brief Enable RCC interrupt.
  963. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  964. * This parameter can be any combination of the following values:
  965. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  966. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  967. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  968. * @note Depending on devices and packages, some clocks may not be available.
  969. * Refer to device datasheet for clocks availability.
  970. * @retval None
  971. */
  972. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) SET_BIT(RCC->CIER, (__INTERRUPT__))
  973. /** @brief Disable RCC interrupt.
  974. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  975. * This parameter can be any combination of the following values:
  976. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  977. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  978. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  979. * @note Depending on devices and packages, some clocks may not be available.
  980. * Refer to device datasheet for clocks availability.
  981. * @retval None
  982. */
  983. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(RCC->CIER, (__INTERRUPT__))
  984. /** @brief Clear RCC interrupt pending bits.
  985. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  986. * This parameter can be any combination of the following values:
  987. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  988. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  989. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  990. * @arg @ref RCC_IT_LSECSS LSE Clock security system interrupt
  991. * @note Depending on devices and packages, some clocks may not be available.
  992. * Refer to device datasheet for clocks availability.
  993. * @retval None
  994. */
  995. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (RCC->CICR = (__INTERRUPT__))
  996. /** @brief Check whether the RCC interrupt has occurred or not.
  997. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  998. * This parameter can be one of the following values:
  999. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1000. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1001. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1002. * @arg @ref RCC_IT_LSECSS LSE Clock security system interrupt
  1003. * @note Depending on devices and packages, some clocks may not be available.
  1004. * Refer to device datasheet for clocks availability.
  1005. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1006. */
  1007. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIFR & (__INTERRUPT__)) == (__INTERRUPT__))
  1008. /** @brief Set RMVF bit to clear the reset flags.
  1009. * The reset flags are: RCC_FLAG_OBLRST, RCC_FLAG_PINRST, RCC_FLAG_PWRRST,
  1010. * RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST.
  1011. * @note Depending on the device and software package, some flag bits may not be available.
  1012. * Refer to the device data sheet for flag bit availability.
  1013. * @retval None
  1014. */
  1015. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1016. /** @brief Check whether the selected RCC flag is set or not.
  1017. * @param __FLAG__ specifies the flag to check.
  1018. * This parameter can be one of the following values:
  1019. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready
  1020. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready
  1021. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready
  1022. * @arg @ref RCC_FLAG_PWRRST BOR or POR/PDR reset
  1023. * @arg @ref RCC_FLAG_OBLRST OBLRST reset
  1024. * @arg @ref RCC_FLAG_PINRST Pin reset
  1025. * @arg @ref RCC_FLAG_SFTRST Software reset
  1026. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset
  1027. * @note Depending on the device and software package, some flag bits may not be available.
  1028. * Refer to the device data sheet for flag bit availability.
  1029. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1030. */
  1031. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((__FLAG__) >> 5U) == CR_REG_INDEX) ? RCC->CR : \
  1032. ((((__FLAG__) >> 5U) == BDCR_REG_INDEX) ? RCC->BDCR : \
  1033. ((((__FLAG__) >> 5U) == CSR_REG_INDEX) ? RCC->CSR : RCC->CIFR))) & \
  1034. (1U << ((__FLAG__) & RCC_FLAG_MASK))) != RESET) \
  1035. ? 1U : 0U)
  1036. /**
  1037. * @}
  1038. */
  1039. /**
  1040. * @}
  1041. */
  1042. /* Include RCC HAL Extended module */
  1043. #include "py32f002b_hal_rcc_ex.h"
  1044. /* Exported functions --------------------------------------------------------*/
  1045. /** @addtogroup RCC_Exported_Functions
  1046. * @{
  1047. */
  1048. /** @addtogroup RCC_Exported_Functions_Group1
  1049. * @{
  1050. */
  1051. /* Initialization and de-initialization functions ******************************/
  1052. HAL_StatusTypeDef HAL_RCC_DeInit(void);
  1053. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1054. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1055. /**
  1056. * @}
  1057. */
  1058. /** @addtogroup RCC_Exported_Functions_Group2
  1059. * @{
  1060. */
  1061. /* Peripheral Control functions ************************************************/
  1062. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1063. void HAL_RCC_EnableLSECSS(void);
  1064. void HAL_RCC_DisableLSECSS(void);
  1065. void HAL_RCC_LSECSSCallback(void);
  1066. uint32_t HAL_RCC_GetSysClockFreq(void);
  1067. uint32_t HAL_RCC_GetHCLKFreq(void);
  1068. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1069. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1070. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1071. /* LSE & HSE CSS NMI IRQ handler */
  1072. void HAL_RCC_NMI_IRQHandler(void);
  1073. /* User Callbacks in non blocking mode (IT mode) */
  1074. void HAL_RCC_CSSCallback(void);
  1075. /**
  1076. * @}
  1077. */
  1078. /**
  1079. * @}
  1080. */
  1081. /**
  1082. * @}
  1083. */
  1084. /**
  1085. * @}
  1086. */
  1087. #ifdef __cplusplus
  1088. }
  1089. #endif
  1090. #endif /* __PY32F002B_HAL_RCC_H */
  1091. /************************ (C) COPYRIGHT Puya *****END OF FILE****/