stm32l0xx_hal_rcc.h 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RCC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file in
  13. * the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. ******************************************************************************
  16. */
  17. /* Define to prevent recursive inclusion -------------------------------------*/
  18. #ifndef __STM32L0xx_HAL_RCC_H
  19. #define __STM32L0xx_HAL_RCC_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32l0xx_hal_def.h"
  25. /** @addtogroup STM32L0xx_HAL_Driver
  26. * @{
  27. */
  28. /** @addtogroup RCC
  29. * @{
  30. */
  31. /** @addtogroup RCC_Private_Constants
  32. * @{
  33. */
  34. /** @defgroup RCC_Timeout RCC Timeout
  35. * @{
  36. */
  37. /* Disable Backup domain write protection state change timeout */
  38. #define RCC_DBP_TIMEOUT_VALUE (100U) /* 100 ms */
  39. /* LSE state change timeout */
  40. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  41. #define CLOCKSWITCH_TIMEOUT_VALUE (5000U) /* 5 s */
  42. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  43. #define MSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  44. #define HSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  45. #define LSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  46. #define PLL_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  47. #if defined(RCC_HSI48_SUPPORT)
  48. #define HSI48_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  49. #endif /* RCC_HSI48_SUPPORT */
  50. /**
  51. * @}
  52. */
  53. /** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
  54. * @brief RCC registers bit address in the alias region
  55. * @{
  56. */
  57. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  58. /* --- CR Register ---*/
  59. /* Alias word address of HSION bit */
  60. #define RCC_CR_OFFSET (RCC_OFFSET + 0x00U)
  61. /* --- CFGR Register ---*/
  62. /* Alias word address of I2SSRC bit */
  63. #define RCC_CFGR_OFFSET (RCC_OFFSET + 0x08U)
  64. /* --- CSR Register ---*/
  65. #define RCC_CSR_OFFSET (RCC_OFFSET + 0x74U)
  66. /* CR register byte 3 (Bits[23:16]) base address */
  67. #define RCC_CR_BYTE2_ADDRESS (0x40023802U)
  68. /* CIER register byte 0 (Bits[0:8]) base address */
  69. #define CIER_BYTE0_ADDRESS ((uint32_t)(RCC_BASE + 0x10U + 0x00U))
  70. /**
  71. * @}
  72. */
  73. /* Defines used for Flags */
  74. #define CR_REG_INDEX ((uint8_t)1)
  75. #define CSR_REG_INDEX ((uint8_t)2)
  76. #define CRRCR_REG_INDEX ((uint8_t)3)
  77. #define RCC_FLAG_MASK ((uint8_t)0x1F)
  78. /**
  79. * @}
  80. */
  81. /** @addtogroup RCC_Private_Macros
  82. * @{
  83. */
  84. #if defined(RCC_HSI48_SUPPORT)
  85. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  86. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  87. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  88. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI48) == RCC_OSCILLATORTYPE_HSI48) || \
  89. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  90. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  91. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI))
  92. #define IS_RCC_HSI48(__HSI48__) (((__HSI48__) == RCC_HSI48_OFF) || ((__HSI48__) == RCC_HSI48_ON))
  93. #else
  94. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  95. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  96. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  97. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  98. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  99. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI))
  100. #endif /* RCC_HSI48_SUPPORT */
  101. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI) || \
  102. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  103. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  104. ((__HSE__) == RCC_HSE_BYPASS))
  105. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  106. ((__LSE__) == RCC_LSE_BYPASS))
  107. #if defined(RCC_CR_HSIOUTEN)
  108. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON) || \
  109. ((__HSI__) == RCC_HSI_DIV4) || ((__HSI__) == RCC_HSI_OUTEN) || \
  110. ((__HSI__) == (RCC_HSI_OUTEN|RCC_HSI_ON)) || ((__HSI__) == (RCC_HSI_OUTEN|RCC_HSI_DIV4)))
  111. #else
  112. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON) || \
  113. ((__HSI__) == RCC_HSI_DIV4))
  114. #endif /* RCC_CR_HSIOUTEN */
  115. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
  116. #define IS_RCC_MSICALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0xFFU)
  117. #define IS_RCC_MSI_CLOCK_RANGE(__RANGE__) (((__RANGE__) == RCC_MSIRANGE_0) || \
  118. ((__RANGE__) == RCC_MSIRANGE_1) || \
  119. ((__RANGE__) == RCC_MSIRANGE_2) || \
  120. ((__RANGE__) == RCC_MSIRANGE_3) || \
  121. ((__RANGE__) == RCC_MSIRANGE_4) || \
  122. ((__RANGE__) == RCC_MSIRANGE_5) || \
  123. ((__RANGE__) == RCC_MSIRANGE_6))
  124. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  125. #define IS_RCC_MSI(__MSI__) (((__MSI__) == RCC_MSI_OFF) || ((__MSI__) == RCC_MSI_ON))
  126. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  127. ((__PLL__) == RCC_PLL_ON))
  128. #define IS_RCC_PLL_DIV(__DIV__) (((__DIV__) == RCC_PLL_DIV2) || \
  129. ((__DIV__) == RCC_PLL_DIV3) || ((__DIV__) == RCC_PLL_DIV4))
  130. #define IS_RCC_PLL_MUL(__MUL__) (((__MUL__) == RCC_PLL_MUL3) || ((__MUL__) == RCC_PLL_MUL4) || \
  131. ((__MUL__) == RCC_PLL_MUL6) || ((__MUL__) == RCC_PLL_MUL8) || \
  132. ((__MUL__) == RCC_PLL_MUL12) || ((__MUL__) == RCC_PLL_MUL16) || \
  133. ((__MUL__) == RCC_PLL_MUL24) || ((__MUL__) == RCC_PLL_MUL32) || \
  134. ((__MUL__) == RCC_PLL_MUL48))
  135. #define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  136. (((CLK) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  137. (((CLK) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) || \
  138. (((CLK) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2))
  139. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_MSI) || \
  140. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  141. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  142. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  143. #define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_MSI) || \
  144. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  145. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  146. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  147. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  148. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  149. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  150. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  151. ((__HCLK__) == RCC_SYSCLK_DIV512))
  152. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  153. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  154. ((__PCLK__) == RCC_HCLK_DIV16))
  155. #if defined(RCC_MCO3_SUPPORT)
  156. #define IS_RCC_MCO(__MCO__) (((__MCO__) == RCC_MCO1) || ((__MCO__) == RCC_MCO2) || ((__MCO__) == RCC_MCO3))
  157. #else
  158. #define IS_RCC_MCO(__MCO__) (((__MCO__) == RCC_MCO1) || ((__MCO__) == RCC_MCO2))
  159. #endif /* RCC_MCO3_SUPPORT */
  160. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1) || ((__DIV__) == RCC_MCODIV_2) || \
  161. ((__DIV__) == RCC_MCODIV_4) || ((__DIV__) == RCC_MCODIV_8) || \
  162. ((__DIV__) == RCC_MCODIV_16))
  163. #if defined(RCC_CFGR_MCOSEL_HSI48)
  164. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK) || ((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || \
  165. ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || ((__SOURCE__) == RCC_MCO1SOURCE_MSI) || \
  166. ((__SOURCE__) == RCC_MCO1SOURCE_HSE) || ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || \
  167. ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || ((__SOURCE__) == RCC_MCO1SOURCE_LSE) || \
  168. ((__SOURCE__) == RCC_MCO1SOURCE_HSI48))
  169. #else
  170. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK) || ((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || \
  171. ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || ((__SOURCE__) == RCC_MCO1SOURCE_MSI) || \
  172. ((__SOURCE__) == RCC_MCO1SOURCE_HSE) || ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || \
  173. ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || ((__SOURCE__) == RCC_MCO1SOURCE_LSE))
  174. #endif /* RCC_CFGR_MCOSEL_HSI48 */
  175. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  176. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  177. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  178. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV2) || \
  179. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV4) || \
  180. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV8) || \
  181. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV16))
  182. /**
  183. * @}
  184. */
  185. /* Exported types ------------------------------------------------------------*/
  186. /** @defgroup RCC_Exported_Types RCC Exported Types
  187. * @{
  188. */
  189. /**
  190. * @brief RCC PLL configuration structure definition
  191. */
  192. typedef struct
  193. {
  194. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  195. This parameter can be a value of @ref RCC_PLL_Config */
  196. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  197. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  198. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  199. This parameter must be a value of @ref RCC_PLL_Multiplication_Factor*/
  200. uint32_t PLLDIV; /*!< PLLDIV: Division factor for PLL VCO input clock
  201. This parameter must be a value of @ref RCC_PLL_Division_Factor*/
  202. } RCC_PLLInitTypeDef;
  203. /**
  204. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  205. */
  206. typedef struct
  207. {
  208. uint32_t OscillatorType; /*!< The oscillators to be configured.
  209. This parameter can be a value of @ref RCC_Oscillator_Type */
  210. uint32_t HSEState; /*!< The new state of the HSE.
  211. This parameter can be a value of @ref RCC_HSE_Config */
  212. uint32_t LSEState; /*!< The new state of the LSE.
  213. This parameter can be a value of @ref RCC_LSE_Config */
  214. uint32_t HSIState; /*!< The new state of the HSI.
  215. This parameter can be a value of @ref RCC_HSI_Config */
  216. uint32_t HSICalibrationValue; /*!< The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT).
  217. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1F */
  218. uint32_t LSIState; /*!< The new state of the LSI.
  219. This parameter can be a value of @ref RCC_LSI_Config */
  220. #if defined(RCC_HSI48_SUPPORT)
  221. uint32_t HSI48State; /*!< The new state of the HSI48.
  222. This parameter can be a value of @ref RCC_HSI48_Config */
  223. #endif /* RCC_HSI48_SUPPORT */
  224. uint32_t MSIState; /*!< The new state of the MSI.
  225. This parameter can be a value of @ref RCC_MSI_Config */
  226. uint32_t MSICalibrationValue; /*!< The MSI calibration trimming value. (default is RCC_MSICALIBRATION_DEFAULT).
  227. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  228. uint32_t MSIClockRange; /*!< The MSI frequency range.
  229. This parameter can be a value of @ref RCC_MSI_Clock_Range */
  230. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  231. } RCC_OscInitTypeDef;
  232. /**
  233. * @brief RCC System, AHB and APB busses clock configuration structure definition
  234. */
  235. typedef struct
  236. {
  237. uint32_t ClockType; /*!< The clock to be configured.
  238. This parameter can be a value of @ref RCC_System_Clock_Type */
  239. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  240. This parameter can be a value of @ref RCC_System_Clock_Source */
  241. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  242. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  243. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  244. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  245. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  246. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  247. } RCC_ClkInitTypeDef;
  248. /**
  249. * @}
  250. */
  251. /* Exported constants --------------------------------------------------------*/
  252. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  253. * @{
  254. */
  255. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  256. * @{
  257. */
  258. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI /*!< HSI clock selected as PLL entry clock source */
  259. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE /*!< HSE clock selected as PLL entry clock source */
  260. /**
  261. * @}
  262. */
  263. /** @defgroup RCC_Oscillator_Type Oscillator Type
  264. * @{
  265. */
  266. #define RCC_OSCILLATORTYPE_NONE (0x00000000U)
  267. #define RCC_OSCILLATORTYPE_HSE (0x00000001U)
  268. #define RCC_OSCILLATORTYPE_HSI (0x00000002U)
  269. #define RCC_OSCILLATORTYPE_LSE (0x00000004U)
  270. #define RCC_OSCILLATORTYPE_LSI (0x00000008U)
  271. #define RCC_OSCILLATORTYPE_MSI (0x00000010U)
  272. #if defined(RCC_HSI48_SUPPORT)
  273. #define RCC_OSCILLATORTYPE_HSI48 (0x00000020U)
  274. #endif /* RCC_HSI48_SUPPORT */
  275. /**
  276. * @}
  277. */
  278. /** @defgroup RCC_HSE_Config HSE Config
  279. * @{
  280. */
  281. #define RCC_HSE_OFF (0x00000000U) /*!< HSE clock deactivation */
  282. #define RCC_HSE_ON RCC_CR_HSEON /*!< HSE clock activation */
  283. #define RCC_HSE_BYPASS ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
  284. /**
  285. * @}
  286. */
  287. /** @defgroup RCC_LSE_Config LSE Config
  288. * @{
  289. */
  290. #define RCC_LSE_OFF (0x00000000U) /*!< LSE clock deactivation */
  291. #define RCC_LSE_ON RCC_CSR_LSEON /*!< LSE clock activation */
  292. #define RCC_LSE_BYPASS ((uint32_t)(RCC_CSR_LSEBYP | RCC_CSR_LSEON)) /*!< External clock source for LSE clock */
  293. /**
  294. * @}
  295. */
  296. /** @defgroup RCC_HSI_Config HSI Config
  297. * @{
  298. */
  299. #define RCC_HSI_OFF (0x00000000U) /*!< HSI clock deactivation */
  300. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  301. #define RCC_HSI_DIV4 (RCC_CR_HSIDIVEN | RCC_CR_HSION) /*!< HSI_DIV4 clock activation */
  302. #if defined(RCC_CR_HSIOUTEN)
  303. #define RCC_HSI_OUTEN RCC_CR_HSIOUTEN /*!< HSI_OUTEN clock activation */
  304. /* This value is to be used in combination with RCC_HSI_ON/RCC_HSI_DIV4 */
  305. #endif /* RCC_CR_HSIOUTEN */
  306. #define RCC_HSICALIBRATION_DEFAULT (0x10U) /* Default HSI calibration trimming value */
  307. /**
  308. * @}
  309. */
  310. /** @defgroup RCC_MSI_Clock_Range MSI Clock Range
  311. * @{
  312. */
  313. #define RCC_MSIRANGE_0 RCC_ICSCR_MSIRANGE_0 /*!< MSI = 65.536 KHz */
  314. #define RCC_MSIRANGE_1 RCC_ICSCR_MSIRANGE_1 /*!< MSI = 131.072 KHz */
  315. #define RCC_MSIRANGE_2 RCC_ICSCR_MSIRANGE_2 /*!< MSI = 262.144 KHz */
  316. #define RCC_MSIRANGE_3 RCC_ICSCR_MSIRANGE_3 /*!< MSI = 524.288 KHz */
  317. #define RCC_MSIRANGE_4 RCC_ICSCR_MSIRANGE_4 /*!< MSI = 1.048 MHz */
  318. #define RCC_MSIRANGE_5 RCC_ICSCR_MSIRANGE_5 /*!< MSI = 2.097 MHz */
  319. #define RCC_MSIRANGE_6 RCC_ICSCR_MSIRANGE_6 /*!< MSI = 4.194 MHz */
  320. /**
  321. * @}
  322. */
  323. /** @defgroup RCC_LSI_Config LSI Config
  324. * @{
  325. */
  326. #define RCC_LSI_OFF (0x00000000U) /*!< LSI clock deactivation */
  327. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  328. /**
  329. * @}
  330. */
  331. /** @defgroup RCC_MSI_Config MSI Config
  332. * @{
  333. */
  334. #define RCC_MSI_OFF (0x00000000U)
  335. #define RCC_MSI_ON (0x00000001U)
  336. #define RCC_MSICALIBRATION_DEFAULT (0x00000000U) /* Default MSI calibration trimming value */
  337. /**
  338. * @}
  339. */
  340. #if defined(RCC_HSI48_SUPPORT)
  341. /** @defgroup RCC_HSI48_Config HSI48 Config
  342. * @{
  343. */
  344. #define RCC_HSI48_OFF ((uint8_t)0x00)
  345. #define RCC_HSI48_ON ((uint8_t)0x01)
  346. /**
  347. * @}
  348. */
  349. #endif /* RCC_HSI48_SUPPORT */
  350. /** @defgroup RCC_PLL_Config PLL Config
  351. * @{
  352. */
  353. #define RCC_PLL_NONE (0x00000000U) /*!< PLL is not configured */
  354. #define RCC_PLL_OFF (0x00000001U) /*!< PLL deactivation */
  355. #define RCC_PLL_ON (0x00000002U) /*!< PLL activation */
  356. /**
  357. * @}
  358. */
  359. /** @defgroup RCC_System_Clock_Type System Clock Type
  360. * @{
  361. */
  362. #define RCC_CLOCKTYPE_SYSCLK (0x00000001U) /*!< SYSCLK to configure */
  363. #define RCC_CLOCKTYPE_HCLK (0x00000002U) /*!< HCLK to configure */
  364. #define RCC_CLOCKTYPE_PCLK1 (0x00000004U) /*!< PCLK1 to configure */
  365. #define RCC_CLOCKTYPE_PCLK2 (0x00000008U) /*!< PCLK2 to configure */
  366. /**
  367. * @}
  368. */
  369. /** @defgroup RCC_System_Clock_Source System Clock Source
  370. * @{
  371. */
  372. #define RCC_SYSCLKSOURCE_MSI RCC_CFGR_SW_MSI /*!< MSI selected as system clock */
  373. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  374. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  375. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  376. /**
  377. * @}
  378. */
  379. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  380. * @{
  381. */
  382. #define RCC_SYSCLKSOURCE_STATUS_MSI RCC_CFGR_SWS_MSI /*!< MSI used as system clock */
  383. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  384. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  385. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  386. /**
  387. * @}
  388. */
  389. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  390. * @{
  391. */
  392. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  393. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  394. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  395. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  396. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  397. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  398. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  399. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  400. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  401. /**
  402. * @}
  403. */
  404. /** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
  405. * @{
  406. */
  407. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1 /*!< HCLK not divided */
  408. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2 /*!< HCLK divided by 2 */
  409. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4 /*!< HCLK divided by 4 */
  410. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8 /*!< HCLK divided by 8 */
  411. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
  412. /**
  413. * @}
  414. */
  415. /** @defgroup RCC_HAL_EC_RTC_HSE_DIV RTC HSE Prescaler
  416. * @{
  417. */
  418. #define RCC_RTC_HSE_DIV_2 (0x00000000U) /*!< HSE is divided by 2 for RTC clock */
  419. #define RCC_RTC_HSE_DIV_4 RCC_CR_RTCPRE_0 /*!< HSE is divided by 4 for RTC clock */
  420. #define RCC_RTC_HSE_DIV_8 RCC_CR_RTCPRE_1 /*!< HSE is divided by 8 for RTC clock */
  421. #define RCC_RTC_HSE_DIV_16 RCC_CR_RTCPRE /*!< HSE is divided by 16 for RTC clock */
  422. /**
  423. * @}
  424. */
  425. /** @defgroup RCC_RTC_LCD_Clock_Source RTC LCD Clock Source
  426. * @{
  427. */
  428. #define RCC_RTCCLKSOURCE_NO_CLK (0x00000000U) /*!< No clock */
  429. #define RCC_RTCCLKSOURCE_LSE RCC_CSR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  430. #define RCC_RTCCLKSOURCE_LSI RCC_CSR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  431. #define RCC_RTCCLKSOURCE_HSE_DIVX RCC_CSR_RTCSEL_HSE /*!< HSE oscillator clock divided by X used as RTC clock */
  432. #define RCC_RTCCLKSOURCE_HSE_DIV2 (RCC_RTC_HSE_DIV_2 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 2 used as RTC clock */
  433. #define RCC_RTCCLKSOURCE_HSE_DIV4 (RCC_RTC_HSE_DIV_4 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 4 used as RTC clock */
  434. #define RCC_RTCCLKSOURCE_HSE_DIV8 (RCC_RTC_HSE_DIV_8 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 8 used as RTC clock */
  435. #define RCC_RTCCLKSOURCE_HSE_DIV16 (RCC_RTC_HSE_DIV_16 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 16 used as RTC clock */
  436. /**
  437. * @}
  438. */
  439. /** @defgroup RCC_PLL_Division_Factor PLL Division Factor
  440. * @{
  441. */
  442. #define RCC_PLL_DIV2 RCC_CFGR_PLLDIV2
  443. #define RCC_PLL_DIV3 RCC_CFGR_PLLDIV3
  444. #define RCC_PLL_DIV4 RCC_CFGR_PLLDIV4
  445. /**
  446. * @}
  447. */
  448. /** @defgroup RCC_PLL_Multiplication_Factor PLL Multiplication Factor
  449. * @{
  450. */
  451. #define RCC_PLL_MUL3 RCC_CFGR_PLLMUL3
  452. #define RCC_PLL_MUL4 RCC_CFGR_PLLMUL4
  453. #define RCC_PLL_MUL6 RCC_CFGR_PLLMUL6
  454. #define RCC_PLL_MUL8 RCC_CFGR_PLLMUL8
  455. #define RCC_PLL_MUL12 RCC_CFGR_PLLMUL12
  456. #define RCC_PLL_MUL16 RCC_CFGR_PLLMUL16
  457. #define RCC_PLL_MUL24 RCC_CFGR_PLLMUL24
  458. #define RCC_PLL_MUL32 RCC_CFGR_PLLMUL32
  459. #define RCC_PLL_MUL48 RCC_CFGR_PLLMUL48
  460. /**
  461. * @}
  462. */
  463. /** @defgroup RCC_MCO_Index MCO Index
  464. * @{
  465. */
  466. #define RCC_MCO1 (0x00000000U)
  467. #define RCC_MCO2 (0x00000001U)
  468. #if defined(RCC_MCO3_SUPPORT)
  469. #define RCC_MCO3 (0x00000002U)
  470. #if defined(RCC_MCO3_AF0_SUPPORT)
  471. #define MCO3_GPIO_AF GPIO_AF0_MCO
  472. #else
  473. #define MCO3_GPIO_AF GPIO_AF2_MCO
  474. #endif /* RCC_MCO3_AF0_SUPPORT */
  475. #endif /* RCC_MCO3_SUPPORT */
  476. /**
  477. * @}
  478. */
  479. /** @defgroup RCC_MCOx_Clock_Prescaler MCO Clock Prescaler
  480. * @{
  481. */
  482. #define RCC_MCODIV_1 RCC_CFGR_MCO_PRE_1
  483. #define RCC_MCODIV_2 RCC_CFGR_MCO_PRE_2
  484. #define RCC_MCODIV_4 RCC_CFGR_MCO_PRE_4
  485. #define RCC_MCODIV_8 RCC_CFGR_MCO_PRE_8
  486. #define RCC_MCODIV_16 RCC_CFGR_MCO_PRE_16
  487. /**
  488. * @}
  489. */
  490. /** @defgroup RCC_MCO1_Clock_Source MCO1 Clock Source
  491. * @{
  492. */
  493. #define RCC_MCO1SOURCE_NOCLOCK RCC_CFGR_MCO_NOCLOCK
  494. #define RCC_MCO1SOURCE_SYSCLK RCC_CFGR_MCO_SYSCLK
  495. #define RCC_MCO1SOURCE_MSI RCC_CFGR_MCO_MSI
  496. #define RCC_MCO1SOURCE_HSI RCC_CFGR_MCO_HSI
  497. #define RCC_MCO1SOURCE_LSE RCC_CFGR_MCO_LSE
  498. #define RCC_MCO1SOURCE_LSI RCC_CFGR_MCO_LSI
  499. #define RCC_MCO1SOURCE_HSE RCC_CFGR_MCO_HSE
  500. #define RCC_MCO1SOURCE_PLLCLK RCC_CFGR_MCO_PLL
  501. #if defined(RCC_CFGR_MCOSEL_HSI48)
  502. #define RCC_MCO1SOURCE_HSI48 RCC_CFGR_MCO_HSI48
  503. #endif /* RCC_CFGR_MCOSEL_HSI48 */
  504. /**
  505. * @}
  506. */
  507. /** @defgroup RCC_Interrupt Interrupts
  508. * @{
  509. */
  510. #define RCC_IT_LSIRDY RCC_CIFR_LSIRDYF /*!< LSI Ready Interrupt flag */
  511. #define RCC_IT_LSERDY RCC_CIFR_LSERDYF /*!< LSE Ready Interrupt flag */
  512. #define RCC_IT_HSIRDY RCC_CIFR_HSIRDYF /*!< HSI Ready Interrupt flag */
  513. #define RCC_IT_HSERDY RCC_CIFR_HSERDYF /*!< HSE Ready Interrupt flag */
  514. #define RCC_IT_PLLRDY RCC_CIFR_PLLRDYF /*!< PLL Ready Interrupt flag */
  515. #define RCC_IT_MSIRDY RCC_CIFR_MSIRDYF /*!< MSI Ready Interrupt flag */
  516. #define RCC_IT_LSECSS RCC_CIFR_CSSLSEF /*!< LSE Clock Security System Interrupt flag */
  517. #if defined(RCC_HSECSS_SUPPORT)
  518. #define RCC_IT_CSS RCC_CIFR_CSSHSEF /*!< Clock Security System Interrupt flag */
  519. #endif /* RCC_HSECSS_SUPPORT */
  520. #if defined(RCC_HSI48_SUPPORT)
  521. #define RCC_IT_HSI48RDY RCC_CIFR_HSI48RDYF /*!< HSI48 Ready Interrupt flag */
  522. #endif /* RCC_HSI48_SUPPORT */
  523. /**
  524. * @}
  525. */
  526. /** @defgroup RCC_Flag Flags
  527. * Elements values convention: XXXYYYYYb
  528. * - YYYYY : Flag position in the register
  529. * - XXX : Register index
  530. * - 001: CR register
  531. * - 010: CSR register
  532. * - 011: CRRCR register (*)
  533. * (*) Applicable only for STM32L052xx, STM32L053xx, (...), STM32L073xx & STM32L082xx
  534. * @{
  535. */
  536. /* Flags in the CR register */
  537. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_HSIRDY_Pos)) /*!< Internal High Speed clock ready flag */
  538. #define RCC_FLAG_HSIDIV ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_HSIDIVF_Pos)) /*!< HSI16 divider flag */
  539. #define RCC_FLAG_MSIRDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_MSIRDY_Pos)) /*!< MSI clock ready flag */
  540. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_HSERDY_Pos)) /*!< External High Speed clock ready flag */
  541. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_PLLRDY_Pos)) /*!< PLL clock ready flag */
  542. /* Flags in the CSR register */
  543. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LSIRDY_Pos)) /*!< Internal Low Speed oscillator Ready */
  544. #define RCC_FLAG_LSERDY ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LSERDY_Pos)) /*!< External Low Speed oscillator Ready */
  545. #define RCC_FLAG_LSECSS ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LSECSSD_Pos)) /*!< CSS on LSE failure Detection */
  546. #define RCC_FLAG_OBLRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_OBLRSTF_Pos)) /*!< Options bytes loading reset flag */
  547. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_PINRSTF_Pos)) /*!< PIN reset flag */
  548. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_PORRSTF_Pos)) /*!< POR/PDR reset flag */
  549. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_SFTRSTF_Pos)) /*!< Software Reset flag */
  550. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_IWDGRSTF_Pos)) /*!< Independent Watchdog reset flag */
  551. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_WWDGRSTF_Pos)) /*!< Window watchdog reset flag */
  552. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LPWRRSTF_Pos)) /*!< Low-Power reset flag */
  553. #if defined(RCC_CSR_FWRSTF)
  554. #define RCC_FLAG_FWRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_FWRSTF_Pos)) /*!< RCC flag FW reset */
  555. #endif /* RCC_CSR_FWRSTF */
  556. /* Flags in the CRRCR register */
  557. #if defined(RCC_HSI48_SUPPORT)
  558. #define RCC_FLAG_HSI48RDY ((uint8_t)((CRRCR_REG_INDEX << 5) | RCC_CRRCR_HSI48RDY_Pos)) /*!< HSI48 clock ready flag */
  559. #endif /* RCC_HSI48_SUPPORT */
  560. /**
  561. * @}
  562. */
  563. /**
  564. * @}
  565. */
  566. /* Exported macro ------------------------------------------------------------*/
  567. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  568. * @{
  569. */
  570. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable AHB Peripheral Clock Enable Disable
  571. * @brief Enable or disable the AHB peripheral clock.
  572. * @note After reset, the peripheral clock (used for registers read/write access)
  573. * is disabled and the application software has to enable this clock before
  574. * using it.
  575. * @{
  576. */
  577. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  578. __IO uint32_t tmpreg; \
  579. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  580. /* Delay after an RCC peripheral clock enabling */ \
  581. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  582. UNUSED(tmpreg); \
  583. } while(0)
  584. #define __HAL_RCC_MIF_CLK_ENABLE() do { \
  585. __IO uint32_t tmpreg; \
  586. SET_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN);\
  587. /* Delay after an RCC peripheral clock enabling */ \
  588. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN);\
  589. UNUSED(tmpreg); \
  590. } while(0)
  591. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  592. __IO uint32_t tmpreg; \
  593. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  594. /* Delay after an RCC peripheral clock enabling */ \
  595. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  596. UNUSED(tmpreg); \
  597. } while(0)
  598. #define __HAL_RCC_DMA1_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN)
  599. #define __HAL_RCC_MIF_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN)
  600. #define __HAL_RCC_CRC_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN)
  601. /**
  602. * @}
  603. */
  604. /** @defgroup RCC_IOPORT_Clock_Enable_Disable IOPORT Peripheral Clock Enable Disable
  605. * @brief Enable or disable the IOPORT peripheral clock.
  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_CLK_ENABLE() do { \
  612. __IO uint32_t tmpreg; \
  613. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  614. /* Delay after an RCC peripheral clock enabling */ \
  615. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  616. UNUSED(tmpreg); \
  617. } while(0)
  618. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  619. __IO uint32_t tmpreg; \
  620. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN);\
  621. /* Delay after an RCC peripheral clock enabling */ \
  622. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN);\
  623. UNUSED(tmpreg); \
  624. } while(0)
  625. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  626. __IO uint32_t tmpreg; \
  627. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN);\
  628. /* Delay after an RCC peripheral clock enabling */ \
  629. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN);\
  630. UNUSED(tmpreg); \
  631. } while(0)
  632. #define __HAL_RCC_GPIOH_CLK_ENABLE() do { \
  633. __IO uint32_t tmpreg; \
  634. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN);\
  635. /* Delay after an RCC peripheral clock enabling */ \
  636. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN);\
  637. UNUSED(tmpreg); \
  638. } while(0)
  639. #define __HAL_RCC_GPIOA_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN)
  640. #define __HAL_RCC_GPIOB_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN)
  641. #define __HAL_RCC_GPIOC_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN)
  642. #define __HAL_RCC_GPIOH_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN)
  643. /**
  644. * @}
  645. */
  646. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Peripheral Clock Enable Disable
  647. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  648. * @note After reset, the peripheral clock (used for registers read/write access)
  649. * is disabled and the application software has to enable this clock before
  650. * using it.
  651. * @{
  652. */
  653. #define __HAL_RCC_WWDG_CLK_ENABLE() SET_BIT(RCC->APB1ENR, (RCC_APB1ENR_WWDGEN))
  654. #define __HAL_RCC_PWR_CLK_ENABLE() SET_BIT(RCC->APB1ENR, (RCC_APB1ENR_PWREN))
  655. #define __HAL_RCC_WWDG_CLK_DISABLE() CLEAR_BIT(RCC->APB1ENR, (RCC_APB1ENR_WWDGEN))
  656. #define __HAL_RCC_PWR_CLK_DISABLE() CLEAR_BIT(RCC->APB1ENR, (RCC_APB1ENR_PWREN))
  657. /**
  658. * @}
  659. */
  660. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Peripheral Clock Enable Disable
  661. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  662. * @note After reset, the peripheral clock (used for registers read/write access)
  663. * is disabled and the application software has to enable this clock before
  664. * using it.
  665. * @{
  666. */
  667. #define __HAL_RCC_SYSCFG_CLK_ENABLE() SET_BIT(RCC->APB2ENR, (RCC_APB2ENR_SYSCFGEN))
  668. #define __HAL_RCC_DBGMCU_CLK_ENABLE() SET_BIT(RCC->APB2ENR, (RCC_APB2ENR_DBGMCUEN))
  669. #define __HAL_RCC_SYSCFG_CLK_DISABLE() CLEAR_BIT(RCC->APB2ENR, (RCC_APB2ENR_SYSCFGEN))
  670. #define __HAL_RCC_DBGMCU_CLK_DISABLE() CLEAR_BIT(RCC->APB2ENR, (RCC_APB2ENR_DBGMCUEN))
  671. /**
  672. * @}
  673. */
  674. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enabled or Disabled Status
  675. * @brief Check whether the AHB peripheral clock is enabled or not.
  676. * @note After reset, the peripheral clock (used for registers read/write access)
  677. * is disabled and the application software has to enable this clock before
  678. * using it.
  679. * @{
  680. */
  681. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN) != 0U)
  682. #define __HAL_RCC_MIF_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN) != 0U)
  683. #define __HAL_RCC_CRC_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) != 0U)
  684. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN) == 0U)
  685. #define __HAL_RCC_MIF_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN) == 0U)
  686. #define __HAL_RCC_CRC_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) == 0U)
  687. /**
  688. * @}
  689. */
  690. /** @defgroup RCC_IOPORT_Peripheral_Clock_Enable_Disable_Status IOPORT Peripheral Clock Enabled or Disabled Status
  691. * @brief Check whether the IOPORT peripheral clock is enabled or not.
  692. * @note After reset, the peripheral clock (used for registers read/write access)
  693. * is disabled and the application software has to enable this clock before
  694. * using it.
  695. * @{
  696. */
  697. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) != 0U)
  698. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) != 0U)
  699. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN) != 0U)
  700. #define __HAL_RCC_GPIOH_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN) != 0U)
  701. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) == 0U)
  702. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) == 0U)
  703. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN) == 0U)
  704. #define __HAL_RCC_GPIOH_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN) == 0U)
  705. /**
  706. * @}
  707. */
  708. /** @defgroup RCC_APB1_Clock_Enable_Disable_Status APB1 Peripheral Clock Enabled or Disabled Status
  709. * @brief Check whether the APB1 peripheral clock is enabled or not.
  710. * @note After reset, the peripheral clock (used for registers read/write access)
  711. * is disabled and the application software has to enable this clock before
  712. * using it.
  713. * @{
  714. */
  715. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN) != 0U)
  716. #define __HAL_RCC_PWR_IS_CLK_ENABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN) != 0U)
  717. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN) == 0U)
  718. #define __HAL_RCC_PWR_IS_CLK_DISABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN) == 0U)
  719. /**
  720. * @}
  721. */
  722. /** @defgroup RCC_APB2_Clock_Enable_Disable_Status APB2 Peripheral Clock Enabled or Disabled Status
  723. * @brief Check whether the APB2 peripheral clock is enabled or not.
  724. * @note After reset, the peripheral clock (used for registers read/write access)
  725. * is disabled and the application software has to enable this clock before
  726. * using it.
  727. * @{
  728. */
  729. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN) != 0U)
  730. #define __HAL_RCC_DBGMCU_IS_CLK_ENABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_DBGMCUEN) != 0U)
  731. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN) == 0U)
  732. #define __HAL_RCC_DBGMCU_IS_CLK_DISABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_DBGMCUEN) == 0U)
  733. /**
  734. * @}
  735. */
  736. /** @defgroup RCC_AHB_Force_Release_Reset AHB Peripheral Force Release Reset
  737. * @brief Force or release AHB peripheral reset.
  738. * @{
  739. */
  740. #define __HAL_RCC_AHB_FORCE_RESET() (RCC->AHBRSTR = 0xFFFFFFFFU)
  741. #define __HAL_RCC_DMA1_FORCE_RESET() SET_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_DMA1RST))
  742. #define __HAL_RCC_MIF_FORCE_RESET() SET_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_MIFRST))
  743. #define __HAL_RCC_CRC_FORCE_RESET() SET_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_CRCRST))
  744. #define __HAL_RCC_AHB_RELEASE_RESET() (RCC->AHBRSTR = 0x00000000U)
  745. #define __HAL_RCC_CRC_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_CRCRST))
  746. #define __HAL_RCC_DMA1_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_DMA1RST))
  747. #define __HAL_RCC_MIF_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_MIFRST))
  748. /**
  749. * @}
  750. */
  751. /** @defgroup RCC_IOPORT_Force_Release_Reset IOPORT Peripheral Force Release Reset
  752. * @brief Force or release IOPORT peripheral reset.
  753. * @{
  754. */
  755. #define __HAL_RCC_IOP_FORCE_RESET() (RCC->IOPRSTR = 0xFFFFFFFFU)
  756. #define __HAL_RCC_GPIOA_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOARST))
  757. #define __HAL_RCC_GPIOB_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOBRST))
  758. #define __HAL_RCC_GPIOC_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOCRST))
  759. #define __HAL_RCC_GPIOH_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOHRST))
  760. #define __HAL_RCC_IOP_RELEASE_RESET() (RCC->IOPRSTR = 0x00000000U)
  761. #define __HAL_RCC_GPIOA_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOARST))
  762. #define __HAL_RCC_GPIOB_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOBRST))
  763. #define __HAL_RCC_GPIOC_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOCRST))
  764. #define __HAL_RCC_GPIOH_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOHRST))
  765. /**
  766. * @}
  767. */
  768. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Peripheral Force Release Reset
  769. * @brief Force or release APB1 peripheral reset.
  770. * @{
  771. */
  772. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFFU)
  773. #define __HAL_RCC_WWDG_FORCE_RESET() SET_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_WWDGRST))
  774. #define __HAL_RCC_PWR_FORCE_RESET() SET_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_PWRRST))
  775. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00000000U)
  776. #define __HAL_RCC_WWDG_RELEASE_RESET() CLEAR_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_WWDGRST))
  777. #define __HAL_RCC_PWR_RELEASE_RESET() CLEAR_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_PWRRST))
  778. /**
  779. * @}
  780. */
  781. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Peripheral Force Release Reset
  782. * @brief Force or release APB2 peripheral reset.
  783. * @{
  784. */
  785. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  786. #define __HAL_RCC_DBGMCU_FORCE_RESET() SET_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_DBGMCURST))
  787. #define __HAL_RCC_SYSCFG_FORCE_RESET() SET_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_SYSCFGRST))
  788. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00000000U)
  789. #define __HAL_RCC_DBGMCU_RELEASE_RESET() CLEAR_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_DBGMCURST))
  790. #define __HAL_RCC_SYSCFG_RELEASE_RESET() CLEAR_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_SYSCFGRST))
  791. /**
  792. * @}
  793. */
  794. /** @defgroup RCC_AHB_Clock_Sleep_Enable_Disable AHB Peripheral Clock Sleep Enable Disable
  795. * @brief Enable or disable the AHB peripheral clock during Low Power (Sleep) mode.
  796. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  797. * power consumption.
  798. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  799. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  800. * @{
  801. */
  802. #define __HAL_RCC_CRC_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_CRCSMEN))
  803. #define __HAL_RCC_MIF_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_MIFSMEN))
  804. #define __HAL_RCC_SRAM_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_SRAMSMEN))
  805. #define __HAL_RCC_DMA1_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_DMA1SMEN))
  806. #define __HAL_RCC_CRC_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_CRCSMEN))
  807. #define __HAL_RCC_MIF_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_MIFSMEN))
  808. #define __HAL_RCC_SRAM_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_SRAMSMEN))
  809. #define __HAL_RCC_DMA1_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_DMA1SMEN))
  810. /**
  811. * @}
  812. */
  813. /** @defgroup RCC_IOPORT_Clock_Sleep_Enable_Disable IOPORT Peripheral Clock Sleep Enable Disable
  814. * @brief Enable or disable the IOPORT peripheral clock during Low Power (Sleep) mode.
  815. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  816. * power consumption.
  817. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  818. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  819. * @{
  820. */
  821. #define __HAL_RCC_GPIOA_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOASMEN))
  822. #define __HAL_RCC_GPIOB_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOBSMEN))
  823. #define __HAL_RCC_GPIOC_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOCSMEN))
  824. #define __HAL_RCC_GPIOH_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOHSMEN))
  825. #define __HAL_RCC_GPIOA_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOASMEN))
  826. #define __HAL_RCC_GPIOB_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOBSMEN))
  827. #define __HAL_RCC_GPIOC_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOCSMEN))
  828. #define __HAL_RCC_GPIOH_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOHSMEN))
  829. /**
  830. * @}
  831. */
  832. /** @defgroup RCC_APB1_Clock_Sleep_Enable_Disable APB1 Peripheral Clock Sleep Enable Disable
  833. * @brief Enable or disable the APB1 peripheral clock during Low Power (Sleep) mode.
  834. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  835. * power consumption.
  836. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  837. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  838. * @{
  839. */
  840. #define __HAL_RCC_WWDG_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_WWDGSMEN))
  841. #define __HAL_RCC_PWR_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_PWRSMEN))
  842. #define __HAL_RCC_WWDG_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_WWDGSMEN))
  843. #define __HAL_RCC_PWR_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_PWRSMEN))
  844. /**
  845. * @}
  846. */
  847. /** @defgroup RCC_APB2_Clock_Sleep_Enable_Disable APB2 Peripheral Clock Sleep Enable Disable
  848. * @brief Enable or disable the APB2 peripheral clock during Low Power (Sleep) mode.
  849. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  850. * power consumption.
  851. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  852. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  853. * @{
  854. */
  855. #define __HAL_RCC_SYSCFG_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_SYSCFGSMEN))
  856. #define __HAL_RCC_DBGMCU_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_DBGMCUSMEN))
  857. #define __HAL_RCC_SYSCFG_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_SYSCFGSMEN))
  858. #define __HAL_RCC_DBGMCU_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_DBGMCUSMEN))
  859. /**
  860. * @}
  861. */
  862. /** @defgroup RCC_AHB_Clock_Sleep_Enable_Disable_Status AHB Peripheral Clock Sleep Enabled or Disabled Status
  863. * @brief Check whether the AHB peripheral clock during Low Power (Sleep) mode is enabled or not.
  864. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  865. * power consumption.
  866. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  867. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  868. * @{
  869. */
  870. #define __HAL_RCC_CRC_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_CRCSMEN) != 0U)
  871. #define __HAL_RCC_MIF_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_MIFSMEN) != 0U)
  872. #define __HAL_RCC_SRAM_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_SRAMSMEN) != 0U)
  873. #define __HAL_RCC_DMA1_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_DMA1SMEN) != 0U)
  874. #define __HAL_RCC_CRC_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_CRCSMEN) == 0U)
  875. #define __HAL_RCC_MIF_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_MIFSMEN) == 0U)
  876. #define __HAL_RCC_SRAM_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_SRAMSMEN) == 0U)
  877. #define __HAL_RCC_DMA1_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_DMA1SMEN) == 0U)
  878. /**
  879. * @}
  880. */
  881. /** @defgroup RCC_IOPORT_Clock_Sleep_Enable_Disable_Status IOPORT Peripheral Clock Sleep Enabled or Disabled Status
  882. * @brief Check whether the IOPORT peripheral clock during Low Power (Sleep) mode is enabled or not.
  883. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  884. * power consumption.
  885. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  886. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  887. * @{
  888. */
  889. #define __HAL_RCC_GPIOA_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOASMEN) != 0U)
  890. #define __HAL_RCC_GPIOB_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOBSMEN) != 0U)
  891. #define __HAL_RCC_GPIOC_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOCSMEN) != 0U)
  892. #define __HAL_RCC_GPIOH_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOHSMEN) != 0U)
  893. #define __HAL_RCC_GPIOA_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOASMEN) == 0U)
  894. #define __HAL_RCC_GPIOB_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOBSMEN) == 0U)
  895. #define __HAL_RCC_GPIOC_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOCSMEN) == 0U)
  896. #define __HAL_RCC_GPIOH_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOHSMEN) == 0U)
  897. /**
  898. * @}
  899. */
  900. /** @defgroup RCC_APB1_Clock_Sleep_Enable_Disable_Status APB1 Peripheral Clock Sleep Enabled or Disabled Status
  901. * @brief Check whether the APB1 peripheral clock during Low Power (Sleep) mode is enabled or not.
  902. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  903. * power consumption.
  904. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  905. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  906. * @{
  907. */
  908. #define __HAL_RCC_WWDG_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_WWDGSMEN) != 0U)
  909. #define __HAL_RCC_PWR_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_PWRSMEN) != 0U)
  910. #define __HAL_RCC_WWDG_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_WWDGSMEN) == 0U)
  911. #define __HAL_RCC_PWR_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_PWRSMEN) == 0U)
  912. /**
  913. * @}
  914. */
  915. /** @defgroup RCC_APB2_Clock_Sleep_Enable_Disable_Status APB2 Peripheral Clock Sleep Enabled or Disabled Status
  916. * @brief Check whether the APB2 peripheral clock during Low Power (Sleep) mode is enabled or not.
  917. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  918. * power consumption.
  919. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  920. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  921. * @{
  922. */
  923. #define __HAL_RCC_SYSCFG_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_SYSCFGSMEN) != 0U)
  924. #define __HAL_RCC_DBGMCU_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_DBGMCUSMEN) != 0U)
  925. #define __HAL_RCC_SYSCFG_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_SYSCFGSMEN) == 0U)
  926. #define __HAL_RCC_DBGMCU_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_DBGMCUSMEN) == 0U)
  927. /**
  928. * @}
  929. */
  930. /** @defgroup RCC_HSI_Configuration HSI Configuration
  931. * @{
  932. */
  933. /** @brief Macro to enable or disable the Internal High Speed oscillator (HSI).
  934. * @note After enabling the HSI, the application software should wait on
  935. * HSIRDY flag to be set indicating that HSI clock is stable and can
  936. * be used to clock the PLL and/or system clock.
  937. * @note HSI can not be stopped if it is used directly or through the PLL
  938. * as system clock. In this case, you have to select another source
  939. * of the system clock then stop the HSI.
  940. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  941. * @param __STATE__ specifies the new state of the HSI.
  942. * This parameter can be one of the following values:
  943. * @arg @ref RCC_HSI_OFF turn OFF the HSI oscillator
  944. * @arg @ref RCC_HSI_ON turn ON the HSI oscillator
  945. * @arg @ref RCC_HSI_DIV4 turn ON the HSI oscillator and divide it by 4
  946. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  947. * clock cycles.
  948. */
  949. #define __HAL_RCC_HSI_CONFIG(__STATE__) \
  950. MODIFY_REG(RCC->CR, RCC_CR_HSION | RCC_CR_HSIDIVEN , (uint32_t)(__STATE__))
  951. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  952. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  953. * It is used (enabled by hardware) as system clock source after startup
  954. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  955. * of the HSE used directly or indirectly as system clock (if the Clock
  956. * Security System CSS is enabled).
  957. * @note HSI can not be stopped if it is used as system clock source. In this case,
  958. * you have to select another source of the system clock then stop the HSI.
  959. * @note After enabling the HSI, the application software should wait on HSIRDY
  960. * flag to be set indicating that HSI clock is stable and can be used as
  961. * system clock source.
  962. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  963. * clock cycles.
  964. */
  965. #define __HAL_RCC_HSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_HSION)
  966. #define __HAL_RCC_HSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_HSION)
  967. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  968. * @note The calibration is used to compensate for the variations in voltage
  969. * and temperature that influence the frequency of the internal HSI RC.
  970. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  971. * (default is RCC_HSICALIBRATION_DEFAULT).
  972. * This parameter must be a number between 0 and 0x1F.
  973. */
  974. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  975. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << RCC_ICSCR_HSITRIM_Pos))
  976. /**
  977. * @}
  978. */
  979. /** @defgroup RCC_LSI_Configuration LSI Configuration
  980. * @{
  981. */
  982. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  983. * @note After enabling the LSI, the application software should wait on
  984. * LSIRDY flag to be set indicating that LSI clock is stable and can
  985. * be used to clock the IWDG and/or the RTC.
  986. */
  987. #define __HAL_RCC_LSI_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_LSION)
  988. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  989. * @note LSI can not be disabled if the IWDG is running.
  990. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  991. * clock cycles.
  992. */
  993. #define __HAL_RCC_LSI_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_LSION)
  994. /**
  995. * @}
  996. */
  997. /** @defgroup RCC_HSE_Configuration HSE Configuration
  998. * @{
  999. */
  1000. /**
  1001. * @brief Macro to configure the External High Speed oscillator (HSE).
  1002. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  1003. * supported by this macro. User should request a transition to HSE Off
  1004. * first and then HSE On or HSE Bypass.
  1005. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  1006. * software should wait on HSERDY flag to be set indicating that HSE clock
  1007. * is stable and can be used to clock the PLL and/or system clock.
  1008. * @note HSE state can not be changed if it is used directly or through the
  1009. * PLL as system clock. In this case, you have to select another source
  1010. * of the system clock then change the HSE state (ex. disable it).
  1011. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  1012. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  1013. * was previously enabled you have to enable it again after calling this
  1014. * function.
  1015. * @param __STATE__ specifies the new state of the HSE.
  1016. * This parameter can be one of the following values:
  1017. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  1018. * 6 HSE oscillator clock cycles.
  1019. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  1020. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  1021. */
  1022. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  1023. do{ \
  1024. __IO uint32_t tmpreg; \
  1025. if ((__STATE__) == RCC_HSE_ON) \
  1026. { \
  1027. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1028. } \
  1029. else if ((__STATE__) == RCC_HSE_BYPASS) \
  1030. { \
  1031. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1032. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1033. } \
  1034. else \
  1035. { \
  1036. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1037. /* Delay after an RCC peripheral clock */ \
  1038. tmpreg = READ_BIT(RCC->CR, RCC_CR_HSEON); \
  1039. UNUSED(tmpreg); \
  1040. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1041. } \
  1042. }while(0)
  1043. /**
  1044. * @}
  1045. */
  1046. /** @defgroup RCC_LSE_Configuration LSE Configuration
  1047. * @{
  1048. */
  1049. /**
  1050. * @brief Macro to configure the External Low Speed oscillator (LSE).
  1051. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  1052. * @note As the LSE is in the Backup domain and write access is denied to
  1053. * this domain after reset, you have to enable write access using
  1054. * @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  1055. * (to be done once after reset).
  1056. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  1057. * software should wait on LSERDY flag to be set indicating that LSE clock
  1058. * is stable and can be used to clock the RTC.
  1059. * @param __STATE__ specifies the new state of the LSE.
  1060. * This parameter can be one of the following values:
  1061. * @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
  1062. * 6 LSE oscillator clock cycles.
  1063. * @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
  1064. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  1065. */
  1066. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  1067. do{ \
  1068. if ((__STATE__) == RCC_LSE_ON) \
  1069. { \
  1070. SET_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1071. } \
  1072. else if ((__STATE__) == RCC_LSE_OFF) \
  1073. { \
  1074. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1075. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1076. } \
  1077. else if ((__STATE__) == RCC_LSE_BYPASS) \
  1078. { \
  1079. SET_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1080. SET_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1081. } \
  1082. else \
  1083. { \
  1084. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1085. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1086. } \
  1087. }while(0)
  1088. /**
  1089. * @}
  1090. */
  1091. /** @defgroup RCC_MSI_Configuration MSI Configuration
  1092. * @{
  1093. */
  1094. /** @brief Macro to enable Internal Multi Speed oscillator (MSI).
  1095. * @note After enabling the MSI, the application software should wait on MSIRDY
  1096. * flag to be set indicating that MSI clock is stable and can be used as
  1097. * system clock source.
  1098. */
  1099. #define __HAL_RCC_MSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_MSION)
  1100. /** @brief Macro to disable the Internal Multi Speed oscillator (MSI).
  1101. * @note The MSI is stopped by hardware when entering STOP and STANDBY modes.
  1102. * It is used (enabled by hardware) as system clock source after startup
  1103. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  1104. * of the HSE used directly or indirectly as system clock (if the Clock
  1105. * Security System CSS is enabled).
  1106. * @note MSI can not be stopped if it is used as system clock source. In this case,
  1107. * you have to select another source of the system clock then stop the MSI.
  1108. * @note When the MSI is stopped, MSIRDY flag goes low after 6 MSI oscillator
  1109. * clock cycles.
  1110. */
  1111. #define __HAL_RCC_MSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_MSION)
  1112. /** @brief Macro adjusts Internal Multi Speed oscillator (MSI) calibration value.
  1113. * @note The calibration is used to compensate for the variations in voltage
  1114. * and temperature that influence the frequency of the internal MSI RC.
  1115. * Refer to the Application Note AN3300 for more details on how to
  1116. * calibrate the MSI.
  1117. * @param _MSICALIBRATIONVALUE_ specifies the calibration trimming value.
  1118. * (default is RCC_MSICALIBRATION_DEFAULT).
  1119. * This parameter must be a number between 0 and 0xFF.
  1120. */
  1121. #define __HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST(_MSICALIBRATIONVALUE_) \
  1122. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_MSITRIM, (uint32_t)(_MSICALIBRATIONVALUE_) << RCC_ICSCR_MSITRIM_Pos))
  1123. /* @brief Macro to configures the Internal Multi Speed oscillator (MSI) clock range.
  1124. * @note After restart from Reset or wakeup from STANDBY, the MSI clock is
  1125. * around 2.097 MHz. The MSI clock does not change after wake-up from
  1126. * STOP mode.
  1127. * @note The MSI clock range can be modified on the fly.
  1128. * @param _MSIRANGEVALUE_ specifies the MSI Clock range.
  1129. * This parameter must be one of the following values:
  1130. * @arg @ref RCC_MSIRANGE_0 MSI clock is around 65.536 KHz
  1131. * @arg @ref RCC_MSIRANGE_1 MSI clock is around 131.072 KHz
  1132. * @arg @ref RCC_MSIRANGE_2 MSI clock is around 262.144 KHz
  1133. * @arg @ref RCC_MSIRANGE_3 MSI clock is around 524.288 KHz
  1134. * @arg @ref RCC_MSIRANGE_4 MSI clock is around 1.048 MHz
  1135. * @arg @ref RCC_MSIRANGE_5 MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  1136. * @arg @ref RCC_MSIRANGE_6 MSI clock is around 4.194 MHz
  1137. */
  1138. #define __HAL_RCC_MSI_RANGE_CONFIG(_MSIRANGEVALUE_) (MODIFY_REG(RCC->ICSCR, \
  1139. RCC_ICSCR_MSIRANGE, (uint32_t)(_MSIRANGEVALUE_)))
  1140. /** @brief Macro to get the Internal Multi Speed oscillator (MSI) clock range in run mode
  1141. * @retval MSI clock range.
  1142. * This parameter must be one of the following values:
  1143. * @arg @ref RCC_MSIRANGE_0 MSI clock is around 65.536 KHz
  1144. * @arg @ref RCC_MSIRANGE_1 MSI clock is around 131.072 KHz
  1145. * @arg @ref RCC_MSIRANGE_2 MSI clock is around 262.144 KHz
  1146. * @arg @ref RCC_MSIRANGE_3 MSI clock is around 524.288 KHz
  1147. * @arg @ref RCC_MSIRANGE_4 MSI clock is around 1.048 MHz
  1148. * @arg @ref RCC_MSIRANGE_5 MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  1149. * @arg @ref RCC_MSIRANGE_6 MSI clock is around 4.194 MHz
  1150. */
  1151. #define __HAL_RCC_GET_MSI_RANGE() (uint32_t)(READ_BIT(RCC->ICSCR, RCC_ICSCR_MSIRANGE))
  1152. /**
  1153. * @}
  1154. */
  1155. /** @defgroup RCC_PLL_Configuration PLL Configuration
  1156. * @{
  1157. */
  1158. /** @brief Macro to enable the main PLL.
  1159. * @note After enabling the main PLL, the application software should wait on
  1160. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1161. * be used as system clock source.
  1162. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1163. */
  1164. #define __HAL_RCC_PLL_ENABLE() SET_BIT(RCC->CR, RCC_CR_PLLON)
  1165. /** @brief Macro to disable the main PLL.
  1166. * @note The main PLL can not be disabled if it is used as system clock source
  1167. */
  1168. #define __HAL_RCC_PLL_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLON)
  1169. /** @brief Macro to configure the main PLL clock source, multiplication and division factors.
  1170. * @note This function must be used only when the main PLL is disabled.
  1171. *
  1172. * @param __RCC_PLLSOURCE__ specifies the PLL entry clock source.
  1173. * This parameter can be one of the following values:
  1174. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL clock entry
  1175. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  1176. * @param __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
  1177. * This parameter can be one of the following values:
  1178. * @arg @ref RCC_PLL_MUL3 PLLVCO = PLL clock entry x 3
  1179. * @arg @ref RCC_PLL_MUL4 PLLVCO = PLL clock entry x 4
  1180. * @arg @ref RCC_PLL_MUL6 PLLVCO = PLL clock entry x 6
  1181. * @arg @ref RCC_PLL_MUL8 PLLVCO = PLL clock entry x 8
  1182. * @arg @ref RCC_PLL_MUL12 PLLVCO = PLL clock entry x 12
  1183. * @arg @ref RCC_PLL_MUL16 PLLVCO = PLL clock entry x 16
  1184. * @arg @ref RCC_PLL_MUL24 PLLVCO = PLL clock entry x 24
  1185. * @arg @ref RCC_PLL_MUL32 PLLVCO = PLL clock entry x 32
  1186. * @arg @ref RCC_PLL_MUL48 PLLVCO = PLL clock entry x 48
  1187. * @note The PLL VCO clock frequency must not exceed 96 MHz when the product is in Range 1,
  1188. * 48 MHz when the product is in Range 2and 24 MHz when the product is in Range 3.
  1189. *
  1190. * @param __PLLDIV__ specifies the division factor for PLL VCO input clock
  1191. * This parameter can be one of the following values:
  1192. * @arg @ref RCC_PLL_DIV2 PLL clock output = PLLVCO / 2
  1193. * @arg @ref RCC_PLL_DIV3 PLL clock output = PLLVCO / 3
  1194. * @arg @ref RCC_PLL_DIV4 PLL clock output = PLLVCO / 4
  1195. *
  1196. */
  1197. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__, __PLLDIV__)\
  1198. MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC|RCC_CFGR_PLLMUL|RCC_CFGR_PLLDIV),((__RCC_PLLSOURCE__) | (__PLLMUL__) | (__PLLDIV__)))
  1199. /** @brief Get oscillator clock selected as PLL input clock
  1200. * @retval The clock source used for PLL entry. The returned value can be one
  1201. * of the following:
  1202. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL input clock
  1203. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  1204. */
  1205. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  1206. /**
  1207. * @}
  1208. */
  1209. /** @defgroup RCC_Get_Clock_source Get Clock source
  1210. * @{
  1211. */
  1212. /**
  1213. * @brief Macro to configure the system clock source.
  1214. * @param __SYSCLKSOURCE__ specifies the system clock source.
  1215. * This parameter can be one of the following values:
  1216. * @arg @ref RCC_SYSCLKSOURCE_MSI MSI oscillator is used as system clock source.
  1217. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  1218. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  1219. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  1220. */
  1221. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  1222. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  1223. /** @brief Macro to get the clock source used as system clock.
  1224. * @retval The clock source used as system clock. The returned value can be one
  1225. * of the following:
  1226. * @arg @ref RCC_SYSCLKSOURCE_STATUS_MSI MSI used as system clock
  1227. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  1228. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  1229. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  1230. */
  1231. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  1232. /**
  1233. * @}
  1234. */
  1235. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  1236. * @{
  1237. */
  1238. /** @brief Macro to configure the MCO clock.
  1239. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1240. * This parameter can be one of the following values:
  1241. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1242. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1243. * @arg @ref RCC_MCO1SOURCE_HSI HSI oscillator clock selected as MCO clock
  1244. * @arg @ref RCC_MCO1SOURCE_MSI MSI oscillator clock selected as MCO clock
  1245. * @arg @ref RCC_MCO1SOURCE_HSE HSE oscillator clock selected as MCO clock
  1246. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock selected as MCO clock
  1247. * @arg @ref RCC_MCO1SOURCE_LSI LSI clock selected as MCO clock
  1248. * @arg @ref RCC_MCO1SOURCE_LSE LSE clock selected as MCO clock
  1249. @if STM32L052xx
  1250. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1251. @elseif STM32L053xx
  1252. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1253. @elseif STM32L062xx
  1254. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1255. @elseif STM32L063xx
  1256. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1257. @elseif STM32L072xx
  1258. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1259. @elseif STM32L073xx
  1260. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1261. @elseif STM32L082xx
  1262. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1263. @elseif STM32L083xx
  1264. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1265. @endif
  1266. * @param __MCODIV__ specifies the MCO clock prescaler.
  1267. * This parameter can be one of the following values:
  1268. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  1269. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  1270. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  1271. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  1272. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  1273. */
  1274. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1275. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCOSEL | RCC_CFGR_MCO_PRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  1276. /**
  1277. * @}
  1278. */
  1279. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  1280. * @{
  1281. */
  1282. /** @brief Macro to configure the RTC clock (RTCCLK).
  1283. * @note As the RTC clock configuration bits are in the Backup domain and write
  1284. * access is denied to this domain after reset, you have to enable write
  1285. * access using the Power Backup Access macro before to configure
  1286. * the RTC clock source (to be done once after reset).
  1287. * @note Once the RTC clock is configured it cannot be changed unless the
  1288. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1289. * a Power On Reset (POR).
  1290. * @note RTC prescaler cannot be modified if HSE is enabled (HSEON = 1).
  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_NO_CLK 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_DIV2 HSE divided by 2 selected as RTC clock
  1298. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV4 HSE divided by 4 selected as RTC clock
  1299. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV8 HSE divided by 8 selected as RTC clock
  1300. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV16 HSE divided by 16 selected as RTC clock
  1301. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1302. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1303. * However, when the HSE clock is used as RTC clock source, the RTC
  1304. * cannot be used in STOP and STANDBY modes.
  1305. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1306. * RTC clock source).
  1307. */
  1308. #define __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__) do { \
  1309. if(((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE) \
  1310. { \
  1311. MODIFY_REG(RCC->CR, RCC_CR_RTCPRE, ((__RTC_CLKSOURCE__) & RCC_CR_RTCPRE)); \
  1312. } \
  1313. } while (0)
  1314. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) do { \
  1315. __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__); \
  1316. RCC->CSR |= ((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL); \
  1317. } while (0)
  1318. /** @brief Macro to get the RTC clock source.
  1319. * @retval The clock source can be one of the following values:
  1320. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1321. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1322. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1323. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIVX HSE divided by X selected as RTC clock (X can be retrieved thanks to @ref __HAL_RCC_GET_RTC_HSE_PRESCALER()
  1324. */
  1325. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->CSR, RCC_CSR_RTCSEL))
  1326. /**
  1327. * @brief Get the RTC and LCD HSE clock divider (RTCCLK / LCDCLK).
  1328. *
  1329. * @retval Returned value can be one of the following values:
  1330. * @arg @ref RCC_RTC_HSE_DIV_2 HSE divided by 2 selected as RTC clock
  1331. * @arg @ref RCC_RTC_HSE_DIV_4 HSE divided by 4 selected as RTC clock
  1332. * @arg @ref RCC_RTC_HSE_DIV_8 HSE divided by 8 selected as RTC clock
  1333. * @arg @ref RCC_RTC_HSE_DIV_16 HSE divided by 16 selected as RTC clock
  1334. *
  1335. */
  1336. #define __HAL_RCC_GET_RTC_HSE_PRESCALER() ((uint32_t)(READ_BIT(RCC->CR, RCC_CR_RTCPRE)))
  1337. /** @brief Macro to enable the the RTC clock.
  1338. * @note These macros must be used only after the RTC clock source was selected.
  1339. */
  1340. #define __HAL_RCC_RTC_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_RTCEN)
  1341. /** @brief Macro to disable the the RTC clock.
  1342. * @note These macros must be used only after the RTC clock source was selected.
  1343. */
  1344. #define __HAL_RCC_RTC_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_RTCEN)
  1345. /** @brief Macro to force the Backup domain reset.
  1346. * @note This function resets the RTC peripheral (including the backup registers)
  1347. * and the RTC clock source selection in RCC_CSR register.
  1348. * @note The BKPSRAM is not affected by this reset.
  1349. */
  1350. #define __HAL_RCC_BACKUPRESET_FORCE() SET_BIT(RCC->CSR, RCC_CSR_RTCRST)
  1351. /** @brief Macros to release the Backup domain reset.
  1352. */
  1353. #define __HAL_RCC_BACKUPRESET_RELEASE() CLEAR_BIT(RCC->CSR, RCC_CSR_RTCRST)
  1354. /**
  1355. * @}
  1356. */
  1357. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1358. * @brief macros to manage the specified RCC Flags and interrupts.
  1359. * @{
  1360. */
  1361. /** @brief Enable RCC interrupt.
  1362. * @note The CSS interrupt doesn't have an enable bit; once the CSS is enabled
  1363. * and if the HSE clock fails, the CSS interrupt occurs and an NMI is
  1364. * automatically generated. The NMI will be executed indefinitely, and
  1365. * since NMI has higher priority than any other IRQ (and main program)
  1366. * the application will be stacked in the NMI ISR unless the CSS interrupt
  1367. * pending bit is cleared.
  1368. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1369. * This parameter can be any combination of the following values:
  1370. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1371. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1372. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1373. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1374. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1375. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1376. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1377. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt (not available on all devices)
  1378. */
  1379. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) SET_BIT(RCC->CIER, (__INTERRUPT__))
  1380. /** @brief Disable RCC interrupt.
  1381. * @note The CSS interrupt doesn't have an enable bit; once the CSS is enabled
  1382. * and if the HSE clock fails, the CSS interrupt occurs and an NMI is
  1383. * automatically generated. The NMI will be executed indefinitely, and
  1384. * since NMI has higher priority than any other IRQ (and main program)
  1385. * the application will be stacked in the NMI ISR unless the CSS interrupt
  1386. * pending bit is cleared.
  1387. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1388. * This parameter can be any combination of the following values:
  1389. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1390. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1391. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1392. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1393. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1394. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1395. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1396. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt (not available on all devices)
  1397. */
  1398. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(RCC->CIER, (__INTERRUPT__))
  1399. /** @brief Clear the RCC's interrupt pending bits.
  1400. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1401. * This parameter can be any combination of the following values:
  1402. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1403. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1404. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1405. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1406. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1407. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1408. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1409. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt (not available on all devices)
  1410. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1411. */
  1412. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (RCC->CICR = (__INTERRUPT__))
  1413. /** @brief Check the RCC's interrupt has occurred or not.
  1414. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1415. * This parameter can be one of the following values:
  1416. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1417. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1418. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1419. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1420. * @arg @ref RCC_IT_PLLRDY PLL ready interrupt
  1421. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1422. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1423. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1424. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1425. */
  1426. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIFR & (__INTERRUPT__)) == (__INTERRUPT__))
  1427. /** @brief Set RMVF bit to clear the reset flags.
  1428. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1429. * RCC_FLAG_OBLRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1430. */
  1431. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1432. /** @brief Check RCC flag is set or not.
  1433. * @param __FLAG__ specifies the flag to check.
  1434. * This parameter can be one of the following values:
  1435. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready
  1436. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready (not available on all devices)
  1437. * @arg @ref RCC_FLAG_HSIDIV HSI16 divider flag
  1438. * @arg @ref RCC_FLAG_MSIRDY MSI oscillator clock ready
  1439. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready
  1440. * @arg @ref RCC_FLAG_PLLRDY PLL clock ready
  1441. * @arg @ref RCC_FLAG_LSECSS LSE oscillator clock CSS detected
  1442. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready
  1443. * @arg @ref RCC_FLAG_FWRST Firewall reset
  1444. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready
  1445. * @arg @ref RCC_FLAG_OBLRST Option Byte Loader (OBL) reset
  1446. * @arg @ref RCC_FLAG_PINRST Pin reset
  1447. * @arg @ref RCC_FLAG_PORRST POR/PDR reset
  1448. * @arg @ref RCC_FLAG_SFTRST Software reset
  1449. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset
  1450. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset
  1451. * @arg @ref RCC_FLAG_LPWRRST Low Power reset
  1452. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1453. */
  1454. #if defined(RCC_HSI48_SUPPORT)
  1455. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((((__FLAG__) >> 5) == CR_REG_INDEX)? RCC->CR :((((__FLAG__) >> 5) == CSR_REG_INDEX) ? RCC->CSR :RCC->CRRCR)))) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK))) != 0U ) ? 1U : 0U )
  1456. #else
  1457. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((((__FLAG__) >> 5) == CR_REG_INDEX)? RCC->CR : RCC->CSR))) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK))) != 0U ) ? 1U : 0U )
  1458. #endif /* RCC_HSI48_SUPPORT */
  1459. /**
  1460. * @}
  1461. */
  1462. /**
  1463. * @}
  1464. */
  1465. /* Include RCC HAL Extension module */
  1466. #include "stm32l0xx_hal_rcc_ex.h"
  1467. /* Exported functions --------------------------------------------------------*/
  1468. /** @addtogroup RCC_Exported_Functions
  1469. * @{
  1470. */
  1471. /** @addtogroup RCC_Exported_Functions_Group1
  1472. * @{
  1473. */
  1474. /* Initialization and de-initialization functions ******************************/
  1475. HAL_StatusTypeDef HAL_RCC_DeInit(void);
  1476. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1477. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1478. /**
  1479. * @}
  1480. */
  1481. /** @addtogroup RCC_Exported_Functions_Group2
  1482. * @{
  1483. */
  1484. /* Peripheral Control functions ************************************************/
  1485. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1486. #if defined(RCC_HSECSS_SUPPORT)
  1487. void HAL_RCC_EnableCSS(void);
  1488. /* CSS NMI IRQ handler */
  1489. void HAL_RCC_NMI_IRQHandler(void);
  1490. /* User Callbacks in non blocking mode (IT mode) */
  1491. void HAL_RCC_CSSCallback(void);
  1492. #endif /* RCC_HSECSS_SUPPORT */
  1493. uint32_t HAL_RCC_GetSysClockFreq(void);
  1494. uint32_t HAL_RCC_GetHCLKFreq(void);
  1495. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1496. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1497. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1498. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1499. /**
  1500. * @}
  1501. */
  1502. /**
  1503. * @}
  1504. */
  1505. /**
  1506. * @}
  1507. */
  1508. /**
  1509. * @}
  1510. */
  1511. #ifdef __cplusplus
  1512. }
  1513. #endif
  1514. #endif /* __STM32L0xx_HAL_RCC_H */