stm32f1xx_hal_rcc.h 67 KB

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