py32f0xx_hal_rcc.h 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_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 __PY32F0xx_HAL_RCC_H
  32. #define __PY32F0xx_HAL_RCC_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx_hal_def.h"
  38. /** @addtogroup PY32F0xx_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. /** @addtogroup RCC_Private_Macros
  60. * @{
  61. */
  62. #if (defined(PY32F003PRE) || defined(PY32F002APRE))
  63. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  64. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  65. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  66. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI))
  67. #else
  68. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  69. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  70. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  71. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  72. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE))
  73. #endif
  74. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  75. ((__HSE__) == RCC_HSE_BYPASS))
  76. #if defined(PY32F002APRE)
  77. #define IS_RCC_HSE_FREQ(__FREQ__) (((__FREQ__) == RCC_HSE_4_8MHz) || ((__FREQ__) == RCC_HSE_8_16MHz) || \
  78. ((__FREQ__) == RCC_HSE_16_24MHz))
  79. #else
  80. #define IS_RCC_HSE_FREQ(__FREQ__) (((__FREQ__) == RCC_HSE_4_8MHz) || ((__FREQ__) == RCC_HSE_8_16MHz) || \
  81. ((__FREQ__) == RCC_HSE_16_32MHz))
  82. #endif
  83. #if defined(RCC_LSE_SUPPORT)
  84. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  85. ((__LSE__) == RCC_LSE_BYPASS))
  86. #endif
  87. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  88. #if defined(PY32F002APRE)
  89. #define IS_RCC_HSI_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) == RCC_HSICALIBRATION_8MHz || \
  90. (__VALUE__) == RCC_HSICALIBRATION_24MHz)
  91. #else
  92. #define IS_RCC_HSI_CALIBRATION_VALUE(__VALUE__) (((__VALUE__) == RCC_HSICALIBRATION_4MHz) || \
  93. ((__VALUE__) == RCC_HSICALIBRATION_8MHz) || \
  94. ((__VALUE__) == RCC_HSICALIBRATION_16MHz) || \
  95. ((__VALUE__) == RCC_HSICALIBRATION_22p12MHz) || \
  96. ((__VALUE__) == RCC_HSICALIBRATION_24MHz))
  97. #endif
  98. #if defined(RCC_HSIDIV_SUPPORT)
  99. #define IS_RCC_HSIDIV(__DIV__) (((__DIV__) == RCC_HSI_DIV1) || ((__DIV__) == RCC_HSI_DIV2) || \
  100. ((__DIV__) == RCC_HSI_DIV4) || ((__DIV__) == RCC_HSI_DIV8) || \
  101. ((__DIV__) == RCC_HSI_DIV16) || ((__DIV__) == RCC_HSI_DIV32)|| \
  102. ((__DIV__) == RCC_HSI_DIV64) || ((__DIV__) == RCC_HSI_DIV128))
  103. #endif
  104. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  105. #if defined(RCC_PLL_SUPPORT)
  106. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) ||((__PLL__) == RCC_PLL_OFF) || \
  107. ((__PLL__) == RCC_PLL_ON))
  108. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI) || \
  109. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  110. #endif
  111. #define IS_RCC_CLOCKTYPE(__CLK__) ((((__CLK__) & RCC_CLOCKTYPE_ALL) != 0x00UL) && (((__CLK__) & ~RCC_CLOCKTYPE_ALL) == 0x00UL))
  112. #if (defined(PY32F003PRE) || defined(PY32F002APRE))
  113. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSISYS) || \
  114. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  115. ((__SOURCE__) == RCC_SYSCLKSOURCE_LSI))
  116. #else
  117. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSISYS) || \
  118. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  119. ((__SOURCE__) == RCC_SYSCLKSOURCE_LSE) || \
  120. ((__SOURCE__) == RCC_SYSCLKSOURCE_LSI) || \
  121. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  122. #endif
  123. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  124. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  125. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  126. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  127. ((__HCLK__) == RCC_SYSCLK_DIV512))
  128. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  129. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  130. ((__PCLK__) == RCC_HCLK_DIV16))
  131. #if defined(RCC_LSE_SUPPORT)
  132. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NONE) || \
  133. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  134. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  135. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV128))
  136. #else
  137. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NONE) || \
  138. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  139. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV128))
  140. #endif
  141. #define IS_RCC_MCO(__MCOX__) ((__MCOX__) == RCC_MCO1)
  142. #if (defined(PY32F003PRE) || defined(PY32F002APRE))
  143. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK) || \
  144. ((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || \
  145. ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || \
  146. ((__SOURCE__) == RCC_MCO1SOURCE_HSE) || \
  147. ((__SOURCE__) == RCC_MCO1SOURCE_LSI))
  148. #else
  149. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK) || \
  150. ((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || \
  151. ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || \
  152. ((__SOURCE__) == RCC_MCO1SOURCE_HSE) || \
  153. ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || \
  154. ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || \
  155. ((__SOURCE__) == RCC_MCO1SOURCE_LSE))
  156. #endif
  157. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1) || ((__DIV__) == RCC_MCODIV_2) || \
  158. ((__DIV__) == RCC_MCODIV_4) || ((__DIV__) == RCC_MCODIV_8) || \
  159. ((__DIV__) == RCC_MCODIV_16)|| ((__DIV__) == RCC_MCODIV_32) || \
  160. ((__DIV__) == RCC_MCODIV_64)|| ((__DIV__) == RCC_MCODIV_128))
  161. #if defined(RCC_LSE_SUPPORT)
  162. #define IS_RCC_LSE_DRIVE(__DRIVE__) (((__DRIVE__) == RCC_LSEDRIVE_LOW) || \
  163. ((__DRIVE__) == RCC_LSEDRIVE_MEDIUM) || \
  164. ((__DRIVE__) == RCC_LSEDRIVE_HIGH))
  165. #endif
  166. /**
  167. * @}
  168. */
  169. /* Exported types ------------------------------------------------------------*/
  170. /** @defgroup RCC_Exported_Types RCC Exported Types
  171. * @{
  172. */
  173. #if defined(RCC_PLL_SUPPORT)
  174. /**
  175. * @brief RCC PLL configuration structure definition
  176. */
  177. typedef struct
  178. {
  179. uint32_t PLLState; /*!< The new state of the PLL.
  180. This parameter can be a value of @ref RCC_PLL_Config */
  181. uint32_t PLLSource; /*!< RCC_PLLSource: PLL entry clock source.
  182. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  183. } RCC_PLLInitTypeDef;
  184. #endif
  185. /**
  186. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  187. */
  188. typedef struct
  189. {
  190. uint32_t OscillatorType; /*!< The oscillators to be configured.
  191. This parameter can be a value of @ref RCC_Oscillator_Type */
  192. uint32_t HSEState; /*!< The new state of the HSE.
  193. This parameter can be a value of @ref RCC_HSE_Config */
  194. uint32_t HSEFreq; /*!< The frequency range of the HSE.
  195. This parameter can be a value of @ref RCC_HSE_Freq */
  196. #if defined(RCC_LSE_SUPPORT)
  197. uint32_t LSEState; /*!< The new state of the LSE.
  198. This parameter can be a value of @ref RCC_LSE_Config */
  199. uint32_t LSEDriver; /*!< The driver factor of the LSE.
  200. This parameter can be a value of @ref RCC_LSE_Driver */
  201. #endif
  202. uint32_t HSIState; /*!< The new state of the HSI.
  203. This parameter can be a value of @ref RCC_HSI_Config */
  204. #if defined(RCC_HSIDIV_SUPPORT)
  205. uint32_t HSIDiv; /*!< The division factor of the HSI.
  206. This parameter can be a value of @ref RCC_HSI_Div */
  207. #endif
  208. uint32_t HSICalibrationValue; /*!< The calibration trimming value (default is RCC_HSICALIBRATION_8MHz).
  209. This parameter can be a value of @ref RCC_HSI_Calibration */
  210. uint32_t LSIState; /*!< The new state of the LSI.
  211. This parameter can be a value of @ref RCC_LSI_Config */
  212. #if defined(RCC_PLL_SUPPORT)
  213. RCC_PLLInitTypeDef PLL; /*!< Main PLL structure parameters */
  214. #endif
  215. } RCC_OscInitTypeDef;
  216. /**
  217. * @brief RCC System, AHB and APB busses clock configuration structure definition
  218. */
  219. typedef struct
  220. {
  221. uint32_t ClockType; /*!< The clock to be configured.
  222. This parameter can be a combination of @ref RCC_System_Clock_Type */
  223. uint32_t SYSCLKSource; /*!< The clock source used as system clock (SYSCLK).
  224. This parameter can be a value of @ref RCC_System_Clock_Source */
  225. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  226. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  227. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  228. This parameter can be a value of @ref RCC_APB1_Clock_Source */
  229. } RCC_ClkInitTypeDef;
  230. /**
  231. * @}
  232. */
  233. /* Exported constants --------------------------------------------------------*/
  234. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  235. * @{
  236. */
  237. /** @defgroup RCC_Timeout_Value Timeout Values
  238. * @{
  239. */
  240. #define RCC_DBP_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
  241. #if defined(RCC_LSE_SUPPORT)
  242. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT /* LSE timeout in ms */
  243. #endif
  244. /**
  245. * @}
  246. */
  247. /** @defgroup RCC_Oscillator_Type Oscillator Type
  248. * @{
  249. */
  250. #define RCC_OSCILLATORTYPE_NONE 0x00000000U /*!< Oscillator configuration unchanged */
  251. #define RCC_OSCILLATORTYPE_HSE 0x00000001U /*!< HSE to configure */
  252. #define RCC_OSCILLATORTYPE_HSI 0x00000002U /*!< HSI to configure */
  253. #if defined(RCC_LSE_SUPPORT)
  254. #define RCC_OSCILLATORTYPE_LSE 0x00000004U /*!< LSE to configure */
  255. #endif
  256. #define RCC_OSCILLATORTYPE_LSI 0x00000008U /*!< LSI to configure */
  257. /**
  258. * @}
  259. */
  260. /** @defgroup RCC_HSE_Config HSE Config
  261. * @{
  262. */
  263. #define RCC_HSE_OFF 0x00000000U /*!< HSE clock deactivation */
  264. #define RCC_HSE_ON RCC_CR_HSEON /*!< HSE clock activation */
  265. #define RCC_HSE_BYPASS ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
  266. /**
  267. * @}
  268. */
  269. /** @defgroup RCC_HSE_Freq HSE Config
  270. * @{
  271. */
  272. #define RCC_HSE_4_8MHz RCC_ECSCR_HSE_FREQ_0
  273. #define RCC_HSE_8_16MHz RCC_ECSCR_HSE_FREQ_1
  274. #if defined(PY32F002APRE)
  275. #define RCC_HSE_16_24MHz (RCC_ECSCR_HSE_FREQ_0 | RCC_ECSCR_HSE_FREQ_1)
  276. #else
  277. #define RCC_HSE_16_32MHz (RCC_ECSCR_HSE_FREQ_0 | RCC_ECSCR_HSE_FREQ_1)
  278. #endif
  279. /**
  280. * @}
  281. */
  282. #if defined(RCC_LSE_SUPPORT)
  283. /** @defgroup RCC_LSE_Config LSE Config
  284. * @{
  285. */
  286. #define RCC_LSE_OFF 0x00000000U /*!< LSE clock deactivation */
  287. #define RCC_LSE_ON RCC_BDCR_LSEON /*!< LSE clock activation */
  288. #define RCC_LSE_BYPASS ((uint32_t)(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON)) /*!< External clock source for LSE clock */
  289. /**
  290. * @}
  291. */
  292. /** @defgroup RCC_LSE_Driver LSE Config
  293. * @{
  294. */
  295. #define RCC_LSEDRIVE_LOW RCC_ECSCR_LSE_DRIVER_0 /*!< LSE low drive capability */
  296. #define RCC_LSEDRIVE_MEDIUM RCC_ECSCR_LSE_DRIVER_1 /*!< LSE medium drive capability */
  297. #define RCC_LSEDRIVE_HIGH (RCC_ECSCR_LSE_DRIVER_0 | RCC_ECSCR_LSE_DRIVER_1) /*!< LSE high drive capability */
  298. /**
  299. * @}
  300. */
  301. #endif
  302. /** @defgroup RCC_HSI_Config HSI Config
  303. * @{
  304. */
  305. #define RCC_HSI_OFF 0x00000000U /*!< HSI clock deactivation */
  306. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  307. /**
  308. * @}
  309. */
  310. /** @defgroup RCC_HSI_Calibration HSI Calibration
  311. * @{
  312. */
  313. #if defined(PY32F002APRE)
  314. #define RCC_HSICALIBRATION_8MHz ((0x1<<13) | ((*(uint32_t *)(0x1FFF0F04)) & 0x1FFF)) /*!< 8MHz HSI calibration trimming value */
  315. #define RCC_HSICALIBRATION_24MHz ((0x4<<13) | ((*(uint32_t *)(0x1FFF0F10)) & 0x1FFF)) /*!< 24MHz HSI calibration trimming value */
  316. #else
  317. #define RCC_HSICALIBRATION_4MHz ((0x0<<13) | ((*(uint32_t *)(0x1FFF0F00)) & 0x1FFF)) /*!< 4MHz HSI calibration trimming value */
  318. #define RCC_HSICALIBRATION_8MHz ((0x1<<13) | ((*(uint32_t *)(0x1FFF0F04)) & 0x1FFF)) /*!< 8MHz HSI calibration trimming value */
  319. #define RCC_HSICALIBRATION_16MHz ((0x2<<13) | ((*(uint32_t *)(0x1FFF0F08)) & 0x1FFF)) /*!< 16MHz HSI calibration trimming value */
  320. #define RCC_HSICALIBRATION_22p12MHz ((0x3<<13) | ((*(uint32_t *)(0x1FFF0F0C)) & 0x1FFF)) /*!< 22.12MHz HSI calibration trimming value */
  321. #define RCC_HSICALIBRATION_24MHz ((0x4<<13) | ((*(uint32_t *)(0x1FFF0F10)) & 0x1FFF)) /*!< 24MHz HSI calibration trimming value */
  322. #endif
  323. /**
  324. * @}
  325. */
  326. #if defined(RCC_HSIDIV_SUPPORT)
  327. /** @defgroup RCC_HSI_Div HSI Div
  328. * @{
  329. */
  330. #define RCC_HSI_DIV1 0x00000000U /*!< HSI clock is not divided */
  331. #define RCC_HSI_DIV2 RCC_CR_HSIDIV_0 /*!< HSI clock is divided by 2 */
  332. #define RCC_HSI_DIV4 RCC_CR_HSIDIV_1 /*!< HSI clock is divided by 4 */
  333. #define RCC_HSI_DIV8 (RCC_CR_HSIDIV_1|RCC_CR_HSIDIV_0) /*!< HSI clock is divided by 8 */
  334. #define RCC_HSI_DIV16 RCC_CR_HSIDIV_2 /*!< HSI clock is divided by 16 */
  335. #define RCC_HSI_DIV32 (RCC_CR_HSIDIV_2|RCC_CR_HSIDIV_0) /*!< HSI clock is divided by 32 */
  336. #define RCC_HSI_DIV64 (RCC_CR_HSIDIV_2|RCC_CR_HSIDIV_1) /*!< HSI clock is divided by 64 */
  337. #define RCC_HSI_DIV128 (RCC_CR_HSIDIV_2|RCC_CR_HSIDIV_1|RCC_CR_HSIDIV_0) /*!< HSI clock is divided by 128 */
  338. /**
  339. * @}
  340. */
  341. #endif
  342. /** @defgroup RCC_LSI_Config LSI Config
  343. * @{
  344. */
  345. #define RCC_LSI_OFF 0x00000000U /*!< LSI clock deactivation */
  346. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  347. /**
  348. * @}
  349. */
  350. #if defined(RCC_PLL_SUPPORT)
  351. /** @defgroup RCC_PLL_Config PLL Config
  352. * @{
  353. */
  354. #define RCC_PLL_NONE 0x00000000U /*!< PLL configuration unchanged */
  355. #define RCC_PLL_OFF 0x00000001U /*!< PLL deactivation */
  356. #define RCC_PLL_ON 0x00000002U /*!< PLL activation */
  357. /**
  358. * @}
  359. */
  360. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  361. * @{
  362. */
  363. #define RCC_PLLSOURCE_HSI RCC_PLLCFGR_PLLSRC_HSI /*!< HSI clock selected as PLL entry clock source */
  364. #define RCC_PLLSOURCE_HSE RCC_PLLCFGR_PLLSRC_HSE /*!< HSE clock selected as PLL entry clock source */
  365. /**
  366. * @}
  367. */
  368. #endif
  369. /** @defgroup RCC_System_Clock_Type System Clock Type
  370. * @{
  371. */
  372. #define RCC_CLOCKTYPE_SYSCLK 0x00000001U /*!< SYSCLK to configure */
  373. #define RCC_CLOCKTYPE_HCLK 0x00000002U /*!< HCLK to configure */
  374. #define RCC_CLOCKTYPE_PCLK1 0x00000004U /*!< PCLK1 to configure */
  375. /**
  376. * @}
  377. */
  378. /** @defgroup RCC_System_Clock_Source System Clock Source
  379. * @{
  380. */
  381. #define RCC_SYSCLKSOURCE_HSI 0x00000000U /*!< HSI selection as system clock */
  382. #define RCC_SYSCLKSOURCE_HSISYS RCC_SYSCLKSOURCE_HSI
  383. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_0 /*!< HSE selection as system clock */
  384. #if defined(RCC_PLL_SUPPORT)
  385. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_1 /*!< PLL selection as system clock */
  386. #endif
  387. #define RCC_SYSCLKSOURCE_LSI (RCC_CFGR_SW_1 | RCC_CFGR_SW_0) /*!< LSI selection as system clock */
  388. #if defined(RCC_LSE_SUPPORT)
  389. #define RCC_SYSCLKSOURCE_LSE RCC_CFGR_SW_2 /*!< LSE selection as system clock */
  390. #endif
  391. /**
  392. * @}
  393. */
  394. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  395. * @{
  396. */
  397. #define RCC_SYSCLKSOURCE_STATUS_HSI 0x00000000U /*!< HSI used as system clock */
  398. #define RCC_SYSCLKSOURCE_STATUS_HSISYS RCC_SYSCLKSOURCE_STATUS_HSI
  399. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_0 /*!< HSE used as system clock */
  400. #if defined(RCC_PLL_SUPPORT)
  401. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_1 /*!< PLL used as system clock */
  402. #endif
  403. #define RCC_SYSCLKSOURCE_STATUS_LSI (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0) /*!< LSI used as system clock */
  404. #if defined(RCC_LSE_SUPPORT)
  405. #define RCC_SYSCLKSOURCE_STATUS_LSE RCC_CFGR_SWS_2 /*!< LSE used as system clock */
  406. #endif
  407. /**
  408. * @}
  409. */
  410. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  411. * @{
  412. */
  413. #define RCC_SYSCLK_DIV1 0x00000000U /*!< SYSCLK not divided */
  414. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_3 /*!< SYSCLK divided by 2 */
  415. #define RCC_SYSCLK_DIV4 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 4 */
  416. #define RCC_SYSCLK_DIV8 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_1) /*!< SYSCLK divided by 8 */
  417. #define RCC_SYSCLK_DIV16 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_1 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 16 */
  418. #define RCC_SYSCLK_DIV64 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2) /*!< SYSCLK divided by 64 */
  419. #define RCC_SYSCLK_DIV128 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 128 */
  420. #define RCC_SYSCLK_DIV256 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2 | RCC_CFGR_HPRE_1) /*!< SYSCLK divided by 256 */
  421. #define RCC_SYSCLK_DIV512 (RCC_CFGR_HPRE_3 | RCC_CFGR_HPRE_2 | RCC_CFGR_HPRE_1 | RCC_CFGR_HPRE_0) /*!< SYSCLK divided by 512 */
  422. /**
  423. * @}
  424. */
  425. /** @defgroup RCC_APB1_Clock_Source APB Clock Source
  426. * @{
  427. */
  428. #define RCC_HCLK_DIV1 0x00000000U /*!< HCLK not divided */
  429. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE_2 /*!< HCLK divided by 2 */
  430. #define RCC_HCLK_DIV4 (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_0) /*!< HCLK divided by 4 */
  431. #define RCC_HCLK_DIV8 (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_1) /*!< HCLK divided by 8 */
  432. #define RCC_HCLK_DIV16 (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_1 | RCC_CFGR_PPRE_0) /*!< HCLK divided by 16 */
  433. /**
  434. * @}
  435. */
  436. #if defined(RCC_BDCR_RTCSEL)
  437. /** @defgroup RCC_RTC_Clock_Source RTC Clock Source
  438. * @{
  439. */
  440. #define RCC_RTCCLKSOURCE_NONE 0x00000000U /*!< No clock configured for RTC */
  441. #if defined(RCC_LSE_SUPPORT)
  442. #define RCC_RTCCLKSOURCE_LSE RCC_BDCR_RTCSEL_0 /*!< LSE oscillator clock used as RTC clock */
  443. #endif
  444. #define RCC_RTCCLKSOURCE_LSI RCC_BDCR_RTCSEL_1 /*!< LSI oscillator clock used as RTC clock */
  445. #define RCC_RTCCLKSOURCE_HSE_DIV128 RCC_BDCR_RTCSEL /*!< HSE oscillator clock divided by 128 used as RTC clock */
  446. /**
  447. * @}
  448. */
  449. #endif
  450. /** @defgroup RCC_MCO_Index MCO Index
  451. * @{
  452. */
  453. #define RCC_MCO 0x00000000U
  454. #define RCC_MCO1 RCC_MCO /*!< PA08 MCO1 to be compliant with other families with 2 MCOs*/
  455. #define RCC_MCO2 0x00000001U /*!< Configure PA01 as the clock output. */
  456. #define RCC_MCO3 0x00000002U /*!< Configure PA05 as the clock output. */
  457. #define RCC_MCO4 0x00000003U /*!< Configure PA09 as the clock output. */
  458. #define RCC_MCO5 0x00000004U /*!< Configure PA13 as the clock output.Note:PA13 is SWD_SWDIO Pin */
  459. #define RCC_MCO6 0x00000005U /*!< Configure PA14 as the clock output.Note:PA14 is SWD_SWCLK Pin */
  460. #define RCC_MCO7 0x00000006U /*!< Configure PF02 as the clock output.Note:Defaults to the reset pin, Optionbyte needs to be configured */
  461. /**
  462. * @}
  463. */
  464. /** @defgroup RCC_MCO1_Clock_Source MCO1 Clock Source
  465. * @{
  466. */
  467. #define RCC_MCO1SOURCE_NOCLOCK 0x00000000U /*!< MCO1 output disabled, no clock on MCO1 */
  468. #define RCC_MCO1SOURCE_SYSCLK RCC_CFGR_MCOSEL_0 /*!< SYSCLK selection as MCO1 source */
  469. #define RCC_MCO1SOURCE_HSI10M RCC_CFGR_MCOSEL_1
  470. #define RCC_MCO1SOURCE_HSI (RCC_CFGR_MCOSEL_0| RCC_CFGR_MCOSEL_1) /*!< HSI selection as MCO1 source */
  471. #define RCC_MCO1SOURCE_HSE RCC_CFGR_MCOSEL_2 /*!< HSE selection as MCO1 source */
  472. #if defined(RCC_PLL_SUPPORT)
  473. #define RCC_MCO1SOURCE_PLLCLK (RCC_CFGR_MCOSEL_0|RCC_CFGR_MCOSEL_2) /*!< PLLCLK selection as MCO1 source */
  474. #endif
  475. #define RCC_MCO1SOURCE_LSI (RCC_CFGR_MCOSEL_1|RCC_CFGR_MCOSEL_2) /*!< LSI selection as MCO1 source */
  476. #if defined(RCC_LSE_SUPPORT)
  477. #define RCC_MCO1SOURCE_LSE (RCC_CFGR_MCOSEL_0|RCC_CFGR_MCOSEL_1|RCC_CFGR_MCOSEL_2) /*!< LSE selection as MCO1 source */
  478. #endif
  479. /**
  480. * @}
  481. */
  482. /** @defgroup RCC_MCOx_Clock_Prescaler MCO1 Clock Prescaler
  483. * @{
  484. */
  485. #define RCC_MCODIV_1 0x00000000U /*!< MCO not divided */
  486. #define RCC_MCODIV_2 RCC_CFGR_MCOPRE_0 /*!< MCO divided by 2 */
  487. #define RCC_MCODIV_4 RCC_CFGR_MCOPRE_1 /*!< MCO divided by 4 */
  488. #define RCC_MCODIV_8 (RCC_CFGR_MCOPRE_1 | RCC_CFGR_MCOPRE_0) /*!< MCO divided by 8 */
  489. #define RCC_MCODIV_16 RCC_CFGR_MCOPRE_2 /*!< MCO divided by 16 */
  490. #define RCC_MCODIV_32 (RCC_CFGR_MCOPRE_2 | RCC_CFGR_MCOPRE_0) /*!< MCO divided by 32 */
  491. #define RCC_MCODIV_64 (RCC_CFGR_MCOPRE_2 | RCC_CFGR_MCOPRE_1) /*!< MCO divided by 64 */
  492. #define RCC_MCODIV_128 (RCC_CFGR_MCOPRE_2 | RCC_CFGR_MCOPRE_1 | RCC_CFGR_MCOPRE_0) /*!< MCO divided by 128 */
  493. /**
  494. * @}
  495. */
  496. /** @defgroup RCC_Interrupt Interrupts
  497. * @{
  498. */
  499. #define RCC_IT_LSIRDY RCC_CIFR_LSIRDYF /*!< LSI Ready Interrupt flag */
  500. #if defined(RCC_LSE_SUPPORT)
  501. #define RCC_IT_LSERDY RCC_CIFR_LSERDYF /*!< LSE Ready Interrupt flag */
  502. #define RCC_IT_LSECSS RCC_CIFR_LSECSSF /*!< LSE Clock Security System Interrupt flag */
  503. #endif
  504. #define RCC_IT_HSIRDY RCC_CIFR_HSIRDYF /*!< HSI Ready Interrupt flag */
  505. #define RCC_IT_HSERDY RCC_CIFR_HSERDYF /*!< HSE Ready Interrupt flag */
  506. #if defined(RCC_PLL_SUPPORT)
  507. #define RCC_IT_PLLRDY RCC_CIFR_PLLRDYF /*!< PLL Ready Interrupt flag */
  508. #endif
  509. #define RCC_IT_CSS RCC_CIFR_CSSF /*!< HSE Clock Security System Interrupt flag */
  510. /**
  511. * @}
  512. */
  513. /** @defgroup RCC_Flag Flags
  514. * Elements values convention: XXXYYYYYb
  515. * - YYYYY : Flag position in the register
  516. * - XXX : Register index
  517. * - 001: CR register
  518. * - 010: BDCR register
  519. * - 011: CSR register
  520. * @{
  521. */
  522. /* Flags in the CR register */
  523. #define RCC_FLAG_HSIRDY ((CR_REG_INDEX << 5U) | RCC_CR_HSIRDY_Pos) /*!< HSI Ready flag */
  524. #define RCC_FLAG_HSERDY ((CR_REG_INDEX << 5U) | RCC_CR_HSERDY_Pos) /*!< HSE Ready flag */
  525. #if defined(RCC_PLL_SUPPORT)
  526. #define RCC_FLAG_PLLRDY ((CR_REG_INDEX << 5U) | RCC_CR_PLLRDY_Pos) /*!< PLL Ready flag */
  527. #endif
  528. #if defined(RCC_LSE_SUPPORT)
  529. /* Flags in the BDCR register */
  530. #define RCC_FLAG_LSERDY ((BDCR_REG_INDEX << 5U) | RCC_BDCR_LSERDY_Pos) /*!< LSE Ready flag */
  531. #endif
  532. /* Flags in the CSR register */
  533. #define RCC_FLAG_LSIRDY ((CSR_REG_INDEX << 5U) | RCC_CSR_LSIRDY_Pos) /*!< LSI Ready flag */
  534. #define RCC_FLAG_OBLRST ((CSR_REG_INDEX << 5U) | RCC_CSR_OBLRSTF_Pos) /*!< Option Byte Loader reset flag */
  535. #define RCC_FLAG_PINRST ((CSR_REG_INDEX << 5U) | RCC_CSR_PINRSTF_Pos) /*!< PIN reset flag */
  536. #define RCC_FLAG_PWRRST ((CSR_REG_INDEX << 5U) | RCC_CSR_PWRRSTF_Pos) /*!< BOR or POR/PDR reset flag */
  537. #define RCC_FLAG_SFTRST ((CSR_REG_INDEX << 5U) | RCC_CSR_SFTRSTF_Pos) /*!< Software Reset flag */
  538. #define RCC_FLAG_IWDGRST ((CSR_REG_INDEX << 5U) | RCC_CSR_IWDGRSTF_Pos) /*!< Independent Watchdog reset flag */
  539. #if defined(WWDG)
  540. #define RCC_FLAG_WWDGRST ((CSR_REG_INDEX << 5U) | RCC_CSR_WWDGRSTF_Pos) /*!< Window watchdog reset flag */
  541. #endif
  542. /**
  543. * @}
  544. */
  545. /**
  546. * @}
  547. */
  548. /* Exported macros -----------------------------------------------------------*/
  549. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  550. * @{
  551. */
  552. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable AHB Peripheral Clock Enable Disable
  553. * @brief Enable or disable the AHB peripheral clock.
  554. * @note After reset, the peripheral clock (used for registers read/write access)
  555. * is disabled and the application software has to enable this clock before
  556. * using it.
  557. * @{
  558. */
  559. #if (defined(DMA) || defined(DMA1))
  560. #define __HAL_RCC_DMA_CLK_ENABLE() do { \
  561. __IO uint32_t tmpreg; \
  562. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMAEN); \
  563. /* Delay after an RCC peripheral clock enabling */ \
  564. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMAEN); \
  565. UNUSED(tmpreg); \
  566. } while(0U)
  567. #endif
  568. #define __HAL_RCC_FLASH_CLK_ENABLE() do { \
  569. __IO uint32_t tmpreg; \
  570. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN); \
  571. /* Delay after an RCC peripheral clock enabling */ \
  572. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN); \
  573. UNUSED(tmpreg); \
  574. } while(0U)
  575. #define __HAL_RCC_SRAM_CLK_ENABLE() do { \
  576. __IO uint32_t tmpreg; \
  577. SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN); \
  578. /* Delay after an RCC peripheral clock enabling */ \
  579. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN); \
  580. UNUSED(tmpreg); \
  581. } while(0U)
  582. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  583. __IO uint32_t tmpreg; \
  584. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN); \
  585. /* Delay after an RCC peripheral clock enabling */ \
  586. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN); \
  587. UNUSED(tmpreg); \
  588. } while(0U)
  589. #if (defined(DMA) || defined(DMA1))
  590. #define __HAL_RCC_DMA_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_DMAEN)
  591. #endif
  592. #define __HAL_RCC_FLASH_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN)
  593. #define __HAL_RCC_SRAM_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN)
  594. #define __HAL_RCC_CRC_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN)
  595. /**
  596. * @}
  597. */
  598. /** @defgroup RCC_IOPORT_Clock_Enable_Disable IOPORT Clock Enable Disable
  599. * @brief Enable or disable the IO Ports clock.
  600. * @note After reset, the IO ports clock (used for registers read/write access)
  601. * is disabled and the application software has to enable this clock before
  602. * using it.
  603. * @{
  604. */
  605. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  606. __IO uint32_t tmpreg; \
  607. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN); \
  608. /* Delay after an RCC peripheral clock enabling */ \
  609. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN); \
  610. UNUSED(tmpreg); \
  611. } while(0U)
  612. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  613. __IO uint32_t tmpreg; \
  614. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN); \
  615. /* Delay after an RCC peripheral clock enabling */ \
  616. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN); \
  617. UNUSED(tmpreg); \
  618. } while(0U)
  619. #define __HAL_RCC_GPIOF_CLK_ENABLE() do { \
  620. __IO uint32_t tmpreg; \
  621. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOFEN); \
  622. /* Delay after an RCC peripheral clock enabling */ \
  623. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOFEN); \
  624. UNUSED(tmpreg); \
  625. } while(0U)
  626. #define __HAL_RCC_GPIOA_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN)
  627. #define __HAL_RCC_GPIOB_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN)
  628. #define __HAL_RCC_GPIOF_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOFEN)
  629. /**
  630. * @}
  631. */
  632. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Peripheral Clock Enable Disable
  633. * @brief Enable or disable the APB1 peripheral clock.
  634. * @note After reset, the peripheral clock (used for registers read/write access)
  635. * is disabled and the application software has to enable this clock before
  636. * using it.
  637. * @{
  638. */
  639. #if defined(TIM3)
  640. #define __HAL_RCC_TIM3_CLK_ENABLE() do { \
  641. __IO uint32_t tmpreg; \
  642. SET_BIT(RCC->APBENR1, RCC_APBENR1_TIM3EN); \
  643. /* Delay after an RCC peripheral clock enabling */ \
  644. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_TIM3EN); \
  645. UNUSED(tmpreg); \
  646. } while(0U)
  647. #endif
  648. #if defined(RTC)
  649. #define __HAL_RCC_RTCAPB_CLK_ENABLE() do { \
  650. __IO uint32_t tmpreg; \
  651. SET_BIT(RCC->APBENR1, RCC_APBENR1_RTCAPBEN); \
  652. /* Delay after an RCC peripheral clock enabling */ \
  653. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_RTCAPBEN); \
  654. UNUSED(tmpreg); \
  655. } while(0U)
  656. #endif
  657. #if defined(WWDG)
  658. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  659. __IO uint32_t tmpreg; \
  660. SET_BIT(RCC->APBENR1, RCC_APBENR1_WWDGEN); \
  661. /* Delay after an RCC peripheral clock enabling */ \
  662. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_WWDGEN); \
  663. UNUSED(tmpreg); \
  664. } while(0U)
  665. #endif
  666. #if defined(SPI2)
  667. #define __HAL_RCC_SPI2_CLK_ENABLE() do { \
  668. __IO uint32_t tmpreg; \
  669. SET_BIT(RCC->APBENR1, RCC_APBENR1_SPI2EN); \
  670. /* Delay after an RCC peripheral clock enabling */ \
  671. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_SPI2EN); \
  672. UNUSED(tmpreg); \
  673. } while(0U)
  674. #endif
  675. #if defined(USART2)
  676. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  677. __IO uint32_t tmpreg; \
  678. SET_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN); \
  679. /* Delay after an RCC peripheral clock enabling */ \
  680. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN); \
  681. UNUSED(tmpreg); \
  682. } while(0U)
  683. #endif
  684. #define __HAL_RCC_I2C_CLK_ENABLE() do { \
  685. __IO uint32_t tmpreg; \
  686. SET_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN); \
  687. /* Delay after an RCC peripheral clock enabling */ \
  688. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN); \
  689. UNUSED(tmpreg); \
  690. } while(0U)
  691. #define __HAL_RCC_DBGMCU_CLK_ENABLE() do { \
  692. __IO uint32_t tmpreg; \
  693. SET_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN); \
  694. /* Delay after an RCC peripheral clock enabling */ \
  695. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN); \
  696. UNUSED(tmpreg); \
  697. } while(0U)
  698. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  699. __IO uint32_t tmpreg; \
  700. SET_BIT(RCC->APBENR1, RCC_APBENR1_PWREN); \
  701. /* Delay after an RCC peripheral clock enabling */ \
  702. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_PWREN); \
  703. UNUSED(tmpreg); \
  704. } while(0U)
  705. #define __HAL_RCC_LPTIM_CLK_ENABLE() do { \
  706. __IO uint32_t tmpreg; \
  707. SET_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN); \
  708. /* Delay after an RCC peripheral clock enabling */ \
  709. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN); \
  710. UNUSED(tmpreg); \
  711. } while(0U)
  712. /**
  713. * @}
  714. */
  715. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Peripheral Clock Enable Disable
  716. * @brief Enable or disable the APB2 peripheral clock.
  717. * @note After reset, the peripheral clock (used for registers read/write access)
  718. * is disabled and the application software has to enable this clock before
  719. * using it.
  720. * @{
  721. */
  722. #define __HAL_RCC_SYSCFG_CLK_ENABLE() do { \
  723. __IO uint32_t tmpreg; \
  724. SET_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN); \
  725. /* Delay after an RCC peripheral clock enabling */ \
  726. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN); \
  727. UNUSED(tmpreg); \
  728. } while(0U)
  729. #define __HAL_RCC_TIM1_CLK_ENABLE() do { \
  730. __IO uint32_t tmpreg; \
  731. SET_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN); \
  732. /* Delay after an RCC peripheral clock enabling */ \
  733. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN); \
  734. UNUSED(tmpreg); \
  735. } while(0U)
  736. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  737. __IO uint32_t tmpreg; \
  738. SET_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN); \
  739. /* Delay after an RCC peripheral clock enabling */ \
  740. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN); \
  741. UNUSED(tmpreg); \
  742. } while(0U)
  743. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  744. __IO uint32_t tmpreg; \
  745. SET_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN); \
  746. /* Delay after an RCC peripheral clock enabling */ \
  747. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN); \
  748. UNUSED(tmpreg); \
  749. } while(0U)
  750. #if defined(TIM14)
  751. #define __HAL_RCC_TIM14_CLK_ENABLE() do { \
  752. __IO uint32_t tmpreg; \
  753. SET_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN); \
  754. /* Delay after an RCC peripheral clock enabling */ \
  755. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN); \
  756. UNUSED(tmpreg); \
  757. } while(0U)
  758. #endif
  759. #define __HAL_RCC_TIM16_CLK_ENABLE() do { \
  760. __IO uint32_t tmpreg; \
  761. SET_BIT(RCC->APBENR2, RCC_APBENR2_TIM16EN); \
  762. /* Delay after an RCC peripheral clock enabling */ \
  763. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM16EN); \
  764. UNUSED(tmpreg); \
  765. } while(0U)
  766. #if defined(TIM17)
  767. #define __HAL_RCC_TIM17_CLK_ENABLE() do { \
  768. __IO uint32_t tmpreg; \
  769. SET_BIT(RCC->APBENR2, RCC_APBENR2_TIM17EN); \
  770. /* Delay after an RCC peripheral clock enabling */ \
  771. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM17EN); \
  772. UNUSED(tmpreg); \
  773. } while(0U)
  774. #endif
  775. #define __HAL_RCC_ADC_CLK_ENABLE() do { \
  776. __IO uint32_t tmpreg; \
  777. SET_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN); \
  778. /* Delay after an RCC peripheral clock enabling */ \
  779. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN); \
  780. UNUSED(tmpreg); \
  781. } while(0U)
  782. #if defined(COMP1)
  783. #define __HAL_RCC_COMP1_CLK_ENABLE() do { \
  784. __IO uint32_t tmpreg; \
  785. SET_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN); \
  786. /* Delay after an RCC peripheral clock enabling */ \
  787. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN); \
  788. UNUSED(tmpreg); \
  789. } while(0U)
  790. #endif
  791. #if defined(COMP2)
  792. #define __HAL_RCC_COMP2_CLK_ENABLE() do { \
  793. __IO uint32_t tmpreg; \
  794. SET_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN); \
  795. /* Delay after an RCC peripheral clock enabling */ \
  796. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN); \
  797. UNUSED(tmpreg); \
  798. } while(0U)
  799. #endif
  800. #if defined(LED)
  801. #define __HAL_RCC_LED_CLK_ENABLE() do { \
  802. __IO uint32_t tmpreg; \
  803. SET_BIT(RCC->APBENR2, RCC_APBENR2_LEDEN); \
  804. /* Delay after an RCC peripheral clock enabling */ \
  805. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_LEDEN); \
  806. UNUSED(tmpreg); \
  807. } while(0U)
  808. #endif
  809. #if defined(TIM3)
  810. #define __HAL_RCC_TIM3_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_TIM3EN)
  811. #endif
  812. #if defined(RTC)
  813. #define __HAL_RCC_RTCAPB_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_RTCAPBEN)
  814. #endif
  815. #if defined(SPI2)
  816. #define __HAL_RCC_SPI2_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_SPI2EN)
  817. #endif
  818. #if defined(USART2)
  819. #define __HAL_RCC_USART2_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN)
  820. #endif
  821. #define __HAL_RCC_I2C_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN)
  822. #define __HAL_RCC_DBGMCU_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN)
  823. #define __HAL_RCC_PWR_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_PWREN)
  824. #define __HAL_RCC_LPTIM_CLK_DISABLE() CLEAR_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN)
  825. #define __HAL_RCC_SYSCFG_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN)
  826. #define __HAL_RCC_TIM1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN)
  827. #define __HAL_RCC_SPI1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN)
  828. #define __HAL_RCC_USART1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN)
  829. #if defined(TIM14)
  830. #define __HAL_RCC_TIM14_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN)
  831. #endif
  832. #define __HAL_RCC_TIM16_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_TIM16EN)
  833. #if defined(TIM17)
  834. #define __HAL_RCC_TIM17_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_TIM17EN)
  835. #endif
  836. #define __HAL_RCC_ADC_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN)
  837. #if defined(COMP1)
  838. #define __HAL_RCC_COMP1_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN)
  839. #endif
  840. #if defined(COMP2)
  841. #define __HAL_RCC_COMP2_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN)
  842. #endif
  843. #if defined(LED)
  844. #define __HAL_RCC_LED_CLK_DISABLE() CLEAR_BIT(RCC->APBENR2, RCC_APBENR2_LEDEN)
  845. #endif
  846. /**
  847. * @}
  848. */
  849. /** @defgroup RCC_AHB_Peripheral_Clock_Enabled_Disabled_Status AHB Peripheral Clock Enabled or Disabled Status
  850. * @brief Check whether the AHB peripheral clock is enabled or not.
  851. * @note After reset, the peripheral clock (used for registers read/write access)
  852. * is disabled and the application software has to enable this clock before
  853. * using it.
  854. * @{
  855. */
  856. #if (defined(DMA) || defined(DMA1))
  857. #define __HAL_RCC_DMA_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_DMAEN) != RESET)
  858. #endif
  859. #define __HAL_RCC_FLASH_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN) != RESET)
  860. #define __HAL_RCC_CRC_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) != RESET)
  861. #if (defined(DMA) || defined(DMA1))
  862. #define __HAL_RCC_DMA_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_DMAEN) == RESET)
  863. #endif
  864. #define __HAL_RCC_FLASH_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_FLASHEN) == RESET)
  865. #define __HAL_RCC_CRC_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) == RESET)
  866. /**
  867. * @}
  868. */
  869. /** @defgroup RCC_IOPORT_Clock_Enabled_Disabled_Status IOPORT Clock Enabled or Disabled Status
  870. * @brief Check whether the IO Port clock is enabled or not.
  871. * @note After reset, the peripheral clock (used for registers read/write access)
  872. * is disabled and the application software has to enable this clock before
  873. * using it.
  874. * @{
  875. */
  876. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) != RESET)
  877. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) != RESET)
  878. #define __HAL_RCC_GPIOF_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOFEN) != RESET)
  879. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) == RESET)
  880. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) == RESET)
  881. #define __HAL_RCC_GPIOF_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOFEN) == RESET)
  882. /**
  883. * @}
  884. */
  885. /** @defgroup RCC_APB1_Clock_Enabled_Disabled_Status APB1 Peripheral Clock Enabled or Disabled Status
  886. * @brief Check whether the APB1 peripheral clock is enabled or not.
  887. * @note After reset, the peripheral clock (used for registers read/write access)
  888. * is disabled and the application software has to enable this clock before
  889. * using it.
  890. * @{
  891. */
  892. #if defined(TIM3)
  893. #define __HAL_RCC_TIM3_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_TIM3EN) != 0U)
  894. #endif
  895. #if defined(RTC)
  896. #define __HAL_RCC_RTCAPB_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_RTCAPBEN) != 0U)
  897. #endif
  898. #if defined(WWDG)
  899. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_WWDGEN) != 0U)
  900. #endif
  901. #if defined(SPI2)
  902. #define __HAL_RCC_SPI2_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_SPI2EN) != 0U)
  903. #endif
  904. #if defined(USART2)
  905. #define __HAL_RCC_USART2_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN) != 0U)
  906. #endif
  907. #define __HAL_RCC_I2C_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN) != 0U)
  908. #define __HAL_RCC_DBGMCU_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN) != 0U)
  909. #define __HAL_RCC_PWR_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_PWREN) != 0U)
  910. #define __HAL_RCC_LPTIM_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN) != 0U)
  911. #if defined(TIM3)
  912. #define __HAL_RCC_TIM3_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_TIM3EN) == 0U)
  913. #endif
  914. #if defined(RTC)
  915. #define __HAL_RCC_RTCAPB_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_RTCAPBEN) == 0U)
  916. #endif
  917. #if defined(WWDG)
  918. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_WWDGEN) == 0U)
  919. #endif
  920. #if defined(SPI2)
  921. #define __HAL_RCC_SPI2_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_SPI2EN) == 0U)
  922. #endif
  923. #if defined(USART2)
  924. #define __HAL_RCC_USART2_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN) == 0U)
  925. #endif
  926. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_I2CEN) == 0U)
  927. #define __HAL_RCC_DBGMCU_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_DBGEN) == 0U)
  928. #define __HAL_RCC_PWR_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_PWREN) == 0U)
  929. #define __HAL_RCC_LPTIM_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR1, RCC_APBENR1_LPTIMEN) == 0U)
  930. /**
  931. * @}
  932. */
  933. /** @defgroup RCC_APB2_Clock_Enabled_Disabled_Status APB2 Peripheral Clock Enabled or Disabled Status
  934. * @brief Check whether the APB2 peripheral clock is enabled or not.
  935. * @note After reset, the peripheral clock (used for registers read/write access)
  936. * is disabled and the application software has to enable this clock before
  937. * using it.
  938. * @{
  939. */
  940. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN) != 0U)
  941. #define __HAL_RCC_TIM1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN) != 0U)
  942. #define __HAL_RCC_SPI1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN) != 0U)
  943. #define __HAL_RCC_USART1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN) != 0U)
  944. #if defined(TIM14)
  945. #define __HAL_RCC_TIM14_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN) != 0U)
  946. #endif
  947. #define __HAL_RCC_TIM16_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM16EN) != 0U)
  948. #if defined(TIM17)
  949. #define __HAL_RCC_TIM17_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM17EN) != 0U)
  950. #endif
  951. #define __HAL_RCC_ADC_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN) != 0U)
  952. #if defined(COMP1)
  953. #define __HAL_RCC_COMP1_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN) != 0U)
  954. #endif
  955. #if defined(COMP2)
  956. #define __HAL_RCC_COMP2_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN) != 0U)
  957. #endif
  958. #if defined(LED)
  959. #define __HAL_RCC_LED_IS_CLK_ENABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_LEDEN) != 0U)
  960. #endif
  961. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SYSCFGEN) == 0U)
  962. #define __HAL_RCC_TIM1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM1EN) == 0U)
  963. #define __HAL_RCC_SPI1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_SPI1EN) == 0U)
  964. #define __HAL_RCC_USART1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN) == 0U)
  965. #if defined(TIM14)
  966. #define __HAL_RCC_TIM14_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM14EN) == 0U)
  967. #endif
  968. #define __HAL_RCC_TIM16_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM16EN) == 0U)
  969. #if defined(TIM17)
  970. #define __HAL_RCC_TIM17_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_TIM17EN) == 0U)
  971. #endif
  972. #define __HAL_RCC_ADC_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_ADCEN) == 0U)
  973. #if defined(COMP1)
  974. #define __HAL_RCC_COMP1_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP1EN) == 0U)
  975. #endif
  976. #if defined(COMP2)
  977. #define __HAL_RCC_COMP2_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_COMP2EN) == 0U)
  978. #endif
  979. #if defined(LED)
  980. #define __HAL_RCC_LED_IS_CLK_DISABLED() (READ_BIT(RCC->APBENR2, RCC_APBENR2_LEDEN) == 0U)
  981. #endif
  982. /**
  983. * @}
  984. */
  985. /** @defgroup RCC_AHB_Force_Release_Reset AHB Peripheral Force Release Reset
  986. * @brief Force or release AHB1 peripheral reset.
  987. * @{
  988. */
  989. #define __HAL_RCC_AHB_FORCE_RESET() WRITE_REG(RCC->AHBRSTR, 0xFFFFFFFFU)
  990. #if (defined(DMA) || defined(DMA1))
  991. #define __HAL_RCC_DMA_FORCE_RESET() SET_BIT(RCC->AHBRSTR, RCC_AHBRSTR_DMARST)
  992. #endif
  993. #define __HAL_RCC_FLASH_FORCE_RESET() SET_BIT(RCC->AHBRSTR, RCC_AHBRSTR_FLASHRST)
  994. #define __HAL_RCC_CRC_FORCE_RESET() SET_BIT(RCC->AHBRSTR, RCC_AHBRSTR_CRCRST)
  995. #define __HAL_RCC_AHB_RELEASE_RESET() WRITE_REG(RCC->AHBRSTR, 0x00000000U)
  996. #if (defined(DMA) || defined(DMA1))
  997. #define __HAL_RCC_DMA_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, RCC_AHBRSTR_DMARST)
  998. #endif
  999. #define __HAL_RCC_FLASH_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, RCC_AHBRSTR_FLASHRST)
  1000. #define __HAL_RCC_CRC_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, RCC_AHBRSTR_CRCRST)
  1001. /**
  1002. * @}
  1003. */
  1004. /** @defgroup RCC_IOPORT_Force_Release_Reset IOPORT Force Release Reset
  1005. * @brief Force or release IO Port reset.
  1006. * @{
  1007. */
  1008. #define __HAL_RCC_IOP_FORCE_RESET() WRITE_REG(RCC->IOPRSTR, 0xFFFFFFFFU)
  1009. #define __HAL_RCC_GPIOA_FORCE_RESET() SET_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOARST)
  1010. #define __HAL_RCC_GPIOB_FORCE_RESET() SET_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOBRST)
  1011. #define __HAL_RCC_GPIOF_FORCE_RESET() SET_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOFRST)
  1012. #define __HAL_RCC_IOP_RELEASE_RESET() WRITE_REG(RCC->IOPRSTR, 0x00000000U)
  1013. #define __HAL_RCC_GPIOA_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOARST)
  1014. #define __HAL_RCC_GPIOB_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOBRST)
  1015. #define __HAL_RCC_GPIOF_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, RCC_IOPRSTR_GPIOFRST)
  1016. /**
  1017. * @}
  1018. */
  1019. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Peripheral Force Release Reset
  1020. * @brief Force or release APB1 peripheral reset.
  1021. * @{
  1022. */
  1023. #define __HAL_RCC_APB1_FORCE_RESET() WRITE_REG(RCC->APBRSTR1, 0xFFFFFFFFU)
  1024. #if defined(TIM3)
  1025. #define __HAL_RCC_TIM3_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_TIM3RST)
  1026. #endif
  1027. #if defined(SPI2)
  1028. #define __HAL_RCC_SPI2_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_SPI2RST)
  1029. #endif
  1030. #if defined(USART2)
  1031. #define __HAL_RCC_USART2_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_USART2RST)
  1032. #endif
  1033. #define __HAL_RCC_I2C_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_I2CRST)
  1034. #define __HAL_RCC_DBGMCU_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_DBGRST)
  1035. #define __HAL_RCC_PWR_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_PWRRST)
  1036. #define __HAL_RCC_LPTIM_FORCE_RESET() SET_BIT(RCC->APBRSTR1, RCC_APBRSTR1_LPTIMRST)
  1037. #define __HAL_RCC_APB1_RELEASE_RESET() WRITE_REG(RCC->APBRSTR1, 0x00000000U)
  1038. #if defined(TIM3)
  1039. #define __HAL_RCC_TIM3_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_TIM3RST)
  1040. #endif
  1041. #if defined(SPI2)
  1042. #define __HAL_RCC_SPI2_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_SPI2RST)
  1043. #endif
  1044. #if defined(USART2)
  1045. #define __HAL_RCC_USART2_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_USART2RST)
  1046. #endif
  1047. #define __HAL_RCC_I2C_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_I2CRST)
  1048. #define __HAL_RCC_DBGMCU_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_DBGRST)
  1049. #define __HAL_RCC_PWR_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_PWRRST)
  1050. #define __HAL_RCC_LPTIM_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR1, RCC_APBRSTR1_LPTIMRST)
  1051. /**
  1052. * @}
  1053. */
  1054. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Peripheral Force Release Reset
  1055. * @brief Force or release APB2 peripheral reset.
  1056. * @{
  1057. */
  1058. #define __HAL_RCC_APB2_FORCE_RESET() WRITE_REG(RCC->APBRSTR2, 0xFFFFFFFFU)
  1059. #define __HAL_RCC_SYSCFG_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SYSCFGRST)
  1060. #define __HAL_RCC_TIM1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM1RST)
  1061. #define __HAL_RCC_SPI1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SPI1RST)
  1062. #define __HAL_RCC_USART1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_USART1RST)
  1063. #if defined(TIM14)
  1064. #define __HAL_RCC_TIM14_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM14RST)
  1065. #endif
  1066. #define __HAL_RCC_TIM16_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM16RST)
  1067. #if defined(TIM17)
  1068. #define __HAL_RCC_TIM17_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM17RST)
  1069. #endif
  1070. #define __HAL_RCC_ADC_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_ADCRST)
  1071. #if defined(COMP1)
  1072. #define __HAL_RCC_COMP1_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP1RST)
  1073. #endif
  1074. #if defined(COMP2)
  1075. #define __HAL_RCC_COMP2_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP2RST)
  1076. #endif
  1077. #if defined(LED)
  1078. #define __HAL_RCC_LED_FORCE_RESET() SET_BIT(RCC->APBRSTR2, RCC_APBRSTR2_LEDRST)
  1079. #endif
  1080. #define __HAL_RCC_APB2_RELEASE_RESET() WRITE_REG(RCC->APBRSTR2, 0x00U)
  1081. #define __HAL_RCC_SYSCFG_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SYSCFGRST)
  1082. #define __HAL_RCC_TIM1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM1RST)
  1083. #define __HAL_RCC_SPI1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_SPI1RST)
  1084. #define __HAL_RCC_USART1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_USART1RST)
  1085. #if defined(TIM14)
  1086. #define __HAL_RCC_TIM14_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM14RST)
  1087. #endif
  1088. #define __HAL_RCC_TIM16_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM16RST)
  1089. #if defined(TIM17)
  1090. #define __HAL_RCC_TIM17_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_TIM17RST)
  1091. #endif
  1092. #define __HAL_RCC_ADC_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_ADCRST)
  1093. #if defined(COMP1)
  1094. #define __HAL_RCC_COMP1_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP1RST)
  1095. #endif
  1096. #if defined(COMP2)
  1097. #define __HAL_RCC_COMP2_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_COMP2RST)
  1098. #endif
  1099. #if defined(LED)
  1100. #define __HAL_RCC_LED_RELEASE_RESET() CLEAR_BIT(RCC->APBRSTR2, RCC_APBRSTR2_LEDRST)
  1101. #endif
  1102. /**
  1103. * @}
  1104. */
  1105. /** @defgroup RCC_Backup_Domain_Reset RCC Backup Domain Reset
  1106. * @{
  1107. */
  1108. /** @brief Macros to force or release the Backup domain reset.
  1109. * @note This function resets the RTC peripheral (including the backup registers)
  1110. * and the RTC clock source selection in RCC_BDCR register.
  1111. * @retval None
  1112. */
  1113. #define __HAL_RCC_BACKUPRESET_FORCE() SET_BIT(RCC->BDCR, RCC_BDCR_BDRST)
  1114. #define __HAL_RCC_BACKUPRESET_RELEASE() CLEAR_BIT(RCC->BDCR, RCC_BDCR_BDRST)
  1115. /**
  1116. * @}
  1117. */
  1118. #if defined(RTC)
  1119. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  1120. * @{
  1121. */
  1122. /** @brief Macros to enable or disable the RTC clock.
  1123. * @note As the RTC is in the Backup domain and write access is denied to
  1124. * this domain after reset, you have to enable write access using
  1125. * HAL_PWR_EnableBkUpAccess() function before to configure the RTC
  1126. * (to be done once after reset).
  1127. * @note These macros must be used after the RTC clock source was selected.
  1128. * @retval None
  1129. */
  1130. #define __HAL_RCC_RTC_ENABLE() SET_BIT(RCC->BDCR, RCC_BDCR_RTCEN)
  1131. #define __HAL_RCC_RTC_DISABLE() CLEAR_BIT(RCC->BDCR, RCC_BDCR_RTCEN)
  1132. /**
  1133. * @}
  1134. */
  1135. #endif
  1136. /** @defgroup RCC_Clock_Configuration RCC Clock Configuration
  1137. * @{
  1138. */
  1139. /** @brief Macros to enable the Internal High Speed oscillator (HSI).
  1140. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  1141. * It is used (enabled by hardware) as system clock source after startup
  1142. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  1143. * of the HSE used directly or indirectly as system clock (if the Clock
  1144. * Security System CSS is enabled).
  1145. * @note After enabling the HSI, the application software should wait on HSIRDY
  1146. * flag to be set indicating that HSI clock is stable and can be used as
  1147. * system clock source.
  1148. * This parameter can be: ENABLE or DISABLE.
  1149. * @retval None
  1150. */
  1151. #define __HAL_RCC_HSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_HSION)
  1152. /** @brief Macros to disable the Internal High Speed oscillator (HSI).
  1153. * @note HSI can not be stopped if it is used as system clock source. In this case,
  1154. * you have to select another source of the system clock then stop the HSI.
  1155. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  1156. * clock cycles.
  1157. * @retval None
  1158. */
  1159. #define __HAL_RCC_HSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_HSION)
  1160. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  1161. * @note The calibration is used to compensate for the variations in voltage
  1162. * and temperature that influence the frequency of the internal HSI RC.
  1163. * @param __HSICALIBRATIONVALUE__ specifies the calibration trimming value
  1164. * (default is RCC_HSICALIBRATION_DEFAULT).
  1165. * This parameter must be a number between 0 and 127.
  1166. * @retval None
  1167. */
  1168. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(__HSICALIBRATIONVALUE__) \
  1169. MODIFY_REG(RCC->ICSCR, (RCC_ICSCR_HSI_FS_Msk|RCC_ICSCR_HSI_TRIM), (uint32_t)(__HSICALIBRATIONVALUE__) << RCC_ICSCR_HSI_TRIM_Pos)
  1170. #if defined(RCC_HSIDIV_SUPPORT)
  1171. /** @brief Macro to configure the HSISYS clock.
  1172. * @param __HSIDIV__ specifies the HSI division factor.
  1173. * This parameter can be one of the following values:
  1174. * @arg @ref RCC_HSI_DIV1 HSI clock source is divided by 1
  1175. * @arg @ref RCC_HSI_DIV2 HSI clock source is divided by 2
  1176. * @arg @ref RCC_HSI_DIV4 HSI clock source is divided by 4
  1177. * @arg @ref RCC_HSI_DIV8 HSI clock source is divided by 8
  1178. * @arg @ref RCC_HSI_DIV16 HSI clock source is divided by 16
  1179. * @arg @ref RCC_HSI_DIV32 HSI clock source is divided by 32
  1180. * @arg @ref RCC_HSI_DIV64 HSI clock source is divided by 64
  1181. * @arg @ref RCC_HSI_DIV128 HSI clock source is divided by 128
  1182. */
  1183. #define __HAL_RCC_HSI_CONFIG(__HSIDIV__) \
  1184. MODIFY_REG(RCC->CR, RCC_CR_HSIDIV, (__HSIDIV__))
  1185. #endif
  1186. /** @brief Macros to enable or disable the Internal Low Speed oscillator (LSI).
  1187. * @note After enabling the LSI, the application software should wait on
  1188. * LSIRDY flag to be set indicating that LSI clock is stable and can
  1189. * be used to clock the IWDG and/or the RTC.
  1190. * @note LSI can not be disabled if the IWDG is running.
  1191. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  1192. * clock cycles.
  1193. * @retval None
  1194. */
  1195. #define __HAL_RCC_LSI_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_LSION)
  1196. #define __HAL_RCC_LSI_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_LSION)
  1197. /**
  1198. * @brief Macro to configure the External High Speed oscillator (HSE).
  1199. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  1200. * supported by this macro. User should request a transition to HSE Off
  1201. * first and then HSE On or HSE Bypass.
  1202. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  1203. * software should wait on HSERDY flag to be set indicating that HSE clock
  1204. * is stable and can be used to clock the PLL and/or system clock.
  1205. * @note HSE state can not be changed if it is used directly or through the
  1206. * PLL as system clock. In this case, you have to select another source
  1207. * of the system clock then change the HSE state (ex. disable it).
  1208. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  1209. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  1210. * was previously enabled you have to enable it again after calling this
  1211. * function.
  1212. * @param __STATE__ specifies the new state of the HSE.
  1213. * This parameter can be one of the following values:
  1214. * @arg @ref RCC_HSE_OFF Turn OFF the HSE oscillator, HSERDY flag goes low after
  1215. * 6 HSE oscillator clock cycles.
  1216. * @arg @ref RCC_HSE_ON Turn ON the HSE oscillator.
  1217. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock.
  1218. * @retval None
  1219. */
  1220. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  1221. do { \
  1222. if((__STATE__) == RCC_HSE_ON) \
  1223. { \
  1224. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1225. } \
  1226. else if((__STATE__) == RCC_HSE_BYPASS) \
  1227. { \
  1228. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1229. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1230. } \
  1231. else \
  1232. { \
  1233. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1234. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1235. } \
  1236. } while(0U)
  1237. #if defined(RCC_LSE_SUPPORT)
  1238. /**
  1239. * @brief Macro to configure the External Low Speed oscillator (LSE).
  1240. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not
  1241. * supported by this macro. User should request a transition to LSE Off
  1242. * first and then LSE On or LSE Bypass.
  1243. * @note As the LSE is in the Backup domain and write access is denied to
  1244. * this domain after reset, you have to enable write access using
  1245. * HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  1246. * (to be done once after reset).
  1247. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  1248. * software should wait on LSERDY flag to be set indicating that LSE clock
  1249. * is stable and can be used to clock the RTC.
  1250. * @param __STATE__ specifies the new state of the LSE.
  1251. * This parameter can be one of the following values:
  1252. * @arg @ref RCC_LSE_OFF Turn OFF the LSE oscillator, LSERDY flag goes low after
  1253. * 6 LSE oscillator clock cycles.
  1254. * @arg @ref RCC_LSE_ON Turn ON the LSE oscillator.
  1255. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  1256. * @retval None
  1257. */
  1258. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  1259. do { \
  1260. if((__STATE__) == RCC_LSE_ON) \
  1261. { \
  1262. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1263. } \
  1264. else if((__STATE__) == RCC_LSE_BYPASS) \
  1265. { \
  1266. SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1267. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1268. } \
  1269. else \
  1270. { \
  1271. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1272. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1273. } \
  1274. } while(0U)
  1275. #endif
  1276. /**
  1277. * @}
  1278. */
  1279. #if defined(RTC)
  1280. /** @addtogroup RCC_RTC_Clock_Configuration
  1281. * @{
  1282. */
  1283. /** @brief Macros to configure the RTC clock (RTCCLK).
  1284. * @note As the RTC clock configuration bits are in the Backup domain and write
  1285. * access is denied to this domain after reset, you have to enable write
  1286. * access using the Power Backup Access macro before to configure
  1287. * the RTC clock source (to be done once after reset).
  1288. * @note Once the RTC clock is configured it cannot be changed unless the
  1289. * Backup domain is reset using __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1290. * a Power On Reset (POR).
  1291. *
  1292. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  1293. * This parameter can be one of the following values:
  1294. * @arg @ref RCC_RTCCLKSOURCE_NONE No clock selected as RTC clock.
  1295. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock.
  1296. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock.
  1297. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE clock divided by 128 selected
  1298. *
  1299. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1300. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1301. * However, when the HSE clock is used as RTC clock source, the RTC
  1302. * cannot be used in STOP and STANDBY modes.
  1303. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1304. * RTC clock source).
  1305. * @retval None
  1306. */
  1307. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) \
  1308. MODIFY_REG( RCC->BDCR, RCC_BDCR_RTCSEL, (__RTC_CLKSOURCE__))
  1309. /** @brief Macro to get the RTC clock source.
  1310. * @retval The returned value can be one of the following:
  1311. * @arg @ref RCC_RTCCLKSOURCE_NONE No clock selected as RTC clock.
  1312. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock.
  1313. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock.
  1314. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE clock divided by 128 selected
  1315. */
  1316. #define __HAL_RCC_GET_RTC_SOURCE() ((uint32_t)(READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL)))
  1317. /** @brief Macros to enable or disable the main PLL.
  1318. * @note After enabling the main PLL, the application software should wait on
  1319. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1320. * be used as system clock source.
  1321. * @note The main PLL can not be disabled if it is used as system clock source
  1322. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1323. * @retval None
  1324. */
  1325. /**
  1326. * @}
  1327. */
  1328. #endif
  1329. /** @addtogroup RCC_Clock_Configuration
  1330. * @{
  1331. */
  1332. #if defined(RCC_PLL_SUPPORT)
  1333. #define __HAL_RCC_PLL_ENABLE() SET_BIT(RCC->CR, RCC_CR_PLLON)
  1334. #define __HAL_RCC_PLL_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLON)
  1335. /** @brief Macro to configure the PLL clock source.
  1336. * @note This function must be used only when the main PLL is disabled.
  1337. * @param __PLLSOURCE__ specifies the PLL entry clock source.
  1338. * This parameter can be one of the following values:
  1339. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL clock entry
  1340. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  1341. * @retval None
  1342. *
  1343. */
  1344. #define __HAL_RCC_PLL_PLLSOURCE_CONFIG(__PLLSOURCE__) \
  1345. MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, (__PLLSOURCE__))
  1346. /** @brief Macro to get the oscillator used as PLL clock source.
  1347. * @retval The oscillator used as PLL clock source. The returned value can be one
  1348. * of the following:
  1349. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator is used as PLL clock source.
  1350. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator is used as PLL clock source.
  1351. */
  1352. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC))
  1353. #endif
  1354. /**
  1355. * @brief Macro to configure the system clock source.
  1356. * @param __SYSCLKSOURCE__ specifies the system clock source.
  1357. * This parameter can be one of the following values:
  1358. * @arg @ref RCC_SYSCLKSOURCE_HSISYS HSISYS oscillator is used as system clock source.
  1359. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  1360. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  1361. * @arg @ref RCC_SYSCLKSOURCE_LSI LSI oscillator is used as system clock source.
  1362. * @arg @ref RCC_SYSCLKSOURCE_LSE LSE oscillator is used as system clock source.
  1363. * @note Depending on devices and packages, some clocks may not be available.
  1364. * Refer to device datasheet for clocks availability.
  1365. * @retval None
  1366. */
  1367. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  1368. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  1369. /** @brief Macro to get the clock source used as system clock.
  1370. * @retval The clock source used as system clock. The returned value can be one
  1371. * of the following:
  1372. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSISYS HSISYS used as system clock.
  1373. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock.
  1374. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock.
  1375. * @arg @ref RCC_SYSCLKSOURCE_STATUS_LSI LSI used as system clock source.
  1376. * @arg @ref RCC_SYSCLKSOURCE_STATUS_LSE LSE used as system clock source.
  1377. * @note Depending on devices and packages, some clocks may not be available.
  1378. * Refer to device datasheet for clocks availability.
  1379. */
  1380. #define __HAL_RCC_GET_SYSCLK_SOURCE() (RCC->CFGR & RCC_CFGR_SWS)
  1381. #if defined(RCC_LSE_SUPPORT)
  1382. /**
  1383. * @brief Macro to configure the External Low Speed oscillator (LSE) drive capability.
  1384. * @note As the LSE is in the Backup domain and write access is denied to
  1385. * this domain after reset, you have to enable write access using
  1386. * HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  1387. * (to be done once after reset).
  1388. * @param __LSEDRIVE__ specifies the new state of the LSE drive capability.
  1389. * This parameter can be one of the following values:
  1390. * @arg @ref RCC_LSEDRIVE_LOW LSE oscillator low drive capability.
  1391. * @arg @ref RCC_LSEDRIVE_MEDIUM LSE oscillator medium low drive capability.
  1392. * @arg @ref RCC_LSEDRIVE_HIGH LSE oscillator high drive capability.
  1393. * @retval None
  1394. */
  1395. #define __HAL_RCC_LSEDRIVE_CONFIG(__LSEDRIVE__) \
  1396. MODIFY_REG(RCC->ECSCR, RCC_ECSCR_LSE_DRIVER, (uint32_t)(__LSEDRIVE__))
  1397. #endif
  1398. /** @brief Macro to configure the MCO clock.
  1399. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1400. * This parameter can be one of the following values:
  1401. * @arg @ref RCC_MCO1SOURCE_NOCLOCK MCO output disabled
  1402. * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock selected as MCO source
  1403. * @arg @ref RCC_MCO1SOURCE_HSI HSI clock selected as MCO source
  1404. * @arg @ref RCC_MCO1SOURCE_HSE HSE clock selected as MCO sourcee
  1405. * @arg @ref RCC_MCO1SOURCE_PLLCLK Main PLL clock selected as MCO source
  1406. * @arg @ref RCC_MCO1SOURCE_LSI LSI clock selected as MCO source
  1407. * @arg @ref RCC_MCO1SOURCE_LSE LSE clock selected as MCO source
  1408. * @note Depending on devices and packages, some clocks may not be available.
  1409. * Refer to device datasheet for clocks availability.
  1410. * @param __MCODIV__ specifies the MCO clock prescaler.
  1411. * This parameter can be one of the following values:
  1412. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  1413. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  1414. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  1415. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  1416. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  1417. * @arg @ref RCC_MCODIV_32 MCO clock source is divided by 32
  1418. * @arg @ref RCC_MCODIV_64 MCO clock source is divided by 64
  1419. * @arg @ref RCC_MCODIV_128 MCO clock source is divided by 128
  1420. */
  1421. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1422. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCOSEL | RCC_CFGR_MCOPRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  1423. /**
  1424. * @}
  1425. */
  1426. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1427. * @brief macros to manage the specified RCC Flags and interrupts.
  1428. * @{
  1429. */
  1430. /** @brief Enable RCC interrupt.
  1431. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1432. * This parameter can be any combination of the following values:
  1433. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1434. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1435. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1436. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1437. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt
  1438. * @note Depending on devices and packages, some clocks may not be available.
  1439. * Refer to device datasheet for clocks availability.
  1440. * @retval None
  1441. */
  1442. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) SET_BIT(RCC->CIER, (__INTERRUPT__))
  1443. /** @brief Disable RCC interrupt.
  1444. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1445. * This parameter can be any combination of the following values:
  1446. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1447. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1448. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1449. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1450. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt
  1451. * @note Depending on devices and packages, some clocks may not be available.
  1452. * Refer to device datasheet for clocks availability.
  1453. * @retval None
  1454. */
  1455. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(RCC->CIER, (__INTERRUPT__))
  1456. /** @brief Clear RCC interrupt pending bits.
  1457. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1458. * This parameter can be any combination of the following values:
  1459. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1460. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1461. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1462. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1463. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt
  1464. * @arg @ref RCC_IT_CSS HSE Clock security system interrupt
  1465. * @arg @ref RCC_IT_LSECSS LSE Clock security system interrupt
  1466. * @note Depending on devices and packages, some clocks may not be available.
  1467. * Refer to device datasheet for clocks availability.
  1468. * @retval None
  1469. */
  1470. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (RCC->CICR = (__INTERRUPT__))
  1471. /** @brief Check whether the RCC interrupt has occurred or not.
  1472. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1473. * This parameter can be one of the following values:
  1474. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1475. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1476. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1477. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1478. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt
  1479. * @arg @ref RCC_IT_CSS HSE Clock security system interrupt
  1480. * @arg @ref RCC_IT_LSECSS LSE Clock security system interrupt
  1481. * @note Depending on devices and packages, some clocks may not be available.
  1482. * Refer to device datasheet for clocks availability.
  1483. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1484. */
  1485. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIFR & (__INTERRUPT__)) == (__INTERRUPT__))
  1486. /** @brief Set RMVF bit to clear the reset flags.
  1487. * The reset flags are: RCC_FLAG_OBLRST, RCC_FLAG_PINRST, RCC_FLAG_PWRRST,
  1488. * RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST.
  1489. * @note Depending on the device and software package, some flag bits may not be available.
  1490. * Refer to the device data sheet for flag bit availability.
  1491. * @retval None
  1492. */
  1493. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1494. /** @brief Check whether the selected RCC flag is set or not.
  1495. * @param __FLAG__ specifies the flag to check.
  1496. * This parameter can be one of the following values:
  1497. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready
  1498. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready
  1499. * @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready
  1500. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready
  1501. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready
  1502. * @arg @ref RCC_FLAG_PWRRST BOR or POR/PDR reset
  1503. * @arg @ref RCC_FLAG_OBLRST OBLRST reset
  1504. * @arg @ref RCC_FLAG_PINRST Pin reset
  1505. * @arg @ref RCC_FLAG_SFTRST Software reset
  1506. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset
  1507. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset
  1508. * @note Depending on the device and software package, some flag bits may not be available.
  1509. * Refer to the device data sheet for flag bit availability.
  1510. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1511. */
  1512. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((__FLAG__) >> 5U) == CR_REG_INDEX) ? RCC->CR : \
  1513. ((((__FLAG__) >> 5U) == BDCR_REG_INDEX) ? RCC->BDCR : \
  1514. ((((__FLAG__) >> 5U) == CSR_REG_INDEX) ? RCC->CSR : RCC->CIFR))) & \
  1515. (1U << ((__FLAG__) & RCC_FLAG_MASK))) != RESET) \
  1516. ? 1U : 0U)
  1517. /**
  1518. * @}
  1519. */
  1520. /**
  1521. * @}
  1522. */
  1523. /* Include RCC HAL Extended module */
  1524. #include "py32f0xx_hal_rcc_ex.h"
  1525. /* Exported functions --------------------------------------------------------*/
  1526. /** @addtogroup RCC_Exported_Functions
  1527. * @{
  1528. */
  1529. /** @addtogroup RCC_Exported_Functions_Group1
  1530. * @{
  1531. */
  1532. /* Initialization and de-initialization functions ******************************/
  1533. HAL_StatusTypeDef HAL_RCC_DeInit(void);
  1534. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1535. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1536. /**
  1537. * @}
  1538. */
  1539. /** @addtogroup RCC_Exported_Functions_Group2
  1540. * @{
  1541. */
  1542. /* Peripheral Control functions ************************************************/
  1543. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1544. void HAL_RCC_EnableCSS(void);
  1545. #if defined(RCC_LSE_SUPPORT)
  1546. void HAL_RCC_EnableLSECSS(void);
  1547. void HAL_RCC_DisableLSECSS(void);
  1548. void HAL_RCC_LSECSSCallback(void);
  1549. #endif
  1550. uint32_t HAL_RCC_GetSysClockFreq(void);
  1551. uint32_t HAL_RCC_GetHCLKFreq(void);
  1552. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1553. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1554. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1555. /* LSE & HSE CSS NMI IRQ handler */
  1556. void HAL_RCC_NMI_IRQHandler(void);
  1557. /* User Callbacks in non blocking mode (IT mode) */
  1558. void HAL_RCC_CSSCallback(void);
  1559. /**
  1560. * @}
  1561. */
  1562. /**
  1563. * @}
  1564. */
  1565. /**
  1566. * @}
  1567. */
  1568. /**
  1569. * @}
  1570. */
  1571. #ifdef __cplusplus
  1572. }
  1573. #endif
  1574. #endif /* __PY32F0xx_HAL_RCC_H */
  1575. /************************ (C) COPYRIGHT Puya *****END OF FILE****/