stm32f1xx_hal_rcc.h 65 KB

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