stm32f4xx_hal_rcc.h 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @version V1.3.0
  6. * @date 09-March-2015
  7. * @brief Header file of RCC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F4xx_HAL_RCC_H
  39. #define __STM32F4xx_HAL_RCC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal_def.h"
  45. /* Include RCC HAL Extended module */
  46. /* (include on top of file since RCC structures are defined in extended file) */
  47. #include "stm32f4xx_hal_rcc_ex.h"
  48. /** @addtogroup STM32F4xx_HAL_Driver
  49. * @{
  50. */
  51. /** @addtogroup RCC
  52. * @{
  53. */
  54. /* Exported types ------------------------------------------------------------*/
  55. /** @defgroup RCC_Exported_Types RCC Exported Types
  56. * @{
  57. */
  58. /**
  59. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  60. */
  61. typedef struct
  62. {
  63. uint32_t OscillatorType; /*!< The oscillators to be configured.
  64. This parameter can be a value of @ref RCC_Oscillator_Type */
  65. uint32_t HSEState; /*!< The new state of the HSE.
  66. This parameter can be a value of @ref RCC_HSE_Config */
  67. uint32_t LSEState; /*!< The new state of the LSE.
  68. This parameter can be a value of @ref RCC_LSE_Config */
  69. uint32_t HSIState; /*!< The new state of the HSI.
  70. This parameter can be a value of @ref RCC_HSI_Config */
  71. uint32_t HSICalibrationValue; /*!< The calibration trimming value.
  72. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1F */
  73. uint32_t LSIState; /*!< The new state of the LSI.
  74. This parameter can be a value of @ref RCC_LSI_Config */
  75. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  76. }RCC_OscInitTypeDef;
  77. /**
  78. * @brief RCC System, AHB and APB busses clock configuration structure definition
  79. */
  80. typedef struct
  81. {
  82. uint32_t ClockType; /*!< The clock to be configured.
  83. This parameter can be a value of @ref RCC_System_Clock_Type */
  84. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  85. This parameter can be a value of @ref RCC_System_Clock_Source */
  86. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  87. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  88. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  89. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  90. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  91. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  92. }RCC_ClkInitTypeDef;
  93. /**
  94. * @}
  95. */
  96. /* Exported constants --------------------------------------------------------*/
  97. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  98. * @{
  99. */
  100. /** @defgroup RCC_Oscillator_Type Oscillator Type
  101. * @{
  102. */
  103. #define RCC_OSCILLATORTYPE_NONE ((uint32_t)0x00000000)
  104. #define RCC_OSCILLATORTYPE_HSE ((uint32_t)0x00000001)
  105. #define RCC_OSCILLATORTYPE_HSI ((uint32_t)0x00000002)
  106. #define RCC_OSCILLATORTYPE_LSE ((uint32_t)0x00000004)
  107. #define RCC_OSCILLATORTYPE_LSI ((uint32_t)0x00000008)
  108. /**
  109. * @}
  110. */
  111. /** @defgroup RCC_HSE_Config HSE Config
  112. * @{
  113. */
  114. #define RCC_HSE_OFF ((uint8_t)0x00)
  115. #define RCC_HSE_ON ((uint8_t)0x01)
  116. #define RCC_HSE_BYPASS ((uint8_t)0x05)
  117. /**
  118. * @}
  119. */
  120. /** @defgroup RCC_LSE_Config LSE Config
  121. * @{
  122. */
  123. #define RCC_LSE_OFF ((uint8_t)0x00)
  124. #define RCC_LSE_ON ((uint8_t)0x01)
  125. #define RCC_LSE_BYPASS ((uint8_t)0x05)
  126. /**
  127. * @}
  128. */
  129. /** @defgroup RCC_HSI_Config HSI Config
  130. * @{
  131. */
  132. #define RCC_HSI_OFF ((uint8_t)0x00)
  133. #define RCC_HSI_ON ((uint8_t)0x01)
  134. /**
  135. * @}
  136. */
  137. /** @defgroup RCC_LSI_Config LSI Config
  138. * @{
  139. */
  140. #define RCC_LSI_OFF ((uint8_t)0x00)
  141. #define RCC_LSI_ON ((uint8_t)0x01)
  142. /**
  143. * @}
  144. */
  145. /** @defgroup RCC_PLL_Config PLL Config
  146. * @{
  147. */
  148. #define RCC_PLL_NONE ((uint8_t)0x00)
  149. #define RCC_PLL_OFF ((uint8_t)0x01)
  150. #define RCC_PLL_ON ((uint8_t)0x02)
  151. /**
  152. * @}
  153. */
  154. /** @defgroup RCC_PLLP_Clock_Divider PLLP Clock Divider
  155. * @{
  156. */
  157. #define RCC_PLLP_DIV2 ((uint32_t)0x00000002)
  158. #define RCC_PLLP_DIV4 ((uint32_t)0x00000004)
  159. #define RCC_PLLP_DIV6 ((uint32_t)0x00000006)
  160. #define RCC_PLLP_DIV8 ((uint32_t)0x00000008)
  161. /**
  162. * @}
  163. */
  164. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  165. * @{
  166. */
  167. #define RCC_PLLSOURCE_HSI RCC_PLLCFGR_PLLSRC_HSI
  168. #define RCC_PLLSOURCE_HSE RCC_PLLCFGR_PLLSRC_HSE
  169. /**
  170. * @}
  171. */
  172. /** @defgroup RCC_System_Clock_Type System Clock Type
  173. * @{
  174. */
  175. #define RCC_CLOCKTYPE_SYSCLK ((uint32_t)0x00000001)
  176. #define RCC_CLOCKTYPE_HCLK ((uint32_t)0x00000002)
  177. #define RCC_CLOCKTYPE_PCLK1 ((uint32_t)0x00000004)
  178. #define RCC_CLOCKTYPE_PCLK2 ((uint32_t)0x00000008)
  179. /**
  180. * @}
  181. */
  182. /** @defgroup RCC_System_Clock_Source System Clock Source
  183. * @{
  184. */
  185. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI
  186. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE
  187. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL
  188. #define RCC_SYSCLKSOURCE_PLLRCLK ((uint32_t)(RCC_CFGR_SW_0 | RCC_CFGR_SW_1))
  189. /**
  190. * @}
  191. */
  192. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  193. * @{
  194. */
  195. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  196. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  197. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  198. #define RCC_SYSCLKSOURCE_STATUS_PLLRCLK ((uint32_t)(RCC_CFGR_SW_0 | RCC_CFGR_SW_1)) /*!< PLLR used as system clock */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  203. * @{
  204. */
  205. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1
  206. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2
  207. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4
  208. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8
  209. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16
  210. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64
  211. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128
  212. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256
  213. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512
  214. /**
  215. * @}
  216. */
  217. /** @defgroup RCC_APB1_APB2_Clock_Source APB1/APB2 Clock Source
  218. * @{
  219. */
  220. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1
  221. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2
  222. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4
  223. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8
  224. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16
  225. /**
  226. * @}
  227. */
  228. /** @defgroup RCC_RTC_Clock_Source RTC Clock Source
  229. * @{
  230. */
  231. #define RCC_RTCCLKSOURCE_LSE ((uint32_t)0x00000100)
  232. #define RCC_RTCCLKSOURCE_LSI ((uint32_t)0x00000200)
  233. #define RCC_RTCCLKSOURCE_HSE_DIV2 ((uint32_t)0x00020300)
  234. #define RCC_RTCCLKSOURCE_HSE_DIV3 ((uint32_t)0x00030300)
  235. #define RCC_RTCCLKSOURCE_HSE_DIV4 ((uint32_t)0x00040300)
  236. #define RCC_RTCCLKSOURCE_HSE_DIV5 ((uint32_t)0x00050300)
  237. #define RCC_RTCCLKSOURCE_HSE_DIV6 ((uint32_t)0x00060300)
  238. #define RCC_RTCCLKSOURCE_HSE_DIV7 ((uint32_t)0x00070300)
  239. #define RCC_RTCCLKSOURCE_HSE_DIV8 ((uint32_t)0x00080300)
  240. #define RCC_RTCCLKSOURCE_HSE_DIV9 ((uint32_t)0x00090300)
  241. #define RCC_RTCCLKSOURCE_HSE_DIV10 ((uint32_t)0x000A0300)
  242. #define RCC_RTCCLKSOURCE_HSE_DIV11 ((uint32_t)0x000B0300)
  243. #define RCC_RTCCLKSOURCE_HSE_DIV12 ((uint32_t)0x000C0300)
  244. #define RCC_RTCCLKSOURCE_HSE_DIV13 ((uint32_t)0x000D0300)
  245. #define RCC_RTCCLKSOURCE_HSE_DIV14 ((uint32_t)0x000E0300)
  246. #define RCC_RTCCLKSOURCE_HSE_DIV15 ((uint32_t)0x000F0300)
  247. #define RCC_RTCCLKSOURCE_HSE_DIV16 ((uint32_t)0x00100300)
  248. #define RCC_RTCCLKSOURCE_HSE_DIV17 ((uint32_t)0x00110300)
  249. #define RCC_RTCCLKSOURCE_HSE_DIV18 ((uint32_t)0x00120300)
  250. #define RCC_RTCCLKSOURCE_HSE_DIV19 ((uint32_t)0x00130300)
  251. #define RCC_RTCCLKSOURCE_HSE_DIV20 ((uint32_t)0x00140300)
  252. #define RCC_RTCCLKSOURCE_HSE_DIV21 ((uint32_t)0x00150300)
  253. #define RCC_RTCCLKSOURCE_HSE_DIV22 ((uint32_t)0x00160300)
  254. #define RCC_RTCCLKSOURCE_HSE_DIV23 ((uint32_t)0x00170300)
  255. #define RCC_RTCCLKSOURCE_HSE_DIV24 ((uint32_t)0x00180300)
  256. #define RCC_RTCCLKSOURCE_HSE_DIV25 ((uint32_t)0x00190300)
  257. #define RCC_RTCCLKSOURCE_HSE_DIV26 ((uint32_t)0x001A0300)
  258. #define RCC_RTCCLKSOURCE_HSE_DIV27 ((uint32_t)0x001B0300)
  259. #define RCC_RTCCLKSOURCE_HSE_DIV28 ((uint32_t)0x001C0300)
  260. #define RCC_RTCCLKSOURCE_HSE_DIV29 ((uint32_t)0x001D0300)
  261. #define RCC_RTCCLKSOURCE_HSE_DIV30 ((uint32_t)0x001E0300)
  262. #define RCC_RTCCLKSOURCE_HSE_DIV31 ((uint32_t)0x001F0300)
  263. /**
  264. * @}
  265. */
  266. /** @defgroup RCC_I2S_Clock_Source I2S Clock Source
  267. * @{
  268. */
  269. #define RCC_I2SCLKSOURCE_PLLI2S ((uint32_t)0x00000000)
  270. #define RCC_I2SCLKSOURCE_EXT ((uint32_t)0x00000001)
  271. /**
  272. * @}
  273. */
  274. /** @defgroup RCC_MCO_Index MCO Index
  275. * @{
  276. */
  277. #define RCC_MCO1 ((uint32_t)0x00000000)
  278. #define RCC_MCO2 ((uint32_t)0x00000001)
  279. /**
  280. * @}
  281. */
  282. /** @defgroup RCC_MCO1_Clock_Source MCO1 Clock Source
  283. * @{
  284. */
  285. #define RCC_MCO1SOURCE_HSI ((uint32_t)0x00000000)
  286. #define RCC_MCO1SOURCE_LSE RCC_CFGR_MCO1_0
  287. #define RCC_MCO1SOURCE_HSE RCC_CFGR_MCO1_1
  288. #define RCC_MCO1SOURCE_PLLCLK RCC_CFGR_MCO1
  289. /**
  290. * @}
  291. */
  292. /** @defgroup RCC_MCO2_Clock_Source MCO2 Clock Source
  293. * @{
  294. */
  295. #define RCC_MCO2SOURCE_SYSCLK ((uint32_t)0x00000000)
  296. #define RCC_MCO2SOURCE_PLLI2SCLK RCC_CFGR_MCO2_0
  297. #define RCC_MCO2SOURCE_HSE RCC_CFGR_MCO2_1
  298. #define RCC_MCO2SOURCE_PLLCLK RCC_CFGR_MCO2
  299. /**
  300. * @}
  301. */
  302. /** @defgroup RCC_MCOx_Clock_Prescaler MCOx Clock Prescaler
  303. * @{
  304. */
  305. #define RCC_MCODIV_1 ((uint32_t)0x00000000)
  306. #define RCC_MCODIV_2 RCC_CFGR_MCO1PRE_2
  307. #define RCC_MCODIV_3 ((uint32_t)RCC_CFGR_MCO1PRE_0 | RCC_CFGR_MCO1PRE_2)
  308. #define RCC_MCODIV_4 ((uint32_t)RCC_CFGR_MCO1PRE_1 | RCC_CFGR_MCO1PRE_2)
  309. #define RCC_MCODIV_5 RCC_CFGR_MCO1PRE
  310. /**
  311. * @}
  312. */
  313. /** @defgroup RCC_Interrupt Interrupts
  314. * @{
  315. */
  316. #define RCC_IT_LSIRDY ((uint8_t)0x01)
  317. #define RCC_IT_LSERDY ((uint8_t)0x02)
  318. #define RCC_IT_HSIRDY ((uint8_t)0x04)
  319. #define RCC_IT_HSERDY ((uint8_t)0x08)
  320. #define RCC_IT_PLLRDY ((uint8_t)0x10)
  321. #define RCC_IT_PLLI2SRDY ((uint8_t)0x20)
  322. #define RCC_IT_CSS ((uint8_t)0x80)
  323. /**
  324. * @}
  325. */
  326. /** @defgroup RCC_Flag Flags
  327. * Elements values convention: 0XXYYYYYb
  328. * - YYYYY : Flag position in the register
  329. * - 0XX : Register index
  330. * - 01: CR register
  331. * - 10: BDCR register
  332. * - 11: CSR register
  333. * @{
  334. */
  335. /* Flags in the CR register */
  336. #define RCC_FLAG_HSIRDY ((uint8_t)0x21)
  337. #define RCC_FLAG_HSERDY ((uint8_t)0x31)
  338. #define RCC_FLAG_PLLRDY ((uint8_t)0x39)
  339. #define RCC_FLAG_PLLI2SRDY ((uint8_t)0x3B)
  340. /* Flags in the BDCR register */
  341. #define RCC_FLAG_LSERDY ((uint8_t)0x41)
  342. /* Flags in the CSR register */
  343. #define RCC_FLAG_LSIRDY ((uint8_t)0x61)
  344. #define RCC_FLAG_BORRST ((uint8_t)0x79)
  345. #define RCC_FLAG_PINRST ((uint8_t)0x7A)
  346. #define RCC_FLAG_PORRST ((uint8_t)0x7B)
  347. #define RCC_FLAG_SFTRST ((uint8_t)0x7C)
  348. #define RCC_FLAG_IWDGRST ((uint8_t)0x7D)
  349. #define RCC_FLAG_WWDGRST ((uint8_t)0x7E)
  350. #define RCC_FLAG_LPWRRST ((uint8_t)0x7F)
  351. /**
  352. * @}
  353. */
  354. /**
  355. * @}
  356. */
  357. /* Exported macro ------------------------------------------------------------*/
  358. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  359. * @{
  360. */
  361. /** @defgroup RCC_AHB1_Clock_Enable_Disable AHB1 Peripheral Clock Enable Disable
  362. * @brief Enable or disable the AHB1 peripheral clock.
  363. * @note After reset, the peripheral clock (used for registers read/write access)
  364. * is disabled and the application software has to enable this clock before
  365. * using it.
  366. * @{
  367. */
  368. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  369. __IO uint32_t tmpreg; \
  370. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN);\
  371. /* Delay after an RCC peripheral clock enabling */ \
  372. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN);\
  373. UNUSED(tmpreg); \
  374. } while(0)
  375. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  376. __IO uint32_t tmpreg; \
  377. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOBEN);\
  378. /* Delay after an RCC peripheral clock enabling */ \
  379. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOBEN);\
  380. UNUSED(tmpreg); \
  381. } while(0)
  382. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  383. __IO uint32_t tmpreg; \
  384. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);\
  385. /* Delay after an RCC peripheral clock enabling */ \
  386. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);\
  387. UNUSED(tmpreg); \
  388. } while(0)
  389. #define __HAL_RCC_GPIOD_CLK_ENABLE() do { \
  390. __IO uint32_t tmpreg; \
  391. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN);\
  392. /* Delay after an RCC peripheral clock enabling */ \
  393. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN);\
  394. UNUSED(tmpreg); \
  395. } while(0)
  396. #define __HAL_RCC_GPIOE_CLK_ENABLE() do { \
  397. __IO uint32_t tmpreg; \
  398. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOEEN);\
  399. /* Delay after an RCC peripheral clock enabling */ \
  400. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOEEN);\
  401. UNUSED(tmpreg); \
  402. } while(0)
  403. #define __HAL_RCC_GPIOH_CLK_ENABLE() do { \
  404. __IO uint32_t tmpreg; \
  405. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOHEN);\
  406. /* Delay after an RCC peripheral clock enabling */ \
  407. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOHEN);\
  408. UNUSED(tmpreg); \
  409. } while(0)
  410. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  411. __IO uint32_t tmpreg; \
  412. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_CRCEN);\
  413. /* Delay after an RCC peripheral clock enabling */ \
  414. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_CRCEN);\
  415. UNUSED(tmpreg); \
  416. } while(0)
  417. #define __HAL_RCC_BKPSRAM_CLK_ENABLE() do { \
  418. __IO uint32_t tmpreg; \
  419. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_BKPSRAMEN);\
  420. /* Delay after an RCC peripheral clock enabling */ \
  421. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_BKPSRAMEN);\
  422. UNUSED(tmpreg); \
  423. } while(0)
  424. #define __HAL_RCC_CCMDATARAMEN_CLK_ENABLE() do { \
  425. __IO uint32_t tmpreg; \
  426. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_CCMDATARAMEN);\
  427. /* Delay after an RCC peripheral clock enabling */ \
  428. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_CCMDATARAMEN);\
  429. UNUSED(tmpreg); \
  430. } while(0)
  431. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  432. __IO uint32_t tmpreg; \
  433. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_DMA1EN);\
  434. /* Delay after an RCC peripheral clock enabling */ \
  435. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_DMA1EN);\
  436. UNUSED(tmpreg); \
  437. } while(0)
  438. #define __HAL_RCC_DMA2_CLK_ENABLE() do { \
  439. __IO uint32_t tmpreg; \
  440. SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_DMA2EN);\
  441. /* Delay after an RCC peripheral clock enabling */ \
  442. tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_DMA2EN);\
  443. UNUSED(tmpreg); \
  444. } while(0)
  445. #define __HAL_RCC_GPIOA_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOAEN))
  446. #define __HAL_RCC_GPIOB_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOBEN))
  447. #define __HAL_RCC_GPIOC_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOCEN))
  448. #define __HAL_RCC_GPIOD_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIODEN))
  449. #define __HAL_RCC_GPIOE_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOEEN))
  450. #define __HAL_RCC_GPIOH_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOHEN))
  451. #define __HAL_RCC_CRC_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_CRCEN))
  452. #define __HAL_RCC_BKPSRAM_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_BKPSRAMEN))
  453. #define __HAL_RCC_CCMDATARAMEN_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_CCMDATARAMEN))
  454. #define __HAL_RCC_DMA1_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_DMA1EN))
  455. #define __HAL_RCC_DMA2_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_DMA2EN))
  456. /**
  457. * @}
  458. */
  459. /** @defgroup RCC_AHB2_Clock_Enable_Disable AHB2 Peripheral Clock Enable Disable
  460. * @brief Enable or disable the AHB2 peripheral clock.
  461. * @note After reset, the peripheral clock (used for registers read/write access)
  462. * is disabled and the application software has to enable this clock before
  463. * using it.
  464. * @{
  465. */
  466. #define __HAL_RCC_USB_OTG_FS_CLK_ENABLE() do {(RCC->AHB2ENR |= (RCC_AHB2ENR_OTGFSEN));\
  467. __HAL_RCC_SYSCFG_CLK_ENABLE();\
  468. }while(0)
  469. #define __HAL_RCC_USB_OTG_FS_CLK_DISABLE() do { (RCC->AHB2ENR &= ~(RCC_AHB2ENR_OTGFSEN));\
  470. __HAL_RCC_SYSCFG_CLK_DISABLE();\
  471. }while(0)
  472. #define __HAL_RCC_RNG_CLK_ENABLE() (RCC->AHB2ENR |= (RCC_AHB2ENR_RNGEN))
  473. #define __HAL_RCC_RNG_CLK_DISABLE() (RCC->AHB2ENR &= ~(RCC_AHB2ENR_RNGEN))
  474. /**
  475. * @}
  476. */
  477. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Peripheral Clock Enable Disable
  478. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  479. * @note After reset, the peripheral clock (used for registers read/write access)
  480. * is disabled and the application software has to enable this clock before
  481. * using it.
  482. * @{
  483. */
  484. #define __HAL_RCC_TIM2_CLK_ENABLE() do { \
  485. __IO uint32_t tmpreg; \
  486. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  487. /* Delay after an RCC peripheral clock enabling */ \
  488. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  489. UNUSED(tmpreg); \
  490. } while(0)
  491. #define __HAL_RCC_TIM3_CLK_ENABLE() do { \
  492. __IO uint32_t tmpreg; \
  493. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  494. /* Delay after an RCC peripheral clock enabling */ \
  495. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  496. UNUSED(tmpreg); \
  497. } while(0)
  498. #define __HAL_RCC_TIM4_CLK_ENABLE() do { \
  499. __IO uint32_t tmpreg; \
  500. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM4EN);\
  501. /* Delay after an RCC peripheral clock enabling */ \
  502. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM4EN);\
  503. UNUSED(tmpreg); \
  504. } while(0)
  505. #define __HAL_RCC_TIM5_CLK_ENABLE() do { \
  506. __IO uint32_t tmpreg; \
  507. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM5EN);\
  508. /* Delay after an RCC peripheral clock enabling */ \
  509. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM5EN);\
  510. UNUSED(tmpreg); \
  511. } while(0)
  512. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  513. __IO uint32_t tmpreg; \
  514. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  515. /* Delay after an RCC peripheral clock enabling */ \
  516. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  517. UNUSED(tmpreg); \
  518. } while(0)
  519. #define __HAL_RCC_SPI2_CLK_ENABLE() do { \
  520. __IO uint32_t tmpreg; \
  521. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI2EN);\
  522. /* Delay after an RCC peripheral clock enabling */ \
  523. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI2EN);\
  524. UNUSED(tmpreg); \
  525. } while(0)
  526. #define __HAL_RCC_SPI3_CLK_ENABLE() do { \
  527. __IO uint32_t tmpreg; \
  528. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI3EN);\
  529. /* Delay after an RCC peripheral clock enabling */ \
  530. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI3EN);\
  531. UNUSED(tmpreg); \
  532. } while(0)
  533. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  534. __IO uint32_t tmpreg; \
  535. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  536. /* Delay after an RCC peripheral clock enabling */ \
  537. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  538. UNUSED(tmpreg); \
  539. } while(0)
  540. #define __HAL_RCC_I2C1_CLK_ENABLE() do { \
  541. __IO uint32_t tmpreg; \
  542. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  543. /* Delay after an RCC peripheral clock enabling */ \
  544. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  545. UNUSED(tmpreg); \
  546. } while(0)
  547. #define __HAL_RCC_I2C2_CLK_ENABLE() do { \
  548. __IO uint32_t tmpreg; \
  549. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C2EN);\
  550. /* Delay after an RCC peripheral clock enabling */ \
  551. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C2EN);\
  552. UNUSED(tmpreg); \
  553. } while(0)
  554. #define __HAL_RCC_I2C3_CLK_ENABLE() do { \
  555. __IO uint32_t tmpreg; \
  556. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C3EN);\
  557. /* Delay after an RCC peripheral clock enabling */ \
  558. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C3EN);\
  559. UNUSED(tmpreg); \
  560. } while(0)
  561. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  562. __IO uint32_t tmpreg; \
  563. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  564. /* Delay after an RCC peripheral clock enabling */ \
  565. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  566. UNUSED(tmpreg); \
  567. } while(0)
  568. #define __HAL_RCC_TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  569. #define __HAL_RCC_TIM3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
  570. #define __HAL_RCC_TIM4_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM4EN))
  571. #define __HAL_RCC_TIM5_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM5EN))
  572. #define __HAL_RCC_WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  573. #define __HAL_RCC_SPI2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI2EN))
  574. #define __HAL_RCC_SPI3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI3EN))
  575. #define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  576. #define __HAL_RCC_I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  577. #define __HAL_RCC_I2C2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C2EN))
  578. #define __HAL_RCC_I2C3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C3EN))
  579. #define __HAL_RCC_PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  580. /**
  581. * @}
  582. */
  583. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Peripheral Clock Enable Disable
  584. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  585. * @note After reset, the peripheral clock (used for registers read/write access)
  586. * is disabled and the application software has to enable this clock before
  587. * using it.
  588. * @{
  589. */
  590. #define __HAL_RCC_TIM1_CLK_ENABLE() do { \
  591. __IO uint32_t tmpreg; \
  592. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  593. /* Delay after an RCC peripheral clock enabling */ \
  594. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  595. UNUSED(tmpreg); \
  596. } while(0)
  597. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  598. __IO uint32_t tmpreg; \
  599. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  600. /* Delay after an RCC peripheral clock enabling */ \
  601. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  602. UNUSED(tmpreg); \
  603. } while(0)
  604. #define __HAL_RCC_USART6_CLK_ENABLE() do { \
  605. __IO uint32_t tmpreg; \
  606. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART6EN);\
  607. /* Delay after an RCC peripheral clock enabling */ \
  608. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART6EN);\
  609. UNUSED(tmpreg); \
  610. } while(0)
  611. #define __HAL_RCC_ADC1_CLK_ENABLE() do { \
  612. __IO uint32_t tmpreg; \
  613. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  614. /* Delay after an RCC peripheral clock enabling */ \
  615. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  616. UNUSED(tmpreg); \
  617. } while(0)
  618. #define __HAL_RCC_SDIO_CLK_ENABLE() do { \
  619. __IO uint32_t tmpreg; \
  620. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SDIOEN);\
  621. /* Delay after an RCC peripheral clock enabling */ \
  622. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SDIOEN);\
  623. UNUSED(tmpreg); \
  624. } while(0)
  625. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  626. __IO uint32_t tmpreg; \
  627. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  628. /* Delay after an RCC peripheral clock enabling */ \
  629. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  630. UNUSED(tmpreg); \
  631. } while(0)
  632. #define __HAL_RCC_SPI4_CLK_ENABLE() do { \
  633. __IO uint32_t tmpreg; \
  634. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI4EN);\
  635. /* Delay after an RCC peripheral clock enabling */ \
  636. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI4EN);\
  637. UNUSED(tmpreg); \
  638. } while(0)
  639. #define __HAL_RCC_SYSCFG_CLK_ENABLE() do { \
  640. __IO uint32_t tmpreg; \
  641. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  642. /* Delay after an RCC peripheral clock enabling */ \
  643. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  644. UNUSED(tmpreg); \
  645. } while(0)
  646. #define __HAL_RCC_TIM9_CLK_ENABLE() do { \
  647. __IO uint32_t tmpreg; \
  648. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM9EN);\
  649. /* Delay after an RCC peripheral clock enabling */ \
  650. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM9EN);\
  651. UNUSED(tmpreg); \
  652. } while(0)
  653. #define __HAL_RCC_TIM10_CLK_ENABLE() do { \
  654. __IO uint32_t tmpreg; \
  655. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM10EN);\
  656. /* Delay after an RCC peripheral clock enabling */ \
  657. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM10EN);\
  658. UNUSED(tmpreg); \
  659. } while(0)
  660. #define __HAL_RCC_TIM11_CLK_ENABLE() do { \
  661. __IO uint32_t tmpreg; \
  662. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM11EN);\
  663. /* Delay after an RCC peripheral clock enabling */ \
  664. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM11EN);\
  665. UNUSED(tmpreg); \
  666. } while(0)
  667. #define __HAL_RCC_TIM1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
  668. #define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  669. #define __HAL_RCC_USART6_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART6EN))
  670. #define __HAL_RCC_ADC1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
  671. #define __HAL_RCC_SDIO_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SDIOEN))
  672. #define __HAL_RCC_SPI1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
  673. #define __HAL_RCC_SPI4_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI4EN))
  674. #define __HAL_RCC_SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
  675. #define __HAL_RCC_TIM9_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM9EN))
  676. #define __HAL_RCC_TIM10_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM10EN))
  677. #define __HAL_RCC_TIM11_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM11EN))
  678. /**
  679. * @}
  680. */
  681. /** @defgroup RCC_AHB1_Force_Release_Reset AHB1 Force Release Reset
  682. * @brief Force or release AHB1 peripheral reset.
  683. * @{
  684. */
  685. #define __HAL_RCC_AHB1_FORCE_RESET() (RCC->AHB1RSTR = 0xFFFFFFFF)
  686. #define __HAL_RCC_GPIOA_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOARST))
  687. #define __HAL_RCC_GPIOB_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOBRST))
  688. #define __HAL_RCC_GPIOC_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOCRST))
  689. #define __HAL_RCC_GPIOD_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIODRST))
  690. #define __HAL_RCC_GPIOE_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOERST))
  691. #define __HAL_RCC_GPIOH_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOHRST))
  692. #define __HAL_RCC_CRC_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_CRCRST))
  693. #define __HAL_RCC_DMA1_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_DMA1RST))
  694. #define __HAL_RCC_DMA2_FORCE_RESET() (RCC->AHB1RSTR |= (RCC_AHB1RSTR_DMA2RST))
  695. #define __HAL_RCC_AHB1_RELEASE_RESET() (RCC->AHB1RSTR = 0x00)
  696. #define __HAL_RCC_GPIOA_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOARST))
  697. #define __HAL_RCC_GPIOB_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOBRST))
  698. #define __HAL_RCC_GPIOC_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOCRST))
  699. #define __HAL_RCC_GPIOD_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIODRST))
  700. #define __HAL_RCC_GPIOE_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOERST))
  701. #define __HAL_RCC_GPIOF_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOFRST))
  702. #define __HAL_RCC_GPIOG_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOGRST))
  703. #define __HAL_RCC_GPIOH_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOHRST))
  704. #define __HAL_RCC_GPIOI_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOIRST))
  705. #define __HAL_RCC_CRC_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_CRCRST))
  706. #define __HAL_RCC_DMA1_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_DMA1RST))
  707. #define __HAL_RCC_DMA2_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_DMA2RST))
  708. /**
  709. * @}
  710. */
  711. /** @defgroup RCC_AHB2_Force_Release_Reset AHB2 Force Release Reset
  712. * @brief Force or release AHB2 peripheral reset.
  713. * @{
  714. */
  715. #define __HAL_RCC_AHB2_FORCE_RESET() (RCC->AHB2RSTR = 0xFFFFFFFF)
  716. #define __HAL_RCC_USB_OTG_FS_FORCE_RESET() (RCC->AHB2RSTR |= (RCC_AHB2RSTR_OTGFSRST))
  717. #define __HAL_RCC_AHB2_RELEASE_RESET() (RCC->AHB2RSTR = 0x00)
  718. #define __HAL_RCC_USB_OTG_FS_RELEASE_RESET() (RCC->AHB2RSTR &= ~(RCC_AHB2RSTR_OTGFSRST))
  719. #define __HAL_RCC_RNG_FORCE_RESET() (RCC->AHB2RSTR |= (RCC_AHB2RSTR_RNGRST))
  720. #define __HAL_RCC_RNG_RELEASE_RESET() (RCC->AHB2RSTR &= ~(RCC_AHB2RSTR_RNGRST))
  721. /**
  722. * @}
  723. */
  724. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Force Release Reset
  725. * @brief Force or release APB1 peripheral reset.
  726. * @{
  727. */
  728. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFF)
  729. #define __HAL_RCC_TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  730. #define __HAL_RCC_TIM3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
  731. #define __HAL_RCC_TIM4_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM4RST))
  732. #define __HAL_RCC_TIM5_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM5RST))
  733. #define __HAL_RCC_WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  734. #define __HAL_RCC_SPI2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI2RST))
  735. #define __HAL_RCC_SPI3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI3RST))
  736. #define __HAL_RCC_USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  737. #define __HAL_RCC_I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  738. #define __HAL_RCC_I2C2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C2RST))
  739. #define __HAL_RCC_I2C3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C3RST))
  740. #define __HAL_RCC_PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  741. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00)
  742. #define __HAL_RCC_TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  743. #define __HAL_RCC_TIM3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
  744. #define __HAL_RCC_TIM4_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM4RST))
  745. #define __HAL_RCC_TIM5_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM5RST))
  746. #define __HAL_RCC_WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  747. #define __HAL_RCC_SPI2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI2RST))
  748. #define __HAL_RCC_SPI3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI3RST))
  749. #define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  750. #define __HAL_RCC_I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  751. #define __HAL_RCC_I2C2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C2RST))
  752. #define __HAL_RCC_I2C3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C3RST))
  753. #define __HAL_RCC_PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  754. /**
  755. * @}
  756. */
  757. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Force Release Reset
  758. * @brief Force or release APB2 peripheral reset.
  759. * @{
  760. */
  761. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFF)
  762. #define __HAL_RCC_TIM1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM1RST))
  763. #define __HAL_RCC_USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  764. #define __HAL_RCC_USART6_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART6RST))
  765. #define __HAL_RCC_ADC_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_ADCRST))
  766. #define __HAL_RCC_SDIO_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SDIORST))
  767. #define __HAL_RCC_SPI1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
  768. #define __HAL_RCC_SPI4_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI4RST))
  769. #define __HAL_RCC_SYSCFG_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SYSCFGRST))
  770. #define __HAL_RCC_TIM9_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM9RST))
  771. #define __HAL_RCC_TIM10_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM10RST))
  772. #define __HAL_RCC_TIM11_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM11RST))
  773. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00)
  774. #define __HAL_RCC_TIM1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM1RST))
  775. #define __HAL_RCC_USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  776. #define __HAL_RCC_USART6_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART6RST))
  777. #define __HAL_RCC_ADC_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADCRST))
  778. #define __HAL_RCC_SDIO_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SDIORST))
  779. #define __HAL_RCC_SPI1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
  780. #define __HAL_RCC_SPI4_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI4RST))
  781. #define __HAL_RCC_SYSCFG_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SYSCFGRST))
  782. #define __HAL_RCC_TIM9_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM9RST))
  783. #define __HAL_RCC_TIM10_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM10RST))
  784. #define __HAL_RCC_TIM11_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM11RST))
  785. /**
  786. * @}
  787. */
  788. /** @defgroup RCC_AHB3_Force_Release_Reset AHB3 Force Release Reset
  789. * @brief Force or release AHB3 peripheral reset.
  790. * @{
  791. */
  792. #define __HAL_RCC_AHB3_FORCE_RESET() (RCC->AHB3RSTR = 0xFFFFFFFF)
  793. #define __HAL_RCC_AHB3_RELEASE_RESET() (RCC->AHB3RSTR = 0x00)
  794. /**
  795. * @}
  796. */
  797. /** @defgroup RCC_AHB1_LowPower_Enable_Disable AHB1 Peripheral Low Power Enable Disable
  798. * @brief Enable or disable the AHB1 peripheral clock during Low Power (Sleep) mode.
  799. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  800. * power consumption.
  801. * @note After wake-up from SLEEP mode, the peripheral clock is enabled again.
  802. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  803. * @{
  804. */
  805. #define __HAL_RCC_GPIOA_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOALPEN))
  806. #define __HAL_RCC_GPIOB_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOBLPEN))
  807. #define __HAL_RCC_GPIOC_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOCLPEN))
  808. #define __HAL_RCC_GPIOD_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIODLPEN))
  809. #define __HAL_RCC_GPIOE_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOELPEN))
  810. #define __HAL_RCC_GPIOH_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOHLPEN))
  811. #define __HAL_RCC_CRC_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_CRCLPEN))
  812. #define __HAL_RCC_FLITF_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_FLITFLPEN))
  813. #define __HAL_RCC_SRAM1_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_SRAM1LPEN))
  814. #define __HAL_RCC_BKPSRAM_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_BKPSRAMLPEN))
  815. #define __HAL_RCC_DMA1_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_DMA1LPEN))
  816. #define __HAL_RCC_DMA2_CLK_SLEEP_ENABLE() (RCC->AHB1LPENR |= (RCC_AHB1LPENR_DMA2LPEN))
  817. #define __HAL_RCC_GPIOA_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOALPEN))
  818. #define __HAL_RCC_GPIOB_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOBLPEN))
  819. #define __HAL_RCC_GPIOC_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOCLPEN))
  820. #define __HAL_RCC_GPIOD_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIODLPEN))
  821. #define __HAL_RCC_GPIOE_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOELPEN))
  822. #define __HAL_RCC_GPIOH_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOHLPEN))
  823. #define __HAL_RCC_CRC_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_CRCLPEN))
  824. #define __HAL_RCC_FLITF_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_FLITFLPEN))
  825. #define __HAL_RCC_SRAM1_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_SRAM1LPEN))
  826. #define __HAL_RCC_BKPSRAM_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_BKPSRAMLPEN))
  827. #define __HAL_RCC_DMA1_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_DMA1LPEN))
  828. #define __HAL_RCC_DMA2_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_DMA2LPEN))
  829. /**
  830. * @}
  831. */
  832. /** @defgroup RCC_AHB2_LowPower_Enable_Disable AHB2 Peripheral Low Power Enable Disable
  833. * @brief Enable or disable the AHB2 peripheral clock during Low Power (Sleep) mode.
  834. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  835. * power consumption.
  836. * @note After wake-up from SLEEP mode, the peripheral clock is enabled again.
  837. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  838. * @{
  839. */
  840. #define __HAL_RCC_USB_OTG_FS_CLK_SLEEP_ENABLE() (RCC->AHB2LPENR |= (RCC_AHB2LPENR_OTGFSLPEN))
  841. #define __HAL_RCC_USB_OTG_FS_CLK_SLEEP_DISABLE() (RCC->AHB2LPENR &= ~(RCC_AHB2LPENR_OTGFSLPEN))
  842. #define __HAL_RCC_RNG_CLK_SLEEP_ENABLE() (RCC->AHB2LPENR |= (RCC_AHB2LPENR_RNGLPEN))
  843. #define __HAL_RCC_RNG_CLK_SLEEP_DISABLE() (RCC->AHB2LPENR &= ~(RCC_AHB2LPENR_RNGLPEN))
  844. /**
  845. * @}
  846. */
  847. /** @defgroup RCC_APB1_LowPower_Enable_Disable APB1 Peripheral Low Power Enable Disable
  848. * @brief Enable or disable the APB1 peripheral clock during Low Power (Sleep) mode.
  849. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  850. * power consumption.
  851. * @note After wake-up from SLEEP mode, the peripheral clock is enabled again.
  852. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  853. * @{
  854. */
  855. #define __HAL_RCC_TIM2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM2LPEN))
  856. #define __HAL_RCC_TIM3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM3LPEN))
  857. #define __HAL_RCC_TIM4_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM4LPEN))
  858. #define __HAL_RCC_TIM5_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM5LPEN))
  859. #define __HAL_RCC_WWDG_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_WWDGLPEN))
  860. #define __HAL_RCC_SPI2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI2LPEN))
  861. #define __HAL_RCC_SPI3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI3LPEN))
  862. #define __HAL_RCC_USART2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USART2LPEN))
  863. #define __HAL_RCC_I2C1_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C1LPEN))
  864. #define __HAL_RCC_I2C2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C2LPEN))
  865. #define __HAL_RCC_I2C3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C3LPEN))
  866. #define __HAL_RCC_PWR_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_PWRLPEN))
  867. #define __HAL_RCC_TIM2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM2LPEN))
  868. #define __HAL_RCC_TIM3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM3LPEN))
  869. #define __HAL_RCC_TIM4_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM4LPEN))
  870. #define __HAL_RCC_TIM5_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM5LPEN))
  871. #define __HAL_RCC_WWDG_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_WWDGLPEN))
  872. #define __HAL_RCC_SPI2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI2LPEN))
  873. #define __HAL_RCC_SPI3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI3LPEN))
  874. #define __HAL_RCC_USART2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART2LPEN))
  875. #define __HAL_RCC_I2C1_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C1LPEN))
  876. #define __HAL_RCC_I2C2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C2LPEN))
  877. #define __HAL_RCC_I2C3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C3LPEN))
  878. #define __HAL_RCC_PWR_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_PWRLPEN))
  879. /**
  880. * @}
  881. */
  882. /** @defgroup RCC_APB2_LowPower_Enable_Disable APB2 Peripheral Low Power Enable Disable
  883. * @brief Enable or disable the APB2 peripheral clock during Low Power (Sleep) mode.
  884. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  885. * power consumption.
  886. * @note After wake-up from SLEEP mode, the peripheral clock is enabled again.
  887. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  888. * @{
  889. */
  890. #define __HAL_RCC_TIM1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM1LPEN))
  891. #define __HAL_RCC_USART1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_USART1LPEN))
  892. #define __HAL_RCC_USART6_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_USART6LPEN))
  893. #define __HAL_RCC_ADC1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_ADC1LPEN))
  894. #define __HAL_RCC_SDIO_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SDIOLPEN))
  895. #define __HAL_RCC_SPI1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SPI1LPEN))
  896. #define __HAL_RCC_SPI4_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SPI4LPEN))
  897. #define __HAL_RCC_SYSCFG_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SYSCFGLPEN))
  898. #define __HAL_RCC_TIM9_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM9LPEN))
  899. #define __HAL_RCC_TIM10_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM10LPEN))
  900. #define __HAL_RCC_TIM11_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM11LPEN))
  901. #define __HAL_RCC_TIM1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM1LPEN))
  902. #define __HAL_RCC_USART1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_USART1LPEN))
  903. #define __HAL_RCC_USART6_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_USART6LPEN))
  904. #define __HAL_RCC_ADC1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_ADC1LPEN))
  905. #define __HAL_RCC_SDIO_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SDIOLPEN))
  906. #define __HAL_RCC_SPI1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SPI1LPEN))
  907. #define __HAL_RCC_SPI4_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SPI4LPEN))
  908. #define __HAL_RCC_SYSCFG_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SYSCFGLPEN))
  909. #define __HAL_RCC_TIM9_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM9LPEN))
  910. #define __HAL_RCC_TIM10_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM10LPEN))
  911. #define __HAL_RCC_TIM11_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM11LPEN))
  912. /**
  913. * @}
  914. */
  915. /** @defgroup RCC_HSI_Configuration HSI Configuration
  916. * @{
  917. */
  918. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  919. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  920. * It is used (enabled by hardware) as system clock source after startup
  921. * from Reset, wake-up from STOP and STANDBY mode, or in case of failure
  922. * of the HSE used directly or indirectly as system clock (if the Clock
  923. * Security System CSS is enabled).
  924. * @note HSI can not be stopped if it is used as system clock source. In this case,
  925. * you have to select another source of the system clock then stop the HSI.
  926. * @note After enabling the HSI, the application software should wait on HSIRDY
  927. * flag to be set indicating that HSI clock is stable and can be used as
  928. * system clock source.
  929. * This parameter can be: ENABLE or DISABLE.
  930. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  931. * clock cycles.
  932. */
  933. #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = ENABLE)
  934. #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = DISABLE)
  935. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  936. * @note The calibration is used to compensate for the variations in voltage
  937. * and temperature that influence the frequency of the internal HSI RC.
  938. * @param __HSICalibrationValue__: specifies the calibration trimming value.
  939. * This parameter must be a number between 0 and 0x1F.
  940. */
  941. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(__HSICalibrationValue__) (MODIFY_REG(RCC->CR,\
  942. RCC_CR_HSITRIM, (uint32_t)(__HSICalibrationValue__) << POSITION_VAL(RCC_CR_HSITRIM)))
  943. /**
  944. * @}
  945. */
  946. /** @defgroup RCC_LSI_Configuration LSI Configuration
  947. * @{
  948. */
  949. /** @brief Macros to enable or disable the Internal Low Speed oscillator (LSI).
  950. * @note After enabling the LSI, the application software should wait on
  951. * LSIRDY flag to be set indicating that LSI clock is stable and can
  952. * be used to clock the IWDG and/or the RTC.
  953. * @note LSI can not be disabled if the IWDG is running.
  954. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  955. * clock cycles.
  956. */
  957. #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = ENABLE)
  958. #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = DISABLE)
  959. /**
  960. * @}
  961. */
  962. /** @defgroup RCC_HSE_Configuration HSE Configuration
  963. * @{
  964. */
  965. /**
  966. * @brief Macro to configure the External High Speed oscillator (HSE).
  967. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not supported by this macro.
  968. * User should request a transition to HSE Off first and then HSE On or HSE Bypass.
  969. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  970. * software should wait on HSERDY flag to be set indicating that HSE clock
  971. * is stable and can be used to clock the PLL and/or system clock.
  972. * @note HSE state can not be changed if it is used directly or through the
  973. * PLL as system clock. In this case, you have to select another source
  974. * of the system clock then change the HSE state (ex. disable it).
  975. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  976. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  977. * was previously enabled you have to enable it again after calling this
  978. * function.
  979. * @param __STATE__: specifies the new state of the HSE.
  980. * This parameter can be one of the following values:
  981. * @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
  982. * 6 HSE oscillator clock cycles.
  983. * @arg RCC_HSE_ON: turn ON the HSE oscillator.
  984. * @arg RCC_HSE_BYPASS: HSE oscillator bypassed with external clock.
  985. */
  986. #define __HAL_RCC_HSE_CONFIG(__STATE__) (*(__IO uint8_t *) RCC_CR_BYTE2_ADDRESS = (__STATE__))
  987. /**
  988. * @}
  989. */
  990. /** @defgroup RCC_LSE_Configuration LSE Configuration
  991. * @{
  992. */
  993. /**
  994. * @brief Macro to configure the External Low Speed oscillator (LSE).
  995. * @note Transition LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  996. * User should request a transition to LSE Off first and then LSE On or LSE Bypass.
  997. * @note As the LSE is in the Backup domain and write access is denied to
  998. * this domain after reset, you have to enable write access using
  999. * HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  1000. * (to be done once after reset).
  1001. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  1002. * software should wait on LSERDY flag to be set indicating that LSE clock
  1003. * is stable and can be used to clock the RTC.
  1004. * @param __STATE__: specifies the new state of the LSE.
  1005. * This parameter can be one of the following values:
  1006. * @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
  1007. * 6 LSE oscillator clock cycles.
  1008. * @arg RCC_LSE_ON: turn ON the LSE oscillator.
  1009. * @arg RCC_LSE_BYPASS: LSE oscillator bypassed with external clock.
  1010. */
  1011. #define __HAL_RCC_LSE_CONFIG(__STATE__) (*(__IO uint8_t *) RCC_BDCR_BYTE0_ADDRESS = (__STATE__))
  1012. /**
  1013. * @}
  1014. */
  1015. /** @defgroup RCC_Internal_RTC_Clock_Configuration RTC Clock Configuration
  1016. * @{
  1017. */
  1018. /** @brief Macros to enable or disable the RTC clock.
  1019. * @note These macros must be used only after the RTC clock source was selected.
  1020. */
  1021. #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = ENABLE)
  1022. #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = DISABLE)
  1023. /** @brief Macros to configure the RTC clock (RTCCLK).
  1024. * @note As the RTC clock configuration bits are in the Backup domain and write
  1025. * access is denied to this domain after reset, you have to enable write
  1026. * access using the Power Backup Access macro before to configure
  1027. * the RTC clock source (to be done once after reset).
  1028. * @note Once the RTC clock is configured it can't be changed unless the
  1029. * Backup domain is reset using __HAL_RCC_BackupReset_RELEASE() macro, or by
  1030. * a Power On Reset (POR).
  1031. * @param __RTCCLKSource__: specifies the RTC clock source.
  1032. * This parameter can be one of the following values:
  1033. * @arg RCC_RTCCLKSOURCE_LSE: LSE selected as RTC clock.
  1034. * @arg RCC_RTCCLKSOURCE_LSI: LSI selected as RTC clock.
  1035. * @arg RCC_RTCCLKSOURCE_HSE_DIVx: HSE clock divided by x selected
  1036. * as RTC clock, where x:[2,31]
  1037. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1038. * work in STOP and STANDBY modes, and can be used as wake-up source.
  1039. * However, when the HSE clock is used as RTC clock source, the RTC
  1040. * cannot be used in STOP and STANDBY modes.
  1041. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1042. * RTC clock source).
  1043. */
  1044. #define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__) (((__RTCCLKSource__) & RCC_BDCR_RTCSEL) == RCC_BDCR_RTCSEL) ? \
  1045. MODIFY_REG(RCC->CFGR, RCC_CFGR_RTCPRE, ((__RTCCLKSource__) & 0xFFFFCFF)) : CLEAR_BIT(RCC->CFGR, RCC_CFGR_RTCPRE)
  1046. #define __HAL_RCC_RTC_CONFIG(__RTCCLKSource__) do { __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__); \
  1047. RCC->BDCR |= ((__RTCCLKSource__) & 0x00000FFF); \
  1048. } while (0)
  1049. /** @brief Macros to force or release the Backup domain reset.
  1050. * @note This function resets the RTC peripheral (including the backup registers)
  1051. * and the RTC clock source selection in RCC_CSR register.
  1052. * @note The BKPSRAM is not affected by this reset.
  1053. */
  1054. #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = ENABLE)
  1055. #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = DISABLE)
  1056. /**
  1057. * @}
  1058. */
  1059. /** @defgroup RCC_PLL_Configuration PLL Configuration
  1060. * @{
  1061. */
  1062. /** @brief Macros to enable or disable the main PLL.
  1063. * @note After enabling the main PLL, the application software should wait on
  1064. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1065. * be used as system clock source.
  1066. * @note The main PLL can not be disabled if it is used as system clock source
  1067. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1068. */
  1069. #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = ENABLE)
  1070. #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = DISABLE)
  1071. /**
  1072. * @}
  1073. */
  1074. /** @brief Macro to configure the PLL clock source.
  1075. * @note This function must be used only when the main PLL is disabled.
  1076. * @param __PLLSOURCE__: specifies the PLL entry clock source.
  1077. * This parameter can be one of the following values:
  1078. * @arg RCC_PLLSOURCE_HSI: HSI oscillator clock selected as PLL clock entry
  1079. * @arg RCC_PLLSOURCE_HSE: HSE oscillator clock selected as PLL clock entry
  1080. *
  1081. */
  1082. #define __HAL_RCC_PLL_PLLSOURCE_CONFIG(__PLLSOURCE__) MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, (__PLLSOURCE__))
  1083. /** @brief Macro to configure the PLL multiplication factor.
  1084. * @note This function must be used only when the main PLL is disabled.
  1085. * @param __PLLM__: specifies the division factor for PLL VCO input clock
  1086. * This parameter must be a number between Min_Data = 2 and Max_Data = 63.
  1087. * @note You have to set the PLLM parameter correctly to ensure that the VCO input
  1088. * frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
  1089. * of 2 MHz to limit PLL jitter.
  1090. *
  1091. */
  1092. #define __HAL_RCC_PLL_PLLM_CONFIG(__PLLM__) MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLM, (__PLLM__))
  1093. /** @defgroup RCC_PLL_I2S_Configuration PLL I2S Configuration
  1094. * @{
  1095. */
  1096. /** @brief Macros to enable or disable the PLLI2S.
  1097. * @note The PLLI2S is disabled by hardware when entering STOP and STANDBY modes.
  1098. */
  1099. #define __HAL_RCC_PLLI2S_ENABLE() (*(__IO uint32_t *) RCC_CR_PLLI2SON_BB = ENABLE)
  1100. #define __HAL_RCC_PLLI2S_DISABLE() (*(__IO uint32_t *) RCC_CR_PLLI2SON_BB = DISABLE)
  1101. /**
  1102. * @}
  1103. */
  1104. /** @defgroup RCC_Get_Clock_source Get Clock source
  1105. * @{
  1106. */
  1107. /**
  1108. * @brief Macro to configure the system clock source.
  1109. * @param __RCC_SYSCLKSOURCE__: specifies the system clock source.
  1110. * This parameter can be one of the following values:
  1111. * - RCC_SYSCLKSOURCE_HSI: HSI oscillator is used as system clock source.
  1112. * - RCC_SYSCLKSOURCE_HSE: HSE oscillator is used as system clock source.
  1113. * - RCC_SYSCLKSOURCE_PLLCLK: PLL output is used as system clock source.
  1114. * - RCC_SYSCLKSOURCE_PLLRCLK: PLLR output is used as system clock source.
  1115. */
  1116. #define __HAL_RCC_SYSCLK_CONFIG(__RCC_SYSCLKSOURCE__) MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__RCC_SYSCLKSOURCE__))
  1117. /** @brief Macro to get the clock source used as system clock.
  1118. * @retval The clock source used as system clock. The returned value can be one
  1119. * of the following:
  1120. * - RCC_SYSCLKSOURCE_STATUS_HSI: HSI used as system clock.
  1121. * - RCC_SYSCLKSOURCE_STATUS_HSE: HSE used as system clock.
  1122. * - RCC_SYSCLKSOURCE_STATUS_PLLCLK: PLL used as system clock.
  1123. * - RCC_SYSCLKSOURCE_STATUS_PLLRCLK: PLLR used as system clock.
  1124. */
  1125. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(RCC->CFGR & RCC_CFGR_SWS))
  1126. /** @brief Macro to get the oscillator used as PLL clock source.
  1127. * @retval The oscillator used as PLL clock source. The returned value can be one
  1128. * of the following:
  1129. * - RCC_PLLSOURCE_HSI: HSI oscillator is used as PLL clock source.
  1130. * - RCC_PLLSOURCE_HSE: HSE oscillator is used as PLL clock source.
  1131. */
  1132. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC))
  1133. /**
  1134. * @}
  1135. */
  1136. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1137. * @brief macros to manage the specified RCC Flags and interrupts.
  1138. * @{
  1139. */
  1140. /** @brief Enable RCC interrupt (Perform Byte access to RCC_CIR[14:8] bits to enable
  1141. * the selected interrupts).
  1142. * @param __INTERRUPT__: specifies the RCC interrupt sources to be enabled.
  1143. * This parameter can be any combination of the following values:
  1144. * @arg RCC_IT_LSIRDY: LSI ready interrupt.
  1145. * @arg RCC_IT_LSERDY: LSE ready interrupt.
  1146. * @arg RCC_IT_HSIRDY: HSI ready interrupt.
  1147. * @arg RCC_IT_HSERDY: HSE ready interrupt.
  1148. * @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
  1149. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
  1150. */
  1151. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  1152. /** @brief Disable RCC interrupt (Perform Byte access to RCC_CIR[14:8] bits to disable
  1153. * the selected interrupts).
  1154. * @param __INTERRUPT__: specifies the RCC interrupt sources to be disabled.
  1155. * This parameter can be any combination of the following values:
  1156. * @arg RCC_IT_LSIRDY: LSI ready interrupt.
  1157. * @arg RCC_IT_LSERDY: LSE ready interrupt.
  1158. * @arg RCC_IT_HSIRDY: HSI ready interrupt.
  1159. * @arg RCC_IT_HSERDY: HSE ready interrupt.
  1160. * @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
  1161. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
  1162. */
  1163. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= ~(__INTERRUPT__))
  1164. /** @brief Clear the RCC's interrupt pending bits (Perform Byte access to RCC_CIR[23:16]
  1165. * bits to clear the selected interrupt pending bits.
  1166. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  1167. * This parameter can be any combination of the following values:
  1168. * @arg RCC_IT_LSIRDY: LSI ready interrupt.
  1169. * @arg RCC_IT_LSERDY: LSE ready interrupt.
  1170. * @arg RCC_IT_HSIRDY: HSI ready interrupt.
  1171. * @arg RCC_IT_HSERDY: HSE ready interrupt.
  1172. * @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
  1173. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
  1174. * @arg RCC_IT_CSS: Clock Security System interrupt
  1175. */
  1176. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  1177. /** @brief Check the RCC's interrupt has occurred or not.
  1178. * @param __INTERRUPT__: specifies the RCC interrupt source to check.
  1179. * This parameter can be one of the following values:
  1180. * @arg RCC_IT_LSIRDY: LSI ready interrupt.
  1181. * @arg RCC_IT_LSERDY: LSE ready interrupt.
  1182. * @arg RCC_IT_HSIRDY: HSI ready interrupt.
  1183. * @arg RCC_IT_HSERDY: HSE ready interrupt.
  1184. * @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
  1185. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
  1186. * @arg RCC_IT_CSS: Clock Security System interrupt
  1187. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1188. */
  1189. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  1190. /** @brief Set RMVF bit to clear the reset flags: RCC_FLAG_PINRST, RCC_FLAG_PORRST,
  1191. * RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST and RCC_FLAG_LPWRRST.
  1192. */
  1193. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1194. /** @brief Check RCC flag is set or not.
  1195. * @param __FLAG__: specifies the flag to check.
  1196. * This parameter can be one of the following values:
  1197. * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready.
  1198. * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready.
  1199. * @arg RCC_FLAG_PLLRDY: Main PLL clock ready.
  1200. * @arg RCC_FLAG_PLLI2SRDY: PLLI2S clock ready.
  1201. * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready.
  1202. * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready.
  1203. * @arg RCC_FLAG_BORRST: POR/PDR or BOR reset.
  1204. * @arg RCC_FLAG_PINRST: Pin reset.
  1205. * @arg RCC_FLAG_PORRST: POR/PDR reset.
  1206. * @arg RCC_FLAG_SFTRST: Software reset.
  1207. * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset.
  1208. * @arg RCC_FLAG_WWDGRST: Window Watchdog reset.
  1209. * @arg RCC_FLAG_LPWRRST: Low Power reset.
  1210. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1211. */
  1212. #define RCC_FLAG_MASK ((uint8_t)0x1F)
  1213. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((__FLAG__) >> 5) == 1)? RCC->CR :((((__FLAG__) >> 5) == 2) ? RCC->BDCR :((((__FLAG__) >> 5) == 3)? RCC->CSR :RCC->CIR))) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK)))!= 0)? 1 : 0)
  1214. /**
  1215. * @}
  1216. */
  1217. /**
  1218. * @}
  1219. */
  1220. /* Exported functions --------------------------------------------------------*/
  1221. /** @addtogroup RCC_Exported_Functions
  1222. * @{
  1223. */
  1224. /** @addtogroup RCC_Exported_Functions_Group1
  1225. * @{
  1226. */
  1227. /* Initialization and de-initialization functions ******************************/
  1228. void HAL_RCC_DeInit(void);
  1229. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1230. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1231. /**
  1232. * @}
  1233. */
  1234. /** @addtogroup RCC_Exported_Functions_Group2
  1235. * @{
  1236. */
  1237. /* Peripheral Control functions ************************************************/
  1238. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1239. void HAL_RCC_EnableCSS(void);
  1240. void HAL_RCC_DisableCSS(void);
  1241. uint32_t HAL_RCC_GetSysClockFreq(void);
  1242. uint32_t HAL_RCC_GetHCLKFreq(void);
  1243. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1244. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1245. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1246. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1247. /* CSS NMI IRQ handler */
  1248. void HAL_RCC_NMI_IRQHandler(void);
  1249. /* User Callbacks in non blocking mode (IT mode) */
  1250. void HAL_RCC_CSSCallback(void);
  1251. /**
  1252. * @}
  1253. */
  1254. /**
  1255. * @}
  1256. */
  1257. /* Private types -------------------------------------------------------------*/
  1258. /* Private variables ---------------------------------------------------------*/
  1259. /* Private constants ---------------------------------------------------------*/
  1260. /** @defgroup RCC_Private_Constants RCC Private Constants
  1261. * @{
  1262. */
  1263. /** @defgroup RCC_BitAddress_AliasRegion RCC BitAddress AliasRegion
  1264. * @brief RCC registers bit address in the alias region
  1265. * @{
  1266. */
  1267. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  1268. /* --- CR Register ---*/
  1269. /* Alias word address of HSION bit */
  1270. #define RCC_CR_OFFSET (RCC_OFFSET + 0x00)
  1271. #define RCC_HSION_BIT_NUMBER 0x00
  1272. #define RCC_CR_HSION_BB (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (RCC_HSION_BIT_NUMBER * 4))
  1273. /* Alias word address of CSSON bit */
  1274. #define RCC_CSSON_BIT_NUMBER 0x13
  1275. #define RCC_CR_CSSON_BB (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (RCC_CSSON_BIT_NUMBER * 4))
  1276. /* Alias word address of PLLON bit */
  1277. #define RCC_PLLON_BIT_NUMBER 0x18
  1278. #define RCC_CR_PLLON_BB (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (RCC_PLLON_BIT_NUMBER * 4))
  1279. /* Alias word address of PLLI2SON bit */
  1280. #define RCC_PLLI2SON_BIT_NUMBER 0x1A
  1281. #define RCC_CR_PLLI2SON_BB (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (RCC_PLLI2SON_BIT_NUMBER * 4))
  1282. /* --- CFGR Register ---*/
  1283. /* Alias word address of I2SSRC bit */
  1284. #define RCC_CFGR_OFFSET (RCC_OFFSET + 0x08)
  1285. #define RCC_I2SSRC_BIT_NUMBER 0x17
  1286. #define RCC_CFGR_I2SSRC_BB (PERIPH_BB_BASE + (RCC_CFGR_OFFSET * 32) + (RCC_I2SSRC_BIT_NUMBER * 4))
  1287. /* --- BDCR Register ---*/
  1288. /* Alias word address of RTCEN bit */
  1289. #define RCC_BDCR_OFFSET (RCC_OFFSET + 0x70)
  1290. #define RCC_RTCEN_BIT_NUMBER 0x0F
  1291. #define RCC_BDCR_RTCEN_BB (PERIPH_BB_BASE + (RCC_BDCR_OFFSET * 32) + (RCC_RTCEN_BIT_NUMBER * 4))
  1292. /* Alias word address of BDRST bit */
  1293. #define RCC_BDRST_BIT_NUMBER 0x10
  1294. #define RCC_BDCR_BDRST_BB (PERIPH_BB_BASE + (RCC_BDCR_OFFSET * 32) + (RCC_BDRST_BIT_NUMBER * 4))
  1295. /* --- CSR Register ---*/
  1296. /* Alias word address of LSION bit */
  1297. #define RCC_CSR_OFFSET (RCC_OFFSET + 0x74)
  1298. #define RCC_LSION_BIT_NUMBER 0x00
  1299. #define RCC_CSR_LSION_BB (PERIPH_BB_BASE + (RCC_CSR_OFFSET * 32) + (RCC_LSION_BIT_NUMBER * 4))
  1300. /* CR register byte 3 (Bits[23:16]) base address */
  1301. #define RCC_CR_BYTE2_ADDRESS ((uint32_t)0x40023802)
  1302. /* CIR register byte 2 (Bits[15:8]) base address */
  1303. #define RCC_CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + 0x0C + 0x01))
  1304. /* CIR register byte 3 (Bits[23:16]) base address */
  1305. #define RCC_CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + 0x0C + 0x02))
  1306. /* BDCR register base address */
  1307. #define RCC_BDCR_BYTE0_ADDRESS (PERIPH_BASE + RCC_BDCR_OFFSET)
  1308. #define RCC_DBP_TIMEOUT_VALUE ((uint32_t)100)
  1309. #define RCC_LSE_TIMEOUT_VALUE ((uint32_t)5000)
  1310. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  1311. #define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
  1312. #define LSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
  1313. #define PLLI2S_TIMEOUT_VALUE ((uint32_t)100) /* Timeout value fixed to 100 ms */
  1314. #define PLLSAI_TIMEOUT_VALUE ((uint32_t)100) /* Timeout value fixed to 100 ms */
  1315. /**
  1316. * @}
  1317. */
  1318. /**
  1319. * @}
  1320. */
  1321. /* Private macros ------------------------------------------------------------*/
  1322. /** @addtogroup RCC_Private_Macros RCC Private Macros
  1323. * @{
  1324. */
  1325. /** @defgroup RCC_IS_RCC_Definitions RCC Private macros to check input parameters
  1326. * @{
  1327. */
  1328. #define IS_RCC_OSCILLATORTYPE(OSCILLATOR) ((OSCILLATOR) <= 15)
  1329. #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
  1330. ((HSE) == RCC_HSE_BYPASS))
  1331. #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
  1332. ((LSE) == RCC_LSE_BYPASS))
  1333. #define IS_RCC_HSI(HSI) (((HSI) == RCC_HSI_OFF) || ((HSI) == RCC_HSI_ON))
  1334. #define IS_RCC_LSI(LSI) (((LSI) == RCC_LSI_OFF) || ((LSI) == RCC_LSI_ON))
  1335. #define IS_RCC_PLL(PLL) (((PLL) == RCC_PLL_NONE) ||((PLL) == RCC_PLL_OFF) || ((PLL) == RCC_PLL_ON))
  1336. #define IS_RCC_PLLSOURCE(SOURCE) (((SOURCE) == RCC_PLLSOURCE_HSI) || \
  1337. ((SOURCE) == RCC_PLLSOURCE_HSE))
  1338. #define IS_RCC_SYSCLKSOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSOURCE_HSI) || \
  1339. ((SOURCE) == RCC_SYSCLKSOURCE_HSE) || \
  1340. ((SOURCE) == RCC_SYSCLKSOURCE_PLLCLK) || \
  1341. ((SOURCE) == RCC_SYSCLKSOURCE_PLLRCLK))
  1342. #define IS_RCC_PLLM_VALUE(VALUE) ((VALUE) <= 63)
  1343. #define IS_RCC_PLLN_VALUE(VALUE) ((192 <= (VALUE)) && ((VALUE) <= 432))
  1344. #define IS_RCC_PLLP_VALUE(VALUE) (((VALUE) == 2) || ((VALUE) == 4) || ((VALUE) == 6) || ((VALUE) == 8))
  1345. #define IS_RCC_PLLQ_VALUE(VALUE) ((4 <= (VALUE)) && ((VALUE) <= 15))
  1346. #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_DIV1) || ((HCLK) == RCC_SYSCLK_DIV2) || \
  1347. ((HCLK) == RCC_SYSCLK_DIV4) || ((HCLK) == RCC_SYSCLK_DIV8) || \
  1348. ((HCLK) == RCC_SYSCLK_DIV16) || ((HCLK) == RCC_SYSCLK_DIV64) || \
  1349. ((HCLK) == RCC_SYSCLK_DIV128) || ((HCLK) == RCC_SYSCLK_DIV256) || \
  1350. ((HCLK) == RCC_SYSCLK_DIV512))
  1351. #define IS_RCC_CLOCKTYPE(CLK) ((1 <= (CLK)) && ((CLK) <= 15))
  1352. #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_DIV1) || ((PCLK) == RCC_HCLK_DIV2) || \
  1353. ((PCLK) == RCC_HCLK_DIV4) || ((PCLK) == RCC_HCLK_DIV8) || \
  1354. ((PCLK) == RCC_HCLK_DIV16))
  1355. #define IS_RCC_MCO(MCOx) (((MCOx) == RCC_MCO1) || ((MCOx) == RCC_MCO2))
  1356. #define IS_RCC_MCO1SOURCE(SOURCE) (((SOURCE) == RCC_MCO1SOURCE_HSI) || ((SOURCE) == RCC_MCO1SOURCE_LSE) || \
  1357. ((SOURCE) == RCC_MCO1SOURCE_HSE) || ((SOURCE) == RCC_MCO1SOURCE_PLLCLK))
  1358. #define IS_RCC_MCO2SOURCE(SOURCE) (((SOURCE) == RCC_MCO2SOURCE_SYSCLK) || ((SOURCE) == RCC_MCO2SOURCE_PLLI2SCLK)|| \
  1359. ((SOURCE) == RCC_MCO2SOURCE_HSE) || ((SOURCE) == RCC_MCO2SOURCE_PLLCLK))
  1360. #define IS_RCC_MCODIV(DIV) (((DIV) == RCC_MCODIV_1) || ((DIV) == RCC_MCODIV_2) || \
  1361. ((DIV) == RCC_MCODIV_3) || ((DIV) == RCC_MCODIV_4) || \
  1362. ((DIV) == RCC_MCODIV_5))
  1363. #define IS_RCC_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
  1364. /**
  1365. * @}
  1366. */
  1367. /**
  1368. * @}
  1369. */
  1370. /**
  1371. * @}
  1372. */
  1373. /**
  1374. * @}
  1375. */
  1376. #ifdef __cplusplus
  1377. }
  1378. #endif
  1379. #endif /* __STM32F4xx_HAL_RCC_H */
  1380. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/