stm32f3xx_hal_rcc.h 88 KB

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