stm32f1xx_hal_rcc.h 67 KB

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