Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1899 lines
102 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RCC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright(c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32L1xx_HAL_RCC_H
  21. #define __STM32L1xx_HAL_RCC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_hal_def.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup RCC
  31. * @{
  32. */
  33. /** @addtogroup RCC_Private_Constants
  34. * @{
  35. */
  36. /** @defgroup RCC_Timeout RCC Timeout
  37. * @{
  38. */
  39. /* Disable Backup domain write protection state change timeout */
  40. #define RCC_DBP_TIMEOUT_VALUE (100U) /* 100 ms */
  41. /* LSE state change timeout */
  42. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  43. #define CLOCKSWITCH_TIMEOUT_VALUE (5000U) /* 5 s */
  44. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  45. #define MSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  46. #define HSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  47. #define LSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  48. #define PLL_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  49. /**
  50. * @}
  51. */
  52. /** @defgroup RCC_Register_Offset Register offsets
  53. * @{
  54. */
  55. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  56. #define RCC_CR_OFFSET 0x00
  57. #define RCC_CFGR_OFFSET 0x08
  58. #define RCC_CIR_OFFSET 0x0C
  59. #define RCC_CSR_OFFSET 0x34
  60. /**
  61. * @}
  62. */
  63. /** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
  64. * @brief RCC registers bit address in the alias region
  65. * @{
  66. */
  67. #define RCC_CR_OFFSET_BB (RCC_OFFSET + RCC_CR_OFFSET)
  68. #define RCC_CFGR_OFFSET_BB (RCC_OFFSET + RCC_CFGR_OFFSET)
  69. #define RCC_CIR_OFFSET_BB (RCC_OFFSET + RCC_CIR_OFFSET)
  70. #define RCC_CSR_OFFSET_BB (RCC_OFFSET + RCC_CSR_OFFSET)
  71. /* --- CR Register ---*/
  72. /* Alias word address of HSION bit */
  73. #define RCC_HSION_BIT_NUMBER RCC_CR_HSION_Pos
  74. #define RCC_CR_HSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSION_BIT_NUMBER * 4U)))
  75. /* Alias word address of MSION bit */
  76. #define RCC_MSION_BIT_NUMBER RCC_CR_MSION_Pos
  77. #define RCC_CR_MSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_MSION_BIT_NUMBER * 4U)))
  78. /* Alias word address of HSEON bit */
  79. #define RCC_HSEON_BIT_NUMBER RCC_CR_HSEON_Pos
  80. #define RCC_CR_HSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSEON_BIT_NUMBER * 4U)))
  81. /* Alias word address of CSSON bit */
  82. #define RCC_CSSON_BIT_NUMBER RCC_CR_CSSON_Pos
  83. #define RCC_CR_CSSON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_CSSON_BIT_NUMBER * 4U)))
  84. /* Alias word address of PLLON bit */
  85. #define RCC_PLLON_BIT_NUMBER RCC_CR_PLLON_Pos
  86. #define RCC_CR_PLLON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_PLLON_BIT_NUMBER * 4U)))
  87. /* --- CSR Register ---*/
  88. /* Alias word address of LSION bit */
  89. #define RCC_LSION_BIT_NUMBER RCC_CSR_LSION_Pos
  90. #define RCC_CSR_LSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_LSION_BIT_NUMBER * 4U)))
  91. /* Alias word address of RMVF bit */
  92. #define RCC_RMVF_BIT_NUMBER RCC_CSR_RMVF_Pos
  93. #define RCC_CSR_RMVF_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_RMVF_BIT_NUMBER * 4U)))
  94. /* Alias word address of LSEON bit */
  95. #define RCC_LSEON_BIT_NUMBER RCC_CSR_LSEON_Pos
  96. #define RCC_CSR_LSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_LSEON_BIT_NUMBER * 4U)))
  97. /* Alias word address of LSEON bit */
  98. #define RCC_LSEBYP_BIT_NUMBER RCC_CSR_LSEBYP_Pos
  99. #define RCC_CSR_LSEBYP_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_LSEBYP_BIT_NUMBER * 4U)))
  100. /* Alias word address of RTCEN bit */
  101. #define RCC_RTCEN_BIT_NUMBER RCC_CSR_RTCEN_Pos
  102. #define RCC_CSR_RTCEN_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_RTCEN_BIT_NUMBER * 4U)))
  103. /* Alias word address of RTCRST bit */
  104. #define RCC_RTCRST_BIT_NUMBER RCC_CSR_RTCRST_Pos
  105. #define RCC_CSR_RTCRST_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_RTCRST_BIT_NUMBER * 4U)))
  106. /**
  107. * @}
  108. */
  109. /* CR register byte 2 (Bits[23:16]) base address */
  110. #define RCC_CR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02U))
  111. /* CIR register byte 1 (Bits[15:8]) base address */
  112. #define RCC_CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01U))
  113. /* CIR register byte 2 (Bits[23:16]) base address */
  114. #define RCC_CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02U))
  115. /* Defines used for Flags */
  116. #define CR_REG_INDEX ((uint8_t)1U)
  117. #define CSR_REG_INDEX ((uint8_t)2U)
  118. #define RCC_FLAG_MASK ((uint8_t)0x1FU)
  119. /**
  120. * @}
  121. */
  122. /** @addtogroup RCC_Private_Macros
  123. * @{
  124. */
  125. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI) || \
  126. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  127. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  128. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  129. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  130. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  131. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  132. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI))
  133. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  134. ((__HSE__) == RCC_HSE_BYPASS))
  135. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  136. ((__LSE__) == RCC_LSE_BYPASS))
  137. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  138. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
  139. #define IS_RCC_MSICALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0xFFU)
  140. #define IS_RCC_MSI_CLOCK_RANGE(__RANGE__) (((__RANGE__) == RCC_MSIRANGE_0) || \
  141. ((__RANGE__) == RCC_MSIRANGE_1) || \
  142. ((__RANGE__) == RCC_MSIRANGE_2) || \
  143. ((__RANGE__) == RCC_MSIRANGE_3) || \
  144. ((__RANGE__) == RCC_MSIRANGE_4) || \
  145. ((__RANGE__) == RCC_MSIRANGE_5) || \
  146. ((__RANGE__) == RCC_MSIRANGE_6))
  147. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  148. #define IS_RCC_MSI(__MSI__) (((__MSI__) == RCC_MSI_OFF) || ((__MSI__) == RCC_MSI_ON))
  149. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  150. ((__PLL__) == RCC_PLL_ON))
  151. #define IS_RCC_PLL_DIV(__DIV__) (((__DIV__) == RCC_PLL_DIV2) || \
  152. ((__DIV__) == RCC_PLL_DIV3) || ((__DIV__) == RCC_PLL_DIV4))
  153. #define IS_RCC_PLL_MUL(__MUL__) (((__MUL__) == RCC_PLL_MUL3) || ((__MUL__) == RCC_PLL_MUL4) || \
  154. ((__MUL__) == RCC_PLL_MUL6) || ((__MUL__) == RCC_PLL_MUL8) || \
  155. ((__MUL__) == RCC_PLL_MUL12) || ((__MUL__) == RCC_PLL_MUL16) || \
  156. ((__MUL__) == RCC_PLL_MUL24) || ((__MUL__) == RCC_PLL_MUL32) || \
  157. ((__MUL__) == RCC_PLL_MUL48))
  158. #define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  159. (((CLK) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  160. (((CLK) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) || \
  161. (((CLK) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2))
  162. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_MSI) || \
  163. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  164. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  165. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  166. #define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_MSI) || \
  167. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  168. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  169. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  170. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  171. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  172. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  173. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  174. ((__HCLK__) == RCC_SYSCLK_DIV512))
  175. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  176. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  177. ((__PCLK__) == RCC_HCLK_DIV16))
  178. #define IS_RCC_MCO(__MCO__) ((__MCO__) == RCC_MCO)
  179. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1) || ((__DIV__) == RCC_MCODIV_2) || \
  180. ((__DIV__) == RCC_MCODIV_4) || ((__DIV__) == RCC_MCODIV_8) || \
  181. ((__DIV__) == RCC_MCODIV_16))
  182. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || ((__SOURCE__) == RCC_MCO1SOURCE_MSI) \
  183. || ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || ((__SOURCE__) == RCC_MCO1SOURCE_LSE) \
  184. || ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || ((__SOURCE__) == RCC_MCO1SOURCE_HSE) \
  185. || ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || ((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK))
  186. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  187. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  188. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  189. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV2) || \
  190. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV4) || \
  191. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV8) || \
  192. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV16))
  193. /**
  194. * @}
  195. */
  196. /* Exported types ------------------------------------------------------------*/
  197. /** @defgroup RCC_Exported_Types RCC Exported Types
  198. * @{
  199. */
  200. /**
  201. * @brief RCC PLL configuration structure definition
  202. */
  203. typedef struct
  204. {
  205. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  206. This parameter can be a value of @ref RCC_PLL_Config */
  207. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  208. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  209. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  210. This parameter must be a value of @ref RCC_PLL_Multiplication_Factor*/
  211. uint32_t PLLDIV; /*!< PLLDIV: Division factor for PLL VCO input clock
  212. This parameter must be a value of @ref RCC_PLL_Division_Factor*/
  213. } RCC_PLLInitTypeDef;
  214. /**
  215. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  216. */
  217. typedef struct
  218. {
  219. uint32_t OscillatorType; /*!< The oscillators to be configured.
  220. This parameter can be a value of @ref RCC_Oscillator_Type */
  221. uint32_t HSEState; /*!< The new state of the HSE.
  222. This parameter can be a value of @ref RCC_HSE_Config */
  223. uint32_t LSEState; /*!< The new state of the LSE.
  224. This parameter can be a value of @ref RCC_LSE_Config */
  225. uint32_t HSIState; /*!< The new state of the HSI.
  226. This parameter can be a value of @ref RCC_HSI_Config */
  227. uint32_t HSICalibrationValue; /*!< The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT).
  228. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1FU */
  229. uint32_t LSIState; /*!< The new state of the LSI.
  230. This parameter can be a value of @ref RCC_LSI_Config */
  231. uint32_t MSIState; /*!< The new state of the MSI.
  232. This parameter can be a value of @ref RCC_MSI_Config */
  233. uint32_t MSICalibrationValue; /*!< The MSI calibration trimming value. (default is RCC_MSICALIBRATION_DEFAULT).
  234. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFU */
  235. uint32_t MSIClockRange; /*!< The MSI frequency range.
  236. This parameter can be a value of @ref RCC_MSI_Clock_Range */
  237. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  238. } RCC_OscInitTypeDef;
  239. /**
  240. * @brief RCC System, AHB and APB busses clock configuration structure definition
  241. */
  242. typedef struct
  243. {
  244. uint32_t ClockType; /*!< The clock to be configured.
  245. This parameter can be a value of @ref RCC_System_Clock_Type */
  246. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  247. This parameter can be a value of @ref RCC_System_Clock_Source */
  248. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  249. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  250. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  251. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  252. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  253. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  254. } RCC_ClkInitTypeDef;
  255. /**
  256. * @}
  257. */
  258. /* Exported constants --------------------------------------------------------*/
  259. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  260. * @{
  261. */
  262. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  263. * @{
  264. */
  265. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI /*!< HSI clock selected as PLL entry clock source */
  266. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE /*!< HSE clock selected as PLL entry clock source */
  267. /**
  268. * @}
  269. */
  270. /** @defgroup RCC_Oscillator_Type Oscillator Type
  271. * @{
  272. */
  273. #define RCC_OSCILLATORTYPE_NONE (0x00000000U)
  274. #define RCC_OSCILLATORTYPE_HSE (0x00000001U)
  275. #define RCC_OSCILLATORTYPE_HSI (0x00000002U)
  276. #define RCC_OSCILLATORTYPE_LSE (0x00000004U)
  277. #define RCC_OSCILLATORTYPE_LSI (0x00000008U)
  278. #define RCC_OSCILLATORTYPE_MSI (0x00000010U)
  279. /**
  280. * @}
  281. */
  282. /** @defgroup RCC_HSE_Config HSE Config
  283. * @{
  284. */
  285. #define RCC_HSE_OFF (0x00000000U) /*!< HSE clock deactivation */
  286. #define RCC_HSE_ON (0x00000001U) /*!< HSE clock activation */
  287. #define RCC_HSE_BYPASS (0x00000005U) /*!< External clock source for HSE clock */
  288. /**
  289. * @}
  290. */
  291. /** @defgroup RCC_LSE_Config LSE Config
  292. * @{
  293. */
  294. #define RCC_LSE_OFF (0x00000000U) /*!< LSE clock deactivation */
  295. #define RCC_LSE_ON (0x00000001U) /*!< LSE clock activation */
  296. #define RCC_LSE_BYPASS (0x00000005U) /*!< External clock source for LSE clock */
  297. /**
  298. * @}
  299. */
  300. /** @defgroup RCC_HSI_Config HSI Config
  301. * @{
  302. */
  303. #define RCC_HSI_OFF (0x00000000U) /*!< HSI clock deactivation */
  304. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  305. #define RCC_HSICALIBRATION_DEFAULT (0x10U) /* Default HSI calibration trimming value */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup RCC_MSI_Clock_Range MSI Clock Range
  310. * @{
  311. */
  312. #define RCC_MSIRANGE_0 RCC_ICSCR_MSIRANGE_0 /*!< MSI = 65.536 KHz */
  313. #define RCC_MSIRANGE_1 RCC_ICSCR_MSIRANGE_1 /*!< MSI = 131.072 KHz */
  314. #define RCC_MSIRANGE_2 RCC_ICSCR_MSIRANGE_2 /*!< MSI = 262.144 KHz */
  315. #define RCC_MSIRANGE_3 RCC_ICSCR_MSIRANGE_3 /*!< MSI = 524.288 KHz */
  316. #define RCC_MSIRANGE_4 RCC_ICSCR_MSIRANGE_4 /*!< MSI = 1.048 MHz */
  317. #define RCC_MSIRANGE_5 RCC_ICSCR_MSIRANGE_5 /*!< MSI = 2.097 MHz */
  318. #define RCC_MSIRANGE_6 RCC_ICSCR_MSIRANGE_6 /*!< MSI = 4.194 MHz */
  319. /**
  320. * @}
  321. */
  322. /** @defgroup RCC_LSI_Config LSI Config
  323. * @{
  324. */
  325. #define RCC_LSI_OFF (0x00000000U) /*!< LSI clock deactivation */
  326. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  327. /**
  328. * @}
  329. */
  330. /** @defgroup RCC_MSI_Config MSI Config
  331. * @{
  332. */
  333. #define RCC_MSI_OFF (0x00000000U)
  334. #define RCC_MSI_ON (0x00000001U)
  335. #define RCC_MSICALIBRATION_DEFAULT (0x00000000U) /* Default MSI calibration trimming value */
  336. /**
  337. * @}
  338. */
  339. /** @defgroup RCC_PLL_Config PLL Config
  340. * @{
  341. */
  342. #define RCC_PLL_NONE (0x00000000U) /*!< PLL is not configured */
  343. #define RCC_PLL_OFF (0x00000001U) /*!< PLL deactivation */
  344. #define RCC_PLL_ON (0x00000002U) /*!< PLL activation */
  345. /**
  346. * @}
  347. */
  348. /** @defgroup RCC_System_Clock_Type System Clock Type
  349. * @{
  350. */
  351. #define RCC_CLOCKTYPE_SYSCLK (0x00000001U) /*!< SYSCLK to configure */
  352. #define RCC_CLOCKTYPE_HCLK (0x00000002U) /*!< HCLK to configure */
  353. #define RCC_CLOCKTYPE_PCLK1 (0x00000004U) /*!< PCLK1 to configure */
  354. #define RCC_CLOCKTYPE_PCLK2 (0x00000008U) /*!< PCLK2 to configure */
  355. /**
  356. * @}
  357. */
  358. /** @defgroup RCC_System_Clock_Source System Clock Source
  359. * @{
  360. */
  361. #define RCC_SYSCLKSOURCE_MSI RCC_CFGR_SW_MSI /*!< MSI selected as system clock */
  362. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  363. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  364. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  365. /**
  366. * @}
  367. */
  368. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  369. * @{
  370. */
  371. #define RCC_SYSCLKSOURCE_STATUS_MSI RCC_CFGR_SWS_MSI /*!< MSI used as system clock */
  372. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  373. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  374. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  375. /**
  376. * @}
  377. */
  378. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  379. * @{
  380. */
  381. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  382. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  383. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  384. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  385. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  386. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  387. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  388. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  389. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  390. /**
  391. * @}
  392. */
  393. /** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
  394. * @{
  395. */
  396. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1 /*!< HCLK not divided */
  397. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2 /*!< HCLK divided by 2 */
  398. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4 /*!< HCLK divided by 4 */
  399. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8 /*!< HCLK divided by 8 */
  400. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
  401. /**
  402. * @}
  403. */
  404. /** @defgroup RCC_HAL_EC_RTC_HSE_DIV RTC HSE Prescaler
  405. * @{
  406. */
  407. #define RCC_RTC_HSE_DIV_2 0x00000000U /*!< HSE is divided by 2 for RTC clock */
  408. #define RCC_RTC_HSE_DIV_4 RCC_CR_RTCPRE_0 /*!< HSE is divided by 4 for RTC clock */
  409. #define RCC_RTC_HSE_DIV_8 RCC_CR_RTCPRE_1 /*!< HSE is divided by 8 for RTC clock */
  410. #define RCC_RTC_HSE_DIV_16 RCC_CR_RTCPRE /*!< HSE is divided by 16 for RTC clock */
  411. /**
  412. * @}
  413. */
  414. /** @defgroup RCC_RTC_LCD_Clock_Source RTC LCD Clock Source
  415. * @{
  416. */
  417. #define RCC_RTCCLKSOURCE_NO_CLK (0x00000000U) /*!< No clock */
  418. #define RCC_RTCCLKSOURCE_LSE RCC_CSR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  419. #define RCC_RTCCLKSOURCE_LSI RCC_CSR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  420. #define RCC_RTCCLKSOURCE_HSE_DIVX RCC_CSR_RTCSEL_HSE /*!< HSE oscillator clock divided by X used as RTC clock */
  421. #define RCC_RTCCLKSOURCE_HSE_DIV2 (RCC_RTC_HSE_DIV_2 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 2 used as RTC clock */
  422. #define RCC_RTCCLKSOURCE_HSE_DIV4 (RCC_RTC_HSE_DIV_4 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 4 used as RTC clock */
  423. #define RCC_RTCCLKSOURCE_HSE_DIV8 (RCC_RTC_HSE_DIV_8 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 8 used as RTC clock */
  424. #define RCC_RTCCLKSOURCE_HSE_DIV16 (RCC_RTC_HSE_DIV_16 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 16 used as RTC clock */
  425. /**
  426. * @}
  427. */
  428. /** @defgroup RCC_PLL_Division_Factor PLL Division Factor
  429. * @{
  430. */
  431. #define RCC_PLL_DIV2 RCC_CFGR_PLLDIV2
  432. #define RCC_PLL_DIV3 RCC_CFGR_PLLDIV3
  433. #define RCC_PLL_DIV4 RCC_CFGR_PLLDIV4
  434. /**
  435. * @}
  436. */
  437. /** @defgroup RCC_PLL_Multiplication_Factor PLL Multiplication Factor
  438. * @{
  439. */
  440. #define RCC_PLL_MUL3 RCC_CFGR_PLLMUL3
  441. #define RCC_PLL_MUL4 RCC_CFGR_PLLMUL4
  442. #define RCC_PLL_MUL6 RCC_CFGR_PLLMUL6
  443. #define RCC_PLL_MUL8 RCC_CFGR_PLLMUL8
  444. #define RCC_PLL_MUL12 RCC_CFGR_PLLMUL12
  445. #define RCC_PLL_MUL16 RCC_CFGR_PLLMUL16
  446. #define RCC_PLL_MUL24 RCC_CFGR_PLLMUL24
  447. #define RCC_PLL_MUL32 RCC_CFGR_PLLMUL32
  448. #define RCC_PLL_MUL48 RCC_CFGR_PLLMUL48
  449. /**
  450. * @}
  451. */
  452. /** @defgroup RCC_MCO_Index MCO Index
  453. * @{
  454. */
  455. #define RCC_MCO1 (0x00000000U)
  456. #define RCC_MCO RCC_MCO1 /*!< MCO1 to be compliant with other families with 2 MCOs*/
  457. /**
  458. * @}
  459. */
  460. /** @defgroup RCC_MCOx_Clock_Prescaler MCO Clock Prescaler
  461. * @{
  462. */
  463. #define RCC_MCODIV_1 ((uint32_t)RCC_CFGR_MCO_DIV1)
  464. #define RCC_MCODIV_2 ((uint32_t)RCC_CFGR_MCO_DIV2)
  465. #define RCC_MCODIV_4 ((uint32_t)RCC_CFGR_MCO_DIV4)
  466. #define RCC_MCODIV_8 ((uint32_t)RCC_CFGR_MCO_DIV8)
  467. #define RCC_MCODIV_16 ((uint32_t)RCC_CFGR_MCO_DIV16)
  468. /**
  469. * @}
  470. */
  471. /** @defgroup RCC_MCO1_Clock_Source MCO1 Clock Source
  472. * @{
  473. */
  474. #define RCC_MCO1SOURCE_NOCLOCK RCC_CFGR_MCO_NOCLOCK
  475. #define RCC_MCO1SOURCE_SYSCLK RCC_CFGR_MCO_SYSCLK
  476. #define RCC_MCO1SOURCE_MSI RCC_CFGR_MCO_MSI
  477. #define RCC_MCO1SOURCE_HSI RCC_CFGR_MCO_HSI
  478. #define RCC_MCO1SOURCE_LSE RCC_CFGR_MCO_LSE
  479. #define RCC_MCO1SOURCE_LSI RCC_CFGR_MCO_LSI
  480. #define RCC_MCO1SOURCE_HSE RCC_CFGR_MCO_HSE
  481. #define RCC_MCO1SOURCE_PLLCLK RCC_CFGR_MCO_PLL
  482. /**
  483. * @}
  484. */
  485. /** @defgroup RCC_Interrupt Interrupts
  486. * @{
  487. */
  488. #define RCC_IT_LSIRDY ((uint8_t)RCC_CIR_LSIRDYF) /*!< LSI Ready Interrupt flag */
  489. #define RCC_IT_LSERDY ((uint8_t)RCC_CIR_LSERDYF) /*!< LSE Ready Interrupt flag */
  490. #define RCC_IT_HSIRDY ((uint8_t)RCC_CIR_HSIRDYF) /*!< HSI Ready Interrupt flag */
  491. #define RCC_IT_HSERDY ((uint8_t)RCC_CIR_HSERDYF) /*!< HSE Ready Interrupt flag */
  492. #define RCC_IT_PLLRDY ((uint8_t)RCC_CIR_PLLRDYF) /*!< PLL Ready Interrupt flag */
  493. #define RCC_IT_MSIRDY ((uint8_t)RCC_CIR_MSIRDYF) /*!< MSI Ready Interrupt flag */
  494. #define RCC_IT_LSECSS ((uint8_t)RCC_CIR_LSECSSF) /*!< LSE Clock Security System Interrupt flag */
  495. #define RCC_IT_CSS ((uint8_t)RCC_CIR_CSSF) /*!< Clock Security System Interrupt flag */
  496. /**
  497. * @}
  498. */
  499. /** @defgroup RCC_Flag Flags
  500. * Elements values convention: XXXYYYYYb
  501. * - YYYYY : Flag position in the register
  502. * - XXX : Register index
  503. * - 001: CR register
  504. * - 010: CSR register
  505. * @{
  506. */
  507. /* Flags in the CR register */
  508. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSIRDY_Pos)) /*!< Internal High Speed clock ready flag */
  509. #define RCC_FLAG_MSIRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_MSIRDY_Pos)) /*!< MSI clock ready flag */
  510. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSERDY_Pos)) /*!< External High Speed clock ready flag */
  511. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_PLLRDY_Pos)) /*!< PLL clock ready flag */
  512. /* Flags in the CSR register */
  513. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LSIRDY_Pos)) /*!< Internal Low Speed oscillator Ready */
  514. #define RCC_FLAG_LSECSS ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LSECSSD_Pos)) /*!< CSS on LSE failure Detection */
  515. #define RCC_FLAG_OBLRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_OBLRSTF_Pos)) /*!< Options bytes loading reset flag */
  516. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PINRSTF_Pos)) /*!< PIN reset flag */
  517. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PORRSTF_Pos)) /*!< POR/PDR reset flag */
  518. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_SFTRSTF_Pos)) /*!< Software Reset flag */
  519. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_IWDGRSTF_Pos)) /*!< Independent Watchdog reset flag */
  520. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_WWDGRSTF_Pos)) /*!< Window watchdog reset flag */
  521. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LPWRRSTF_Pos)) /*!< Low-Power reset flag */
  522. #define RCC_FLAG_LSERDY ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LSERDY_Pos)) /*!< External Low Speed oscillator Ready */
  523. /**
  524. * @}
  525. */
  526. /**
  527. * @}
  528. */
  529. /* Exported macro ------------------------------------------------------------*/
  530. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  531. * @{
  532. */
  533. /** @defgroup RCC_Peripheral_Clock_Enable_Disable Peripheral Clock Enable Disable
  534. * @brief Enable or disable the AHB1 peripheral clock.
  535. * @note After reset, the peripheral clock (used for registers read/write access)
  536. * is disabled and the application software has to enable this clock before
  537. * using it.
  538. * @{
  539. */
  540. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  541. __IO uint32_t tmpreg; \
  542. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
  543. /* Delay after an RCC peripheral clock enabling */\
  544. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
  545. UNUSED(tmpreg); \
  546. } while(0U)
  547. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  548. __IO uint32_t tmpreg; \
  549. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOBEN);\
  550. /* Delay after an RCC peripheral clock enabling */\
  551. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOBEN);\
  552. UNUSED(tmpreg); \
  553. } while(0U)
  554. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  555. __IO uint32_t tmpreg; \
  556. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOCEN);\
  557. /* Delay after an RCC peripheral clock enabling */\
  558. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOCEN);\
  559. UNUSED(tmpreg); \
  560. } while(0U)
  561. #define __HAL_RCC_GPIOD_CLK_ENABLE() do { \
  562. __IO uint32_t tmpreg; \
  563. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN);\
  564. /* Delay after an RCC peripheral clock enabling */\
  565. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN);\
  566. UNUSED(tmpreg); \
  567. } while(0U)
  568. #define __HAL_RCC_GPIOH_CLK_ENABLE() do { \
  569. __IO uint32_t tmpreg; \
  570. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOHEN);\
  571. /* Delay after an RCC peripheral clock enabling */\
  572. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOHEN);\
  573. UNUSED(tmpreg); \
  574. } while(0U)
  575. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  576. __IO uint32_t tmpreg; \
  577. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  578. /* Delay after an RCC peripheral clock enabling */\
  579. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  580. UNUSED(tmpreg); \
  581. } while(0U)
  582. #define __HAL_RCC_FLITF_CLK_ENABLE() do { \
  583. __IO uint32_t tmpreg; \
  584. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  585. /* Delay after an RCC peripheral clock enabling */\
  586. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  587. UNUSED(tmpreg); \
  588. } while(0U)
  589. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  590. __IO uint32_t tmpreg; \
  591. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  592. /* Delay after an RCC peripheral clock enabling */\
  593. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  594. UNUSED(tmpreg); \
  595. } while(0U)
  596. #define __HAL_RCC_GPIOA_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOAEN))
  597. #define __HAL_RCC_GPIOB_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOBEN))
  598. #define __HAL_RCC_GPIOC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOCEN))
  599. #define __HAL_RCC_GPIOD_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIODEN))
  600. #define __HAL_RCC_GPIOH_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOHEN))
  601. #define __HAL_RCC_CRC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
  602. #define __HAL_RCC_FLITF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
  603. #define __HAL_RCC_DMA1_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
  604. /**
  605. * @}
  606. */
  607. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Clock Enable Disable
  608. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  609. * @note After reset, the peripheral clock (used for registers read/write access)
  610. * is disabled and the application software has to enable this clock before
  611. * using it.
  612. * @{
  613. */
  614. #define __HAL_RCC_TIM2_CLK_ENABLE() do { \
  615. __IO uint32_t tmpreg; \
  616. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  617. /* Delay after an RCC peripheral clock enabling */\
  618. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  619. UNUSED(tmpreg); \
  620. } while(0U)
  621. #define __HAL_RCC_TIM3_CLK_ENABLE() do { \
  622. __IO uint32_t tmpreg; \
  623. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  624. /* Delay after an RCC peripheral clock enabling */\
  625. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  626. UNUSED(tmpreg); \
  627. } while(0U)
  628. #define __HAL_RCC_TIM4_CLK_ENABLE() do { \
  629. __IO uint32_t tmpreg; \
  630. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM4EN);\
  631. /* Delay after an RCC peripheral clock enabling */\
  632. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM4EN);\
  633. UNUSED(tmpreg); \
  634. } while(0U)
  635. #define __HAL_RCC_TIM6_CLK_ENABLE() do { \
  636. __IO uint32_t tmpreg; \
  637. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM6EN);\
  638. /* Delay after an RCC peripheral clock enabling */\
  639. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM6EN);\
  640. UNUSED(tmpreg); \
  641. } while(0U)
  642. #define __HAL_RCC_TIM7_CLK_ENABLE() do { \
  643. __IO uint32_t tmpreg; \
  644. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM7EN);\
  645. /* Delay after an RCC peripheral clock enabling */\
  646. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM7EN);\
  647. UNUSED(tmpreg); \
  648. } while(0U)
  649. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  650. __IO uint32_t tmpreg; \
  651. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  652. /* Delay after an RCC peripheral clock enabling */\
  653. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  654. UNUSED(tmpreg); \
  655. } while(0U)
  656. #define __HAL_RCC_SPI2_CLK_ENABLE() do { \
  657. __IO uint32_t tmpreg; \
  658. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI2EN);\
  659. /* Delay after an RCC peripheral clock enabling */\
  660. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI2EN);\
  661. UNUSED(tmpreg); \
  662. } while(0U)
  663. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  664. __IO uint32_t tmpreg; \
  665. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  666. /* Delay after an RCC peripheral clock enabling */\
  667. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  668. UNUSED(tmpreg); \
  669. } while(0U)
  670. #define __HAL_RCC_USART3_CLK_ENABLE() do { \
  671. __IO uint32_t tmpreg; \
  672. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
  673. /* Delay after an RCC peripheral clock enabling */\
  674. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
  675. UNUSED(tmpreg); \
  676. } while(0U)
  677. #define __HAL_RCC_I2C1_CLK_ENABLE() do { \
  678. __IO uint32_t tmpreg; \
  679. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  680. /* Delay after an RCC peripheral clock enabling */\
  681. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  682. UNUSED(tmpreg); \
  683. } while(0U)
  684. #define __HAL_RCC_I2C2_CLK_ENABLE() do { \
  685. __IO uint32_t tmpreg; \
  686. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C2EN);\
  687. /* Delay after an RCC peripheral clock enabling */\
  688. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C2EN);\
  689. UNUSED(tmpreg); \
  690. } while(0U)
  691. #define __HAL_RCC_USB_CLK_ENABLE() do { \
  692. __IO uint32_t tmpreg; \
  693. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USBEN);\
  694. /* Delay after an RCC peripheral clock enabling */\
  695. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USBEN);\
  696. UNUSED(tmpreg); \
  697. } while(0U)
  698. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  699. __IO uint32_t tmpreg; \
  700. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  701. /* Delay after an RCC peripheral clock enabling */\
  702. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  703. UNUSED(tmpreg); \
  704. } while(0U)
  705. #define __HAL_RCC_DAC_CLK_ENABLE() do { \
  706. __IO uint32_t tmpreg; \
  707. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_DACEN);\
  708. /* Delay after an RCC peripheral clock enabling */\
  709. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_DACEN);\
  710. UNUSED(tmpreg); \
  711. } while(0U)
  712. #define __HAL_RCC_COMP_CLK_ENABLE() do { \
  713. __IO uint32_t tmpreg; \
  714. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_COMPEN);\
  715. /* Delay after an RCC peripheral clock enabling */\
  716. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_COMPEN);\
  717. UNUSED(tmpreg); \
  718. } while(0U)
  719. #define __HAL_RCC_TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  720. #define __HAL_RCC_TIM3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
  721. #define __HAL_RCC_TIM4_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM4EN))
  722. #define __HAL_RCC_TIM6_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM6EN))
  723. #define __HAL_RCC_TIM7_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM7EN))
  724. #define __HAL_RCC_WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  725. #define __HAL_RCC_SPI2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI2EN))
  726. #define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  727. #define __HAL_RCC_USART3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART3EN))
  728. #define __HAL_RCC_I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  729. #define __HAL_RCC_I2C2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C2EN))
  730. #define __HAL_RCC_USB_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USBEN))
  731. #define __HAL_RCC_PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  732. #define __HAL_RCC_DAC_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_DACEN))
  733. #define __HAL_RCC_COMP_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_COMPEN))
  734. /**
  735. * @}
  736. */
  737. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Clock Enable Disable
  738. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  739. * @note After reset, the peripheral clock (used for registers read/write access)
  740. * is disabled and the application software has to enable this clock before
  741. * using it.
  742. * @{
  743. */
  744. #define __HAL_RCC_SYSCFG_CLK_ENABLE() do { \
  745. __IO uint32_t tmpreg; \
  746. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  747. /* Delay after an RCC peripheral clock enabling */\
  748. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  749. UNUSED(tmpreg); \
  750. } while(0U)
  751. #define __HAL_RCC_TIM9_CLK_ENABLE() do { \
  752. __IO uint32_t tmpreg; \
  753. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM9EN);\
  754. /* Delay after an RCC peripheral clock enabling */\
  755. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM9EN);\
  756. UNUSED(tmpreg); \
  757. } while(0U)
  758. #define __HAL_RCC_TIM10_CLK_ENABLE() do { \
  759. __IO uint32_t tmpreg; \
  760. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM10EN);\
  761. /* Delay after an RCC peripheral clock enabling */\
  762. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM10EN);\
  763. UNUSED(tmpreg); \
  764. } while(0U)
  765. #define __HAL_RCC_TIM11_CLK_ENABLE() do { \
  766. __IO uint32_t tmpreg; \
  767. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM11EN);\
  768. /* Delay after an RCC peripheral clock enabling */\
  769. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM11EN);\
  770. UNUSED(tmpreg); \
  771. } while(0U)
  772. #define __HAL_RCC_ADC1_CLK_ENABLE() do { \
  773. __IO uint32_t tmpreg; \
  774. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  775. /* Delay after an RCC peripheral clock enabling */\
  776. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  777. UNUSED(tmpreg); \
  778. } while(0U)
  779. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  780. __IO uint32_t tmpreg; \
  781. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  782. /* Delay after an RCC peripheral clock enabling */\
  783. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  784. UNUSED(tmpreg); \
  785. } while(0U)
  786. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  787. __IO uint32_t tmpreg; \
  788. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  789. /* Delay after an RCC peripheral clock enabling */\
  790. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  791. UNUSED(tmpreg); \
  792. } while(0U)
  793. #define __HAL_RCC_SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
  794. #define __HAL_RCC_TIM9_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM9EN))
  795. #define __HAL_RCC_TIM10_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM10EN))
  796. #define __HAL_RCC_TIM11_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM11EN))
  797. #define __HAL_RCC_ADC1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
  798. #define __HAL_RCC_SPI1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
  799. #define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  800. /**
  801. * @}
  802. */
  803. /** @defgroup RCC_Peripheral_Clock_Force_Release RCC Peripheral Clock Force Release
  804. * @brief Force or release AHB peripheral reset.
  805. * @{
  806. */
  807. #define __HAL_RCC_AHB_FORCE_RESET() (RCC->AHBRSTR = 0xFFFFFFFFU)
  808. #define __HAL_RCC_GPIOA_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOARST))
  809. #define __HAL_RCC_GPIOB_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOBRST))
  810. #define __HAL_RCC_GPIOC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOCRST))
  811. #define __HAL_RCC_GPIOD_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIODRST))
  812. #define __HAL_RCC_GPIOH_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOHRST))
  813. #define __HAL_RCC_CRC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_CRCRST))
  814. #define __HAL_RCC_FLITF_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_FLITFRST))
  815. #define __HAL_RCC_DMA1_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_DMA1RST))
  816. #define __HAL_RCC_AHB_RELEASE_RESET() (RCC->AHBRSTR = 0x00000000U)
  817. #define __HAL_RCC_GPIOA_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOARST))
  818. #define __HAL_RCC_GPIOB_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOBRST))
  819. #define __HAL_RCC_GPIOC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOCRST))
  820. #define __HAL_RCC_GPIOD_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIODRST))
  821. #define __HAL_RCC_GPIOH_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOHRST))
  822. #define __HAL_RCC_CRC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_CRCRST))
  823. #define __HAL_RCC_FLITF_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_FLITFRST))
  824. #define __HAL_RCC_DMA1_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_DMA1RST))
  825. /**
  826. * @}
  827. */
  828. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Force Release Reset
  829. * @brief Force or release APB1 peripheral reset.
  830. * @{
  831. */
  832. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFFU)
  833. #define __HAL_RCC_TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  834. #define __HAL_RCC_TIM3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
  835. #define __HAL_RCC_TIM4_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM4RST))
  836. #define __HAL_RCC_TIM6_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM6RST))
  837. #define __HAL_RCC_TIM7_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM7RST))
  838. #define __HAL_RCC_WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  839. #define __HAL_RCC_SPI2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI2RST))
  840. #define __HAL_RCC_USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  841. #define __HAL_RCC_USART3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART3RST))
  842. #define __HAL_RCC_I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  843. #define __HAL_RCC_I2C2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C2RST))
  844. #define __HAL_RCC_USB_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USBRST))
  845. #define __HAL_RCC_PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  846. #define __HAL_RCC_DAC_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_DACRST))
  847. #define __HAL_RCC_COMP_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_COMPRST))
  848. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00000000U)
  849. #define __HAL_RCC_TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  850. #define __HAL_RCC_TIM3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
  851. #define __HAL_RCC_TIM4_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM4RST))
  852. #define __HAL_RCC_TIM6_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM6RST))
  853. #define __HAL_RCC_TIM7_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM7RST))
  854. #define __HAL_RCC_WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  855. #define __HAL_RCC_SPI2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI2RST))
  856. #define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  857. #define __HAL_RCC_USART3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART3RST))
  858. #define __HAL_RCC_I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  859. #define __HAL_RCC_I2C2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C2RST))
  860. #define __HAL_RCC_USB_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USBRST))
  861. #define __HAL_RCC_PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  862. #define __HAL_RCC_DAC_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_DACRST))
  863. #define __HAL_RCC_COMP_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_COMPRST))
  864. /**
  865. * @}
  866. */
  867. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Force Release Reset
  868. * @brief Force or release APB1 peripheral reset.
  869. * @{
  870. */
  871. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  872. #define __HAL_RCC_SYSCFG_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SYSCFGRST))
  873. #define __HAL_RCC_TIM9_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM9RST))
  874. #define __HAL_RCC_TIM10_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM10RST))
  875. #define __HAL_RCC_TIM11_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM11RST))
  876. #define __HAL_RCC_ADC1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_ADC1RST))
  877. #define __HAL_RCC_SPI1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
  878. #define __HAL_RCC_USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  879. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00000000U)
  880. #define __HAL_RCC_SYSCFG_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SYSCFGRST))
  881. #define __HAL_RCC_TIM9_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM9RST))
  882. #define __HAL_RCC_TIM10_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM10RST))
  883. #define __HAL_RCC_TIM11_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM11RST))
  884. #define __HAL_RCC_ADC1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADC1RST))
  885. #define __HAL_RCC_SPI1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
  886. #define __HAL_RCC_USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  887. /**
  888. * @}
  889. */
  890. /** @defgroup RCC_Peripheral_Clock_Sleep_Enable_Disable RCC Peripheral Clock Sleep Enable Disable
  891. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  892. * power consumption.
  893. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  894. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  895. * @{
  896. */
  897. #define __HAL_RCC_GPIOA_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOALPEN))
  898. #define __HAL_RCC_GPIOB_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOBLPEN))
  899. #define __HAL_RCC_GPIOC_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOCLPEN))
  900. #define __HAL_RCC_GPIOD_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIODLPEN))
  901. #define __HAL_RCC_GPIOH_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_GPIOHLPEN))
  902. #define __HAL_RCC_CRC_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_CRCLPEN))
  903. #define __HAL_RCC_FLITF_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_FLITFLPEN))
  904. #define __HAL_RCC_DMA1_CLK_SLEEP_ENABLE() (RCC->AHBLPENR |= (RCC_AHBLPENR_DMA1LPEN))
  905. #define __HAL_RCC_GPIOA_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOALPEN))
  906. #define __HAL_RCC_GPIOB_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOBLPEN))
  907. #define __HAL_RCC_GPIOC_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOCLPEN))
  908. #define __HAL_RCC_GPIOD_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIODLPEN))
  909. #define __HAL_RCC_GPIOH_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_GPIOHLPEN))
  910. #define __HAL_RCC_CRC_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_CRCLPEN))
  911. #define __HAL_RCC_FLITF_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_FLITFLPEN))
  912. #define __HAL_RCC_DMA1_CLK_SLEEP_DISABLE() (RCC->AHBLPENR &= ~(RCC_AHBLPENR_DMA1LPEN))
  913. /** @brief Enable or disable the APB1 peripheral clock during Low Power (Sleep) mode.
  914. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  915. * power consumption.
  916. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  917. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  918. */
  919. #define __HAL_RCC_TIM2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM2LPEN))
  920. #define __HAL_RCC_TIM3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM3LPEN))
  921. #define __HAL_RCC_TIM4_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM4LPEN))
  922. #define __HAL_RCC_TIM6_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM6LPEN))
  923. #define __HAL_RCC_TIM7_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM7LPEN))
  924. #define __HAL_RCC_WWDG_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_WWDGLPEN))
  925. #define __HAL_RCC_SPI2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI2LPEN))
  926. #define __HAL_RCC_USART2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USART2LPEN))
  927. #define __HAL_RCC_USART3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USART3LPEN))
  928. #define __HAL_RCC_I2C1_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C1LPEN))
  929. #define __HAL_RCC_I2C2_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C2LPEN))
  930. #define __HAL_RCC_USB_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USBLPEN))
  931. #define __HAL_RCC_PWR_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_PWRLPEN))
  932. #define __HAL_RCC_DAC_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_DACLPEN))
  933. #define __HAL_RCC_COMP_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_COMPLPEN))
  934. #define __HAL_RCC_TIM2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM2LPEN))
  935. #define __HAL_RCC_TIM3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM3LPEN))
  936. #define __HAL_RCC_TIM4_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM4LPEN))
  937. #define __HAL_RCC_TIM6_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM6LPEN))
  938. #define __HAL_RCC_TIM7_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM7LPEN))
  939. #define __HAL_RCC_WWDG_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_WWDGLPEN))
  940. #define __HAL_RCC_SPI2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI2LPEN))
  941. #define __HAL_RCC_USART2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART2LPEN))
  942. #define __HAL_RCC_USART3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART3LPEN))
  943. #define __HAL_RCC_I2C1_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C1LPEN))
  944. #define __HAL_RCC_I2C2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C2LPEN))
  945. #define __HAL_RCC_USB_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USBLPEN))
  946. #define __HAL_RCC_PWR_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_PWRLPEN))
  947. #define __HAL_RCC_DAC_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_DACLPEN))
  948. #define __HAL_RCC_COMP_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_COMPLPEN))
  949. /** @brief Enable or disable the APB2 peripheral clock during Low Power (Sleep) mode.
  950. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  951. * power consumption.
  952. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  953. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  954. */
  955. #define __HAL_RCC_SYSCFG_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SYSCFGLPEN))
  956. #define __HAL_RCC_TIM9_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM9LPEN))
  957. #define __HAL_RCC_TIM10_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM10LPEN))
  958. #define __HAL_RCC_TIM11_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM11LPEN))
  959. #define __HAL_RCC_ADC1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_ADC1LPEN))
  960. #define __HAL_RCC_SPI1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_SPI1LPEN))
  961. #define __HAL_RCC_USART1_CLK_SLEEP_ENABLE() (RCC->APB2LPENR |= (RCC_APB2LPENR_USART1LPEN))
  962. #define __HAL_RCC_SYSCFG_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SYSCFGLPEN))
  963. #define __HAL_RCC_TIM9_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM9LPEN))
  964. #define __HAL_RCC_TIM10_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM10LPEN))
  965. #define __HAL_RCC_TIM11_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM11LPEN))
  966. #define __HAL_RCC_ADC1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_ADC1LPEN))
  967. #define __HAL_RCC_SPI1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SPI1LPEN))
  968. #define __HAL_RCC_USART1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_USART1LPEN))
  969. /**
  970. * @}
  971. */
  972. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enable Disable Status
  973. * @brief Get the enable or disable status of the AHB peripheral clock.
  974. * @note After reset, the peripheral clock (used for registers read/write access)
  975. * is disabled and the application software has to enable this clock before
  976. * using it.
  977. * @{
  978. */
  979. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOAEN)) != 0U)
  980. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOBEN)) != 0U)
  981. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOCEN)) != 0U)
  982. #define __HAL_RCC_GPIOD_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIODEN)) != 0U)
  983. #define __HAL_RCC_GPIOH_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOHEN)) != 0U)
  984. #define __HAL_RCC_CRC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) != 0U)
  985. #define __HAL_RCC_FLITF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) != 0U)
  986. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) != 0U)
  987. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOAEN)) == 0U)
  988. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOBEN)) == 0U)
  989. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOCEN)) == 0U)
  990. #define __HAL_RCC_GPIOD_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIODEN)) == 0U)
  991. #define __HAL_RCC_GPIOH_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOHEN)) == 0U)
  992. #define __HAL_RCC_CRC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) == 0U)
  993. #define __HAL_RCC_FLITF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) == 0U)
  994. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) == 0U)
  995. /**
  996. * @}
  997. */
  998. /** @defgroup RCC_APB1_Peripheral_Clock_Enable_Disable_Status APB1 Peripheral Clock Enable Disable Status
  999. * @brief Get the enable or disable status of the APB1 peripheral clock.
  1000. * @note After reset, the peripheral clock (used for registers read/write access)
  1001. * is disabled and the application software has to enable this clock before
  1002. * using it.
  1003. * @{
  1004. */
  1005. #define __HAL_RCC_TIM2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) != 0U)
  1006. #define __HAL_RCC_TIM3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) != 0U)
  1007. #define __HAL_RCC_TIM4_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM4EN)) != 0U)
  1008. #define __HAL_RCC_TIM6_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM6EN)) != 0U)
  1009. #define __HAL_RCC_TIM7_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM7EN)) != 0U)
  1010. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) != 0U)
  1011. #define __HAL_RCC_SPI2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_SPI2EN)) != 0U)
  1012. #define __HAL_RCC_USART2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != 0U)
  1013. #define __HAL_RCC_USART3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) != 0U)
  1014. #define __HAL_RCC_I2C1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) != 0U)
  1015. #define __HAL_RCC_I2C2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C2EN)) != 0U)
  1016. #define __HAL_RCC_USB_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USBEN)) != 0U)
  1017. #define __HAL_RCC_PWR_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) != 0U)
  1018. #define __HAL_RCC_DAC_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_DACEN)) != 0U)
  1019. #define __HAL_RCC_COMP_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_COMPEN)) != 0U)
  1020. #define __HAL_RCC_TIM2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) == 0U)
  1021. #define __HAL_RCC_TIM3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) == 0U)
  1022. #define __HAL_RCC_TIM4_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM4EN)) == 0U)
  1023. #define __HAL_RCC_TIM6_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM6EN)) == 0U)
  1024. #define __HAL_RCC_TIM7_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM7EN)) == 0U)
  1025. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) == 0U)
  1026. #define __HAL_RCC_SPI2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_SPI2EN)) == 0U)
  1027. #define __HAL_RCC_USART2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == 0U)
  1028. #define __HAL_RCC_USART3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) == 0U)
  1029. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) == 0U)
  1030. #define __HAL_RCC_I2C2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C2EN)) == 0U)
  1031. #define __HAL_RCC_USB_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USBEN)) == 0U)
  1032. #define __HAL_RCC_PWR_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) == 0U)
  1033. #define __HAL_RCC_DAC_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_DACEN)) == 0U)
  1034. #define __HAL_RCC_COMP_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_COMPEN)) == 0U)
  1035. /**
  1036. * @}
  1037. */
  1038. /** @defgroup RCC_APB2_Peripheral_Clock_Enable_Disable_Status APB2 Peripheral Clock Enable Disable Status
  1039. * @brief Get the enable or disable status of the APB2 peripheral clock.
  1040. * @note After reset, the peripheral clock (used for registers read/write access)
  1041. * is disabled and the application software has to enable this clock before
  1042. * using it.
  1043. * @{
  1044. */
  1045. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) != 0U)
  1046. #define __HAL_RCC_TIM9_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM9EN)) != 0U)
  1047. #define __HAL_RCC_TIM10_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM10EN)) != 0U)
  1048. #define __HAL_RCC_TIM11_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM11EN)) != 0U)
  1049. #define __HAL_RCC_ADC1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) != 0U)
  1050. #define __HAL_RCC_SPI1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) != 0U)
  1051. #define __HAL_RCC_USART1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) != 0U)
  1052. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) == 0U)
  1053. #define __HAL_RCC_TIM9_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM9EN)) == 0U)
  1054. #define __HAL_RCC_TIM10_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM10EN)) == 0U)
  1055. #define __HAL_RCC_TIM11_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM11EN)) == 0U)
  1056. #define __HAL_RCC_ADC1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) == 0U)
  1057. #define __HAL_RCC_SPI1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) == 0U)
  1058. #define __HAL_RCC_USART1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) == 0U)
  1059. /**
  1060. * @}
  1061. */
  1062. /** @defgroup RCC_AHB_Clock_Sleep_Enable_Disable_Status AHB Peripheral Clock Sleep Enable Disable Status
  1063. * @brief Get the enable or disable status of the AHB peripheral clock during Low Power (Sleep) mode.
  1064. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  1065. * power consumption.
  1066. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  1067. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  1068. * @{
  1069. */
  1070. #define __HAL_RCC_GPIOA_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOALPEN)) != 0U)
  1071. #define __HAL_RCC_GPIOB_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOBLPEN)) != 0U)
  1072. #define __HAL_RCC_GPIOC_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOCLPEN)) != 0U)
  1073. #define __HAL_RCC_GPIOD_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIODLPEN)) != 0U)
  1074. #define __HAL_RCC_GPIOH_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOHLPEN)) != 0U)
  1075. #define __HAL_RCC_CRC_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_CRCLPEN)) != 0U)
  1076. #define __HAL_RCC_FLITF_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_FLITFLPEN)) != 0U)
  1077. #define __HAL_RCC_DMA1_IS_CLK_SLEEP_ENABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_DMA1LPEN)) != 0U)
  1078. #define __HAL_RCC_GPIOA_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOALPEN)) == 0U)
  1079. #define __HAL_RCC_GPIOB_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOBLPEN)) == 0U)
  1080. #define __HAL_RCC_GPIOC_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOCLPEN)) == 0U)
  1081. #define __HAL_RCC_GPIOD_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIODLPEN)) == 0U)
  1082. #define __HAL_RCC_GPIOH_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_GPIOHLPEN)) == 0U)
  1083. #define __HAL_RCC_CRC_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_CRCLPEN)) == 0U)
  1084. #define __HAL_RCC_FLITF_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_FLITFLPEN)) == 0U)
  1085. #define __HAL_RCC_DMA1_IS_CLK_SLEEP_DISABLED() ((RCC->AHBLPENR & (RCC_AHBLPENR_DMA1LPEN)) == 0U)
  1086. /**
  1087. * @}
  1088. */
  1089. /** @defgroup RCC_APB1_Clock_Sleep_Enable_Disable_Status APB1 Peripheral Clock Sleep Enable Disable Status
  1090. * @brief Get the enable or disable status of the APB1 peripheral clock during Low Power (Sleep) mode.
  1091. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  1092. * power consumption.
  1093. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  1094. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  1095. * @{
  1096. */
  1097. #define __HAL_RCC_TIM2_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM2LPEN)) != 0U)
  1098. #define __HAL_RCC_TIM3_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM3LPEN)) != 0U)
  1099. #define __HAL_RCC_TIM4_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM4LPEN)) != 0U)
  1100. #define __HAL_RCC_TIM6_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM6LPEN)) != 0U)
  1101. #define __HAL_RCC_TIM7_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM7LPEN)) != 0U)
  1102. #define __HAL_RCC_WWDG_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_WWDGLPEN)) != 0U)
  1103. #define __HAL_RCC_SPI2_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_SPI2LPEN)) != 0U)
  1104. #define __HAL_RCC_USART2_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_USART2LPEN)) != 0U)
  1105. #define __HAL_RCC_USART3_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_USART3LPEN)) != 0U)
  1106. #define __HAL_RCC_I2C1_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_I2C1LPEN)) != 0U)
  1107. #define __HAL_RCC_I2C2_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_I2C2LPEN)) != 0U)
  1108. #define __HAL_RCC_USB_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_USBLPEN)) != 0U)
  1109. #define __HAL_RCC_PWR_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_PWRLPEN)) != 0U)
  1110. #define __HAL_RCC_DAC_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_DACLPEN)) != 0U)
  1111. #define __HAL_RCC_COMP_IS_CLK_SLEEP_ENABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_COMPLPEN)) != 0U)
  1112. #define __HAL_RCC_TIM2_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM2LPEN)) == 0U)
  1113. #define __HAL_RCC_TIM3_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM3LPEN)) == 0U)
  1114. #define __HAL_RCC_TIM4_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM4LPEN)) == 0U)
  1115. #define __HAL_RCC_TIM6_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM6LPEN)) == 0U)
  1116. #define __HAL_RCC_TIM7_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_TIM7LPEN)) == 0U)
  1117. #define __HAL_RCC_WWDG_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_WWDGLPEN)) == 0U)
  1118. #define __HAL_RCC_SPI2_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_SPI2LPEN)) == 0U)
  1119. #define __HAL_RCC_USART2_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_USART2LPEN)) == 0U)
  1120. #define __HAL_RCC_USART3_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_USART3LPEN)) == 0U)
  1121. #define __HAL_RCC_I2C1_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_I2C1LPEN)) == 0U)
  1122. #define __HAL_RCC_I2C2_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_I2C2LPEN)) == 0U)
  1123. #define __HAL_RCC_USB_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_USBLPEN)) == 0U)
  1124. #define __HAL_RCC_PWR_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_PWRLPEN)) == 0U)
  1125. #define __HAL_RCC_DAC_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_DACLPEN)) == 0U)
  1126. #define __HAL_RCC_COMP_IS_CLK_SLEEP_DISABLED() ((RCC->APB1LPENR & (RCC_APB1LPENR_COMPLPEN)) == 0U)
  1127. /**
  1128. * @}
  1129. */
  1130. /** @defgroup RCC_APB2_Clock_Sleep_Enable_Disable_Status APB2 Peripheral Clock Sleep Enable Disable Status
  1131. * @brief Get the enable or disable status of the APB2 peripheral clock during Low Power (Sleep) mode.
  1132. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  1133. * power consumption.
  1134. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  1135. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  1136. * @{
  1137. */
  1138. #define __HAL_RCC_SYSCFG_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_SYSCFGLPEN)) != 0U)
  1139. #define __HAL_RCC_TIM9_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_TIM9LPEN)) != 0U)
  1140. #define __HAL_RCC_TIM10_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_TIM10LPEN)) != 0U)
  1141. #define __HAL_RCC_TIM11_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_TIM11LPEN)) != 0U)
  1142. #define __HAL_RCC_ADC1_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_ADC1LPEN)) != 0U)
  1143. #define __HAL_RCC_SPI1_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_SPI1LPEN)) != 0U)
  1144. #define __HAL_RCC_USART1_IS_CLK_SLEEP_ENABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_USART1LPEN)) != 0U)
  1145. #define __HAL_RCC_SYSCFG_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_SYSCFGLPEN)) == 0U)
  1146. #define __HAL_RCC_TIM9_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_TIM9LPEN)) == 0U)
  1147. #define __HAL_RCC_TIM10_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_TIM10LPEN)) == 0U)
  1148. #define __HAL_RCC_TIM11_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_TIM11LPEN)) == 0U)
  1149. #define __HAL_RCC_ADC1_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_ADC1LPEN)) == 0U)
  1150. #define __HAL_RCC_SPI1_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_SPI1LPEN)) == 0U)
  1151. #define __HAL_RCC_USART1_IS_CLK_SLEEP_DISABLED() ((RCC->APB2LPENR & (RCC_APB2LPENR_USART1LPEN)) == 0U)
  1152. /**
  1153. * @}
  1154. */
  1155. /** @defgroup RCC_HSI_Configuration HSI Configuration
  1156. * @{
  1157. */
  1158. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  1159. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  1160. * @note HSI can not be stopped if it is used as system clock source. In this case,
  1161. * you have to select another source of the system clock then stop the HSI.
  1162. * @note After enabling the HSI, the application software should wait on HSIRDY
  1163. * flag to be set indicating that HSI clock is stable and can be used as
  1164. * system clock source.
  1165. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  1166. * clock cycles.
  1167. */
  1168. #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = ENABLE)
  1169. #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = DISABLE)
  1170. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  1171. * @note The calibration is used to compensate for the variations in voltage
  1172. * and temperature that influence the frequency of the internal HSI RC.
  1173. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  1174. * (default is RCC_HSICALIBRATION_DEFAULT).
  1175. * This parameter must be a number between 0 and 0x1F.
  1176. */
  1177. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  1178. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << RCC_ICSCR_HSITRIM_Pos))
  1179. /**
  1180. * @}
  1181. */
  1182. /** @defgroup RCC_LSI_Configuration LSI Configuration
  1183. * @{
  1184. */
  1185. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  1186. * @note After enabling the LSI, the application software should wait on
  1187. * LSIRDY flag to be set indicating that LSI clock is stable and can
  1188. * be used to clock the IWDG and/or the RTC.
  1189. */
  1190. #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = ENABLE)
  1191. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  1192. * @note LSI can not be disabled if the IWDG is running.
  1193. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  1194. * clock cycles.
  1195. */
  1196. #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = DISABLE)
  1197. /**
  1198. * @}
  1199. */
  1200. /** @defgroup RCC_HSE_Configuration HSE Configuration
  1201. * @{
  1202. */
  1203. /**
  1204. * @brief Macro to configure the External High Speed oscillator (HSE).
  1205. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  1206. * supported by this macro. User should request a transition to HSE Off
  1207. * first and then HSE On or HSE Bypass.
  1208. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  1209. * software should wait on HSERDY flag to be set indicating that HSE clock
  1210. * is stable and can be used to clock the PLL and/or system clock.
  1211. * @note HSE state can not be changed if it is used directly or through the
  1212. * PLL as system clock. In this case, you have to select another source
  1213. * of the system clock then change the HSE state (ex. disable it).
  1214. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  1215. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  1216. * was previously enabled you have to enable it again after calling this
  1217. * function.
  1218. * @param __STATE__ specifies the new state of the HSE.
  1219. * This parameter can be one of the following values:
  1220. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  1221. * 6 HSE oscillator clock cycles.
  1222. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  1223. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  1224. */
  1225. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  1226. do{ \
  1227. if ((__STATE__) == RCC_HSE_ON) \
  1228. { \
  1229. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1230. } \
  1231. else if ((__STATE__) == RCC_HSE_OFF) \
  1232. { \
  1233. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1234. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1235. } \
  1236. else if ((__STATE__) == RCC_HSE_BYPASS) \
  1237. { \
  1238. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1239. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1240. } \
  1241. else \
  1242. { \
  1243. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1244. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1245. } \
  1246. }while(0U)
  1247. /**
  1248. * @}
  1249. */
  1250. /** @defgroup RCC_LSE_Configuration LSE Configuration
  1251. * @{
  1252. */
  1253. /**
  1254. * @brief Macro to configure the External Low Speed oscillator (LSE).
  1255. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  1256. * @note As the LSE is in the Backup domain and write access is denied to
  1257. * this domain after reset, you have to enable write access using
  1258. * @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  1259. * (to be done once after reset).
  1260. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  1261. * software should wait on LSERDY flag to be set indicating that LSE clock
  1262. * is stable and can be used to clock the RTC.
  1263. * @param __STATE__ specifies the new state of the LSE.
  1264. * This parameter can be one of the following values:
  1265. * @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
  1266. * 6 LSE oscillator clock cycles.
  1267. * @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
  1268. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  1269. */
  1270. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  1271. do{ \
  1272. if ((__STATE__) == RCC_LSE_ON) \
  1273. { \
  1274. SET_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1275. } \
  1276. else if ((__STATE__) == RCC_LSE_OFF) \
  1277. { \
  1278. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1279. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1280. } \
  1281. else if ((__STATE__) == RCC_LSE_BYPASS) \
  1282. { \
  1283. SET_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1284. SET_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1285. } \
  1286. else \
  1287. { \
  1288. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1289. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1290. } \
  1291. }while(0U)
  1292. /**
  1293. * @}
  1294. */
  1295. /** @defgroup RCC_MSI_Configuration MSI Configuration
  1296. * @{
  1297. */
  1298. /** @brief Macro to enable Internal Multi Speed oscillator (MSI).
  1299. * @note After enabling the MSI, the application software should wait on MSIRDY
  1300. * flag to be set indicating that MSI clock is stable and can be used as
  1301. * system clock source.
  1302. */
  1303. #define __HAL_RCC_MSI_ENABLE() (*(__IO uint32_t *) RCC_CR_MSION_BB = ENABLE)
  1304. /** @brief Macro to disable the Internal Multi Speed oscillator (MSI).
  1305. * @note The MSI is stopped by hardware when entering STOP and STANDBY modes.
  1306. * It is used (enabled by hardware) as system clock source after startup
  1307. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  1308. * of the HSE used directly or indirectly as system clock (if the Clock
  1309. * Security System CSS is enabled).
  1310. * @note MSI can not be stopped if it is used as system clock source. In this case,
  1311. * you have to select another source of the system clock then stop the MSI.
  1312. * @note When the MSI is stopped, MSIRDY flag goes low after 6 MSI oscillator
  1313. * clock cycles.
  1314. */
  1315. #define __HAL_RCC_MSI_DISABLE() (*(__IO uint32_t *) RCC_CR_MSION_BB = DISABLE)
  1316. /** @brief Macro adjusts Internal Multi Speed oscillator (MSI) calibration value.
  1317. * @note The calibration is used to compensate for the variations in voltage
  1318. * and temperature that influence the frequency of the internal MSI RC.
  1319. * @param _MSICALIBRATIONVALUE_ specifies the calibration trimming value.
  1320. * (default is RCC_MSICALIBRATION_DEFAULT).
  1321. * This parameter must be a number between 0 and 0xFF.
  1322. */
  1323. #define __HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST(_MSICALIBRATIONVALUE_) \
  1324. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_MSITRIM, (uint32_t)(_MSICALIBRATIONVALUE_) << RCC_ICSCR_MSITRIM_Pos))
  1325. /* @brief Macro to configures the Internal Multi Speed oscillator (MSI) clock range.
  1326. * @note After restart from Reset or wakeup from STANDBY, the MSI clock is
  1327. * around 2.097 MHz. The MSI clock does not change after wake-up from
  1328. * STOP mode.
  1329. * @note The MSI clock range can be modified on the fly.
  1330. * @param _MSIRANGEVALUE_ specifies the MSI Clock range.
  1331. * This parameter must be one of the following values:
  1332. * @arg @ref RCC_MSIRANGE_0 MSI clock is around 65.536 KHz
  1333. * @arg @ref RCC_MSIRANGE_1 MSI clock is around 131.072 KHz
  1334. * @arg @ref RCC_MSIRANGE_2 MSI clock is around 262.144 KHz
  1335. * @arg @ref RCC_MSIRANGE_3 MSI clock is around 524.288 KHz
  1336. * @arg @ref RCC_MSIRANGE_4 MSI clock is around 1.048 MHz
  1337. * @arg @ref RCC_MSIRANGE_5 MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  1338. * @arg @ref RCC_MSIRANGE_6 MSI clock is around 4.194 MHz
  1339. */
  1340. #define __HAL_RCC_MSI_RANGE_CONFIG(_MSIRANGEVALUE_) (MODIFY_REG(RCC->ICSCR, \
  1341. RCC_ICSCR_MSIRANGE, (uint32_t)(_MSIRANGEVALUE_)))
  1342. /** @brief Macro to get the Internal Multi Speed oscillator (MSI) clock range in run mode
  1343. * @retval MSI clock range.
  1344. * This parameter must be one of the following values:
  1345. * @arg @ref RCC_MSIRANGE_0 MSI clock is around 65.536 KHz
  1346. * @arg @ref RCC_MSIRANGE_1 MSI clock is around 131.072 KHz
  1347. * @arg @ref RCC_MSIRANGE_2 MSI clock is around 262.144 KHz
  1348. * @arg @ref RCC_MSIRANGE_3 MSI clock is around 524.288 KHz
  1349. * @arg @ref RCC_MSIRANGE_4 MSI clock is around 1.048 MHz
  1350. * @arg @ref RCC_MSIRANGE_5 MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  1351. * @arg @ref RCC_MSIRANGE_6 MSI clock is around 4.194 MHz
  1352. */
  1353. #define __HAL_RCC_GET_MSI_RANGE() (uint32_t)(READ_BIT(RCC->ICSCR, RCC_ICSCR_MSIRANGE))
  1354. /**
  1355. * @}
  1356. */
  1357. /** @defgroup RCC_PLL_Configuration PLL Configuration
  1358. * @{
  1359. */
  1360. /** @brief Macro to enable the main PLL.
  1361. * @note After enabling the main PLL, the application software should wait on
  1362. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1363. * be used as system clock source.
  1364. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1365. */
  1366. #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = ENABLE)
  1367. /** @brief Macro to disable the main PLL.
  1368. * @note The main PLL can not be disabled if it is used as system clock source
  1369. */
  1370. #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = DISABLE)
  1371. /** @brief Macro to configure the main PLL clock source, multiplication and division factors.
  1372. * @note This function must be used only when the main PLL is disabled.
  1373. *
  1374. * @param __RCC_PLLSOURCE__ specifies the PLL entry clock source.
  1375. * This parameter can be one of the following values:
  1376. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL clock entry
  1377. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  1378. * @param __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
  1379. * This parameter can be one of the following values:
  1380. * @arg @ref RCC_PLL_MUL3 PLLVCO = PLL clock entry x 3
  1381. * @arg @ref RCC_PLL_MUL4 PLLVCO = PLL clock entry x 4
  1382. * @arg @ref RCC_PLL_MUL6 PLLVCO = PLL clock entry x 6
  1383. * @arg @ref RCC_PLL_MUL8 PLLVCO = PLL clock entry x 8
  1384. * @arg @ref RCC_PLL_MUL12 PLLVCO = PLL clock entry x 12
  1385. * @arg @ref RCC_PLL_MUL16 PLLVCO = PLL clock entry x 16
  1386. * @arg @ref RCC_PLL_MUL24 PLLVCO = PLL clock entry x 24
  1387. * @arg @ref RCC_PLL_MUL32 PLLVCO = PLL clock entry x 32
  1388. * @arg @ref RCC_PLL_MUL48 PLLVCO = PLL clock entry x 48
  1389. * @note The PLL VCO clock frequency must not exceed 96 MHz when the product is in
  1390. * Range 1, 48 MHz when the product is in Range 2 and 24 MHz when the product is
  1391. * in Range 3.
  1392. *
  1393. * @param __PLLDIV__ specifies the division factor for PLL VCO input clock
  1394. * This parameter can be one of the following values:
  1395. * @arg @ref RCC_PLL_DIV2 PLL clock output = PLLVCO / 2
  1396. * @arg @ref RCC_PLL_DIV3 PLL clock output = PLLVCO / 3
  1397. * @arg @ref RCC_PLL_DIV4 PLL clock output = PLLVCO / 4
  1398. *
  1399. */
  1400. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__, __PLLDIV__)\
  1401. MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC|RCC_CFGR_PLLMUL|RCC_CFGR_PLLDIV),((__RCC_PLLSOURCE__) | (__PLLMUL__) | (__PLLDIV__)))
  1402. /** @brief Get oscillator clock selected as PLL input clock
  1403. * @retval The clock source used for PLL entry. The returned value can be one
  1404. * of the following:
  1405. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL input clock
  1406. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  1407. */
  1408. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  1409. /**
  1410. * @}
  1411. */
  1412. /** @defgroup RCC_Get_Clock_source Get Clock source
  1413. * @{
  1414. */
  1415. /**
  1416. * @brief Macro to configure the system clock source.
  1417. * @param __SYSCLKSOURCE__ specifies the system clock source.
  1418. * This parameter can be one of the following values:
  1419. * @arg @ref RCC_SYSCLKSOURCE_MSI MSI oscillator is used as system clock source.
  1420. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  1421. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  1422. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  1423. */
  1424. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  1425. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  1426. /** @brief Macro to get the clock source used as system clock.
  1427. * @retval The clock source used as system clock. The returned value can be one
  1428. * of the following:
  1429. * @arg @ref RCC_SYSCLKSOURCE_STATUS_MSI MSI used as system clock
  1430. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  1431. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  1432. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  1433. */
  1434. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  1435. /**
  1436. * @}
  1437. */
  1438. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  1439. * @{
  1440. */
  1441. /** @brief Macro to configure the MCO clock.
  1442. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1443. * This parameter can be one of the following values:
  1444. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1445. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1446. * @arg @ref RCC_MCO1SOURCE_HSI HSI oscillator clock selected as MCO clock
  1447. * @arg @ref RCC_MCO1SOURCE_MSI MSI oscillator clock selected as MCO clock
  1448. * @arg @ref RCC_MCO1SOURCE_HSE HSE oscillator clock selected as MCO clock
  1449. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock selected as MCO clock
  1450. * @arg @ref RCC_MCO1SOURCE_LSI LSI clock selected as MCO clock
  1451. * @arg @ref RCC_MCO1SOURCE_LSE LSE clock selected as MCO clock
  1452. * @param __MCODIV__ specifies the MCO clock prescaler.
  1453. * This parameter can be one of the following values:
  1454. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  1455. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  1456. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  1457. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  1458. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  1459. */
  1460. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1461. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCOSEL | RCC_CFGR_MCOPRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  1462. /**
  1463. * @}
  1464. */
  1465. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  1466. * @{
  1467. */
  1468. /** @brief Macro to configure the RTC clock (RTCCLK).
  1469. * @note As the RTC clock configuration bits are in the Backup domain and write
  1470. * access is denied to this domain after reset, you have to enable write
  1471. * access using the Power Backup Access macro before to configure
  1472. * the RTC clock source (to be done once after reset).
  1473. * @note Once the RTC clock is configured it cannot be changed unless the
  1474. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1475. * a Power On Reset (POR).
  1476. * @note RTC prescaler cannot be modified if HSE is enabled (HSEON = 1).
  1477. *
  1478. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  1479. * This parameter can be one of the following values:
  1480. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1481. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1482. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1483. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV2 HSE divided by 2 selected as RTC clock
  1484. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV4 HSE divided by 4 selected as RTC clock
  1485. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV8 HSE divided by 8 selected as RTC clock
  1486. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV16 HSE divided by 16 selected as RTC clock
  1487. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1488. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1489. * However, when the HSE clock is used as RTC clock source, the RTC
  1490. * cannot be used in STOP and STANDBY modes.
  1491. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1492. * RTC clock source).
  1493. */
  1494. #define __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__) do { \
  1495. if(((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE) \
  1496. { \
  1497. MODIFY_REG(RCC->CR, RCC_CR_RTCPRE, ((__RTC_CLKSOURCE__) & RCC_CR_RTCPRE)); \
  1498. } \
  1499. } while (0U)
  1500. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) do { \
  1501. __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__); \
  1502. RCC->CSR |= ((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL); \
  1503. } while (0U)
  1504. /** @brief Macro to get the RTC clock source.
  1505. * @retval The clock source can be one of the following values:
  1506. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1507. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1508. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1509. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIVX HSE divided by X selected as RTC clock (X can be retrieved thanks to @ref __HAL_RCC_GET_RTC_HSE_PRESCALER()
  1510. */
  1511. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->CSR, RCC_CSR_RTCSEL))
  1512. /**
  1513. * @brief Get the RTC and LCD HSE clock divider (RTCCLK / LCDCLK).
  1514. *
  1515. * @retval Returned value can be one of the following values:
  1516. * @arg @ref RCC_RTC_HSE_DIV_2 HSE divided by 2 selected as RTC clock
  1517. * @arg @ref RCC_RTC_HSE_DIV_4 HSE divided by 4 selected as RTC clock
  1518. * @arg @ref RCC_RTC_HSE_DIV_8 HSE divided by 8 selected as RTC clock
  1519. * @arg @ref RCC_RTC_HSE_DIV_16 HSE divided by 16 selected as RTC clock
  1520. *
  1521. */
  1522. #define __HAL_RCC_GET_RTC_HSE_PRESCALER() ((uint32_t)(READ_BIT(RCC->CR, RCC_CR_RTCPRE)))
  1523. /** @brief Macro to enable the the RTC clock.
  1524. * @note These macros must be used only after the RTC clock source was selected.
  1525. */
  1526. #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) RCC_CSR_RTCEN_BB = ENABLE)
  1527. /** @brief Macro to disable the the RTC clock.
  1528. * @note These macros must be used only after the RTC clock source was selected.
  1529. */
  1530. #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) RCC_CSR_RTCEN_BB = DISABLE)
  1531. /** @brief Macro to force the Backup domain reset.
  1532. * @note This function resets the RTC peripheral (including the backup registers)
  1533. * and the RTC clock source selection in RCC_CSR register.
  1534. * @note The BKPSRAM is not affected by this reset.
  1535. */
  1536. #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) RCC_CSR_RTCRST_BB = ENABLE)
  1537. /** @brief Macros to release the Backup domain reset.
  1538. */
  1539. #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) RCC_CSR_RTCRST_BB = DISABLE)
  1540. /**
  1541. * @}
  1542. */
  1543. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1544. * @brief macros to manage the specified RCC Flags and interrupts.
  1545. * @{
  1546. */
  1547. /** @brief Enable RCC interrupt.
  1548. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1549. * This parameter can be any combination of the following values:
  1550. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1551. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1552. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1553. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1554. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1555. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1556. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB devices)
  1557. */
  1558. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  1559. /** @brief Disable RCC interrupt.
  1560. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1561. * This parameter can be any combination of the following values:
  1562. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1563. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1564. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1565. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1566. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1567. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1568. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB devices)
  1569. */
  1570. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= (uint8_t)(~(__INTERRUPT__)))
  1571. /** @brief Clear the RCC's interrupt pending bits.
  1572. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1573. * This parameter can be any combination of the following values:
  1574. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1575. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1576. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1577. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1578. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1579. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1580. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB devices)
  1581. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1582. */
  1583. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  1584. /** @brief Check the RCC's interrupt has occurred or not.
  1585. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1586. * This parameter can be one of the following values:
  1587. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1588. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1589. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1590. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1591. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1592. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1593. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt (not available for STM32L100xB || STM32L151xB || STM32L152xB devices)
  1594. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1595. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1596. */
  1597. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  1598. /** @brief Set RMVF bit to clear the reset flags.
  1599. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1600. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1601. */
  1602. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1603. /** @brief Check RCC flag is set or not.
  1604. * @param __FLAG__ specifies the flag to check.
  1605. * This parameter can be one of the following values:
  1606. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready.
  1607. * @arg @ref RCC_FLAG_MSIRDY MSI oscillator clock ready.
  1608. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready.
  1609. * @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready.
  1610. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready.
  1611. * @arg @ref RCC_FLAG_LSECSS CSS on LSE failure Detection (*)
  1612. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready.
  1613. * @arg @ref RCC_FLAG_OBLRST Option Byte Load reset
  1614. * @arg @ref RCC_FLAG_PINRST Pin reset.
  1615. * @arg @ref RCC_FLAG_PORRST POR/PDR reset.
  1616. * @arg @ref RCC_FLAG_SFTRST Software reset.
  1617. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset.
  1618. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset.
  1619. * @arg @ref RCC_FLAG_LPWRRST Low Power reset.
  1620. * @note (*) This bit is available in high and medium+ density devices only.
  1621. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1622. */
  1623. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5U) == CR_REG_INDEX)? RCC->CR :RCC->CSR) & (1U << ((__FLAG__) & RCC_FLAG_MASK)))
  1624. /**
  1625. * @}
  1626. */
  1627. /**
  1628. * @}
  1629. */
  1630. /* Include RCC HAL Extension module */
  1631. #include "stm32l1xx_hal_rcc_ex.h"
  1632. /* Exported functions --------------------------------------------------------*/
  1633. /** @addtogroup RCC_Exported_Functions
  1634. * @{
  1635. */
  1636. /** @addtogroup RCC_Exported_Functions_Group1
  1637. * @{
  1638. */
  1639. /* Initialization and de-initialization functions ******************************/
  1640. HAL_StatusTypeDef HAL_RCC_DeInit(void);
  1641. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1642. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1643. /**
  1644. * @}
  1645. */
  1646. /** @addtogroup RCC_Exported_Functions_Group2
  1647. * @{
  1648. */
  1649. /* Peripheral Control functions ************************************************/
  1650. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1651. void HAL_RCC_EnableCSS(void);
  1652. /* CSS NMI IRQ handler */
  1653. void HAL_RCC_NMI_IRQHandler(void);
  1654. /* User Callbacks in non blocking mode (IT mode) */
  1655. void HAL_RCC_CSSCallback(void);
  1656. void HAL_RCC_DisableCSS(void);
  1657. uint32_t HAL_RCC_GetSysClockFreq(void);
  1658. uint32_t HAL_RCC_GetHCLKFreq(void);
  1659. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1660. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1661. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1662. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1663. /**
  1664. * @}
  1665. */
  1666. /**
  1667. * @}
  1668. */
  1669. /**
  1670. * @}
  1671. */
  1672. /**
  1673. * @}
  1674. */
  1675. #ifdef __cplusplus
  1676. }
  1677. #endif
  1678. #endif /* __STM32L1xx_HAL_RCC_H */
  1679. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/