stm32l1xx_hal_rcc.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 5-September-2014
  7. * @brief Header file of RCC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 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 __STM32L1xx_HAL_RCC_H
  39. #define __STM32L1xx_HAL_RCC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l1xx_hal_def.h"
  45. /** @addtogroup STM32L1xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup RCC
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup RCC_Exported_Types RCC Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief RCC PLL configuration structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t PLLState; /*!< The new state of the PLL.
  61. This parameter can be a value of @ref RCC_PLL_Config */
  62. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  63. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  64. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  65. This parameter must be a value of @ref RCC_PLL_Multiplication_Factor*/
  66. uint32_t PLLDIV; /*!< PLLDIV: Division factor for PLL VCO input clock
  67. This parameter must be a value of @ref RCC_PLL_Division_Factor*/
  68. } RCC_PLLInitTypeDef;
  69. /**
  70. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  71. */
  72. typedef struct
  73. {
  74. uint32_t OscillatorType; /*!< The oscillators to be configured.
  75. This parameter can be a value of @ref RCC_Oscillator_Type */
  76. uint32_t HSEState; /*!< The new state of the HSE.
  77. This parameter can be a value of @ref RCC_HSE_Config */
  78. uint32_t LSEState; /*!< The new state of the LSE.
  79. This parameter can be a value of @ref RCC_LSE_Config */
  80. uint32_t HSIState; /*!< The new state of the HSI.
  81. This parameter can be a value of @ref RCC_HSI_Config */
  82. uint32_t HSICalibrationValue; /*!< The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT).
  83. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1F */
  84. uint32_t LSIState; /*!< The new state of the LSI.
  85. This parameter can be a value of @ref RCC_LSI_Config */
  86. uint32_t MSIState; /*!< The new state of the MSI.
  87. This parameter can be a value of @ref RCC_MSI_Config */
  88. uint32_t MSICalibrationValue; /*!< The MSI calibration trimming value. (default is RCC_MSICALIBRATION_DEFAULT).
  89. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  90. uint32_t MSIClockRange; /*!< The MSI frequency range.
  91. This parameter can be a value of @ref RCC_MSI_Clock_Range */
  92. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  93. } RCC_OscInitTypeDef;
  94. /**
  95. * @brief RCC System, AHB and APB busses clock configuration structure definition
  96. */
  97. typedef struct
  98. {
  99. uint32_t ClockType; /*!< The clock to be configured.
  100. This parameter can be a value of @ref RCC_System_Clock_Type */
  101. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  102. This parameter can be a value of @ref RCC_System_Clock_Source */
  103. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  104. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  105. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  106. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  107. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  108. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  109. } RCC_ClkInitTypeDef;
  110. /**
  111. * @}
  112. */
  113. /* Exported constants --------------------------------------------------------*/
  114. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  115. * @{
  116. */
  117. #define DBP_TIMEOUT_VALUE ((uint32_t)100)
  118. #define LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  119. /** @defgroup RCC_BitAddress_AliasRegion RCC BitAddress AliasRegion
  120. * @brief RCC registers bit address in the alias region
  121. * @{
  122. */
  123. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  124. #define RCC_CR_OFFSET 0x00
  125. #define RCC_CFGR_OFFSET 0x08
  126. #define RCC_CIR_OFFSET 0x0C
  127. #define RCC_CSR_OFFSET 0x34
  128. #define RCC_CR_OFFSET_BB (RCC_OFFSET + RCC_CR_OFFSET)
  129. #define RCC_CFGR_OFFSET_BB (RCC_OFFSET + RCC_CFGR_OFFSET)
  130. #define RCC_CIR_OFFSET_BB (RCC_OFFSET + RCC_CIR_OFFSET)
  131. #define RCC_CSR_OFFSET_BB (RCC_OFFSET + RCC_CSR_OFFSET)
  132. /* --- CR Register ---*/
  133. /* Alias word address of HSION bit */
  134. #define HSION_BITNUMBER POSITION_VAL(RCC_CR_HSION)
  135. #define CR_HSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (HSION_BITNUMBER * 4)))
  136. /* Alias word address of MSION bit */
  137. #define MSION_BITNUMBER POSITION_VAL(RCC_CR_MSION)
  138. #define CR_MSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (MSION_BITNUMBER * 4)))
  139. /* Alias word address of HSEON bit */
  140. #define HSEON_BITNUMBER POSITION_VAL(RCC_CR_HSEON)
  141. #define CR_HSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (HSEON_BITNUMBER * 4)))
  142. /* Alias word address of CSSON bit */
  143. #define CSSON_BITNUMBER POSITION_VAL(RCC_CR_CSSON)
  144. #define CR_CSSON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (CSSON_BITNUMBER * 4)))
  145. /* Alias word address of PLLON bit */
  146. #define PLLON_BITNUMBER POSITION_VAL(RCC_CR_PLLON)
  147. #define CR_PLLON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32) + (PLLON_BITNUMBER * 4)))
  148. /* --- CSR Register ---*/
  149. /* Alias word address of LSION bit */
  150. #define LSION_BITNUMBER POSITION_VAL(RCC_CSR_LSION)
  151. #define CSR_LSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (LSION_BITNUMBER * 4)))
  152. /* Alias word address of LSEON bit */
  153. #define LSEON_BITNUMBER POSITION_VAL(RCC_CSR_LSEON)
  154. #define CSR_LSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (LSEON_BITNUMBER * 4)))
  155. /* Alias word address of LSEON bit */
  156. #define LSEBYP_BITNUMBER POSITION_VAL(RCC_CSR_LSEBYP)
  157. #define CSR_LSEBYP_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (LSEBYP_BITNUMBER * 4)))
  158. /* Alias word address of RTCEN bit */
  159. #define RTCEN_BITNUMBER POSITION_VAL(RCC_CSR_RTCEN)
  160. #define CSR_RTCEN_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (RTCEN_BITNUMBER * 4)))
  161. /* Alias word address of RTCRST bit */
  162. #define RTCRST_BITNUMBER POSITION_VAL(RCC_CSR_RTCRST)
  163. #define CSR_RTCRST_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32) + (RTCRST_BITNUMBER * 4)))
  164. /* CR register byte 2 (Bits[23:16]) base address */
  165. #define CR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02))
  166. /* CIR register byte 1 (Bits[15:8]) base address */
  167. #define CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01))
  168. /* CIR register byte 2 (Bits[23:16]) base address */
  169. #define CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02))
  170. /**
  171. * @}
  172. */
  173. /** @defgroup RCC_PLL_Clock_Source RCC PLL Clock Source
  174. * @{
  175. */
  176. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI
  177. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE
  178. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI) || \
  179. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  180. /**
  181. * @}
  182. */
  183. /** @defgroup RCC_Oscillator_Type RCC Oscillator Type
  184. * @{
  185. */
  186. #define RCC_OSCILLATORTYPE_NONE ((uint32_t)0x00000000)
  187. #define RCC_OSCILLATORTYPE_HSE ((uint32_t)0x00000001)
  188. #define RCC_OSCILLATORTYPE_HSI ((uint32_t)0x00000002)
  189. #define RCC_OSCILLATORTYPE_LSE ((uint32_t)0x00000004)
  190. #define RCC_OSCILLATORTYPE_LSI ((uint32_t)0x00000008)
  191. #define RCC_OSCILLATORTYPE_MSI ((uint32_t)0x00000010)
  192. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  193. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  194. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  195. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  196. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  197. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI))
  198. /**
  199. * @}
  200. */
  201. /** @defgroup RCC_HSE_Config RCC HSE Config
  202. * @{
  203. */
  204. #define RCC_HSE_OFF ((uint32_t)0x00000000)
  205. #define RCC_HSE_ON ((uint32_t)0x00000001)
  206. #define RCC_HSE_BYPASS ((uint32_t)0x00000005)
  207. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  208. ((__HSE__) == RCC_HSE_BYPASS))
  209. /**
  210. * @}
  211. */
  212. /** @defgroup RCC_LSE_Config RCC LSE Config
  213. * @{
  214. */
  215. #define RCC_LSE_OFF ((uint32_t)0x00000000)
  216. #define RCC_LSE_ON ((uint32_t)0x00000001)
  217. #define RCC_LSE_BYPASS ((uint32_t)0x00000005)
  218. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  219. ((__LSE__) == RCC_LSE_BYPASS))
  220. /**
  221. * @}
  222. */
  223. /** @defgroup RCC_HSI_Config RCC HSI Config
  224. * @{
  225. */
  226. #define RCC_HSI_OFF ((uint32_t)0x00000000)
  227. #define RCC_HSI_ON ((uint32_t)0x00000001)
  228. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  229. #define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10) /* Default HSI calibration trimming value */
  230. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1F)
  231. /**
  232. * @}
  233. */
  234. /** @defgroup RCC_MSI_Clock_Range RCC MSI Clock Range
  235. * @{
  236. */
  237. #define RCC_MSIRANGE_0 ((uint32_t)RCC_ICSCR_MSIRANGE_0) /*!< MSI = 65.536 KHz */
  238. #define RCC_MSIRANGE_1 ((uint32_t)RCC_ICSCR_MSIRANGE_1) /*!< MSI = 131.072 KHz */
  239. #define RCC_MSIRANGE_2 ((uint32_t)RCC_ICSCR_MSIRANGE_2) /*!< MSI = 262.144 KHz */
  240. #define RCC_MSIRANGE_3 ((uint32_t)RCC_ICSCR_MSIRANGE_3) /*!< MSI = 524.288 KHz */
  241. #define RCC_MSIRANGE_4 ((uint32_t)RCC_ICSCR_MSIRANGE_4) /*!< MSI = 1.048 MHz */
  242. #define RCC_MSIRANGE_5 ((uint32_t)RCC_ICSCR_MSIRANGE_5) /*!< MSI = 2.097 MHz */
  243. #define RCC_MSIRANGE_6 ((uint32_t)RCC_ICSCR_MSIRANGE_6) /*!< MSI = 4.194 MHz */
  244. #define IS_RCC_MSIRANGE(__RANGE__) (((__RANGE__) == RCC_MSIRANGE_0) || \
  245. ((__RANGE__) == RCC_MSIRANGE_1) || \
  246. ((__RANGE__) == RCC_MSIRANGE_2) || \
  247. ((__RANGE__) == RCC_MSIRANGE_3) || \
  248. ((__RANGE__) == RCC_MSIRANGE_4) || \
  249. ((__RANGE__) == RCC_MSIRANGE_5) || \
  250. ((__RANGE__) == RCC_MSIRANGE_6))
  251. /**
  252. * @}
  253. */
  254. /** @defgroup RCC_LSI_Config RCC LSI Config
  255. * @{
  256. */
  257. #define RCC_LSI_OFF ((uint32_t)0x00000000)
  258. #define RCC_LSI_ON ((uint32_t)0x00000001)
  259. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  260. /**
  261. * @}
  262. */
  263. /** @defgroup RCC_MSI_Config RCC MSI Config
  264. * @{
  265. */
  266. #define RCC_MSI_OFF ((uint32_t)0x00000000)
  267. #define RCC_MSI_ON ((uint32_t)0x00000001)
  268. #define IS_RCC_MSI(__MSI__) (((__MSI__) == RCC_MSI_OFF) || ((__MSI__) == RCC_MSI_ON))
  269. #define RCC_MSICALIBRATION_DEFAULT ((uint32_t)0x00) /* Default MSI calibration trimming value */
  270. /**
  271. * @}
  272. */
  273. /** @defgroup RCC_PLL_Config RCC PLL Config
  274. * @{
  275. */
  276. #define RCC_PLL_NONE ((uint32_t)0x00000000)
  277. #define RCC_PLL_OFF ((uint32_t)0x00000001)
  278. #define RCC_PLL_ON ((uint32_t)0x00000002)
  279. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  280. ((__PLL__) == RCC_PLL_ON))
  281. /**
  282. * @}
  283. */
  284. /** @defgroup RCC_PLL_Division_Factor RCC PLL Division Factor
  285. * @{
  286. */
  287. #define RCC_PLL_DIV2 RCC_CFGR_PLLDIV2
  288. #define RCC_PLL_DIV3 RCC_CFGR_PLLDIV3
  289. #define RCC_PLL_DIV4 RCC_CFGR_PLLDIV4
  290. #define IS_RCC_PLL_DIV(__DIV__) (((__DIV__) == RCC_PLL_DIV2) || \
  291. ((__DIV__) == RCC_PLL_DIV3) || ((__DIV__) == RCC_PLL_DIV4))
  292. /**
  293. * @}
  294. */
  295. /** @defgroup RCC_PLL_Multiplication_Factor RCC PLL Multiplication Factor
  296. * @{
  297. */
  298. #define RCC_PLL_MUL3 RCC_CFGR_PLLMUL3
  299. #define RCC_PLL_MUL4 RCC_CFGR_PLLMUL4
  300. #define RCC_PLL_MUL6 RCC_CFGR_PLLMUL6
  301. #define RCC_PLL_MUL8 RCC_CFGR_PLLMUL8
  302. #define RCC_PLL_MUL12 RCC_CFGR_PLLMUL12
  303. #define RCC_PLL_MUL16 RCC_CFGR_PLLMUL16
  304. #define RCC_PLL_MUL24 RCC_CFGR_PLLMUL24
  305. #define RCC_PLL_MUL32 RCC_CFGR_PLLMUL32
  306. #define RCC_PLL_MUL48 RCC_CFGR_PLLMUL48
  307. #define IS_RCC_PLL_MUL(__MUL__) (((__MUL__) == RCC_PLL_MUL3) || ((__MUL__) == RCC_PLL_MUL4) || \
  308. ((__MUL__) == RCC_PLL_MUL6) || ((__MUL__) == RCC_PLL_MUL8) || \
  309. ((__MUL__) == RCC_PLL_MUL12) || ((__MUL__) == RCC_PLL_MUL16) || \
  310. ((__MUL__) == RCC_PLL_MUL24) || ((__MUL__) == RCC_PLL_MUL32) || \
  311. ((__MUL__) == RCC_PLL_MUL48))
  312. /**
  313. * @}
  314. */
  315. /** @defgroup RCC_System_Clock_Type RCC System Clock Type
  316. * @{
  317. */
  318. #define RCC_CLOCKTYPE_SYSCLK ((uint32_t)0x00000001)
  319. #define RCC_CLOCKTYPE_HCLK ((uint32_t)0x00000002)
  320. #define RCC_CLOCKTYPE_PCLK1 ((uint32_t)0x00000004)
  321. #define RCC_CLOCKTYPE_PCLK2 ((uint32_t)0x00000008)
  322. #define IS_RCC_CLOCKTYPE(__CLK__) ((1 <= (__CLK__)) && ((__CLK__) <= 15))
  323. /**
  324. * @}
  325. */
  326. /** @defgroup RCC_System_Clock_Source RCC System Clock Source
  327. * @{
  328. */
  329. #define RCC_SYSCLKSOURCE_MSI ((uint32_t)RCC_CFGR_SW_MSI)
  330. #define RCC_SYSCLKSOURCE_HSI ((uint32_t)RCC_CFGR_SW_HSI)
  331. #define RCC_SYSCLKSOURCE_HSE ((uint32_t)RCC_CFGR_SW_HSE)
  332. #define RCC_SYSCLKSOURCE_PLLCLK ((uint32_t)RCC_CFGR_SW_PLL)
  333. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_MSI) || \
  334. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  335. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  336. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  337. /**
  338. * @}
  339. */
  340. /** @defgroup RCC_AHB_Clock_Source RCC AHB Clock Source
  341. * @{
  342. */
  343. #define RCC_SYSCLK_DIV1 ((uint32_t)RCC_CFGR_HPRE_DIV1)
  344. #define RCC_SYSCLK_DIV2 ((uint32_t)RCC_CFGR_HPRE_DIV2)
  345. #define RCC_SYSCLK_DIV4 ((uint32_t)RCC_CFGR_HPRE_DIV4)
  346. #define RCC_SYSCLK_DIV8 ((uint32_t)RCC_CFGR_HPRE_DIV8)
  347. #define RCC_SYSCLK_DIV16 ((uint32_t)RCC_CFGR_HPRE_DIV16)
  348. #define RCC_SYSCLK_DIV64 ((uint32_t)RCC_CFGR_HPRE_DIV64)
  349. #define RCC_SYSCLK_DIV128 ((uint32_t)RCC_CFGR_HPRE_DIV128)
  350. #define RCC_SYSCLK_DIV256 ((uint32_t)RCC_CFGR_HPRE_DIV256)
  351. #define RCC_SYSCLK_DIV512 ((uint32_t)RCC_CFGR_HPRE_DIV512)
  352. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  353. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  354. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  355. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  356. ((__HCLK__) == RCC_SYSCLK_DIV512))
  357. /**
  358. * @}
  359. */
  360. /** @defgroup RCC_APB1_APB2_Clock_Source RCC APB1 APB2 Clock Source
  361. * @{
  362. */
  363. #define RCC_HCLK_DIV1 ((uint32_t)RCC_CFGR_PPRE1_DIV1)
  364. #define RCC_HCLK_DIV2 ((uint32_t)RCC_CFGR_PPRE1_DIV2)
  365. #define RCC_HCLK_DIV4 ((uint32_t)RCC_CFGR_PPRE1_DIV4)
  366. #define RCC_HCLK_DIV8 ((uint32_t)RCC_CFGR_PPRE1_DIV8)
  367. #define RCC_HCLK_DIV16 ((uint32_t)RCC_CFGR_PPRE1_DIV16)
  368. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  369. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  370. ((__PCLK__) == RCC_HCLK_DIV16))
  371. /**
  372. * @}
  373. */
  374. /** @defgroup RCC_RTC_LCD_Clock_Source RCC RTC LCD Clock Source
  375. * @{
  376. */
  377. #define RCC_RTCCLKSOURCE_LSE ((uint32_t)RCC_CSR_RTCSEL_LSE)
  378. #define RCC_RTCCLKSOURCE_LSI ((uint32_t)RCC_CSR_RTCSEL_LSI)
  379. #define RCC_RTCCLKSOURCE_HSE_DIV2 ((uint32_t)RCC_CSR_RTCSEL_HSE)
  380. #define RCC_RTCCLKSOURCE_HSE_DIV4 ((uint32_t)(RCC_CR_RTCPRE_0 | RCC_CSR_RTCSEL_HSE))
  381. #define RCC_RTCCLKSOURCE_HSE_DIV8 ((uint32_t)(RCC_CR_RTCPRE_1 | RCC_CSR_RTCSEL_HSE))
  382. #define RCC_RTCCLKSOURCE_HSE_DIV16 ((uint32_t)(RCC_CR_RTCPRE | RCC_CSR_RTCSEL_HSE))
  383. /**
  384. * @}
  385. */
  386. /** @defgroup RCC_MCO_Index RCC MCO Index
  387. * @{
  388. */
  389. #define RCC_MCO1 ((uint32_t)0x00000000)
  390. #define RCC_MCO RCC_MCO1
  391. #define IS_RCC_MCO(__MCO__) (((__MCO__) == RCC_MCO))
  392. /**
  393. * @}
  394. */
  395. /** @defgroup RCC_MCOx_Clock_Prescaler RCC MCO1 Clock Prescaler
  396. * @{
  397. */
  398. #define RCC_MCODIV_1 ((uint32_t)RCC_CFGR_MCO_DIV1)
  399. #define RCC_MCODIV_2 ((uint32_t)RCC_CFGR_MCO_DIV2)
  400. #define RCC_MCODIV_4 ((uint32_t)RCC_CFGR_MCO_DIV4)
  401. #define RCC_MCODIV_8 ((uint32_t)RCC_CFGR_MCO_DIV8)
  402. #define RCC_MCODIV_16 ((uint32_t)RCC_CFGR_MCO_DIV16)
  403. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1) || ((__DIV__) == RCC_MCODIV_2) || \
  404. ((__DIV__) == RCC_MCODIV_4) || ((__DIV__) == RCC_MCODIV_8) || \
  405. ((__DIV__) == RCC_MCODIV_16))
  406. /**
  407. * @}
  408. */
  409. /** @defgroup RCC_MCO1_Clock_Source RCC MCO1 Clock Source
  410. * @{
  411. */
  412. #define RCC_MCO1SOURCE_NOCLOCK ((uint32_t)RCC_CFGR_MCO_NOCLOCK)
  413. #define RCC_MCO1SOURCE_SYSCLK ((uint32_t)RCC_CFGR_MCO_SYSCLK)
  414. #define RCC_MCO1SOURCE_MSI ((uint32_t)RCC_CFGR_MCO_MSI)
  415. #define RCC_MCO1SOURCE_HSI ((uint32_t)RCC_CFGR_MCO_HSI)
  416. #define RCC_MCO1SOURCE_LSE ((uint32_t)RCC_CFGR_MCO_LSE)
  417. #define RCC_MCO1SOURCE_LSI ((uint32_t)RCC_CFGR_MCO_LSI)
  418. #define RCC_MCO1SOURCE_HSE ((uint32_t)RCC_CFGR_MCO_HSE)
  419. #define RCC_MCO1SOURCE_PLLCLK ((uint32_t)RCC_CFGR_MCO_PLL)
  420. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || ((__SOURCE__) == RCC_MCO1SOURCE_MSI) \
  421. || ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || ((__SOURCE__) == RCC_MCO1SOURCE_LSE) \
  422. || ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || ((__SOURCE__) == RCC_MCO1SOURCE_HSE) \
  423. || ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || ((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK))
  424. /**
  425. * @}
  426. */
  427. /** @defgroup RCC_Interrupt RCC Interrupt
  428. * @{
  429. */
  430. #define RCC_IT_LSIRDY ((uint8_t)RCC_CIR_LSIRDYF)
  431. #define RCC_IT_LSERDY ((uint8_t)RCC_CIR_LSERDYF)
  432. #define RCC_IT_HSIRDY ((uint8_t)RCC_CIR_HSIRDYF)
  433. #define RCC_IT_HSERDY ((uint8_t)RCC_CIR_HSERDYF)
  434. #define RCC_IT_PLLRDY ((uint8_t)RCC_CIR_PLLRDYF)
  435. #define RCC_IT_MSIRDY ((uint8_t)RCC_CIR_MSIRDYF)
  436. #define RCC_IT_LSECSS ((uint8_t)RCC_CIR_LSECSS)
  437. #define RCC_IT_CSS ((uint8_t)RCC_CIR_CSSF)
  438. /**
  439. * @}
  440. */
  441. /** @defgroup RCC_Flag RCC Flag
  442. * Elements values convention: 0XXYYYYYb
  443. * - YYYYY : Flag position in the register
  444. * - XX : Register index
  445. * - 01: CR register
  446. * - 11: CSR register
  447. * @{
  448. */
  449. #define CR_REG_INDEX ((uint8_t)1)
  450. #define CSR_REG_INDEX ((uint8_t)3)
  451. /* Flags in the CR register */
  452. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_HSIRDY)))
  453. #define RCC_FLAG_MSIRDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_MSIRDY)))
  454. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_HSERDY)))
  455. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5) | POSITION_VAL(RCC_CR_PLLRDY)))
  456. /* Flags in the CSR register */
  457. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_LSIRDY)))
  458. #define RCC_FLAG_LSERDY ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_LSERDY)))
  459. #define RCC_FLAG_LSECSS ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_LSECSSD)))
  460. #define RCC_FLAG_RMV ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_RMVF)))
  461. #define RCC_FLAG_OBLRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_OBLRSTF)))
  462. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_PINRSTF)))
  463. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_PORRSTF)))
  464. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_SFTRSTF)))
  465. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_IWDGRSTF)))
  466. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_WWDGRSTF)))
  467. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5) | POSITION_VAL(RCC_CSR_LPWRRSTF)))
  468. #define RCC_FLAG_MASK ((uint8_t)0x1F)
  469. /**
  470. * @}
  471. */
  472. /**
  473. * @}
  474. */
  475. /* Exported macro ------------------------------------------------------------*/
  476. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  477. * @{
  478. */
  479. /** @defgroup RCC_Peripheral_Clock_Enable_Disable RCC Peripheral Clock Enable Disable
  480. * @brief Enable or disable the AHB1 peripheral clock.
  481. * @note After reset, the peripheral clock (used for registers read/write access)
  482. * is disabled and the application software has to enable this clock before
  483. * using it.
  484. * @{
  485. */
  486. #define __GPIOA_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_GPIOAEN))
  487. #define __GPIOB_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_GPIOBEN))
  488. #define __GPIOC_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_GPIOCEN))
  489. #define __GPIOD_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_GPIODEN))
  490. #define __GPIOH_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_GPIOHEN))
  491. #define __CRC_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_CRCEN))
  492. #define __FLITF_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_FLITFEN))
  493. #define __DMA1_CLK_ENABLE() (RCC->AHBENR |= (RCC_AHBENR_DMA1EN))
  494. #define __GPIOA_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOAEN))
  495. #define __GPIOB_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOBEN))
  496. #define __GPIOC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOCEN))
  497. #define __GPIOD_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIODEN))
  498. #define __GPIOH_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOHEN))
  499. #define __CRC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
  500. #define __FLITF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
  501. #define __DMA1_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
  502. /** @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  503. * @note After reset, the peripheral clock (used for registers read/write access)
  504. * is disabled and the application software has to enable this clock before
  505. * using it.
  506. */
  507. #define __TIM2_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_TIM2EN))
  508. #define __TIM3_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_TIM3EN))
  509. #define __TIM4_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_TIM4EN))
  510. #define __TIM6_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_TIM6EN))
  511. #define __TIM7_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_TIM7EN))
  512. #define __WWDG_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_WWDGEN))
  513. #define __SPI2_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_SPI2EN))
  514. #define __USART2_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_USART2EN))
  515. #define __USART3_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_USART3EN))
  516. #define __I2C1_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_I2C1EN))
  517. #define __I2C2_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_I2C2EN))
  518. #define __USB_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_USBEN))
  519. #define __PWR_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_PWREN))
  520. #define __DAC_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_DACEN))
  521. #define __COMP_CLK_ENABLE() (RCC->APB1ENR |= (RCC_APB1ENR_COMPEN))
  522. #define __TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  523. #define __TIM3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
  524. #define __TIM4_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM4EN))
  525. #define __TIM6_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM6EN))
  526. #define __TIM7_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM7EN))
  527. #define __WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  528. #define __SPI2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI2EN))
  529. #define __USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  530. #define __USART3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART3EN))
  531. #define __I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  532. #define __I2C2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C2EN))
  533. #define __USB_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USBEN))
  534. #define __PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  535. #define __DAC_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_DACEN))
  536. #define __COMP_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_COMPEN))
  537. /** @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  538. * @note After reset, the peripheral clock (used for registers read/write access)
  539. * is disabled and the application software has to enable this clock before
  540. * using it.
  541. */
  542. #define __SYSCFG_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_SYSCFGEN))
  543. #define __TIM9_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_TIM9EN))
  544. #define __TIM10_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_TIM10EN))
  545. #define __TIM11_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_TIM11EN))
  546. #define __ADC1_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_ADC1EN))
  547. #define __SPI1_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_SPI1EN))
  548. #define __USART1_CLK_ENABLE() (RCC->APB2ENR |= (RCC_APB2ENR_USART1EN))
  549. #define __SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
  550. #define __TIM9_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM9EN))
  551. #define __TIM10_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM10EN))
  552. #define __TIM11_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM11EN))
  553. #define __ADC1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
  554. #define __SPI1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
  555. #define __USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  556. /**
  557. * @}
  558. */
  559. /** @defgroup RCC_Peripheral_Clock_Force_Release RCC Peripheral Clock Force Release
  560. * @brief Force or release AHB peripheral reset.
  561. * @{
  562. */
  563. #define __AHB_FORCE_RESET() (RCC->AHBRSTR = 0xFFFFFFFF)
  564. #define __GPIOA_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOARST))
  565. #define __GPIOB_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOBRST))
  566. #define __GPIOC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOCRST))
  567. #define __GPIOD_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIODRST))
  568. #define __GPIOH_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOHRST))
  569. #define __CRC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_CRCRST))
  570. #define __FLITF_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_FLITFRST))
  571. #define __DMA1_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_DMA1RST))
  572. #define __AHB_RELEASE_RESET() (RCC->AHBRSTR = 0x00)
  573. #define __GPIOA_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOARST))
  574. #define __GPIOB_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOBRST))
  575. #define __GPIOC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOCRST))
  576. #define __GPIOD_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIODRST))
  577. #define __GPIOH_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOHRST))
  578. #define __CRC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_CRCRST))
  579. #define __FLITF_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_FLITFRST))
  580. #define __DMA1_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_DMA1RST))
  581. /** @brief Force or release APB1 peripheral reset.
  582. */
  583. #define __APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFF)
  584. #define __TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  585. #define __TIM3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
  586. #define __TIM4_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM4RST))
  587. #define __TIM6_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM6RST))
  588. #define __TIM7_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM7RST))
  589. #define __WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  590. #define __SPI2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI2RST))
  591. #define __USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  592. #define __USART3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART3RST))
  593. #define __I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  594. #define __I2C2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C2RST))
  595. #define __USB_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USBRST))
  596. #define __PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  597. #define __DAC_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_DACRST))
  598. #define __COMP_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_COMPRST))
  599. #define __APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00)
  600. #define __TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  601. #define __TIM3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
  602. #define __TIM4_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM4RST))
  603. #define __TIM6_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM6RST))
  604. #define __TIM7_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM7RST))
  605. #define __WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  606. #define __SPI2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI2RST))
  607. #define __USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  608. #define __USART3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART3RST))
  609. #define __I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  610. #define __I2C2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C2RST))
  611. #define __USB_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USBRST))
  612. #define __PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  613. #define __DAC_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_DACRST))
  614. #define __COMP_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_COMPRST))
  615. /** @brief Force or release APB2 peripheral reset.
  616. */
  617. #define __APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFF)
  618. #define __SYSCFG_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SYSCFGRST))
  619. #define __TIM9_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM9RST))
  620. #define __TIM10_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM10RST))
  621. #define __TIM11_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM11RST))
  622. #define __ADC1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_ADC1RST))
  623. #define __SPI1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
  624. #define __USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  625. #define __APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00)
  626. #define __SYSCFG_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SYSCFGRST))
  627. #define __TIM9_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM9RST))
  628. #define __TIM10_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM10RST))
  629. #define __TIM11_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM11RST))
  630. #define __ADC1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADC1RST))
  631. #define __SPI1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
  632. #define __USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  633. /**
  634. * @}
  635. */
  636. /** @defgroup RCC_Peripheral_Clock_Sleep_Enable_Disable RCC Peripheral Clock Sleep Enable Disable
  637. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  638. * power consumption.
  639. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  640. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  641. * @{
  642. */
  643. #define __GPIOA_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOALPEN))
  644. #define __GPIOB_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOBLPEN))
  645. #define __GPIOC_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOCLPEN))
  646. #define __GPIOD_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIODLPEN))
  647. #define __GPIOH_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOHLPEN))
  648. #define __CRC_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_CRCLPEN))
  649. #define __FLITF_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_FLITFLPEN))
  650. #define __DMA1_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_DMA1LPEN))
  651. #define __GPIOA_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOALPEN))
  652. #define __GPIOB_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOBLPEN))
  653. #define __GPIOC_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOCLPEN))
  654. #define __GPIOD_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIODLPEN))
  655. #define __GPIOH_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOHLPEN))
  656. #define __CRC_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_CRCLPEN))
  657. #define __FLITF_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_FLITFLPEN))
  658. #define __DMA1_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_DMA1LPEN))
  659. /** @brief Enable or disable the APB1 peripheral clock during Low Power (Sleep) mode.
  660. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  661. * power consumption.
  662. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  663. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  664. */
  665. #define __TIM2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM2LPEN))
  666. #define __TIM3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM3LPEN))
  667. #define __TIM4_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM4LPEN))
  668. #define __TIM6_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM6LPEN))
  669. #define __TIM7_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM7LPEN))
  670. #define __WWDG_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_WWDGLPEN))
  671. #define __SPI2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI2LPEN))
  672. #define __USART2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USART2LPEN))
  673. #define __USART3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USART3LPEN))
  674. #define __I2C1_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C1LPEN))
  675. #define __I2C2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C2LPEN))
  676. #define __USB_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USBLPEN))
  677. #define __PWR_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_PWRLPEN))
  678. #define __DAC_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_DACLPEN))
  679. #define __COMP_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_COMPLPEN))
  680. #define __TIM2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM2LPEN))
  681. #define __TIM3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM3LPEN))
  682. #define __TIM4_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM4LPEN))
  683. #define __TIM6_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM6LPEN))
  684. #define __TIM7_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM7LPEN))
  685. #define __WWDG_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_WWDGLPEN))
  686. #define __SPI2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI2LPEN))
  687. #define __USART2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART2LPEN))
  688. #define __USART3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART3LPEN))
  689. #define __I2C1_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C1LPEN))
  690. #define __I2C2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C2LPEN))
  691. #define __USB_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USBLPEN))
  692. #define __PWR_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_PWRLPEN))
  693. #define __DAC_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_DACLPEN))
  694. #define __COMP_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_COMPLPEN))
  695. /** @brief Enable or disable the APB2 peripheral clock during Low Power (Sleep) mode.
  696. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  697. * power consumption.
  698. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  699. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  700. */
  701. #define __SYSCFG_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SYSCFGLPEN))
  702. #define __TIM9_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM9LPEN))
  703. #define __TIM10_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM10LPEN))
  704. #define __TIM11_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM11LPEN))
  705. #define __ADC1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_ADC1LPEN))
  706. #define __SPI1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SPI1LPEN))
  707. #define __USART1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_USART1LPEN))
  708. #define __SYSCFG_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SYSCFGLPEN))
  709. #define __TIM9_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM9LPEN))
  710. #define __TIM10_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM10LPEN))
  711. #define __TIM11_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM11LPEN))
  712. #define __ADC1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_ADC1LPEN))
  713. #define __SPI1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SPI1LPEN))
  714. #define __USART1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_USART1LPEN))
  715. /**
  716. * @}
  717. */
  718. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  719. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  720. * @note HSI can not be stopped if it is used as system clock source. In this case,
  721. * you have to select another source of the system clock then stop the HSI.
  722. * @note After enabling the HSI, the application software should wait on HSIRDY
  723. * flag to be set indicating that HSI clock is stable and can be used as
  724. * system clock source.
  725. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  726. * clock cycles.
  727. */
  728. #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) CR_HSION_BB = ENABLE)
  729. #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) CR_HSION_BB = DISABLE)
  730. /** @brief Macros to enable or disable the External High Speed oscillator (HSE).
  731. * @param __HSE_STATE__: specifies the new state of the HSE.
  732. * This parameter can be one of the following values:
  733. * @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
  734. * 6 HSE oscillator clock cycles.
  735. * @arg RCC_HSE_ON: turn ON the HSE oscillator
  736. * @arg RCC_HSE_BYPASS: HSE oscillator bypassed with external clock
  737. */
  738. #define __HAL_RCC_HSE_CONFIG(__HSE_STATE__) (*(__IO uint8_t *) CR_BYTE2_ADDRESS = (__HSE_STATE__))
  739. /** @brief Macros to enable or disable the Internal Multi Speed oscillator (MSI).
  740. * @note The MSI is stopped by hardware when entering STOP and STANDBY modes.
  741. * It is used (enabled by hardware) as system clock source after startup
  742. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  743. * of the HSE used directly or indirectly as system clock (if the Clock
  744. * Security System CSS is enabled).
  745. * @note MSI can not be stopped if it is used as system clock source. In this case,
  746. * you have to select another source of the system clock then stop the MSI.
  747. * @note After enabling the MSI, the application software should wait on MSIRDY
  748. * flag to be set indicating that MSI clock is stable and can be used as
  749. * system clock source.
  750. * @note When the MSI is stopped, MSIRDY flag goes low after 6 MSI oscillator
  751. * clock cycles.
  752. */
  753. #define __HAL_RCC_MSI_ENABLE() (*(__IO uint32_t *) CR_MSION_BB = ENABLE)
  754. #define __HAL_RCC_MSI_DISABLE() (*(__IO uint32_t *) CR_MSION_BB = DISABLE)
  755. /** @brief macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  756. * @note The calibration is used to compensate for the variations in voltage
  757. * and temperature that influence the frequency of the internal HSI RC.
  758. * @param _HSICALIBRATIONVALUE_: specifies the calibration trimming value.
  759. * (default is RCC_HSICALIBRATION_DEFAULT).
  760. * This parameter must be a number between 0 and 0x1F.
  761. */
  762. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  763. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << POSITION_VAL(RCC_ICSCR_HSITRIM)))
  764. /** @brief macro to adjust the Internal Multi Speed oscillator (MSI) calibration value.
  765. * @note The calibration is used to compensate for the variations in voltage
  766. * and temperature that influence the frequency of the internal MSI RC.
  767. * @param _MSICALIBRATIONVALUE_: specifies the calibration trimming value.
  768. * (default is RCC_MSICALIBRATION_DEFAULT).
  769. * This parameter must be a number between 0 and 0x1F.
  770. */
  771. #define __HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST(_MSICALIBRATIONVALUE_) \
  772. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_MSITRIM, (uint32_t)(_MSICALIBRATIONVALUE_) << POSITION_VAL(RCC_ICSCR_MSITRIM)))
  773. /* @brief Macro to configures the Internal Multi Speed oscillator (MSI) clock range.
  774. * @note After restart from Reset or wakeup from STANDBY, the MSI clock is
  775. * around 2.097 MHz. The MSI clock does not change after wake-up from
  776. * STOP mode.
  777. * @note The MSI clock range can be modified on the fly.
  778. * @param _MSIRANGEVALUE_: specifies the MSI Clock range.
  779. * This parameter must be one of the following values:
  780. * @arg RCC_MSIRANGE_0: MSI clock is around 65.536 KHz
  781. * @arg RCC_MSIRANGE_1: MSI clock is around 131.072 KHz
  782. * @arg RCC_MSIRANGE_2: MSI clock is around 262.144 KHz
  783. * @arg RCC_MSIRANGE_3: MSI clock is around 524.288 KHz
  784. * @arg RCC_MSIRANGE_4: MSI clock is around 1.048 MHz
  785. * @arg RCC_MSIRANGE_5: MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  786. * @arg RCC_MSIRANGE_6: MSI clock is around 4.194 MHz
  787. */
  788. #define __HAL_RCC_MSI_RANGE_CONFIG(_MSIRANGEVALUE_) (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_MSIRANGE, (uint32_t)(_MSIRANGEVALUE_)))
  789. /** @brief Macros to enable or disable the Internal Low Speed oscillator (LSI).
  790. * @note After enabling the LSI, the application software should wait on
  791. * LSIRDY flag to be set indicating that LSI clock is stable and can
  792. * be used to clock the IWDG and/or the RTC.
  793. * @note LSI can not be disabled if the IWDG is running.
  794. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  795. * clock cycles.
  796. */
  797. #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) CSR_LSION_BB = ENABLE)
  798. #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) CSR_LSION_BB = DISABLE)
  799. /** @brief Macros to enable or disable the Internal Low Speed oscillator (LSE).
  800. */
  801. #define __HAL_RCC_LSE_CONFIG(__LSE_STATE__) \
  802. do{ \
  803. if ((__LSE_STATE__) == RCC_LSE_OFF) \
  804. { \
  805. *(__IO uint32_t *) CSR_LSEON_BB = DISABLE; \
  806. *(__IO uint32_t *) CSR_LSEBYP_BB = DISABLE; \
  807. } \
  808. else if ((__LSE_STATE__) == RCC_LSE_ON) \
  809. { \
  810. *(__IO uint32_t *) CSR_LSEBYP_BB = DISABLE; \
  811. *(__IO uint32_t *) CSR_LSEON_BB = ENABLE; \
  812. } \
  813. else \
  814. { \
  815. *(__IO uint32_t *) CSR_LSEON_BB = DISABLE; \
  816. *(__IO uint32_t *) CSR_LSEBYP_BB = ENABLE; \
  817. } \
  818. }while(0)
  819. /** @brief Macros to enable or disable the the RTC clock.
  820. * @note These macros must be used only after the RTC clock source was selected.
  821. */
  822. #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) CSR_RTCEN_BB = ENABLE)
  823. #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) CSR_RTCEN_BB = DISABLE)
  824. /** @brief Macros to force or release the Backup domain reset.
  825. * @note This function resets the RTC peripheral (including the backup registers)
  826. * and the RTC clock source selection in RCC_CSR register.
  827. * @note The BKPSRAM is not affected by this reset.
  828. */
  829. #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) CSR_RTCRST_BB = ENABLE)
  830. #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) CSR_RTCRST_BB = DISABLE)
  831. /** @brief Macro to configures the RTC clock (RTCCLK).
  832. * @note As the RTC clock configuration bits are in the Backup domain and write
  833. * access is denied to this domain after reset, you have to enable write
  834. * access using the Power Backup Access macro before to configure
  835. * the RTC clock source (to be done once after reset).
  836. * @note Once the RTC clock is configured it can't be changed unless the
  837. * Backup domain is reset using __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  838. * a Power On Reset (POR).
  839. * @note RTC prescaler cannot be modified if HSE is enabled (HSEON = 1).
  840. *
  841. * @param __RTC_CLKSOURCE__: specifies the RTC clock source.
  842. * This parameter can be one of the following values:
  843. * @arg RCC_RTCCLKSOURCE_LSE: LSE selected as RTC clock
  844. * @arg RCC_RTCCLKSOURCE_LSI: LSI selected as RTC clock
  845. * @arg RCC_RTCCLKSOURCE_HSE_DIV2: HSE divided by 2 selected as RTC clock
  846. * @arg RCC_RTCCLKSOURCE_HSE_DIV4: HSE divided by 4 selected as RTC clock
  847. * @arg RCC_RTCCLKSOURCE_HSE_DIV8: HSE divided by 8 selected as RTC clock
  848. * @arg RCC_RTCCLKSOURCE_HSE_DIV16: HSE divided by 16 selected as RTC clock
  849. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  850. * work in STOP and STANDBY modes, and can be used as wakeup source.
  851. * However, when the HSE clock is used as RTC clock source, the RTC
  852. * cannot be used in STOP and STANDBY modes.
  853. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  854. * RTC clock source).
  855. */
  856. #define __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__) do { \
  857. if(((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE) \
  858. { \
  859. MODIFY_REG(RCC->CR, RCC_CR_RTCPRE, ((__RTC_CLKSOURCE__) & RCC_CR_RTCPRE)); \
  860. } \
  861. } while (0)
  862. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) do { \
  863. __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__); \
  864. RCC->CSR |= ((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL); \
  865. } while (0)
  866. /** @brief macros to get the RTC clock source.
  867. */
  868. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->CSR, RCC_CSR_RTCSEL))
  869. /** @brief Macros to enable or disable the main PLL.
  870. * @note After enabling the main PLL, the application software should wait on
  871. * PLLRDY flag to be set indicating that PLL clock is stable and can
  872. * be used as system clock source.
  873. * @note The main PLL can not be disabled if it is used as system clock source
  874. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  875. */
  876. #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) CR_PLLON_BB = ENABLE)
  877. #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) CR_PLLON_BB = DISABLE)
  878. /** @brief macros to configure the main PLL clock source, multiplication and division factors.
  879. * @note This function must be used only when the main PLL is disabled.
  880. *
  881. * @param __RCC_PLLSOURCE__: specifies the PLL entry clock source.
  882. * This parameter can be one of the following values:
  883. * @arg RCC_PLLSOURCE_HSI: HSI oscillator clock selected as PLL clock entry
  884. * @arg RCC_PLLSOURCE_HSE: HSE oscillator clock selected as PLL clock entry
  885. * @param __PLLMUL__: specifies the multiplication factor for PLL VCO output clock
  886. * This parameter can be one of the following values:
  887. * @arg RCC_PLL_MUL3: PLLVCO = PLL clock entry x 3
  888. * @arg RCC_PLL_MUL4: PLLVCO = PLL clock entry x 4
  889. * @arg RCC_PLL_MUL6: PLLVCO = PLL clock entry x 6
  890. * @arg RCC_PLL_MUL8: PLLVCO = PLL clock entry x 8
  891. * @arg RCC_PLL_MUL12: PLLVCO = PLL clock entry x 12
  892. * @arg RCC_PLL_MUL16: PLLVCO = PLL clock entry x 16
  893. * @arg RCC_PLL_MUL24: PLLVCO = PLL clock entry x 24
  894. * @arg RCC_PLL_MUL32: PLLVCO = PLL clock entry x 32
  895. * @arg RCC_PLL_MUL48: PLLVCO = PLL clock entry x 48
  896. * @note The PLL VCO clock frequency must not exceed 96 MHz when the product is in
  897. * Range 1, 48 MHz when the product is in Range 2 and 24 MHz when the product is
  898. * in Range 3.
  899. *
  900. * @param __PLLDIV__: specifies the division factor for PLL VCO input clock
  901. * This parameter can be one of the following values:
  902. * @arg RCC_PLL_DIV2: PLL clock output = PLLVCO / 2
  903. * @arg RCC_PLL_DIV3: PLL clock output = PLLVCO / 3
  904. * @arg RCC_PLL_DIV4: PLL clock output = PLLVCO / 4
  905. *
  906. */
  907. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__, __PLLDIV__)\
  908. MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC|RCC_CFGR_PLLMUL|RCC_CFGR_PLLDIV),((__RCC_PLLSOURCE__) | (__PLLMUL__) | (__PLLDIV__)))
  909. /** @brief Macro to get the clock source used as system clock.
  910. * @retval The clock source used as system clock. The returned value can be one
  911. * of the following:
  912. * @arg RCC_CFGR_SWS_MSI: MSI used as system clock
  913. * @arg RCC_CFGR_SWS_HSI: HSI used as system clock
  914. * @arg RCC_CFGR_SWS_HSE: HSE used as system clock
  915. * @arg RCC_CFGR_SWS_PLL: PLL used as system clock
  916. */
  917. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  918. /** @brief macros to manage the specified RCC Flags and interrupts.
  919. */
  920. /** @brief Enable RCC interrupt (Perform Byte access to RCC_CIR[14:8] bits to enable
  921. * the selected interrupts.).
  922. * @param __INTERRUPT__: specifies the RCC interrupt sources to be enabled.
  923. * This parameter can be any combination of the following values:
  924. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  925. * @arg RCC_IT_LSERDY: LSE ready interrupt
  926. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  927. * @arg RCC_IT_HSERDY: HSE ready interrupt
  928. * @arg RCC_IT_PLLRDY: main PLL ready interrupt
  929. * @arg RCC_IT_MSIRDY: MSI ready interrupt
  930. * @arg RCC_IT_LSECSS: LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB device)
  931. */
  932. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  933. /** @brief Disable RCC interrupt (Perform Byte access to RCC_CIR[14:8] bits to disable
  934. * the selected interrupts).
  935. * @param __INTERRUPT__: specifies the RCC interrupt sources to be disabled.
  936. * This parameter can be any combination of the following values:
  937. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  938. * @arg RCC_IT_LSERDY: LSE ready interrupt
  939. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  940. * @arg RCC_IT_HSERDY: HSE ready interrupt
  941. * @arg RCC_IT_PLLRDY: main PLL ready interrupt
  942. * @arg RCC_IT_MSIRDY: MSI ready interrupt
  943. * @arg RCC_IT_LSECSS: LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB device)
  944. */
  945. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) CIR_BYTE1_ADDRESS &= ~(__INTERRUPT__))
  946. /** @brief Clear the RCC's interrupt pending bits ( Perform Byte access to RCC_CIR[23:16]
  947. * bits to clear the selected interrupt pending bits.
  948. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  949. * This parameter can be any combination of the following values:
  950. * @arg RCC_IT_LSIRDY: LSI ready interrupt.
  951. * @arg RCC_IT_LSERDY: LSE ready interrupt.
  952. * @arg RCC_IT_HSIRDY: HSI ready interrupt.
  953. * @arg RCC_IT_HSERDY: HSE ready interrupt.
  954. * @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
  955. * @arg RCC_IT_MSIRDY: MSI ready interrupt.
  956. * @arg RCC_IT_LSECSS: LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB device)
  957. * @arg RCC_IT_CSS: Clock Security System interrupt
  958. */
  959. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  960. /** @brief Check the RCC's interrupt has occurred or not.
  961. * @param __INTERRUPT__: specifies the RCC interrupt source to check.
  962. * This parameter can be one of the following values:
  963. * @arg RCC_IT_LSIRDY: LSI ready interrupt.
  964. * @arg RCC_IT_LSERDY: LSE ready interrupt.
  965. * @arg RCC_IT_HSIRDY: HSI ready interrupt.
  966. * @arg RCC_IT_HSERDY: HSE ready interrupt.
  967. * @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
  968. * @arg RCC_IT_MSIRDY: MSI ready interrupt.
  969. * @arg RCC_IT_LSECSS: LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB device)
  970. * @arg RCC_IT_CSS: Clock Security System interrupt
  971. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  972. */
  973. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  974. /** @brief Set RMVF bit to clear the reset flags: RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  975. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  976. */
  977. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  978. /** @brief Check RCC flag is set or not.
  979. * @param __FLAG__: specifies the flag to check.
  980. * This parameter can be one of the following values:
  981. * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready.
  982. * @arg RCC_FLAG_MSIRDY: MSI oscillator clock ready.
  983. * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready.
  984. * @arg RCC_FLAG_PLLRDY: Main PLL clock ready.
  985. * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready.
  986. * @arg RCC_FLAG_LSECSS: CSS on LSE failure Detection (*)
  987. * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready.
  988. * @arg RCC_FLAG_BORRST: POR/PDR or BOR reset.
  989. * @arg RCC_FLAG_PINRST: Pin reset.
  990. * @arg RCC_FLAG_PORRST: POR/PDR reset.
  991. * @arg RCC_FLAG_SFTRST: Software reset.
  992. * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset.
  993. * @arg RCC_FLAG_WWDGRST: Window Watchdog reset.
  994. * @arg RCC_FLAG_LPWRRST: Low Power reset.
  995. * @note (*) This bit is available in high and medium+ density devices only.
  996. * @retval The new state of __FLAG__ (TRUE or FALSE).
  997. */
  998. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5) == CR_REG_INDEX)? RCC->CR :RCC->CSR) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK)))
  999. /** @brief Get oscillator clock selected as PLL input clock
  1000. * @retval The clock source used for PLL entry. The returned value can be one
  1001. * of the following:
  1002. * @arg RCC_PLLSOURCE_HSI: HSI oscillator clock selected as PLL input clock
  1003. * @arg RCC_PLLSOURCE_HSE: HSE oscillator clock selected as PLL input clock
  1004. */
  1005. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((RCC->CFGR & RCC_CFGR_PLLSRC))
  1006. /**
  1007. * @}
  1008. */
  1009. /* Include RCC HAL Extension module */
  1010. #include "stm32l1xx_hal_rcc_ex.h"
  1011. /* Exported functions --------------------------------------------------------*/
  1012. /** @addtogroup RCC_Private_Functions
  1013. * @{
  1014. */
  1015. /** @addtogroup RCC_Exported_Functions_Group1
  1016. * @{
  1017. */
  1018. /* Initialization and de-initialization functions ******************************/
  1019. void HAL_RCC_DeInit(void);
  1020. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1021. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1022. /**
  1023. * @}
  1024. */
  1025. /** @addtogroup RCC_Exported_Functions_Group2
  1026. * @{
  1027. */
  1028. /* Peripheral Control functions ************************************************/
  1029. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1030. void HAL_RCC_EnableCSS(void);
  1031. void HAL_RCC_DisableCSS(void);
  1032. uint32_t HAL_RCC_GetSysClockFreq(void);
  1033. uint32_t HAL_RCC_GetHCLKFreq(void);
  1034. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1035. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1036. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1037. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1038. /* CSS NMI IRQ handler */
  1039. void HAL_RCC_NMI_IRQHandler(void);
  1040. /* User Callbacks in non blocking mode (IT mode) */
  1041. void HAL_RCC_CCSCallback(void);
  1042. /**
  1043. * @}
  1044. */
  1045. /**
  1046. * @}
  1047. */
  1048. /**
  1049. * @}
  1050. */
  1051. /**
  1052. * @}
  1053. */
  1054. #ifdef __cplusplus
  1055. }
  1056. #endif
  1057. #endif /* __STM32L1xx_HAL_RCC_H */
  1058. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/