stm32f1xx_hal_rcc.h 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @version V1.0.4
  6. * @date 29-April-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 __STM32F1xx_HAL_RCC_H
  39. #define __STM32F1xx_HAL_RCC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f1xx_hal_def.h"
  45. /** @addtogroup STM32F1xx_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 ((uint32_t)100) /* 100 ms */
  59. /* LSE state change timeout */
  60. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  61. #define CLOCKSWITCH_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */
  62. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  63. #define HSI_TIMEOUT_VALUE ((uint32_t)2) /* 2 ms (minimum Tick + 1) */
  64. #define LSI_TIMEOUT_VALUE ((uint32_t)2) /* 2 ms (minimum Tick + 1) */
  65. #define PLL_TIMEOUT_VALUE ((uint32_t)2) /* 2 ms (minimum Tick + 1) */
  66. #define LSI_VALUE ((uint32_t)40000) /* 40kHz */
  67. /**
  68. * @}
  69. */
  70. /** @defgroup RCC_Register_Offset Register offsets
  71. * @{
  72. */
  73. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  74. #define RCC_CR_OFFSET 0x00
  75. #define RCC_CFGR_OFFSET 0x04
  76. #define RCC_CIR_OFFSET 0x08
  77. #define RCC_BDCR_OFFSET 0x20
  78. #define RCC_CSR_OFFSET 0x24
  79. /**
  80. * @}
  81. */
  82. /** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
  83. * @brief RCC registers bit address in the alias region
  84. * @{
  85. */
  86. #define RCC_CR_OFFSET_BB (RCC_OFFSET + RCC_CR_OFFSET)
  87. #define RCC_CFGR_OFFSET_BB (RCC_OFFSET + RCC_CFGR_OFFSET)
  88. #define RCC_CIR_OFFSET_BB (RCC_OFFSET + RCC_CIR_OFFSET)
  89. #define RCC_BDCR_OFFSET_BB (RCC_OFFSET + RCC_BDCR_OFFSET)
  90. #define RCC_CSR_OFFSET_BB (RCC_OFFSET + RCC_CSR_OFFSET)
  91. /* --- CR Register ---*/
  92. /* Alias word address of HSION bit */
  93. #define RCC_HSION_BIT_NUMBER POSITION_VAL(RCC_CR_HSION)
  94. #define RCC_CR_HSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (RCC_HSION_BIT_NUMBER * 4)))
  95. /* Alias word address of HSEON bit */
  96. #define RCC_HSEON_BIT_NUMBER POSITION_VAL(RCC_CR_HSEON)
  97. #define RCC_CR_HSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (RCC_HSEON_BIT_NUMBER * 4)))
  98. /* Alias word address of CSSON bit */
  99. #define RCC_CSSON_BIT_NUMBER POSITION_VAL(RCC_CR_CSSON)
  100. #define RCC_CR_CSSON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (RCC_CSSON_BIT_NUMBER * 4)))
  101. /* Alias word address of PLLON bit */
  102. #define RCC_PLLON_BIT_NUMBER POSITION_VAL(RCC_CR_PLLON)
  103. #define RCC_CR_PLLON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (RCC_PLLON_BIT_NUMBER * 4)))
  104. /* --- CSR Register ---*/
  105. /* Alias word address of LSION bit */
  106. #define RCC_LSION_BIT_NUMBER POSITION_VAL(RCC_CSR_LSION)
  107. #define RCC_CSR_LSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (RCC_LSION_BIT_NUMBER * 4)))
  108. /* Alias word address of RMVF bit */
  109. #define RCC_RMVF_BIT_NUMBER POSITION_VAL(RCC_CSR_RMVF)
  110. #define RCC_CSR_RMVF_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (RCC_RMVF_BIT_NUMBER * 4)))
  111. /* --- BDCR Registers ---*/
  112. /* Alias word address of LSEON bit */
  113. #define RCC_LSEON_BIT_NUMBER POSITION_VAL(RCC_BDCR_LSEON)
  114. #define RCC_BDCR_LSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32) + (RCC_LSEON_BIT_NUMBER * 4)))
  115. /* Alias word address of LSEON bit */
  116. #define RCC_LSEBYP_BIT_NUMBER POSITION_VAL(RCC_BDCR_LSEBYP)
  117. #define RCC_BDCR_LSEBYP_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32) + (RCC_LSEBYP_BIT_NUMBER * 4)))
  118. /* Alias word address of RTCEN bit */
  119. #define RCC_RTCEN_BIT_NUMBER POSITION_VAL(RCC_BDCR_RTCEN)
  120. #define RCC_BDCR_RTCEN_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32) + (RCC_RTCEN_BIT_NUMBER * 4)))
  121. /* Alias word address of BDRST bit */
  122. #define RCC_BDRST_BIT_NUMBER POSITION_VAL(RCC_BDCR_BDRST)
  123. #define RCC_BDCR_BDRST_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32) + (RCC_BDRST_BIT_NUMBER * 4)))
  124. /**
  125. * @}
  126. */
  127. /* CR register byte 2 (Bits[23:16]) base address */
  128. #define RCC_CR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02))
  129. /* CIR register byte 1 (Bits[15:8]) base address */
  130. #define RCC_CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01))
  131. /* CIR register byte 2 (Bits[23:16]) base address */
  132. #define RCC_CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02))
  133. /* Defines used for Flags */
  134. #define CR_REG_INDEX ((uint8_t)1)
  135. #define BDCR_REG_INDEX ((uint8_t)2)
  136. #define CSR_REG_INDEX ((uint8_t)3)
  137. #define RCC_FLAG_MASK ((uint8_t)0x1F)
  138. /**
  139. * @}
  140. */
  141. /** @addtogroup RCC_Private_Macros
  142. * @{
  143. */
  144. /** @defgroup RCC_Alias_For_Legacy Alias define maintained for legacy
  145. * @{
  146. */
  147. #define __HAL_RCC_SYSCFG_CLK_DISABLE __HAL_RCC_AFIO_CLK_DISABLE
  148. #define __HAL_RCC_SYSCFG_CLK_ENABLE __HAL_RCC_AFIO_CLK_ENABLE
  149. #define __HAL_RCC_SYSCFG_FORCE_RESET __HAL_RCC_AFIO_FORCE_RESET
  150. #define __HAL_RCC_SYSCFG_RELEASE_RESET __HAL_RCC_AFIO_RELEASE_RESET
  151. /**
  152. * @}
  153. */
  154. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI_DIV2) || \
  155. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  156. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  157. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  158. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  159. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  160. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE))
  161. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  162. ((__HSE__) == RCC_HSE_BYPASS))
  163. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  164. ((__LSE__) == RCC_LSE_BYPASS))
  165. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  166. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1F)
  167. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  168. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  169. ((__PLL__) == RCC_PLL_ON))
  170. #define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  171. (((CLK) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  172. (((CLK) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) || \
  173. (((CLK) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2))
  174. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  175. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  176. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  177. #define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  178. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  179. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  180. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  181. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  182. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  183. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  184. ((__HCLK__) == RCC_SYSCLK_DIV512))
  185. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  186. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  187. ((__PCLK__) == RCC_HCLK_DIV16))
  188. #define IS_RCC_MCO(__MCO__) ((__MCO__) == RCC_MCO)
  189. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1))
  190. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  191. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  192. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  193. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV128))
  194. /**
  195. * @}
  196. */
  197. /* Exported types ------------------------------------------------------------*/
  198. /** @defgroup RCC_Exported_Types RCC Exported Types
  199. * @{
  200. */
  201. /**
  202. * @brief RCC PLL configuration structure definition
  203. */
  204. typedef struct
  205. {
  206. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  207. This parameter can be a value of @ref RCC_PLL_Config */
  208. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  209. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  210. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  211. This parameter must be a value of @ref RCCEx_PLL_Multiplication_Factor */
  212. } RCC_PLLInitTypeDef;
  213. /**
  214. * @brief RCC System, AHB and APB busses clock configuration structure definition
  215. */
  216. typedef struct
  217. {
  218. uint32_t ClockType; /*!< The clock to be configured.
  219. This parameter can be a value of @ref RCC_System_Clock_Type */
  220. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  221. This parameter can be a value of @ref RCC_System_Clock_Source */
  222. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  223. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  224. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  225. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  226. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  227. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  228. } RCC_ClkInitTypeDef;
  229. /**
  230. * @}
  231. */
  232. /* Exported constants --------------------------------------------------------*/
  233. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  234. * @{
  235. */
  236. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  237. * @{
  238. */
  239. #define RCC_PLLSOURCE_HSI_DIV2 ((uint32_t)0x00000000) /*!< HSI clock divided by 2 selected as PLL entry clock source */
  240. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC /*!< HSE clock selected as PLL entry clock source */
  241. /**
  242. * @}
  243. */
  244. /** @defgroup RCC_Oscillator_Type Oscillator Type
  245. * @{
  246. */
  247. #define RCC_OSCILLATORTYPE_NONE ((uint32_t)0x00000000)
  248. #define RCC_OSCILLATORTYPE_HSE ((uint32_t)0x00000001)
  249. #define RCC_OSCILLATORTYPE_HSI ((uint32_t)0x00000002)
  250. #define RCC_OSCILLATORTYPE_LSE ((uint32_t)0x00000004)
  251. #define RCC_OSCILLATORTYPE_LSI ((uint32_t)0x00000008)
  252. /**
  253. * @}
  254. */
  255. /** @defgroup RCC_HSE_Config HSE Config
  256. * @{
  257. */
  258. #define RCC_HSE_OFF ((uint32_t)0x00000000) /*!< HSE clock deactivation */
  259. #define RCC_HSE_ON RCC_CR_HSEON /*!< HSE clock activation */
  260. #define RCC_HSE_BYPASS ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
  261. /**
  262. * @}
  263. */
  264. /** @defgroup RCC_LSE_Config LSE Config
  265. * @{
  266. */
  267. #define RCC_LSE_OFF ((uint32_t)0x00000000) /*!< LSE clock deactivation */
  268. #define RCC_LSE_ON RCC_BDCR_LSEON /*!< LSE clock activation */
  269. #define RCC_LSE_BYPASS ((uint32_t)(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON)) /*!< External clock source for LSE clock */
  270. /**
  271. * @}
  272. */
  273. /** @defgroup RCC_HSI_Config HSI Config
  274. * @{
  275. */
  276. #define RCC_HSI_OFF ((uint32_t)0x00000000) /*!< HSI clock deactivation */
  277. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  278. #define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10) /* Default HSI calibration trimming value */
  279. /**
  280. * @}
  281. */
  282. /** @defgroup RCC_LSI_Config LSI Config
  283. * @{
  284. */
  285. #define RCC_LSI_OFF ((uint32_t)0x00000000) /*!< LSI clock deactivation */
  286. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  287. /**
  288. * @}
  289. */
  290. /** @defgroup RCC_PLL_Config PLL Config
  291. * @{
  292. */
  293. #define RCC_PLL_NONE ((uint32_t)0x00000000) /*!< PLL is not configured */
  294. #define RCC_PLL_OFF ((uint32_t)0x00000001) /*!< PLL deactivation */
  295. #define RCC_PLL_ON ((uint32_t)0x00000002) /*!< PLL activation */
  296. /**
  297. * @}
  298. */
  299. /** @defgroup RCC_System_Clock_Type System Clock Type
  300. * @{
  301. */
  302. #define RCC_CLOCKTYPE_SYSCLK ((uint32_t)0x00000001) /*!< SYSCLK to configure */
  303. #define RCC_CLOCKTYPE_HCLK ((uint32_t)0x00000002) /*!< HCLK to configure */
  304. #define RCC_CLOCKTYPE_PCLK1 ((uint32_t)0x00000004) /*!< PCLK1 to configure */
  305. #define RCC_CLOCKTYPE_PCLK2 ((uint32_t)0x00000008) /*!< PCLK2 to configure */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup RCC_System_Clock_Source System Clock Source
  310. * @{
  311. */
  312. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  313. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  314. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  315. /**
  316. * @}
  317. */
  318. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  319. * @{
  320. */
  321. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  322. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  323. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  324. /**
  325. * @}
  326. */
  327. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  328. * @{
  329. */
  330. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  331. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  332. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  333. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  334. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  335. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  336. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  337. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  338. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  339. /**
  340. * @}
  341. */
  342. /** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
  343. * @{
  344. */
  345. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1 /*!< HCLK not divided */
  346. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2 /*!< HCLK divided by 2 */
  347. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4 /*!< HCLK divided by 4 */
  348. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8 /*!< HCLK divided by 8 */
  349. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
  350. /**
  351. * @}
  352. */
  353. /** @defgroup RCC_RTC_Clock_Source RTC Clock Source
  354. * @{
  355. */
  356. #define RCC_RTCCLKSOURCE_NO_CLK ((uint32_t)0x00000000) /*!< No clock */
  357. #define RCC_RTCCLKSOURCE_LSE RCC_BDCR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  358. #define RCC_RTCCLKSOURCE_LSI RCC_BDCR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  359. #define RCC_RTCCLKSOURCE_HSE_DIV128 RCC_BDCR_RTCSEL_HSE /*!< HSE oscillator clock divided by 128 used as RTC clock */
  360. /**
  361. * @}
  362. */
  363. /** @defgroup RCC_MCO_Index MCO Index
  364. * @{
  365. */
  366. #define RCC_MCO1 ((uint32_t)0x00000000)
  367. #define RCC_MCO RCC_MCO1 /*!< MCO1 to be compliant with other families with 2 MCOs*/
  368. /**
  369. * @}
  370. */
  371. /** @defgroup RCC_MCOx_Clock_Prescaler MCO Clock Prescaler
  372. * @{
  373. */
  374. #define RCC_MCODIV_1 ((uint32_t)0x00000000)
  375. /**
  376. * @}
  377. */
  378. /** @defgroup RCC_Interrupt Interrupts
  379. * @{
  380. */
  381. #define RCC_IT_LSIRDY ((uint8_t)RCC_CIR_LSIRDYF) /*!< LSI Ready Interrupt flag */
  382. #define RCC_IT_LSERDY ((uint8_t)RCC_CIR_LSERDYF) /*!< LSE Ready Interrupt flag */
  383. #define RCC_IT_HSIRDY ((uint8_t)RCC_CIR_HSIRDYF) /*!< HSI Ready Interrupt flag */
  384. #define RCC_IT_HSERDY ((uint8_t)RCC_CIR_HSERDYF) /*!< HSE Ready Interrupt flag */
  385. #define RCC_IT_PLLRDY ((uint8_t)RCC_CIR_PLLRDYF) /*!< PLL Ready Interrupt flag */
  386. #define RCC_IT_CSS ((uint8_t)RCC_CIR_CSSF) /*!< Clock Security System Interrupt flag */
  387. /**
  388. * @}
  389. */
  390. /** @defgroup RCC_Flag Flags
  391. * Elements values convention: XXXYYYYYb
  392. * - YYYYY : Flag position in the register
  393. * - XXX : Register index
  394. * - 001: CR register
  395. * - 010: BDCR register
  396. * - 011: CSR register
  397. * @{
  398. */
  399. /* Flags in the CR register */
  400. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_HSIRDY))) /*!< Internal High Speed clock ready flag */
  401. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_HSERDY))) /*!< External High Speed clock ready flag */
  402. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_PLLRDY))) /*!< PLL clock ready flag */
  403. /* Flags in the CSR register */
  404. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_LSIRDY))) /*!< Internal Low Speed oscillator Ready */
  405. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_PINRSTF))) /*!< PIN reset flag */
  406. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_PORRSTF))) /*!< POR/PDR reset flag */
  407. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_SFTRSTF))) /*!< Software Reset flag */
  408. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_IWDGRSTF))) /*!< Independent Watchdog reset flag */
  409. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_WWDGRSTF))) /*!< Window watchdog reset flag */
  410. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_LPWRRSTF))) /*!< Low-Power reset flag */
  411. /* Flags in the BDCR register */
  412. #define RCC_FLAG_LSERDY ((uint8_t)((BDCR_REG_INDEX << 5) | POSITION_VAL(RCC_BDCR_LSERDY))) /*!< External Low Speed oscillator Ready */
  413. /**
  414. * @}
  415. */
  416. /**
  417. * @}
  418. */
  419. /* Exported macro ------------------------------------------------------------*/
  420. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  421. * @{
  422. */
  423. /** @defgroup RCC_Peripheral_Clock_Enable_Disable Peripheral Clock Enable Disable
  424. * @brief Enable or disable the AHB1 peripheral clock.
  425. * @note After reset, the peripheral clock (used for registers read/write access)
  426. * is disabled and the application software has to enable this clock before
  427. * using it.
  428. * @{
  429. */
  430. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  431. __IO uint32_t tmpreg; \
  432. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  433. /* Delay after an RCC peripheral clock enabling */\
  434. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  435. UNUSED(tmpreg); \
  436. } while(0)
  437. #define __HAL_RCC_SRAM_CLK_ENABLE() do { \
  438. __IO uint32_t tmpreg; \
  439. SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  440. /* Delay after an RCC peripheral clock enabling */\
  441. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  442. UNUSED(tmpreg); \
  443. } while(0)
  444. #define __HAL_RCC_FLITF_CLK_ENABLE() do { \
  445. __IO uint32_t tmpreg; \
  446. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  447. /* Delay after an RCC peripheral clock enabling */\
  448. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  449. UNUSED(tmpreg); \
  450. } while(0)
  451. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  452. __IO uint32_t tmpreg; \
  453. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  454. /* Delay after an RCC peripheral clock enabling */\
  455. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  456. UNUSED(tmpreg); \
  457. } while(0)
  458. #define __HAL_RCC_DMA1_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
  459. #define __HAL_RCC_SRAM_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_SRAMEN))
  460. #define __HAL_RCC_FLITF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
  461. #define __HAL_RCC_CRC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
  462. /**
  463. * @}
  464. */
  465. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enable Disable Status
  466. * @brief Get the enable or disable status of the AHB peripheral clock.
  467. * @note After reset, the peripheral clock (used for registers read/write access)
  468. * is disabled and the application software has to enable this clock before
  469. * using it.
  470. * @{
  471. */
  472. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) != RESET)
  473. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) == RESET)
  474. #define __HAL_RCC_SRAM_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) != RESET)
  475. #define __HAL_RCC_SRAM_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) == RESET)
  476. #define __HAL_RCC_FLITF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) != RESET)
  477. #define __HAL_RCC_FLITF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) == RESET)
  478. #define __HAL_RCC_CRC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) != RESET)
  479. #define __HAL_RCC_CRC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) == RESET)
  480. /**
  481. * @}
  482. */
  483. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Clock Enable Disable
  484. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  485. * @note After reset, the peripheral clock (used for registers read/write access)
  486. * is disabled and the application software has to enable this clock before
  487. * using it.
  488. * @{
  489. */
  490. #define __HAL_RCC_TIM2_CLK_ENABLE() do { \
  491. __IO uint32_t tmpreg; \
  492. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  493. /* Delay after an RCC peripheral clock enabling */\
  494. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  495. UNUSED(tmpreg); \
  496. } while(0)
  497. #define __HAL_RCC_TIM3_CLK_ENABLE() do { \
  498. __IO uint32_t tmpreg; \
  499. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  500. /* Delay after an RCC peripheral clock enabling */\
  501. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  502. UNUSED(tmpreg); \
  503. } while(0)
  504. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  505. __IO uint32_t tmpreg; \
  506. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  507. /* Delay after an RCC peripheral clock enabling */\
  508. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  509. UNUSED(tmpreg); \
  510. } while(0)
  511. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  512. __IO uint32_t tmpreg; \
  513. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  514. /* Delay after an RCC peripheral clock enabling */\
  515. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  516. UNUSED(tmpreg); \
  517. } while(0)
  518. #define __HAL_RCC_I2C1_CLK_ENABLE() do { \
  519. __IO uint32_t tmpreg; \
  520. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  521. /* Delay after an RCC peripheral clock enabling */\
  522. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  523. UNUSED(tmpreg); \
  524. } while(0)
  525. #define __HAL_RCC_BKP_CLK_ENABLE() do { \
  526. __IO uint32_t tmpreg; \
  527. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_BKPEN);\
  528. /* Delay after an RCC peripheral clock enabling */\
  529. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_BKPEN);\
  530. UNUSED(tmpreg); \
  531. } while(0)
  532. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  533. __IO uint32_t tmpreg; \
  534. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  535. /* Delay after an RCC peripheral clock enabling */\
  536. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  537. UNUSED(tmpreg); \
  538. } while(0)
  539. #define __HAL_RCC_TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  540. #define __HAL_RCC_TIM3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
  541. #define __HAL_RCC_WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  542. #define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  543. #define __HAL_RCC_I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  544. #define __HAL_RCC_BKP_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_BKPEN))
  545. #define __HAL_RCC_PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  546. /**
  547. * @}
  548. */
  549. /** @defgroup RCC_APB1_Peripheral_Clock_Enable_Disable_Status APB1 Peripheral Clock Enable Disable Status
  550. * @brief Get the enable or disable status of the APB1 peripheral clock.
  551. * @note After reset, the peripheral clock (used for registers read/write access)
  552. * is disabled and the application software has to enable this clock before
  553. * using it.
  554. * @{
  555. */
  556. #define __HAL_RCC_TIM2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) != RESET)
  557. #define __HAL_RCC_TIM2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) == RESET)
  558. #define __HAL_RCC_TIM3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) != RESET)
  559. #define __HAL_RCC_TIM3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) == RESET)
  560. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) != RESET)
  561. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) == RESET)
  562. #define __HAL_RCC_USART2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != RESET)
  563. #define __HAL_RCC_USART2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == RESET)
  564. #define __HAL_RCC_I2C1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) != RESET)
  565. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) == RESET)
  566. #define __HAL_RCC_BKP_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_BKPEN)) != RESET)
  567. #define __HAL_RCC_BKP_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_BKPEN)) == RESET)
  568. #define __HAL_RCC_PWR_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) != RESET)
  569. #define __HAL_RCC_PWR_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) == RESET)
  570. /**
  571. * @}
  572. */
  573. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Clock Enable Disable
  574. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  575. * @note After reset, the peripheral clock (used for registers read/write access)
  576. * is disabled and the application software has to enable this clock before
  577. * using it.
  578. * @{
  579. */
  580. #define __HAL_RCC_AFIO_CLK_ENABLE() do { \
  581. __IO uint32_t tmpreg; \
  582. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_AFIOEN);\
  583. /* Delay after an RCC peripheral clock enabling */\
  584. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_AFIOEN);\
  585. UNUSED(tmpreg); \
  586. } while(0)
  587. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  588. __IO uint32_t tmpreg; \
  589. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);\
  590. /* Delay after an RCC peripheral clock enabling */\
  591. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);\
  592. UNUSED(tmpreg); \
  593. } while(0)
  594. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  595. __IO uint32_t tmpreg; \
  596. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);\
  597. /* Delay after an RCC peripheral clock enabling */\
  598. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);\
  599. UNUSED(tmpreg); \
  600. } while(0)
  601. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  602. __IO uint32_t tmpreg; \
  603. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPCEN);\
  604. /* Delay after an RCC peripheral clock enabling */\
  605. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPCEN);\
  606. UNUSED(tmpreg); \
  607. } while(0)
  608. #define __HAL_RCC_GPIOD_CLK_ENABLE() do { \
  609. __IO uint32_t tmpreg; \
  610. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);\
  611. /* Delay after an RCC peripheral clock enabling */\
  612. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);\
  613. UNUSED(tmpreg); \
  614. } while(0)
  615. #define __HAL_RCC_ADC1_CLK_ENABLE() do { \
  616. __IO uint32_t tmpreg; \
  617. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  618. /* Delay after an RCC peripheral clock enabling */\
  619. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  620. UNUSED(tmpreg); \
  621. } while(0)
  622. #define __HAL_RCC_TIM1_CLK_ENABLE() do { \
  623. __IO uint32_t tmpreg; \
  624. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  625. /* Delay after an RCC peripheral clock enabling */\
  626. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  627. UNUSED(tmpreg); \
  628. } while(0)
  629. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  630. __IO uint32_t tmpreg; \
  631. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  632. /* Delay after an RCC peripheral clock enabling */\
  633. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  634. UNUSED(tmpreg); \
  635. } while(0)
  636. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  637. __IO uint32_t tmpreg; \
  638. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  639. /* Delay after an RCC peripheral clock enabling */\
  640. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  641. UNUSED(tmpreg); \
  642. } while(0)
  643. #define __HAL_RCC_AFIO_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_AFIOEN))
  644. #define __HAL_RCC_GPIOA_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPAEN))
  645. #define __HAL_RCC_GPIOB_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPBEN))
  646. #define __HAL_RCC_GPIOC_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPCEN))
  647. #define __HAL_RCC_GPIOD_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPDEN))
  648. #define __HAL_RCC_ADC1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
  649. #define __HAL_RCC_TIM1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
  650. #define __HAL_RCC_SPI1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
  651. #define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  652. /**
  653. * @}
  654. */
  655. /** @defgroup RCC_APB2_Peripheral_Clock_Enable_Disable_Status APB2 Peripheral Clock Enable Disable Status
  656. * @brief Get the enable or disable status of the APB2 peripheral clock.
  657. * @note After reset, the peripheral clock (used for registers read/write access)
  658. * is disabled and the application software has to enable this clock before
  659. * using it.
  660. * @{
  661. */
  662. #define __HAL_RCC_AFIO_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_AFIOEN)) != RESET)
  663. #define __HAL_RCC_AFIO_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_AFIOEN)) == RESET)
  664. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPAEN)) != RESET)
  665. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPAEN)) == RESET)
  666. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPBEN)) != RESET)
  667. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPBEN)) == RESET)
  668. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPCEN)) != RESET)
  669. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPCEN)) == RESET)
  670. #define __HAL_RCC_GPIOD_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPDEN)) != RESET)
  671. #define __HAL_RCC_GPIOD_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPDEN)) == RESET)
  672. #define __HAL_RCC_ADC1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) != RESET)
  673. #define __HAL_RCC_ADC1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) == RESET)
  674. #define __HAL_RCC_TIM1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) != RESET)
  675. #define __HAL_RCC_TIM1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) == RESET)
  676. #define __HAL_RCC_SPI1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) != RESET)
  677. #define __HAL_RCC_SPI1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) == RESET)
  678. #define __HAL_RCC_USART1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) != RESET)
  679. #define __HAL_RCC_USART1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) == RESET)
  680. /**
  681. * @}
  682. */
  683. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Force Release Reset
  684. * @brief Force or release APB1 peripheral reset.
  685. * @{
  686. */
  687. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  688. #define __HAL_RCC_TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  689. #define __HAL_RCC_TIM3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
  690. #define __HAL_RCC_WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  691. #define __HAL_RCC_USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  692. #define __HAL_RCC_I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  693. #define __HAL_RCC_BKP_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_BKPRST))
  694. #define __HAL_RCC_PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  695. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00)
  696. #define __HAL_RCC_TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  697. #define __HAL_RCC_TIM3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
  698. #define __HAL_RCC_WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  699. #define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  700. #define __HAL_RCC_I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  701. #define __HAL_RCC_BKP_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_BKPRST))
  702. #define __HAL_RCC_PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  703. /**
  704. * @}
  705. */
  706. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Force Release Reset
  707. * @brief Force or release APB2 peripheral reset.
  708. * @{
  709. */
  710. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  711. #define __HAL_RCC_AFIO_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_AFIORST))
  712. #define __HAL_RCC_GPIOA_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPARST))
  713. #define __HAL_RCC_GPIOB_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPBRST))
  714. #define __HAL_RCC_GPIOC_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPCRST))
  715. #define __HAL_RCC_GPIOD_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPDRST))
  716. #define __HAL_RCC_ADC1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_ADC1RST))
  717. #define __HAL_RCC_TIM1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM1RST))
  718. #define __HAL_RCC_SPI1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
  719. #define __HAL_RCC_USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  720. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00)
  721. #define __HAL_RCC_AFIO_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_AFIORST))
  722. #define __HAL_RCC_GPIOA_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPARST))
  723. #define __HAL_RCC_GPIOB_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPBRST))
  724. #define __HAL_RCC_GPIOC_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPCRST))
  725. #define __HAL_RCC_GPIOD_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPDRST))
  726. #define __HAL_RCC_ADC1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADC1RST))
  727. #define __HAL_RCC_TIM1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM1RST))
  728. #define __HAL_RCC_SPI1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
  729. #define __HAL_RCC_USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  730. /**
  731. * @}
  732. */
  733. /** @defgroup RCC_HSI_Configuration HSI Configuration
  734. * @{
  735. */
  736. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  737. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  738. * @note HSI can not be stopped if it is used as system clock source. In this case,
  739. * you have to select another source of the system clock then stop the HSI.
  740. * @note After enabling the HSI, the application software should wait on HSIRDY
  741. * flag to be set indicating that HSI clock is stable and can be used as
  742. * system clock source.
  743. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  744. * clock cycles.
  745. */
  746. #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = ENABLE)
  747. #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = DISABLE)
  748. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  749. * @note The calibration is used to compensate for the variations in voltage
  750. * and temperature that influence the frequency of the internal HSI RC.
  751. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  752. * (default is RCC_HSICALIBRATION_DEFAULT).
  753. * This parameter must be a number between 0 and 0x1F.
  754. */
  755. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  756. (MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << POSITION_VAL(RCC_CR_HSITRIM)))
  757. /**
  758. * @}
  759. */
  760. /** @defgroup RCC_LSI_Configuration LSI Configuration
  761. * @{
  762. */
  763. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  764. * @note After enabling the LSI, the application software should wait on
  765. * LSIRDY flag to be set indicating that LSI clock is stable and can
  766. * be used to clock the IWDG and/or the RTC.
  767. */
  768. #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = ENABLE)
  769. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  770. * @note LSI can not be disabled if the IWDG is running.
  771. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  772. * clock cycles.
  773. */
  774. #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = DISABLE)
  775. /**
  776. * @}
  777. */
  778. /** @defgroup RCC_HSE_Configuration HSE Configuration
  779. * @{
  780. */
  781. /**
  782. * @brief Macro to configure the External High Speed oscillator (HSE).
  783. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  784. * supported by this macro. User should request a transition to HSE Off
  785. * first and then HSE On or HSE Bypass.
  786. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  787. * software should wait on HSERDY flag to be set indicating that HSE clock
  788. * is stable and can be used to clock the PLL and/or system clock.
  789. * @note HSE state can not be changed if it is used directly or through the
  790. * PLL as system clock. In this case, you have to select another source
  791. * of the system clock then change the HSE state (ex. disable it).
  792. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  793. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  794. * was previously enabled you have to enable it again after calling this
  795. * function.
  796. * @param __STATE__ specifies the new state of the HSE.
  797. * This parameter can be one of the following values:
  798. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  799. * 6 HSE oscillator clock cycles.
  800. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  801. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  802. */
  803. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  804. do{ \
  805. if ((__STATE__) == RCC_HSE_ON) \
  806. { \
  807. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  808. } \
  809. else if ((__STATE__) == RCC_HSE_OFF) \
  810. { \
  811. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  812. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  813. } \
  814. else if ((__STATE__) == RCC_HSE_BYPASS) \
  815. { \
  816. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  817. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  818. } \
  819. else \
  820. { \
  821. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  822. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  823. } \
  824. }while(0)
  825. /**
  826. * @}
  827. */
  828. /** @defgroup RCC_LSE_Configuration LSE Configuration
  829. * @{
  830. */
  831. /**
  832. * @brief Macro to configure the External Low Speed oscillator (LSE).
  833. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  834. * @note As the LSE is in the Backup domain and write access is denied to
  835. * this domain after reset, you have to enable write access using
  836. * @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  837. * (to be done once after reset).
  838. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  839. * software should wait on LSERDY flag to be set indicating that LSE clock
  840. * is stable and can be used to clock the RTC.
  841. * @param __STATE__ specifies the new state of the LSE.
  842. * This parameter can be one of the following values:
  843. * @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
  844. * 6 LSE oscillator clock cycles.
  845. * @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
  846. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  847. */
  848. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  849. do{ \
  850. if ((__STATE__) == RCC_LSE_ON) \
  851. { \
  852. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  853. } \
  854. else if ((__STATE__) == RCC_LSE_OFF) \
  855. { \
  856. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  857. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  858. } \
  859. else if ((__STATE__) == RCC_LSE_BYPASS) \
  860. { \
  861. SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  862. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  863. } \
  864. else \
  865. { \
  866. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  867. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  868. } \
  869. }while(0)
  870. /**
  871. * @}
  872. */
  873. /** @defgroup RCC_PLL_Configuration PLL Configuration
  874. * @{
  875. */
  876. /** @brief Macro to enable the main PLL.
  877. * @note After enabling the main PLL, the application software should wait on
  878. * PLLRDY flag to be set indicating that PLL clock is stable and can
  879. * be used as system clock source.
  880. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  881. */
  882. #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = ENABLE)
  883. /** @brief Macro to disable the main PLL.
  884. * @note The main PLL can not be disabled if it is used as system clock source
  885. */
  886. #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = DISABLE)
  887. /** @brief Macro to configure the main PLL clock source and multiplication factors.
  888. * @note This function must be used only when the main PLL is disabled.
  889. *
  890. * @param __RCC_PLLSOURCE__ specifies the PLL entry clock source.
  891. * This parameter can be one of the following values:
  892. * @arg @ref RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL clock entry
  893. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  894. * @param __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
  895. * This parameter can be one of the following values:
  896. * @arg @ref RCC_PLL_MUL4 PLLVCO = PLL clock entry x 4
  897. * @arg @ref RCC_PLL_MUL6 PLLVCO = PLL clock entry x 6
  898. @if STM32F105xC
  899. * @arg @ref RCC_PLL_MUL6_5 PLLVCO = PLL clock entry x 6.5
  900. @elseif STM32F107xC
  901. * @arg @ref RCC_PLL_MUL6_5 PLLVCO = PLL clock entry x 6.5
  902. @else
  903. * @arg @ref RCC_PLL_MUL2 PLLVCO = PLL clock entry x 2
  904. * @arg @ref RCC_PLL_MUL3 PLLVCO = PLL clock entry x 3
  905. * @arg @ref RCC_PLL_MUL10 PLLVCO = PLL clock entry x 10
  906. * @arg @ref RCC_PLL_MUL11 PLLVCO = PLL clock entry x 11
  907. * @arg @ref RCC_PLL_MUL12 PLLVCO = PLL clock entry x 12
  908. * @arg @ref RCC_PLL_MUL13 PLLVCO = PLL clock entry x 13
  909. * @arg @ref RCC_PLL_MUL14 PLLVCO = PLL clock entry x 14
  910. * @arg @ref RCC_PLL_MUL15 PLLVCO = PLL clock entry x 15
  911. * @arg @ref RCC_PLL_MUL16 PLLVCO = PLL clock entry x 16
  912. @endif
  913. * @arg @ref RCC_PLL_MUL8 PLLVCO = PLL clock entry x 8
  914. * @arg @ref RCC_PLL_MUL9 PLLVCO = PLL clock entry x 9
  915. *
  916. */
  917. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__)\
  918. MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL),((__RCC_PLLSOURCE__) | (__PLLMUL__) ))
  919. /** @brief Get oscillator clock selected as PLL input clock
  920. * @retval The clock source used for PLL entry. The returned value can be one
  921. * of the following:
  922. * @arg @ref RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL input clock
  923. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  924. */
  925. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  926. /**
  927. * @}
  928. */
  929. /** @defgroup RCC_Get_Clock_source Get Clock source
  930. * @{
  931. */
  932. /**
  933. * @brief Macro to configure the system clock source.
  934. * @param __SYSCLKSOURCE__ specifies the system clock source.
  935. * This parameter can be one of the following values:
  936. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  937. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  938. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  939. */
  940. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  941. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  942. /** @brief Macro to get the clock source used as system clock.
  943. * @retval The clock source used as system clock. The returned value can be one
  944. * of the following:
  945. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  946. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  947. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  948. */
  949. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  950. /**
  951. * @}
  952. */
  953. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  954. * @{
  955. */
  956. #if defined(RCC_CFGR_MCO_3)
  957. /** @brief Macro to configure the MCO clock.
  958. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  959. * This parameter can be one of the following values:
  960. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  961. * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock (SYSCLK) selected as MCO clock
  962. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  963. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  964. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO clock
  965. * @arg @ref RCC_MCO1SOURCE_PLL2CLK PLL2 clock selected by 2 selected as MCO clock
  966. * @arg @ref RCC_MCO1SOURCE_PLL3CLK_DIV2 PLL3 clock divided by 2 selected as MCO clock
  967. * @arg @ref RCC_MCO1SOURCE_EXT_HSE XT1 external 3-25 MHz oscillator clock selected (for Ethernet) as MCO clock
  968. * @arg @ref RCC_MCO1SOURCE_PLL3CLK PLL3 clock selected (for Ethernet) as MCO clock
  969. * @param __MCODIV__ specifies the MCO clock prescaler.
  970. * This parameter can be one of the following values:
  971. * @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
  972. */
  973. #else
  974. /** @brief Macro to configure the MCO clock.
  975. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  976. * This parameter can be one of the following values:
  977. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  978. * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock (SYSCLK) selected as MCO clock
  979. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  980. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  981. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO clock
  982. * @param __MCODIV__ specifies the MCO clock prescaler.
  983. * This parameter can be one of the following values:
  984. * @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
  985. */
  986. #endif
  987. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  988. MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, (__MCOCLKSOURCE__))
  989. /**
  990. * @}
  991. */
  992. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  993. * @{
  994. */
  995. /** @brief Macro to configure the RTC clock (RTCCLK).
  996. * @note As the RTC clock configuration bits are in the Backup domain and write
  997. * access is denied to this domain after reset, you have to enable write
  998. * access using the Power Backup Access macro before to configure
  999. * the RTC clock source (to be done once after reset).
  1000. * @note Once the RTC clock is configured it can't be changed unless the
  1001. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1002. * a Power On Reset (POR).
  1003. *
  1004. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  1005. * This parameter can be one of the following values:
  1006. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1007. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1008. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1009. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock
  1010. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1011. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1012. * However, when the HSE clock is used as RTC clock source, the RTC
  1013. * cannot be used in STOP and STANDBY modes.
  1014. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1015. * RTC clock source).
  1016. */
  1017. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, (__RTC_CLKSOURCE__))
  1018. /** @brief Macro to get the RTC clock source.
  1019. * @retval The clock source can be one of the following values:
  1020. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1021. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1022. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1023. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock
  1024. */
  1025. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL))
  1026. /** @brief Macro to enable the the RTC clock.
  1027. * @note These macros must be used only after the RTC clock source was selected.
  1028. */
  1029. #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = ENABLE)
  1030. /** @brief Macro to disable the the RTC clock.
  1031. * @note These macros must be used only after the RTC clock source was selected.
  1032. */
  1033. #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = DISABLE)
  1034. /** @brief Macro to force the Backup domain reset.
  1035. * @note This function resets the RTC peripheral (including the backup registers)
  1036. * and the RTC clock source selection in RCC_BDCR register.
  1037. */
  1038. #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = ENABLE)
  1039. /** @brief Macros to release the Backup domain reset.
  1040. */
  1041. #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = DISABLE)
  1042. /**
  1043. * @}
  1044. */
  1045. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1046. * @brief macros to manage the specified RCC Flags and interrupts.
  1047. * @{
  1048. */
  1049. /** @brief Enable RCC interrupt.
  1050. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1051. * This parameter can be any combination of the following values:
  1052. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1053. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1054. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1055. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1056. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1057. @if STM32F105xx
  1058. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1059. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1060. @elsif STM32F107xx
  1061. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1062. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1063. @endif
  1064. */
  1065. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  1066. /** @brief Disable RCC interrupt.
  1067. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1068. * This parameter can be any combination of the following values:
  1069. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1070. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1071. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1072. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1073. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1074. @if STM32F105xx
  1075. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1076. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1077. @elsif STM32F107xx
  1078. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1079. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1080. @endif
  1081. */
  1082. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= (uint8_t)(~(__INTERRUPT__)))
  1083. /** @brief Clear the RCC's interrupt pending bits.
  1084. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1085. * This parameter can be any combination of the following values:
  1086. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1087. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1088. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1089. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1090. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1091. @if STM32F105xx
  1092. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1093. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1094. @elsif STM32F107xx
  1095. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1096. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1097. @endif
  1098. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1099. */
  1100. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  1101. /** @brief Check the RCC's interrupt has occurred or not.
  1102. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1103. * This parameter can be one of the following values:
  1104. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1105. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1106. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1107. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1108. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1109. @if STM32F105xx
  1110. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1111. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1112. @elsif STM32F107xx
  1113. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  1114. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  1115. @endif
  1116. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1117. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1118. */
  1119. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  1120. /** @brief Set RMVF bit to clear the reset flags.
  1121. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1122. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1123. */
  1124. #define __HAL_RCC_CLEAR_RESET_FLAGS() (*(__IO uint32_t *)RCC_CSR_RMVF_BB = ENABLE)
  1125. /** @brief Check RCC flag is set or not.
  1126. * @param __FLAG__ specifies the flag to check.
  1127. * This parameter can be one of the following values:
  1128. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready.
  1129. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready.
  1130. * @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready.
  1131. @if STM32F105xx
  1132. * @arg @ref RCC_FLAG_PLL2RDY Main PLL2 clock ready.
  1133. * @arg @ref RCC_FLAG_PLLI2SRDY Main PLLI2S clock ready.
  1134. @elsif STM32F107xx
  1135. * @arg @ref RCC_FLAG_PLL2RDY Main PLL2 clock ready.
  1136. * @arg @ref RCC_FLAG_PLLI2SRDY Main PLLI2S clock ready.
  1137. @endif
  1138. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready.
  1139. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready.
  1140. * @arg @ref RCC_FLAG_PINRST Pin reset.
  1141. * @arg @ref RCC_FLAG_PORRST POR/PDR reset.
  1142. * @arg @ref RCC_FLAG_SFTRST Software reset.
  1143. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset.
  1144. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset.
  1145. * @arg @ref RCC_FLAG_LPWRRST Low Power reset.
  1146. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1147. */
  1148. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5) == CR_REG_INDEX)? RCC->CR : \
  1149. ((((__FLAG__) >> 5) == BDCR_REG_INDEX)? RCC->BDCR : \
  1150. RCC->CSR)) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK)))
  1151. /**
  1152. * @}
  1153. */
  1154. /**
  1155. * @}
  1156. */
  1157. /* Include RCC HAL Extension module */
  1158. #include "stm32f1xx_hal_rcc_ex.h"
  1159. /* Exported functions --------------------------------------------------------*/
  1160. /** @addtogroup RCC_Exported_Functions
  1161. * @{
  1162. */
  1163. /** @addtogroup RCC_Exported_Functions_Group1
  1164. * @{
  1165. */
  1166. /* Initialization and de-initialization functions ******************************/
  1167. void HAL_RCC_DeInit(void);
  1168. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1169. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1170. /**
  1171. * @}
  1172. */
  1173. /** @addtogroup RCC_Exported_Functions_Group2
  1174. * @{
  1175. */
  1176. /* Peripheral Control functions ************************************************/
  1177. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1178. void HAL_RCC_EnableCSS(void);
  1179. void HAL_RCC_DisableCSS(void);
  1180. uint32_t HAL_RCC_GetSysClockFreq(void);
  1181. uint32_t HAL_RCC_GetHCLKFreq(void);
  1182. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1183. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1184. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1185. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1186. /* CSS NMI IRQ handler */
  1187. void HAL_RCC_NMI_IRQHandler(void);
  1188. /* User Callbacks in non blocking mode (IT mode) */
  1189. void HAL_RCC_CSSCallback(void);
  1190. /**
  1191. * @}
  1192. */
  1193. /**
  1194. * @}
  1195. */
  1196. /**
  1197. * @}
  1198. */
  1199. /**
  1200. * @}
  1201. */
  1202. #ifdef __cplusplus
  1203. }
  1204. #endif
  1205. #endif /* __STM32F1xx_HAL_RCC_H */
  1206. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/