stm32f3xx_hal_rcc.h 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @version V1.4.0
  6. * @date 16-December-2016
  7. * @brief Header file of RCC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F3xx_HAL_RCC_H
  39. #define __STM32F3xx_HAL_RCC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f3xx_hal_def.h"
  45. /** @addtogroup STM32F3xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup RCC
  49. * @{
  50. */
  51. /** @addtogroup RCC_Private_Constants
  52. * @{
  53. */
  54. /** @defgroup RCC_Timeout RCC Timeout
  55. * @{
  56. */
  57. /* Disable Backup domain write protection state change timeout */
  58. #define RCC_DBP_TIMEOUT_VALUE (100U) /* 100 ms */
  59. /* LSE state change timeout */
  60. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  61. #define CLOCKSWITCH_TIMEOUT_VALUE (5000U) /* 5 s */
  62. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  63. #define HSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  64. #define LSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  65. #define PLL_TIMEOUT_VALUE (2U) * 100000 /* 2 ms (minimum Tick + 1U) */
  66. /**
  67. * @}
  68. */
  69. /** @defgroup RCC_Register_Offset Register offsets
  70. * @{
  71. */
  72. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  73. #define RCC_CR_OFFSET 0x00
  74. #define RCC_CFGR_OFFSET 0x04
  75. #define RCC_CIR_OFFSET 0x08
  76. #define RCC_BDCR_OFFSET 0x20
  77. #define RCC_CSR_OFFSET 0x24
  78. /**
  79. * @}
  80. */
  81. /** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
  82. * @brief RCC registers bit address in the alias region
  83. * @{
  84. */
  85. #define RCC_CR_OFFSET_BB (RCC_OFFSET + RCC_CR_OFFSET)
  86. #define RCC_CFGR_OFFSET_BB (RCC_OFFSET + RCC_CFGR_OFFSET)
  87. #define RCC_CIR_OFFSET_BB (RCC_OFFSET + RCC_CIR_OFFSET)
  88. #define RCC_BDCR_OFFSET_BB (RCC_OFFSET + RCC_BDCR_OFFSET)
  89. #define RCC_CSR_OFFSET_BB (RCC_OFFSET + RCC_CSR_OFFSET)
  90. /* --- CR Register ---*/
  91. /* Alias word address of HSION bit */
  92. #define RCC_HSION_BIT_NUMBER POSITION_VAL(RCC_CR_HSION)
  93. #define RCC_CR_HSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSION_BIT_NUMBER * 4U)))
  94. /* Alias word address of HSEON bit */
  95. #define RCC_HSEON_BIT_NUMBER POSITION_VAL(RCC_CR_HSEON)
  96. #define RCC_CR_HSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSEON_BIT_NUMBER * 4U)))
  97. /* Alias word address of CSSON bit */
  98. #define RCC_CSSON_BIT_NUMBER POSITION_VAL(RCC_CR_CSSON)
  99. #define RCC_CR_CSSON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_CSSON_BIT_NUMBER * 4U)))
  100. /* Alias word address of PLLON bit */
  101. #define RCC_PLLON_BIT_NUMBER POSITION_VAL(RCC_CR_PLLON)
  102. #define RCC_CR_PLLON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_PLLON_BIT_NUMBER * 4U)))
  103. /* --- CSR Register ---*/
  104. /* Alias word address of LSION bit */
  105. #define RCC_LSION_BIT_NUMBER POSITION_VAL(RCC_CSR_LSION)
  106. #define RCC_CSR_LSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_LSION_BIT_NUMBER * 4U)))
  107. /* Alias word address of RMVF bit */
  108. #define RCC_RMVF_BIT_NUMBER POSITION_VAL(RCC_CSR_RMVF)
  109. #define RCC_CSR_RMVF_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_RMVF_BIT_NUMBER * 4U)))
  110. /* --- BDCR Registers ---*/
  111. /* Alias word address of LSEON bit */
  112. #define RCC_LSEON_BIT_NUMBER POSITION_VAL(RCC_BDCR_LSEON)
  113. #define RCC_BDCR_LSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_LSEON_BIT_NUMBER * 4U)))
  114. /* Alias word address of LSEON bit */
  115. #define RCC_LSEBYP_BIT_NUMBER POSITION_VAL(RCC_BDCR_LSEBYP)
  116. #define RCC_BDCR_LSEBYP_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_LSEBYP_BIT_NUMBER * 4U)))
  117. /* Alias word address of RTCEN bit */
  118. #define RCC_RTCEN_BIT_NUMBER POSITION_VAL(RCC_BDCR_RTCEN)
  119. #define RCC_BDCR_RTCEN_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_RTCEN_BIT_NUMBER * 4U)))
  120. /* Alias word address of BDRST bit */
  121. #define RCC_BDRST_BIT_NUMBER POSITION_VAL(RCC_BDCR_BDRST)
  122. #define RCC_BDCR_BDRST_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_BDRST_BIT_NUMBER * 4U)))
  123. /**
  124. * @}
  125. */
  126. /* CR register byte 2 (Bits[23:16]) base address */
  127. #define RCC_CR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02U))
  128. /* CIR register byte 1 (Bits[15:8]) base address */
  129. #define RCC_CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01U))
  130. /* CIR register byte 2 (Bits[23:16]) base address */
  131. #define RCC_CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02U))
  132. /* Defines used for Flags */
  133. #define CR_REG_INDEX ((uint8_t)1U)
  134. #define BDCR_REG_INDEX ((uint8_t)2U)
  135. #define CSR_REG_INDEX ((uint8_t)3U)
  136. #define CFGR_REG_INDEX ((uint8_t)4U)
  137. #define RCC_FLAG_MASK ((uint8_t)0x1FU)
  138. /**
  139. * @}
  140. */
  141. /** @addtogroup RCC_Private_Macros
  142. * @{
  143. */
  144. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI) || \
  145. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  146. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  147. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  148. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  149. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  150. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE))
  151. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  152. ((__HSE__) == RCC_HSE_BYPASS))
  153. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  154. ((__LSE__) == RCC_LSE_BYPASS))
  155. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  156. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
  157. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  158. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  159. ((__PLL__) == RCC_PLL_ON))
  160. #if defined(RCC_CFGR_PLLSRC_HSI_PREDIV)
  161. #define IS_RCC_PREDIV(__PREDIV__) (((__PREDIV__) == RCC_PREDIV_DIV1) || ((__PREDIV__) == RCC_PREDIV_DIV2) || \
  162. ((__PREDIV__) == RCC_PREDIV_DIV3) || ((__PREDIV__) == RCC_PREDIV_DIV4) || \
  163. ((__PREDIV__) == RCC_PREDIV_DIV5) || ((__PREDIV__) == RCC_PREDIV_DIV6) || \
  164. ((__PREDIV__) == RCC_PREDIV_DIV7) || ((__PREDIV__) == RCC_PREDIV_DIV8) || \
  165. ((__PREDIV__) == RCC_PREDIV_DIV9) || ((__PREDIV__) == RCC_PREDIV_DIV10) || \
  166. ((__PREDIV__) == RCC_PREDIV_DIV11) || ((__PREDIV__) == RCC_PREDIV_DIV12) || \
  167. ((__PREDIV__) == RCC_PREDIV_DIV13) || ((__PREDIV__) == RCC_PREDIV_DIV14) || \
  168. ((__PREDIV__) == RCC_PREDIV_DIV15) || ((__PREDIV__) == RCC_PREDIV_DIV16))
  169. #else
  170. #define IS_RCC_PLL_DIV(__DIV__) (((__DIV__) == RCC_PLL_DIV2) || \
  171. ((__DIV__) == RCC_PLL_DIV3) || ((__DIV__) == RCC_PLL_DIV4))
  172. #endif
  173. #if defined(RCC_CFGR_PLLSRC_HSI_DIV2)
  174. #define IS_RCC_HSE_PREDIV(DIV) (((DIV) == RCC_HSE_PREDIV_DIV1) || ((DIV) == RCC_HSE_PREDIV_DIV2) || \
  175. ((DIV) == RCC_HSE_PREDIV_DIV3) || ((DIV) == RCC_HSE_PREDIV_DIV4) || \
  176. ((DIV) == RCC_HSE_PREDIV_DIV5) || ((DIV) == RCC_HSE_PREDIV_DIV6) || \
  177. ((DIV) == RCC_HSE_PREDIV_DIV7) || ((DIV) == RCC_HSE_PREDIV_DIV8) || \
  178. ((DIV) == RCC_HSE_PREDIV_DIV9) || ((DIV) == RCC_HSE_PREDIV_DIV10) || \
  179. ((DIV) == RCC_HSE_PREDIV_DIV11) || ((DIV) == RCC_HSE_PREDIV_DIV12) || \
  180. ((DIV) == RCC_HSE_PREDIV_DIV13) || ((DIV) == RCC_HSE_PREDIV_DIV14) || \
  181. ((DIV) == RCC_HSE_PREDIV_DIV15) || ((DIV) == RCC_HSE_PREDIV_DIV16))
  182. #endif /* RCC_CFGR_PLLSRC_HSI_DIV2 */
  183. #define IS_RCC_PLL_MUL(__MUL__) (((__MUL__) == RCC_PLL_MUL2) || ((__MUL__) == RCC_PLL_MUL3) || \
  184. ((__MUL__) == RCC_PLL_MUL4) || ((__MUL__) == RCC_PLL_MUL5) || \
  185. ((__MUL__) == RCC_PLL_MUL6) || ((__MUL__) == RCC_PLL_MUL7) || \
  186. ((__MUL__) == RCC_PLL_MUL8) || ((__MUL__) == RCC_PLL_MUL9) || \
  187. ((__MUL__) == RCC_PLL_MUL10) || ((__MUL__) == RCC_PLL_MUL11) || \
  188. ((__MUL__) == RCC_PLL_MUL12) || ((__MUL__) == RCC_PLL_MUL13) || \
  189. ((__MUL__) == RCC_PLL_MUL14) || ((__MUL__) == RCC_PLL_MUL15) || \
  190. ((__MUL__) == RCC_PLL_MUL16))
  191. #define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  192. (((CLK) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  193. (((CLK) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) || \
  194. (((CLK) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2))
  195. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  196. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  197. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  198. #define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  199. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  200. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  201. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  202. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  203. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  204. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  205. ((__HCLK__) == RCC_SYSCLK_DIV512))
  206. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  207. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  208. ((__PCLK__) == RCC_HCLK_DIV16))
  209. #define IS_RCC_MCO(__MCO__) ((__MCO__) == RCC_MCO)
  210. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  211. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  212. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  213. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV32))
  214. #if defined(RCC_CFGR3_USART2SW)
  215. #define IS_RCC_USART2CLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_USART2CLKSOURCE_PCLK1) || \
  216. ((__SOURCE__) == RCC_USART2CLKSOURCE_SYSCLK) || \
  217. ((__SOURCE__) == RCC_USART2CLKSOURCE_LSE) || \
  218. ((__SOURCE__) == RCC_USART2CLKSOURCE_HSI))
  219. #endif /* RCC_CFGR3_USART2SW */
  220. #if defined(RCC_CFGR3_USART3SW)
  221. #define IS_RCC_USART3CLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_USART3CLKSOURCE_PCLK1) || \
  222. ((__SOURCE__) == RCC_USART3CLKSOURCE_SYSCLK) || \
  223. ((__SOURCE__) == RCC_USART3CLKSOURCE_LSE) || \
  224. ((__SOURCE__) == RCC_USART3CLKSOURCE_HSI))
  225. #endif /* RCC_CFGR3_USART3SW */
  226. #define IS_RCC_I2C1CLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_I2C1CLKSOURCE_HSI) || \
  227. ((__SOURCE__) == RCC_I2C1CLKSOURCE_SYSCLK))
  228. /**
  229. * @}
  230. */
  231. /* Exported types ------------------------------------------------------------*/
  232. /** @defgroup RCC_Exported_Types RCC Exported Types
  233. * @{
  234. */
  235. /**
  236. * @brief RCC PLL configuration structure definition
  237. */
  238. typedef struct
  239. {
  240. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  241. This parameter can be a value of @ref RCC_PLL_Config */
  242. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  243. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  244. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  245. This parameter must be a value of @ref RCC_PLL_Multiplication_Factor*/
  246. #if defined(RCC_CFGR_PLLSRC_HSI_PREDIV)
  247. uint32_t PREDIV; /*!< PREDIV: Predivision factor for PLL VCO input clock
  248. This parameter must be a value of @ref RCC_PLL_Prediv_Factor */
  249. #endif
  250. } RCC_PLLInitTypeDef;
  251. /**
  252. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  253. */
  254. typedef struct
  255. {
  256. uint32_t OscillatorType; /*!< The oscillators to be configured.
  257. This parameter can be a value of @ref RCC_Oscillator_Type */
  258. uint32_t HSEState; /*!< The new state of the HSE.
  259. This parameter can be a value of @ref RCC_HSE_Config */
  260. #if defined(RCC_CFGR_PLLSRC_HSI_DIV2)
  261. uint32_t HSEPredivValue; /*!< The HSE predivision factor value.
  262. This parameter can be a value of @ref RCC_PLL_HSE_Prediv_Factor */
  263. #endif /* RCC_CFGR_PLLSRC_HSI_DIV2 */
  264. uint32_t LSEState; /*!< The new state of the LSE.
  265. This parameter can be a value of @ref RCC_LSE_Config */
  266. uint32_t HSIState; /*!< The new state of the HSI.
  267. This parameter can be a value of @ref RCC_HSI_Config */
  268. uint32_t HSICalibrationValue; /*!< The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT).
  269. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1FU */
  270. uint32_t LSIState; /*!< The new state of the LSI.
  271. This parameter can be a value of @ref RCC_LSI_Config */
  272. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  273. } RCC_OscInitTypeDef;
  274. /**
  275. * @brief RCC System, AHB and APB busses clock configuration structure definition
  276. */
  277. typedef struct
  278. {
  279. uint32_t ClockType; /*!< The clock to be configured.
  280. This parameter can be a value of @ref RCC_System_Clock_Type */
  281. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  282. This parameter can be a value of @ref RCC_System_Clock_Source */
  283. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  284. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  285. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  286. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  287. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  288. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  289. } RCC_ClkInitTypeDef;
  290. /**
  291. * @}
  292. */
  293. /* Exported constants --------------------------------------------------------*/
  294. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  295. * @{
  296. */
  297. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  298. * @{
  299. */
  300. #if defined(RCC_CFGR_PLLSRC_HSI_PREDIV)
  301. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI_PREDIV /*!< HSI clock selected as PLL entry clock source */
  302. #endif /* RCC_CFGR_PLLSRC_HSI_PREDIV */
  303. #if defined(RCC_CFGR_PLLSRC_HSI_DIV2)
  304. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI_DIV2 /*!< HSI clock divided by 2 selected as PLL entry clock source */
  305. #endif /* RCC_CFGR_PLLSRC_HSI_DIV2 */
  306. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE_PREDIV /*!< HSE clock selected as PLL entry clock source */
  307. /**
  308. * @}
  309. */
  310. /** @defgroup RCC_Oscillator_Type Oscillator Type
  311. * @{
  312. */
  313. #define RCC_OSCILLATORTYPE_NONE (0x00000000U)
  314. #define RCC_OSCILLATORTYPE_HSE (0x00000001U)
  315. #define RCC_OSCILLATORTYPE_HSI (0x00000002U)
  316. #define RCC_OSCILLATORTYPE_LSE (0x00000004U)
  317. #define RCC_OSCILLATORTYPE_LSI (0x00000008U)
  318. /**
  319. * @}
  320. */
  321. /** @defgroup RCC_HSE_Config HSE Config
  322. * @{
  323. */
  324. #define RCC_HSE_OFF (0x00000000U) /*!< HSE clock deactivation */
  325. #define RCC_HSE_ON RCC_CR_HSEON /*!< HSE clock activation */
  326. #define RCC_HSE_BYPASS ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
  327. /**
  328. * @}
  329. */
  330. /** @defgroup RCC_LSE_Config LSE Config
  331. * @{
  332. */
  333. #define RCC_LSE_OFF (0x00000000U) /*!< LSE clock deactivation */
  334. #define RCC_LSE_ON RCC_BDCR_LSEON /*!< LSE clock activation */
  335. #define RCC_LSE_BYPASS ((uint32_t)(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON)) /*!< External clock source for LSE clock */
  336. /**
  337. * @}
  338. */
  339. /** @defgroup RCC_HSI_Config HSI Config
  340. * @{
  341. */
  342. #define RCC_HSI_OFF (0x00000000U) /*!< HSI clock deactivation */
  343. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  344. #define RCC_HSICALIBRATION_DEFAULT (0x10U) /* Default HSI calibration trimming value */
  345. /**
  346. * @}
  347. */
  348. /** @defgroup RCC_LSI_Config LSI Config
  349. * @{
  350. */
  351. #define RCC_LSI_OFF (0x00000000U) /*!< LSI clock deactivation */
  352. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  353. /**
  354. * @}
  355. */
  356. /** @defgroup RCC_PLL_Config PLL Config
  357. * @{
  358. */
  359. #define RCC_PLL_NONE (0x00000000U) /*!< PLL is not configured */
  360. #define RCC_PLL_OFF (0x00000001U) /*!< PLL deactivation */
  361. #define RCC_PLL_ON (0x00000002U) /*!< PLL activation */
  362. /**
  363. * @}
  364. */
  365. /** @defgroup RCC_System_Clock_Type System Clock Type
  366. * @{
  367. */
  368. #define RCC_CLOCKTYPE_SYSCLK (0x00000001U) /*!< SYSCLK to configure */
  369. #define RCC_CLOCKTYPE_HCLK (0x00000002U) /*!< HCLK to configure */
  370. #define RCC_CLOCKTYPE_PCLK1 (0x00000004U) /*!< PCLK1 to configure */
  371. #define RCC_CLOCKTYPE_PCLK2 (0x00000008U) /*!< PCLK2 to configure */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup RCC_System_Clock_Source System Clock Source
  376. * @{
  377. */
  378. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  379. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  380. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  381. /**
  382. * @}
  383. */
  384. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  385. * @{
  386. */
  387. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  388. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  389. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  390. /**
  391. * @}
  392. */
  393. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  394. * @{
  395. */
  396. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  397. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  398. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  399. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  400. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  401. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  402. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  403. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  404. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  405. /**
  406. * @}
  407. */
  408. /** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
  409. * @{
  410. */
  411. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1 /*!< HCLK not divided */
  412. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2 /*!< HCLK divided by 2 */
  413. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4 /*!< HCLK divided by 4 */
  414. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8 /*!< HCLK divided by 8 */
  415. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
  416. /**
  417. * @}
  418. */
  419. /** @defgroup RCC_RTC_Clock_Source RTC Clock Source
  420. * @{
  421. */
  422. #define RCC_RTCCLKSOURCE_NO_CLK RCC_BDCR_RTCSEL_NOCLOCK /*!< No clock */
  423. #define RCC_RTCCLKSOURCE_LSE RCC_BDCR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  424. #define RCC_RTCCLKSOURCE_LSI RCC_BDCR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  425. #define RCC_RTCCLKSOURCE_HSE_DIV32 RCC_BDCR_RTCSEL_HSE /*!< HSE oscillator clock divided by 32 used as RTC clock */
  426. /**
  427. * @}
  428. */
  429. /** @defgroup RCC_PLL_Multiplication_Factor RCC PLL Multiplication Factor
  430. * @{
  431. */
  432. #define RCC_PLL_MUL2 RCC_CFGR_PLLMUL2
  433. #define RCC_PLL_MUL3 RCC_CFGR_PLLMUL3
  434. #define RCC_PLL_MUL4 RCC_CFGR_PLLMUL4
  435. #define RCC_PLL_MUL5 RCC_CFGR_PLLMUL5
  436. #define RCC_PLL_MUL6 RCC_CFGR_PLLMUL6
  437. #define RCC_PLL_MUL7 RCC_CFGR_PLLMUL7
  438. #define RCC_PLL_MUL8 RCC_CFGR_PLLMUL8
  439. #define RCC_PLL_MUL9 RCC_CFGR_PLLMUL9
  440. #define RCC_PLL_MUL10 RCC_CFGR_PLLMUL10
  441. #define RCC_PLL_MUL11 RCC_CFGR_PLLMUL11
  442. #define RCC_PLL_MUL12 RCC_CFGR_PLLMUL12
  443. #define RCC_PLL_MUL13 RCC_CFGR_PLLMUL13
  444. #define RCC_PLL_MUL14 RCC_CFGR_PLLMUL14
  445. #define RCC_PLL_MUL15 RCC_CFGR_PLLMUL15
  446. #define RCC_PLL_MUL16 RCC_CFGR_PLLMUL16
  447. /**
  448. * @}
  449. */
  450. #if defined(RCC_CFGR_PLLSRC_HSI_PREDIV)
  451. /** @defgroup RCC_PLL_Prediv_Factor RCC PLL Prediv Factor
  452. * @{
  453. */
  454. #define RCC_PREDIV_DIV1 RCC_CFGR2_PREDIV_DIV1
  455. #define RCC_PREDIV_DIV2 RCC_CFGR2_PREDIV_DIV2
  456. #define RCC_PREDIV_DIV3 RCC_CFGR2_PREDIV_DIV3
  457. #define RCC_PREDIV_DIV4 RCC_CFGR2_PREDIV_DIV4
  458. #define RCC_PREDIV_DIV5 RCC_CFGR2_PREDIV_DIV5
  459. #define RCC_PREDIV_DIV6 RCC_CFGR2_PREDIV_DIV6
  460. #define RCC_PREDIV_DIV7 RCC_CFGR2_PREDIV_DIV7
  461. #define RCC_PREDIV_DIV8 RCC_CFGR2_PREDIV_DIV8
  462. #define RCC_PREDIV_DIV9 RCC_CFGR2_PREDIV_DIV9
  463. #define RCC_PREDIV_DIV10 RCC_CFGR2_PREDIV_DIV10
  464. #define RCC_PREDIV_DIV11 RCC_CFGR2_PREDIV_DIV11
  465. #define RCC_PREDIV_DIV12 RCC_CFGR2_PREDIV_DIV12
  466. #define RCC_PREDIV_DIV13 RCC_CFGR2_PREDIV_DIV13
  467. #define RCC_PREDIV_DIV14 RCC_CFGR2_PREDIV_DIV14
  468. #define RCC_PREDIV_DIV15 RCC_CFGR2_PREDIV_DIV15
  469. #define RCC_PREDIV_DIV16 RCC_CFGR2_PREDIV_DIV16
  470. /**
  471. * @}
  472. */
  473. #endif
  474. #if defined(RCC_CFGR_PLLSRC_HSI_DIV2)
  475. /** @defgroup RCC_PLL_HSE_Prediv_Factor RCC PLL HSE Prediv Factor
  476. * @{
  477. */
  478. #define RCC_HSE_PREDIV_DIV1 RCC_CFGR2_PREDIV_DIV1
  479. #define RCC_HSE_PREDIV_DIV2 RCC_CFGR2_PREDIV_DIV2
  480. #define RCC_HSE_PREDIV_DIV3 RCC_CFGR2_PREDIV_DIV3
  481. #define RCC_HSE_PREDIV_DIV4 RCC_CFGR2_PREDIV_DIV4
  482. #define RCC_HSE_PREDIV_DIV5 RCC_CFGR2_PREDIV_DIV5
  483. #define RCC_HSE_PREDIV_DIV6 RCC_CFGR2_PREDIV_DIV6
  484. #define RCC_HSE_PREDIV_DIV7 RCC_CFGR2_PREDIV_DIV7
  485. #define RCC_HSE_PREDIV_DIV8 RCC_CFGR2_PREDIV_DIV8
  486. #define RCC_HSE_PREDIV_DIV9 RCC_CFGR2_PREDIV_DIV9
  487. #define RCC_HSE_PREDIV_DIV10 RCC_CFGR2_PREDIV_DIV10
  488. #define RCC_HSE_PREDIV_DIV11 RCC_CFGR2_PREDIV_DIV11
  489. #define RCC_HSE_PREDIV_DIV12 RCC_CFGR2_PREDIV_DIV12
  490. #define RCC_HSE_PREDIV_DIV13 RCC_CFGR2_PREDIV_DIV13
  491. #define RCC_HSE_PREDIV_DIV14 RCC_CFGR2_PREDIV_DIV14
  492. #define RCC_HSE_PREDIV_DIV15 RCC_CFGR2_PREDIV_DIV15
  493. #define RCC_HSE_PREDIV_DIV16 RCC_CFGR2_PREDIV_DIV16
  494. /**
  495. * @}
  496. */
  497. #endif /* RCC_CFGR_PLLSRC_HSI_DIV2 */
  498. #if defined(RCC_CFGR3_USART2SW)
  499. /** @defgroup RCC_USART2_Clock_Source RCC USART2 Clock Source
  500. * @{
  501. */
  502. #define RCC_USART2CLKSOURCE_PCLK1 RCC_CFGR3_USART2SW_PCLK
  503. #define RCC_USART2CLKSOURCE_SYSCLK RCC_CFGR3_USART2SW_SYSCLK
  504. #define RCC_USART2CLKSOURCE_LSE RCC_CFGR3_USART2SW_LSE
  505. #define RCC_USART2CLKSOURCE_HSI RCC_CFGR3_USART2SW_HSI
  506. /**
  507. * @}
  508. */
  509. #endif /* RCC_CFGR3_USART2SW */
  510. #if defined(RCC_CFGR3_USART3SW)
  511. /** @defgroup RCC_USART3_Clock_Source RCC USART3 Clock Source
  512. * @{
  513. */
  514. #define RCC_USART3CLKSOURCE_PCLK1 RCC_CFGR3_USART3SW_PCLK
  515. #define RCC_USART3CLKSOURCE_SYSCLK RCC_CFGR3_USART3SW_SYSCLK
  516. #define RCC_USART3CLKSOURCE_LSE RCC_CFGR3_USART3SW_LSE
  517. #define RCC_USART3CLKSOURCE_HSI RCC_CFGR3_USART3SW_HSI
  518. /**
  519. * @}
  520. */
  521. #endif /* RCC_CFGR3_USART3SW */
  522. /** @defgroup RCC_I2C1_Clock_Source RCC I2C1 Clock Source
  523. * @{
  524. */
  525. #define RCC_I2C1CLKSOURCE_HSI RCC_CFGR3_I2C1SW_HSI
  526. #define RCC_I2C1CLKSOURCE_SYSCLK RCC_CFGR3_I2C1SW_SYSCLK
  527. /**
  528. * @}
  529. */
  530. /** @defgroup RCC_MCO_Index MCO Index
  531. * @{
  532. */
  533. #define RCC_MCO1 (0x00000000U)
  534. #define RCC_MCO RCC_MCO1 /*!< MCO1 to be compliant with other families with 2 MCOs*/
  535. /**
  536. * @}
  537. */
  538. /** @defgroup RCC_Interrupt Interrupts
  539. * @{
  540. */
  541. #define RCC_IT_LSIRDY ((uint8_t)RCC_CIR_LSIRDYF) /*!< LSI Ready Interrupt flag */
  542. #define RCC_IT_LSERDY ((uint8_t)RCC_CIR_LSERDYF) /*!< LSE Ready Interrupt flag */
  543. #define RCC_IT_HSIRDY ((uint8_t)RCC_CIR_HSIRDYF) /*!< HSI Ready Interrupt flag */
  544. #define RCC_IT_HSERDY ((uint8_t)RCC_CIR_HSERDYF) /*!< HSE Ready Interrupt flag */
  545. #define RCC_IT_PLLRDY ((uint8_t)RCC_CIR_PLLRDYF) /*!< PLL Ready Interrupt flag */
  546. #define RCC_IT_CSS ((uint8_t)RCC_CIR_CSSF) /*!< Clock Security System Interrupt flag */
  547. /**
  548. * @}
  549. */
  550. /** @defgroup RCC_Flag Flags
  551. * Elements values convention: XXXYYYYYb
  552. * - YYYYY : Flag position in the register
  553. * - XXX : Register index
  554. * - 001: CR register
  555. * - 010: BDCR register
  556. * - 011: CSR register
  557. * - 100: CFGR register
  558. * @{
  559. */
  560. /* Flags in the CR register */
  561. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5U) | POSITION_VAL(RCC_CR_HSIRDY))) /*!< Internal High Speed clock ready flag */
  562. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5U) | POSITION_VAL(RCC_CR_HSERDY))) /*!< External High Speed clock ready flag */
  563. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5U) | POSITION_VAL(RCC_CR_PLLRDY))) /*!< PLL clock ready flag */
  564. /* Flags in the CSR register */
  565. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_LSIRDY))) /*!< Internal Low Speed oscillator Ready */
  566. #if defined(RCC_CSR_V18PWRRSTF)
  567. #define RCC_FLAG_V18PWRRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_V18PWRRSTF)))
  568. #endif
  569. #define RCC_FLAG_OBLRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_OBLRSTF))) /*!< Options bytes loading reset flag */
  570. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_PINRSTF))) /*!< PIN reset flag */
  571. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_PORRSTF))) /*!< POR/PDR reset flag */
  572. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_SFTRSTF))) /*!< Software Reset flag */
  573. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_IWDGRSTF))) /*!< Independent Watchdog reset flag */
  574. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_WWDGRSTF))) /*!< Window watchdog reset flag */
  575. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5U) | POSITION_VAL(RCC_CSR_LPWRRSTF))) /*!< Low-Power reset flag */
  576. /* Flags in the BDCR register */
  577. #define RCC_FLAG_LSERDY ((uint8_t)((BDCR_REG_INDEX << 5U) | POSITION_VAL(RCC_BDCR_LSERDY))) /*!< External Low Speed oscillator Ready */
  578. /* Flags in the CFGR register */
  579. #if defined(RCC_CFGR_MCOF)
  580. #define RCC_FLAG_MCO ((uint8_t)((CFGR_REG_INDEX << 5U) | POSITION_VAL(RCC_CFGR_MCOF))) /*!< Microcontroller Clock Output Flag */
  581. #endif /* RCC_CFGR_MCOF */
  582. /**
  583. * @}
  584. */
  585. /**
  586. * @}
  587. */
  588. /* Exported macro ------------------------------------------------------------*/
  589. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  590. * @{
  591. */
  592. /** @defgroup RCC_AHB_Clock_Enable_Disable RCC AHB Clock Enable Disable
  593. * @brief Enable or disable the AHB peripheral clock.
  594. * @note After reset, the peripheral clock (used for registers read/write access)
  595. * is disabled and the application software has to enable this clock before
  596. * using it.
  597. * @{
  598. */
  599. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  600. __IO uint32_t tmpreg; \
  601. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
  602. /* Delay after an RCC peripheral clock enabling */ \
  603. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
  604. UNUSED(tmpreg); \
  605. } while(0U)
  606. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  607. __IO uint32_t tmpreg; \
  608. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOBEN);\
  609. /* Delay after an RCC peripheral clock enabling */ \
  610. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOBEN);\
  611. UNUSED(tmpreg); \
  612. } while(0U)
  613. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  614. __IO uint32_t tmpreg; \
  615. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOCEN);\
  616. /* Delay after an RCC peripheral clock enabling */ \
  617. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOCEN);\
  618. UNUSED(tmpreg); \
  619. } while(0U)
  620. #define __HAL_RCC_GPIOD_CLK_ENABLE() do { \
  621. __IO uint32_t tmpreg; \
  622. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN);\
  623. /* Delay after an RCC peripheral clock enabling */ \
  624. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN);\
  625. UNUSED(tmpreg); \
  626. } while(0U)
  627. #define __HAL_RCC_GPIOF_CLK_ENABLE() do { \
  628. __IO uint32_t tmpreg; \
  629. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOFEN);\
  630. /* Delay after an RCC peripheral clock enabling */ \
  631. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOFEN);\
  632. UNUSED(tmpreg); \
  633. } while(0U)
  634. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  635. __IO uint32_t tmpreg; \
  636. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  637. /* Delay after an RCC peripheral clock enabling */ \
  638. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  639. UNUSED(tmpreg); \
  640. } while(0U)
  641. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  642. __IO uint32_t tmpreg; \
  643. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  644. /* Delay after an RCC peripheral clock enabling */ \
  645. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  646. UNUSED(tmpreg); \
  647. } while(0U)
  648. #define __HAL_RCC_SRAM_CLK_ENABLE() do { \
  649. __IO uint32_t tmpreg; \
  650. SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  651. /* Delay after an RCC peripheral clock enabling */ \
  652. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  653. UNUSED(tmpreg); \
  654. } while(0U)
  655. #define __HAL_RCC_FLITF_CLK_ENABLE() do { \
  656. __IO uint32_t tmpreg; \
  657. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  658. /* Delay after an RCC peripheral clock enabling */ \
  659. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  660. UNUSED(tmpreg); \
  661. } while(0U)
  662. #define __HAL_RCC_TSC_CLK_ENABLE() do { \
  663. __IO uint32_t tmpreg; \
  664. SET_BIT(RCC->AHBENR, RCC_AHBENR_TSCEN);\
  665. /* Delay after an RCC peripheral clock enabling */ \
  666. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_TSCEN);\
  667. UNUSED(tmpreg); \
  668. } while(0U)
  669. #define __HAL_RCC_GPIOA_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOAEN))
  670. #define __HAL_RCC_GPIOB_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOBEN))
  671. #define __HAL_RCC_GPIOC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOCEN))
  672. #define __HAL_RCC_GPIOD_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIODEN))
  673. #define __HAL_RCC_GPIOF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOFEN))
  674. #define __HAL_RCC_CRC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
  675. #define __HAL_RCC_DMA1_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
  676. #define __HAL_RCC_SRAM_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_SRAMEN))
  677. #define __HAL_RCC_FLITF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
  678. #define __HAL_RCC_TSC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_TSCEN))
  679. /**
  680. * @}
  681. */
  682. /** @defgroup RCC_APB1_Clock_Enable_Disable RCC APB1 Clock Enable Disable
  683. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  684. * @note After reset, the peripheral clock (used for registers read/write access)
  685. * is disabled and the application software has to enable this clock before
  686. * using it.
  687. * @{
  688. */
  689. #define __HAL_RCC_TIM2_CLK_ENABLE() do { \
  690. __IO uint32_t tmpreg; \
  691. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  692. /* Delay after an RCC peripheral clock enabling */ \
  693. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  694. UNUSED(tmpreg); \
  695. } while(0U)
  696. #define __HAL_RCC_TIM6_CLK_ENABLE() do { \
  697. __IO uint32_t tmpreg; \
  698. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM6EN);\
  699. /* Delay after an RCC peripheral clock enabling */ \
  700. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM6EN);\
  701. UNUSED(tmpreg); \
  702. } while(0U)
  703. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  704. __IO uint32_t tmpreg; \
  705. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  706. /* Delay after an RCC peripheral clock enabling */ \
  707. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  708. UNUSED(tmpreg); \
  709. } while(0U)
  710. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  711. __IO uint32_t tmpreg; \
  712. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  713. /* Delay after an RCC peripheral clock enabling */ \
  714. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  715. UNUSED(tmpreg); \
  716. } while(0U)
  717. #define __HAL_RCC_USART3_CLK_ENABLE() do { \
  718. __IO uint32_t tmpreg; \
  719. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
  720. /* Delay after an RCC peripheral clock enabling */ \
  721. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
  722. UNUSED(tmpreg); \
  723. } while(0U)
  724. #define __HAL_RCC_I2C1_CLK_ENABLE() do { \
  725. __IO uint32_t tmpreg; \
  726. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  727. /* Delay after an RCC peripheral clock enabling */ \
  728. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  729. UNUSED(tmpreg); \
  730. } while(0U)
  731. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  732. __IO uint32_t tmpreg; \
  733. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  734. /* Delay after an RCC peripheral clock enabling */ \
  735. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  736. UNUSED(tmpreg); \
  737. } while(0U)
  738. #define __HAL_RCC_DAC1_CLK_ENABLE() do { \
  739. __IO uint32_t tmpreg; \
  740. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_DAC1EN);\
  741. /* Delay after an RCC peripheral clock enabling */ \
  742. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_DAC1EN);\
  743. UNUSED(tmpreg); \
  744. } while(0U)
  745. #define __HAL_RCC_TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  746. #define __HAL_RCC_TIM6_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM6EN))
  747. #define __HAL_RCC_WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  748. #define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  749. #define __HAL_RCC_USART3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART3EN))
  750. #define __HAL_RCC_I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  751. #define __HAL_RCC_PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  752. #define __HAL_RCC_DAC1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_DAC1EN))
  753. /**
  754. * @}
  755. */
  756. /** @defgroup RCC_APB2_Clock_Enable_Disable RCC APB2 Clock Enable Disable
  757. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  758. * @note After reset, the peripheral clock (used for registers read/write access)
  759. * is disabled and the application software has to enable this clock before
  760. * using it.
  761. * @{
  762. */
  763. #define __HAL_RCC_SYSCFG_CLK_ENABLE() do { \
  764. __IO uint32_t tmpreg; \
  765. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  766. /* Delay after an RCC peripheral clock enabling */ \
  767. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  768. UNUSED(tmpreg); \
  769. } while(0U)
  770. #define __HAL_RCC_TIM15_CLK_ENABLE() do { \
  771. __IO uint32_t tmpreg; \
  772. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM15EN);\
  773. /* Delay after an RCC peripheral clock enabling */ \
  774. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM15EN);\
  775. UNUSED(tmpreg); \
  776. } while(0U)
  777. #define __HAL_RCC_TIM16_CLK_ENABLE() do { \
  778. __IO uint32_t tmpreg; \
  779. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM16EN);\
  780. /* Delay after an RCC peripheral clock enabling */ \
  781. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM16EN);\
  782. UNUSED(tmpreg); \
  783. } while(0U)
  784. #define __HAL_RCC_TIM17_CLK_ENABLE() do { \
  785. __IO uint32_t tmpreg; \
  786. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM17EN);\
  787. /* Delay after an RCC peripheral clock enabling */ \
  788. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM17EN);\
  789. UNUSED(tmpreg); \
  790. } while(0U)
  791. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  792. __IO uint32_t tmpreg; \
  793. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  794. /* Delay after an RCC peripheral clock enabling */ \
  795. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  796. UNUSED(tmpreg); \
  797. } while(0U)
  798. #define __HAL_RCC_SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
  799. #define __HAL_RCC_TIM15_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM15EN))
  800. #define __HAL_RCC_TIM16_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM16EN))
  801. #define __HAL_RCC_TIM17_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM17EN))
  802. #define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  803. /**
  804. * @}
  805. */
  806. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enable Disable Status
  807. * @brief Get the enable or disable status of the AHB peripheral clock.
  808. * @note After reset, the peripheral clock (used for registers read/write access)
  809. * is disabled and the application software has to enable this clock before
  810. * using it.
  811. * @{
  812. */
  813. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOAEN)) != RESET)
  814. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOBEN)) != RESET)
  815. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOCEN)) != RESET)
  816. #define __HAL_RCC_GPIOD_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIODEN)) != RESET)
  817. #define __HAL_RCC_GPIOF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOFEN)) != RESET)
  818. #define __HAL_RCC_CRC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) != RESET)
  819. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) != RESET)
  820. #define __HAL_RCC_SRAM_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) != RESET)
  821. #define __HAL_RCC_FLITF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) != RESET)
  822. #define __HAL_RCC_TSC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_TSCEN)) != RESET)
  823. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOAEN)) == RESET)
  824. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOBEN)) == RESET)
  825. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOCEN)) == RESET)
  826. #define __HAL_RCC_GPIOD_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIODEN)) == RESET)
  827. #define __HAL_RCC_GPIOF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOFEN)) == RESET)
  828. #define __HAL_RCC_CRC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) == RESET)
  829. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) == RESET)
  830. #define __HAL_RCC_SRAM_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) == RESET)
  831. #define __HAL_RCC_FLITF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) == RESET)
  832. #define __HAL_RCC_TSC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_TSCEN)) == RESET)
  833. /**
  834. * @}
  835. */
  836. /** @defgroup RCC_APB1_Clock_Enable_Disable_Status APB1 Peripheral Clock Enable Disable Status
  837. * @brief Get the enable or disable status of the APB1 peripheral clock.
  838. * @note After reset, the peripheral clock (used for registers read/write access)
  839. * is disabled and the application software has to enable this clock before
  840. * using it.
  841. * @{
  842. */
  843. #define __HAL_RCC_TIM2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) != RESET)
  844. #define __HAL_RCC_TIM6_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM6EN)) != RESET)
  845. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) != RESET)
  846. #define __HAL_RCC_USART2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != RESET)
  847. #define __HAL_RCC_USART3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) != RESET)
  848. #define __HAL_RCC_I2C1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) != RESET)
  849. #define __HAL_RCC_PWR_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) != RESET)
  850. #define __HAL_RCC_DAC1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_DAC1EN)) != RESET)
  851. #define __HAL_RCC_TIM2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) == RESET)
  852. #define __HAL_RCC_TIM6_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM6EN)) == RESET)
  853. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) == RESET)
  854. #define __HAL_RCC_USART2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == RESET)
  855. #define __HAL_RCC_USART3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) == RESET)
  856. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) == RESET)
  857. #define __HAL_RCC_PWR_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) == RESET)
  858. #define __HAL_RCC_DAC1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_DAC1EN)) == RESET)
  859. /**
  860. * @}
  861. */
  862. /** @defgroup RCC_APB2_Clock_Enable_Disable_Status APB2 Peripheral Clock Enable Disable Status
  863. * @brief EGet the enable or disable status of the APB2 peripheral clock.
  864. * @note After reset, the peripheral clock (used for registers read/write access)
  865. * is disabled and the application software has to enable this clock before
  866. * using it.
  867. * @{
  868. */
  869. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) != RESET)
  870. #define __HAL_RCC_TIM15_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM15EN)) != RESET)
  871. #define __HAL_RCC_TIM16_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM16EN)) != RESET)
  872. #define __HAL_RCC_TIM17_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM17EN)) != RESET)
  873. #define __HAL_RCC_USART1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) != RESET)
  874. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) == RESET)
  875. #define __HAL_RCC_TIM15_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM15EN)) == RESET)
  876. #define __HAL_RCC_TIM16_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM16EN)) == RESET)
  877. #define __HAL_RCC_TIM17_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM17EN)) == RESET)
  878. #define __HAL_RCC_USART1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) == RESET)
  879. /**
  880. * @}
  881. */
  882. /** @defgroup RCC_AHB_Force_Release_Reset RCC AHB Force Release Reset
  883. * @brief Force or release AHB peripheral reset.
  884. * @{
  885. */
  886. #define __HAL_RCC_AHB_FORCE_RESET() (RCC->AHBRSTR = 0xFFFFFFFFU)
  887. #define __HAL_RCC_GPIOA_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOARST))
  888. #define __HAL_RCC_GPIOB_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOBRST))
  889. #define __HAL_RCC_GPIOC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOCRST))
  890. #define __HAL_RCC_GPIOD_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIODRST))
  891. #define __HAL_RCC_GPIOF_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOFRST))
  892. #define __HAL_RCC_TSC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_TSCRST))
  893. #define __HAL_RCC_AHB_RELEASE_RESET() (RCC->AHBRSTR = 0x00000000U)
  894. #define __HAL_RCC_GPIOA_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOARST))
  895. #define __HAL_RCC_GPIOB_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOBRST))
  896. #define __HAL_RCC_GPIOC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOCRST))
  897. #define __HAL_RCC_GPIOD_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIODRST))
  898. #define __HAL_RCC_GPIOF_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOFRST))
  899. #define __HAL_RCC_TSC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_TSCRST))
  900. /**
  901. * @}
  902. */
  903. /** @defgroup RCC_APB1_Force_Release_Reset RCC APB1 Force Release Reset
  904. * @brief Force or release APB1 peripheral reset.
  905. * @{
  906. */
  907. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFFU)
  908. #define __HAL_RCC_TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  909. #define __HAL_RCC_TIM6_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM6RST))
  910. #define __HAL_RCC_WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  911. #define __HAL_RCC_USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  912. #define __HAL_RCC_USART3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART3RST))
  913. #define __HAL_RCC_I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  914. #define __HAL_RCC_PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  915. #define __HAL_RCC_DAC1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_DAC1RST))
  916. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00000000U)
  917. #define __HAL_RCC_TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  918. #define __HAL_RCC_TIM6_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM6RST))
  919. #define __HAL_RCC_WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  920. #define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  921. #define __HAL_RCC_USART3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART3RST))
  922. #define __HAL_RCC_I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  923. #define __HAL_RCC_PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  924. #define __HAL_RCC_DAC1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_DAC1RST))
  925. /**
  926. * @}
  927. */
  928. /** @defgroup RCC_APB2_Force_Release_Reset RCC APB2 Force Release Reset
  929. * @brief Force or release APB2 peripheral reset.
  930. * @{
  931. */
  932. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  933. #define __HAL_RCC_SYSCFG_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SYSCFGRST))
  934. #define __HAL_RCC_TIM15_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM15RST))
  935. #define __HAL_RCC_TIM16_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM16RST))
  936. #define __HAL_RCC_TIM17_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM17RST))
  937. #define __HAL_RCC_USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  938. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00000000U)
  939. #define __HAL_RCC_SYSCFG_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SYSCFGRST))
  940. #define __HAL_RCC_TIM15_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM15RST))
  941. #define __HAL_RCC_TIM16_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM16RST))
  942. #define __HAL_RCC_TIM17_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM17RST))
  943. #define __HAL_RCC_USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  944. /**
  945. * @}
  946. */
  947. /** @defgroup RCC_HSI_Configuration HSI Configuration
  948. * @{
  949. */
  950. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  951. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  952. * It is used (enabled by hardware) as system clock source after startup
  953. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  954. * of the HSE used directly or indirectly as system clock (if the Clock
  955. * Security System CSS is enabled).
  956. * @note HSI can not be stopped if it is used as system clock source. In this case,
  957. * you have to select another source of the system clock then stop the HSI.
  958. * @note After enabling the HSI, the application software should wait on HSIRDY
  959. * flag to be set indicating that HSI clock is stable and can be used as
  960. * system clock source.
  961. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  962. * clock cycles.
  963. */
  964. #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = ENABLE)
  965. #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = DISABLE)
  966. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  967. * @note The calibration is used to compensate for the variations in voltage
  968. * and temperature that influence the frequency of the internal HSI RC.
  969. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  970. * (default is RCC_HSICALIBRATION_DEFAULT).
  971. * This parameter must be a number between 0 and 0x1F.
  972. */
  973. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  974. (MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << POSITION_VAL(RCC_CR_HSITRIM)))
  975. /**
  976. * @}
  977. */
  978. /** @defgroup RCC_LSI_Configuration LSI Configuration
  979. * @{
  980. */
  981. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  982. * @note After enabling the LSI, the application software should wait on
  983. * LSIRDY flag to be set indicating that LSI clock is stable and can
  984. * be used to clock the IWDG and/or the RTC.
  985. */
  986. #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = ENABLE)
  987. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  988. * @note LSI can not be disabled if the IWDG is running.
  989. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  990. * clock cycles.
  991. */
  992. #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = DISABLE)
  993. /**
  994. * @}
  995. */
  996. /** @defgroup RCC_HSE_Configuration HSE Configuration
  997. * @{
  998. */
  999. /**
  1000. * @brief Macro to configure the External High Speed oscillator (HSE).
  1001. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  1002. * supported by this macro. User should request a transition to HSE Off
  1003. * first and then HSE On or HSE Bypass.
  1004. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  1005. * software should wait on HSERDY flag to be set indicating that HSE clock
  1006. * is stable and can be used to clock the PLL and/or system clock.
  1007. * @note HSE state can not be changed if it is used directly or through the
  1008. * PLL as system clock. In this case, you have to select another source
  1009. * of the system clock then change the HSE state (ex. disable it).
  1010. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  1011. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  1012. * was previously enabled you have to enable it again after calling this
  1013. * function.
  1014. * @param __STATE__ specifies the new state of the HSE.
  1015. * This parameter can be one of the following values:
  1016. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  1017. * 6 HSE oscillator clock cycles.
  1018. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  1019. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  1020. */
  1021. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  1022. do{ \
  1023. if ((__STATE__) == RCC_HSE_ON) \
  1024. { \
  1025. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1026. } \
  1027. else if ((__STATE__) == RCC_HSE_OFF) \
  1028. { \
  1029. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1030. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1031. } \
  1032. else if ((__STATE__) == RCC_HSE_BYPASS) \
  1033. { \
  1034. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1035. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1036. } \
  1037. else \
  1038. { \
  1039. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1040. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1041. } \
  1042. }while(0U)
  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->BDCR, RCC_BDCR_LSEON); \
  1071. } \
  1072. else if ((__STATE__) == RCC_LSE_OFF) \
  1073. { \
  1074. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1075. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1076. } \
  1077. else if ((__STATE__) == RCC_LSE_BYPASS) \
  1078. { \
  1079. SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1080. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1081. } \
  1082. else \
  1083. { \
  1084. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1085. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1086. } \
  1087. }while(0U)
  1088. /**
  1089. * @}
  1090. */
  1091. /** @defgroup RCC_USARTx_Clock_Config RCC USARTx Clock Config
  1092. * @{
  1093. */
  1094. /** @brief Macro to configure the USART1 clock (USART1CLK).
  1095. * @param __USART1CLKSOURCE__ specifies the USART1 clock source.
  1096. * This parameter can be one of the following values:
  1097. @if STM32F302xC
  1098. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1099. @endif
  1100. @if STM32F303xC
  1101. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1102. @endif
  1103. @if STM32F358xx
  1104. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1105. @endif
  1106. @if STM32F302xE
  1107. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1108. @endif
  1109. @if STM32F303xE
  1110. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1111. @endif
  1112. @if STM32F398xx
  1113. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1114. @endif
  1115. @if STM32F373xC
  1116. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1117. @endif
  1118. @if STM32F378xx
  1119. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1120. @endif
  1121. @if STM32F301x8
  1122. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1123. @endif
  1124. @if STM32F302x8
  1125. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1126. @endif
  1127. @if STM32F318xx
  1128. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1129. @endif
  1130. @if STM32F303x8
  1131. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1132. @endif
  1133. @if STM32F334x8
  1134. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1135. @endif
  1136. @if STM32F328xx
  1137. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1138. @endif
  1139. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  1140. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  1141. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  1142. */
  1143. #define __HAL_RCC_USART1_CONFIG(__USART1CLKSOURCE__) \
  1144. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USART1SW, (uint32_t)(__USART1CLKSOURCE__))
  1145. /** @brief Macro to get the USART1 clock source.
  1146. * @retval The clock source can be one of the following values:
  1147. @if STM32F302xC
  1148. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1149. @endif
  1150. @if STM32F303xC
  1151. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1152. @endif
  1153. @if STM32F358xx
  1154. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1155. @endif
  1156. @if STM32F302xE
  1157. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1158. @endif
  1159. @if STM32F303xE
  1160. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1161. @endif
  1162. @if STM32F398xx
  1163. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1164. @endif
  1165. @if STM32F373xC
  1166. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1167. @endif
  1168. @if STM32F378xx
  1169. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1170. @endif
  1171. @if STM32F301x8
  1172. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1173. @endif
  1174. @if STM32F302x8
  1175. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1176. @endif
  1177. @if STM32F318xx
  1178. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1179. @endif
  1180. @if STM32F303x8
  1181. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1182. @endif
  1183. @if STM32F334x8
  1184. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1185. @endif
  1186. @if STM32F328xx
  1187. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1188. @endif
  1189. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  1190. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  1191. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  1192. */
  1193. #define __HAL_RCC_GET_USART1_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USART1SW)))
  1194. #if defined(RCC_CFGR3_USART2SW)
  1195. /** @brief Macro to configure the USART2 clock (USART2CLK).
  1196. * @param __USART2CLKSOURCE__ specifies the USART2 clock source.
  1197. * This parameter can be one of the following values:
  1198. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  1199. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  1200. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  1201. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  1202. */
  1203. #define __HAL_RCC_USART2_CONFIG(__USART2CLKSOURCE__) \
  1204. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USART2SW, (uint32_t)(__USART2CLKSOURCE__))
  1205. /** @brief Macro to get the USART2 clock source.
  1206. * @retval The clock source can be one of the following values:
  1207. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  1208. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  1209. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  1210. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  1211. */
  1212. #define __HAL_RCC_GET_USART2_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USART2SW)))
  1213. #endif /* RCC_CFGR3_USART2SW */
  1214. #if defined(RCC_CFGR3_USART3SW)
  1215. /** @brief Macro to configure the USART3 clock (USART3CLK).
  1216. * @param __USART3CLKSOURCE__ specifies the USART3 clock source.
  1217. * This parameter can be one of the following values:
  1218. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  1219. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  1220. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  1221. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  1222. */
  1223. #define __HAL_RCC_USART3_CONFIG(__USART3CLKSOURCE__) \
  1224. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USART3SW, (uint32_t)(__USART3CLKSOURCE__))
  1225. /** @brief Macro to get the USART3 clock source.
  1226. * @retval The clock source can be one of the following values:
  1227. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  1228. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  1229. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  1230. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  1231. */
  1232. #define __HAL_RCC_GET_USART3_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USART3SW)))
  1233. #endif /* RCC_CFGR3_USART2SW */
  1234. /**
  1235. * @}
  1236. */
  1237. /** @defgroup RCC_I2Cx_Clock_Config RCC I2Cx Clock Config
  1238. * @{
  1239. */
  1240. /** @brief Macro to configure the I2C1 clock (I2C1CLK).
  1241. * @param __I2C1CLKSOURCE__ specifies the I2C1 clock source.
  1242. * This parameter can be one of the following values:
  1243. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  1244. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  1245. */
  1246. #define __HAL_RCC_I2C1_CONFIG(__I2C1CLKSOURCE__) \
  1247. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_I2C1SW, (uint32_t)(__I2C1CLKSOURCE__))
  1248. /** @brief Macro to get the I2C1 clock source.
  1249. * @retval The clock source can be one of the following values:
  1250. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  1251. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  1252. */
  1253. #define __HAL_RCC_GET_I2C1_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_I2C1SW)))
  1254. /**
  1255. * @}
  1256. */
  1257. /** @defgroup RCC_PLL_Configuration PLL Configuration
  1258. * @{
  1259. */
  1260. /** @brief Macro to enable the main PLL.
  1261. * @note After enabling the main PLL, the application software should wait on
  1262. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1263. * be used as system clock source.
  1264. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1265. */
  1266. #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = ENABLE)
  1267. /** @brief Macro to disable the main PLL.
  1268. * @note The main PLL can not be disabled if it is used as system clock source
  1269. */
  1270. #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = DISABLE)
  1271. /** @brief Get oscillator clock selected as PLL input clock
  1272. * @retval The clock source used for PLL entry. The returned value can be one
  1273. * of the following:
  1274. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL input clock
  1275. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  1276. */
  1277. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  1278. /**
  1279. * @}
  1280. */
  1281. /** @defgroup RCC_Get_Clock_source Get Clock source
  1282. * @{
  1283. */
  1284. /**
  1285. * @brief Macro to configure the system clock source.
  1286. * @param __SYSCLKSOURCE__ specifies the system clock source.
  1287. * This parameter can be one of the following values:
  1288. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  1289. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  1290. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  1291. */
  1292. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  1293. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  1294. /** @brief Macro to get the clock source used as system clock.
  1295. * @retval The clock source used as system clock. The returned value can be one
  1296. * of the following:
  1297. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  1298. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  1299. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  1300. */
  1301. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  1302. /**
  1303. * @}
  1304. */
  1305. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  1306. * @{
  1307. */
  1308. #if defined(RCC_CFGR_MCOPRE)
  1309. /** @brief Macro to configure the MCO clock.
  1310. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1311. * This parameter can be one of the following values:
  1312. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1313. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1314. * @arg @ref RCC_MCO1SOURCE_HSI HSI oscillator clock selected as MCO clock
  1315. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  1316. * @arg @ref RCC_MCO1SOURCE_LSI LSI selected as MCO clock
  1317. * @arg @ref RCC_MCO1SOURCE_LSE LSE selected as MCO clock
  1318. * @arg @ref RCC_MCO1SOURCE_PLLCLK_DIV2 PLLCLK Divided by 2 selected as MCO clock
  1319. * @param __MCODIV__ specifies the MCO clock prescaler.
  1320. * This parameter can be one of the following values:
  1321. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  1322. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  1323. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  1324. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  1325. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  1326. * @arg @ref RCC_MCODIV_32 MCO clock source is divided by 32
  1327. * @arg @ref RCC_MCODIV_64 MCO clock source is divided by 64
  1328. * @arg @ref RCC_MCODIV_128 MCO clock source is divided by 128
  1329. */
  1330. #else
  1331. /** @brief Macro to configure the MCO clock.
  1332. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1333. * This parameter can be one of the following values:
  1334. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1335. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1336. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  1337. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  1338. * @arg @ref RCC_MCO1SOURCE_LSI LSI selected as MCO clock
  1339. * @arg @ref RCC_MCO1SOURCE_LSE LSE selected as MCO clock
  1340. * @arg @ref RCC_MCO1SOURCE_PLLCLK_DIV2 PLLCLK Divided by 2 selected as MCO clock
  1341. * @param __MCODIV__ specifies the MCO clock prescaler.
  1342. * This parameter can be one of the following values:
  1343. * @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
  1344. */
  1345. #endif
  1346. #if defined(RCC_CFGR_MCOPRE)
  1347. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1348. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO | RCC_CFGR_MCOPRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  1349. #else
  1350. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1351. MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, (__MCOCLKSOURCE__))
  1352. #endif
  1353. /**
  1354. * @}
  1355. */
  1356. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  1357. * @{
  1358. */
  1359. /** @brief Macro to configure the RTC clock (RTCCLK).
  1360. * @note As the RTC clock configuration bits are in the Backup domain and write
  1361. * access is denied to this domain after reset, you have to enable write
  1362. * access using the Power Backup Access macro before to configure
  1363. * the RTC clock source (to be done once after reset).
  1364. * @note Once the RTC clock is configured it cannot be changed unless the
  1365. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1366. * a Power On Reset (POR).
  1367. *
  1368. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  1369. * This parameter can be one of the following values:
  1370. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1371. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1372. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1373. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV32 HSE clock divided by 32
  1374. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1375. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1376. * However, when the LSI clock and HSE clock divided by 32 is used as RTC clock source,
  1377. * the RTC cannot be used in STOP and STANDBY modes.
  1378. * @note The system must always be configured so as to get a PCLK frequency greater than or
  1379. * equal to the RTCCLK frequency for a proper operation of the RTC.
  1380. */
  1381. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, (__RTC_CLKSOURCE__))
  1382. /** @brief Macro to get the RTC clock source.
  1383. * @retval The clock source can be one of the following values:
  1384. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1385. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1386. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1387. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV32 HSE clock divided by 32
  1388. */
  1389. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL))
  1390. /** @brief Macro to enable the the RTC clock.
  1391. * @note These macros must be used only after the RTC clock source was selected.
  1392. */
  1393. #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = ENABLE)
  1394. /** @brief Macro to disable the the RTC clock.
  1395. * @note These macros must be used only after the RTC clock source was selected.
  1396. */
  1397. #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = DISABLE)
  1398. /** @brief Macro to force the Backup domain reset.
  1399. * @note This function resets the RTC peripheral (including the backup registers)
  1400. * and the RTC clock source selection in RCC_BDCR register.
  1401. */
  1402. #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = ENABLE)
  1403. /** @brief Macros to release the Backup domain reset.
  1404. */
  1405. #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = DISABLE)
  1406. /**
  1407. * @}
  1408. */
  1409. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1410. * @brief macros to manage the specified RCC Flags and interrupts.
  1411. * @{
  1412. */
  1413. /** @brief Enable RCC interrupt.
  1414. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1415. * This parameter can be any combination 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 main PLL ready interrupt
  1421. */
  1422. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  1423. /** @brief Disable RCC interrupt.
  1424. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1425. * This parameter can be any combination of the following values:
  1426. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1427. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1428. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1429. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1430. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1431. */
  1432. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= (uint8_t)(~(__INTERRUPT__)))
  1433. /** @brief Clear the RCC's interrupt pending bits.
  1434. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1435. * This parameter can be any combination of the following values:
  1436. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1437. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1438. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1439. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1440. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1441. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1442. */
  1443. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  1444. /** @brief Check the RCC's interrupt has occurred or not.
  1445. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1446. * This parameter can be one of the following values:
  1447. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1448. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1449. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1450. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1451. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1452. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1453. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1454. */
  1455. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  1456. /** @brief Set RMVF bit to clear the reset flags.
  1457. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1458. * RCC_FLAG_OBLRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1459. */
  1460. #define __HAL_RCC_CLEAR_RESET_FLAGS() (*(__IO uint32_t *)RCC_CSR_RMVF_BB = ENABLE)
  1461. /** @brief Check RCC flag is set or not.
  1462. * @param __FLAG__ specifies the flag to check.
  1463. * This parameter can be one of the following values:
  1464. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready.
  1465. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready.
  1466. * @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready.
  1467. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready.
  1468. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready.
  1469. * @arg @ref RCC_FLAG_OBLRST Option Byte Load reset
  1470. * @arg @ref RCC_FLAG_PINRST Pin reset.
  1471. * @arg @ref RCC_FLAG_PORRST POR/PDR reset.
  1472. * @arg @ref RCC_FLAG_SFTRST Software reset.
  1473. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset.
  1474. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset.
  1475. * @arg @ref RCC_FLAG_LPWRRST Low Power reset.
  1476. @if defined(STM32F301x8)
  1477. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1478. @endif
  1479. @if defined(STM32F302x8)
  1480. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1481. @endif
  1482. @if defined(STM32F302xC)
  1483. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1484. * @arg @ref RCC_FLAG_MCO Microcontroller Clock Output
  1485. @endif
  1486. @if defined(STM32F302xE)
  1487. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1488. @endif
  1489. @if defined(STM32F303x8)
  1490. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1491. @endif
  1492. @if defined(STM32F303xC)
  1493. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1494. * @arg @ref RCC_FLAG_MCO Microcontroller Clock Output
  1495. @endif
  1496. @if defined(STM32F303xE)
  1497. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1498. @endif
  1499. @if defined(STM32F334x8)
  1500. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1501. @endif
  1502. @if defined(STM32F358xx)
  1503. * @arg @ref RCC_FLAG_MCO Microcontroller Clock Output
  1504. @endif
  1505. @if defined(STM32F373xC)
  1506. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1507. @endif
  1508. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1509. */
  1510. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5U) == CR_REG_INDEX) ? RCC->CR : \
  1511. (((__FLAG__) >> 5U) == BDCR_REG_INDEX)? RCC->BDCR : \
  1512. (((__FLAG__) >> 5U) == CFGR_REG_INDEX)? RCC->CFGR : \
  1513. RCC->CSR) & (1U << ((__FLAG__) & RCC_FLAG_MASK)))
  1514. /**
  1515. * @}
  1516. */
  1517. /**
  1518. * @}
  1519. */
  1520. /* Include RCC HAL Extension module */
  1521. #include "stm32f3xx_hal_rcc_ex.h"
  1522. /* Exported functions --------------------------------------------------------*/
  1523. /** @addtogroup RCC_Exported_Functions
  1524. * @{
  1525. */
  1526. /** @addtogroup RCC_Exported_Functions_Group1
  1527. * @{
  1528. */
  1529. /* Initialization and de-initialization functions ******************************/
  1530. void HAL_RCC_DeInit(void);
  1531. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1532. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1533. /**
  1534. * @}
  1535. */
  1536. /** @addtogroup RCC_Exported_Functions_Group2
  1537. * @{
  1538. */
  1539. /* Peripheral Control functions ************************************************/
  1540. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1541. void HAL_RCC_EnableCSS(void);
  1542. /* CSS NMI IRQ handler */
  1543. void HAL_RCC_NMI_IRQHandler(void);
  1544. /* User Callbacks in non blocking mode (IT mode) */
  1545. void HAL_RCC_CSSCallback(void);
  1546. void HAL_RCC_DisableCSS(void);
  1547. uint32_t HAL_RCC_GetSysClockFreq(void);
  1548. uint32_t HAL_RCC_GetHCLKFreq(void);
  1549. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1550. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1551. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1552. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1553. /**
  1554. * @}
  1555. */
  1556. /**
  1557. * @}
  1558. */
  1559. /**
  1560. * @}
  1561. */
  1562. /**
  1563. * @}
  1564. */
  1565. #ifdef __cplusplus
  1566. }
  1567. #endif
  1568. #endif /* __STM32F3xx_HAL_RCC_H */
  1569. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/