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.
 
 
 

1739 lines
85 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RCC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright(c) 2016 STMicroelectronics.
  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 __STM32L0xx_HAL_RCC_H
  21. #define __STM32L0xx_HAL_RCC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l0xx_hal_def.h"
  27. /** @addtogroup STM32L0xx_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 + 1) */
  46. #define HSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  47. #define LSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  48. #define PLL_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  49. #if defined(RCC_HSI48_SUPPORT)
  50. #define HSI48_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
  51. #endif /* RCC_HSI48_SUPPORT */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
  56. * @brief RCC registers bit address in the alias region
  57. * @{
  58. */
  59. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  60. /* --- CR Register ---*/
  61. /* Alias word address of HSION bit */
  62. #define RCC_CR_OFFSET (RCC_OFFSET + 0x00U)
  63. /* --- CFGR Register ---*/
  64. /* Alias word address of I2SSRC bit */
  65. #define RCC_CFGR_OFFSET (RCC_OFFSET + 0x08U)
  66. /* --- CSR Register ---*/
  67. #define RCC_CSR_OFFSET (RCC_OFFSET + 0x74U)
  68. /* CR register byte 3 (Bits[23:16]) base address */
  69. #define RCC_CR_BYTE2_ADDRESS (0x40023802U)
  70. /* CIER register byte 0 (Bits[0:8]) base address */
  71. #define CIER_BYTE0_ADDRESS ((uint32_t)(RCC_BASE + 0x10U + 0x00U))
  72. /**
  73. * @}
  74. */
  75. /* Defines used for Flags */
  76. #define CR_REG_INDEX ((uint8_t)1)
  77. #define CSR_REG_INDEX ((uint8_t)2)
  78. #define CRRCR_REG_INDEX ((uint8_t)3)
  79. #define RCC_FLAG_MASK ((uint8_t)0x1F)
  80. /**
  81. * @}
  82. */
  83. /** @addtogroup RCC_Private_Macros
  84. * @{
  85. */
  86. #if defined(RCC_HSI48_SUPPORT)
  87. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  88. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  89. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  90. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI48) == RCC_OSCILLATORTYPE_HSI48) || \
  91. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  92. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  93. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI))
  94. #define IS_RCC_HSI48(__HSI48__) (((__HSI48__) == RCC_HSI48_OFF) || ((__HSI48__) == RCC_HSI48_ON))
  95. #else
  96. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  97. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  98. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  99. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  100. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  101. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI))
  102. #endif /* RCC_HSI48_SUPPORT */
  103. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI) || \
  104. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  105. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  106. ((__HSE__) == RCC_HSE_BYPASS))
  107. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  108. ((__LSE__) == RCC_LSE_BYPASS))
  109. #if defined(RCC_CR_HSIOUTEN)
  110. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON) || \
  111. ((__HSI__) == RCC_HSI_DIV4) || ((__HSI__) == RCC_HSI_OUTEN) || \
  112. ((__HSI__) == (RCC_HSI_OUTEN|RCC_HSI_ON)) || ((__HSI__) == (RCC_HSI_OUTEN|RCC_HSI_DIV4)))
  113. #else
  114. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON) || \
  115. ((__HSI__) == RCC_HSI_DIV4))
  116. #endif /* RCC_CR_HSIOUTEN */
  117. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
  118. #define IS_RCC_MSICALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0xFFU)
  119. #define IS_RCC_MSI_CLOCK_RANGE(__RANGE__) (((__RANGE__) == RCC_MSIRANGE_0) || \
  120. ((__RANGE__) == RCC_MSIRANGE_1) || \
  121. ((__RANGE__) == RCC_MSIRANGE_2) || \
  122. ((__RANGE__) == RCC_MSIRANGE_3) || \
  123. ((__RANGE__) == RCC_MSIRANGE_4) || \
  124. ((__RANGE__) == RCC_MSIRANGE_5) || \
  125. ((__RANGE__) == RCC_MSIRANGE_6))
  126. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  127. #define IS_RCC_MSI(__MSI__) (((__MSI__) == RCC_MSI_OFF) || ((__MSI__) == RCC_MSI_ON))
  128. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  129. ((__PLL__) == RCC_PLL_ON))
  130. #define IS_RCC_PLL_DIV(__DIV__) (((__DIV__) == RCC_PLL_DIV2) || \
  131. ((__DIV__) == RCC_PLL_DIV3) || ((__DIV__) == RCC_PLL_DIV4))
  132. #define IS_RCC_PLL_MUL(__MUL__) (((__MUL__) == RCC_PLL_MUL3) || ((__MUL__) == RCC_PLL_MUL4) || \
  133. ((__MUL__) == RCC_PLL_MUL6) || ((__MUL__) == RCC_PLL_MUL8) || \
  134. ((__MUL__) == RCC_PLL_MUL12) || ((__MUL__) == RCC_PLL_MUL16) || \
  135. ((__MUL__) == RCC_PLL_MUL24) || ((__MUL__) == RCC_PLL_MUL32) || \
  136. ((__MUL__) == RCC_PLL_MUL48))
  137. #define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  138. (((CLK) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  139. (((CLK) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) || \
  140. (((CLK) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2))
  141. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_MSI) || \
  142. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  143. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  144. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  145. #define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_MSI) || \
  146. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  147. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  148. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  149. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  150. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  151. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  152. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  153. ((__HCLK__) == RCC_SYSCLK_DIV512))
  154. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  155. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  156. ((__PCLK__) == RCC_HCLK_DIV16))
  157. #if defined(STM32L031xx) || defined(STM32L041xx) || defined(STM32L073xx) || defined(STM32L083xx) \
  158. || defined(STM32L072xx) || defined(STM32L082xx) || defined(STM32L071xx) || defined(STM32L081xx)
  159. #define IS_RCC_MCO(__MCO__) (((__MCO__) == RCC_MCO1) || ((__MCO__) == RCC_MCO2) || ((__MCO__) == RCC_MCO3))
  160. #else
  161. #define IS_RCC_MCO(__MCO__) (((__MCO__) == RCC_MCO1) || ((__MCO__) == RCC_MCO2))
  162. #endif
  163. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1) || ((__DIV__) == RCC_MCODIV_2) || \
  164. ((__DIV__) == RCC_MCODIV_4) || ((__DIV__) == RCC_MCODIV_8) || \
  165. ((__DIV__) == RCC_MCODIV_16))
  166. #if defined(RCC_CFGR_MCOSEL_HSI48)
  167. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK) || ((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || \
  168. ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || ((__SOURCE__) == RCC_MCO1SOURCE_MSI) || \
  169. ((__SOURCE__) == RCC_MCO1SOURCE_HSE) || ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || \
  170. ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || ((__SOURCE__) == RCC_MCO1SOURCE_LSE) || \
  171. ((__SOURCE__) == RCC_MCO1SOURCE_HSI48))
  172. #else
  173. #define IS_RCC_MCO1SOURCE(__SOURCE__) (((__SOURCE__) == RCC_MCO1SOURCE_NOCLOCK) || ((__SOURCE__) == RCC_MCO1SOURCE_SYSCLK) || \
  174. ((__SOURCE__) == RCC_MCO1SOURCE_HSI) || ((__SOURCE__) == RCC_MCO1SOURCE_MSI) || \
  175. ((__SOURCE__) == RCC_MCO1SOURCE_HSE) || ((__SOURCE__) == RCC_MCO1SOURCE_PLLCLK) || \
  176. ((__SOURCE__) == RCC_MCO1SOURCE_LSI) || ((__SOURCE__) == RCC_MCO1SOURCE_LSE))
  177. #endif /* RCC_CFGR_MCOSEL_HSI48 */
  178. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  179. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  180. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  181. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV2) || \
  182. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV4) || \
  183. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV8) || \
  184. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV16))
  185. /**
  186. * @}
  187. */
  188. /* Exported types ------------------------------------------------------------*/
  189. /** @defgroup RCC_Exported_Types RCC Exported Types
  190. * @{
  191. */
  192. /**
  193. * @brief RCC PLL configuration structure definition
  194. */
  195. typedef struct
  196. {
  197. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  198. This parameter can be a value of @ref RCC_PLL_Config */
  199. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  200. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  201. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  202. This parameter must be a value of @ref RCC_PLL_Multiplication_Factor*/
  203. uint32_t PLLDIV; /*!< PLLDIV: Division factor for PLL VCO input clock
  204. This parameter must be a value of @ref RCC_PLL_Division_Factor*/
  205. } RCC_PLLInitTypeDef;
  206. /**
  207. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  208. */
  209. typedef struct
  210. {
  211. uint32_t OscillatorType; /*!< The oscillators to be configured.
  212. This parameter can be a value of @ref RCC_Oscillator_Type */
  213. uint32_t HSEState; /*!< The new state of the HSE.
  214. This parameter can be a value of @ref RCC_HSE_Config */
  215. uint32_t LSEState; /*!< The new state of the LSE.
  216. This parameter can be a value of @ref RCC_LSE_Config */
  217. uint32_t HSIState; /*!< The new state of the HSI.
  218. This parameter can be a value of @ref RCC_HSI_Config */
  219. uint32_t HSICalibrationValue; /*!< The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT).
  220. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1F */
  221. uint32_t LSIState; /*!< The new state of the LSI.
  222. This parameter can be a value of @ref RCC_LSI_Config */
  223. #if defined(RCC_HSI48_SUPPORT)
  224. uint32_t HSI48State; /*!< The new state of the HSI48.
  225. This parameter can be a value of @ref RCC_HSI48_Config */
  226. #endif /* RCC_HSI48_SUPPORT */
  227. uint32_t MSIState; /*!< The new state of the MSI.
  228. This parameter can be a value of @ref RCC_MSI_Config */
  229. uint32_t MSICalibrationValue; /*!< The MSI calibration trimming value. (default is RCC_MSICALIBRATION_DEFAULT).
  230. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  231. uint32_t MSIClockRange; /*!< The MSI frequency range.
  232. This parameter can be a value of @ref RCC_MSI_Clock_Range */
  233. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  234. } RCC_OscInitTypeDef;
  235. /**
  236. * @brief RCC System, AHB and APB busses clock configuration structure definition
  237. */
  238. typedef struct
  239. {
  240. uint32_t ClockType; /*!< The clock to be configured.
  241. This parameter can be a value of @ref RCC_System_Clock_Type */
  242. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  243. This parameter can be a value of @ref RCC_System_Clock_Source */
  244. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  245. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  246. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  247. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  248. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  249. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  250. } RCC_ClkInitTypeDef;
  251. /**
  252. * @}
  253. */
  254. /* Exported constants --------------------------------------------------------*/
  255. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  256. * @{
  257. */
  258. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  259. * @{
  260. */
  261. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI /*!< HSI clock selected as PLL entry clock source */
  262. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE /*!< HSE clock selected as PLL entry clock source */
  263. /**
  264. * @}
  265. */
  266. /** @defgroup RCC_Oscillator_Type Oscillator Type
  267. * @{
  268. */
  269. #define RCC_OSCILLATORTYPE_NONE ((uint32_t)0x00000000)
  270. #define RCC_OSCILLATORTYPE_HSE ((uint32_t)0x00000001)
  271. #define RCC_OSCILLATORTYPE_HSI ((uint32_t)0x00000002)
  272. #define RCC_OSCILLATORTYPE_LSE ((uint32_t)0x00000004)
  273. #define RCC_OSCILLATORTYPE_LSI ((uint32_t)0x00000008)
  274. #define RCC_OSCILLATORTYPE_MSI ((uint32_t)0x00000010)
  275. #if defined(RCC_HSI48_SUPPORT)
  276. #define RCC_OSCILLATORTYPE_HSI48 ((uint32_t)0x00000020)
  277. #endif /* RCC_HSI48_SUPPORT */
  278. /**
  279. * @}
  280. */
  281. /** @defgroup RCC_HSE_Config HSE Config
  282. * @{
  283. */
  284. #define RCC_HSE_OFF ((uint32_t)0x00000000) /*!< HSE clock deactivation */
  285. #define RCC_HSE_ON RCC_CR_HSEON /*!< HSE clock activation */
  286. #define RCC_HSE_BYPASS ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
  287. /**
  288. * @}
  289. */
  290. /** @defgroup RCC_LSE_Config LSE Config
  291. * @{
  292. */
  293. #define RCC_LSE_OFF ((uint32_t)0x00000000) /*!< LSE clock deactivation */
  294. #define RCC_LSE_ON RCC_CSR_LSEON /*!< LSE clock activation */
  295. #define RCC_LSE_BYPASS ((uint32_t)(RCC_CSR_LSEBYP | RCC_CSR_LSEON)) /*!< External clock source for LSE clock */
  296. /**
  297. * @}
  298. */
  299. /** @defgroup RCC_HSI_Config HSI Config
  300. * @{
  301. */
  302. #define RCC_HSI_OFF ((uint32_t)0x00000000) /*!< HSI clock deactivation */
  303. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  304. #define RCC_HSI_DIV4 (RCC_CR_HSIDIVEN | RCC_CR_HSION) /*!< HSI_DIV4 clock activation */
  305. #if defined(RCC_CR_HSIOUTEN)
  306. #define RCC_HSI_OUTEN RCC_CR_HSIOUTEN /*!< HSI_OUTEN clock activation */
  307. /* This value is to be used in combination with RCC_HSI_ON/RCC_HSI_DIV4 */
  308. #endif /* RCC_CR_HSIOUTEN */
  309. #define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10) /* Default HSI calibration trimming value */
  310. /**
  311. * @}
  312. */
  313. /** @defgroup RCC_MSI_Clock_Range MSI Clock Range
  314. * @{
  315. */
  316. #define RCC_MSIRANGE_0 RCC_ICSCR_MSIRANGE_0 /*!< MSI = 65.536 KHz */
  317. #define RCC_MSIRANGE_1 RCC_ICSCR_MSIRANGE_1 /*!< MSI = 131.072 KHz */
  318. #define RCC_MSIRANGE_2 RCC_ICSCR_MSIRANGE_2 /*!< MSI = 262.144 KHz */
  319. #define RCC_MSIRANGE_3 RCC_ICSCR_MSIRANGE_3 /*!< MSI = 524.288 KHz */
  320. #define RCC_MSIRANGE_4 RCC_ICSCR_MSIRANGE_4 /*!< MSI = 1.048 MHz */
  321. #define RCC_MSIRANGE_5 RCC_ICSCR_MSIRANGE_5 /*!< MSI = 2.097 MHz */
  322. #define RCC_MSIRANGE_6 RCC_ICSCR_MSIRANGE_6 /*!< MSI = 4.194 MHz */
  323. /**
  324. * @}
  325. */
  326. /** @defgroup RCC_LSI_Config LSI Config
  327. * @{
  328. */
  329. #define RCC_LSI_OFF ((uint32_t)0x00000000) /*!< LSI clock deactivation */
  330. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  331. /**
  332. * @}
  333. */
  334. /** @defgroup RCC_MSI_Config MSI Config
  335. * @{
  336. */
  337. #define RCC_MSI_OFF ((uint32_t)0x00000000)
  338. #define RCC_MSI_ON ((uint32_t)0x00000001)
  339. #define RCC_MSICALIBRATION_DEFAULT ((uint32_t)0x00000000U) /* Default MSI calibration trimming value */
  340. /**
  341. * @}
  342. */
  343. #if defined(RCC_HSI48_SUPPORT)
  344. /** @defgroup RCC_HSI48_Config HSI48 Config
  345. * @{
  346. */
  347. #define RCC_HSI48_OFF ((uint8_t)0x00)
  348. #define RCC_HSI48_ON ((uint8_t)0x01)
  349. /**
  350. * @}
  351. */
  352. #endif /* RCC_HSI48_SUPPORT */
  353. /** @defgroup RCC_PLL_Config PLL Config
  354. * @{
  355. */
  356. #define RCC_PLL_NONE ((uint32_t)0x00000000) /*!< PLL is not configured */
  357. #define RCC_PLL_OFF ((uint32_t)0x00000001) /*!< PLL deactivation */
  358. #define RCC_PLL_ON ((uint32_t)0x00000002) /*!< PLL activation */
  359. /**
  360. * @}
  361. */
  362. /** @defgroup RCC_System_Clock_Type System Clock Type
  363. * @{
  364. */
  365. #define RCC_CLOCKTYPE_SYSCLK ((uint32_t)0x00000001) /*!< SYSCLK to configure */
  366. #define RCC_CLOCKTYPE_HCLK ((uint32_t)0x00000002) /*!< HCLK to configure */
  367. #define RCC_CLOCKTYPE_PCLK1 ((uint32_t)0x00000004) /*!< PCLK1 to configure */
  368. #define RCC_CLOCKTYPE_PCLK2 ((uint32_t)0x00000008) /*!< PCLK2 to configure */
  369. /**
  370. * @}
  371. */
  372. /** @defgroup RCC_System_Clock_Source System Clock Source
  373. * @{
  374. */
  375. #define RCC_SYSCLKSOURCE_MSI RCC_CFGR_SW_MSI /*!< MSI selected as system clock */
  376. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  377. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  378. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  379. /**
  380. * @}
  381. */
  382. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  383. * @{
  384. */
  385. #define RCC_SYSCLKSOURCE_STATUS_MSI RCC_CFGR_SWS_MSI /*!< MSI used as system clock */
  386. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  387. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  388. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  389. /**
  390. * @}
  391. */
  392. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  393. * @{
  394. */
  395. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  396. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  397. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  398. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  399. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  400. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  401. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  402. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  403. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  404. /**
  405. * @}
  406. */
  407. /** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
  408. * @{
  409. */
  410. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1 /*!< HCLK not divided */
  411. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2 /*!< HCLK divided by 2 */
  412. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4 /*!< HCLK divided by 4 */
  413. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8 /*!< HCLK divided by 8 */
  414. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
  415. /**
  416. * @}
  417. */
  418. /** @defgroup RCC_HAL_EC_RTC_HSE_DIV RTC HSE Prescaler
  419. * @{
  420. */
  421. #define RCC_RTC_HSE_DIV_2 (uint32_t)0x00000000U /*!< HSE is divided by 2 for RTC clock */
  422. #define RCC_RTC_HSE_DIV_4 RCC_CR_RTCPRE_0 /*!< HSE is divided by 4 for RTC clock */
  423. #define RCC_RTC_HSE_DIV_8 RCC_CR_RTCPRE_1 /*!< HSE is divided by 8 for RTC clock */
  424. #define RCC_RTC_HSE_DIV_16 RCC_CR_RTCPRE /*!< HSE is divided by 16 for RTC clock */
  425. /**
  426. * @}
  427. */
  428. /** @defgroup RCC_RTC_LCD_Clock_Source RTC LCD Clock Source
  429. * @{
  430. */
  431. #define RCC_RTCCLKSOURCE_NO_CLK ((uint32_t)0x00000000) /*!< No clock */
  432. #define RCC_RTCCLKSOURCE_LSE RCC_CSR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  433. #define RCC_RTCCLKSOURCE_LSI RCC_CSR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  434. #define RCC_RTCCLKSOURCE_HSE_DIVX RCC_CSR_RTCSEL_HSE /*!< HSE oscillator clock divided by X used as RTC clock */
  435. #define RCC_RTCCLKSOURCE_HSE_DIV2 (RCC_RTC_HSE_DIV_2 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 2 used as RTC clock */
  436. #define RCC_RTCCLKSOURCE_HSE_DIV4 (RCC_RTC_HSE_DIV_4 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 4 used as RTC clock */
  437. #define RCC_RTCCLKSOURCE_HSE_DIV8 (RCC_RTC_HSE_DIV_8 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 8 used as RTC clock */
  438. #define RCC_RTCCLKSOURCE_HSE_DIV16 (RCC_RTC_HSE_DIV_16 | RCC_CSR_RTCSEL_HSE) /*!< HSE oscillator clock divided by 16 used as RTC clock */
  439. /**
  440. * @}
  441. */
  442. /** @defgroup RCC_PLL_Division_Factor PLL Division Factor
  443. * @{
  444. */
  445. #define RCC_PLL_DIV2 RCC_CFGR_PLLDIV2
  446. #define RCC_PLL_DIV3 RCC_CFGR_PLLDIV3
  447. #define RCC_PLL_DIV4 RCC_CFGR_PLLDIV4
  448. /**
  449. * @}
  450. */
  451. /** @defgroup RCC_PLL_Multiplication_Factor PLL Multiplication Factor
  452. * @{
  453. */
  454. #define RCC_PLL_MUL3 RCC_CFGR_PLLMUL3
  455. #define RCC_PLL_MUL4 RCC_CFGR_PLLMUL4
  456. #define RCC_PLL_MUL6 RCC_CFGR_PLLMUL6
  457. #define RCC_PLL_MUL8 RCC_CFGR_PLLMUL8
  458. #define RCC_PLL_MUL12 RCC_CFGR_PLLMUL12
  459. #define RCC_PLL_MUL16 RCC_CFGR_PLLMUL16
  460. #define RCC_PLL_MUL24 RCC_CFGR_PLLMUL24
  461. #define RCC_PLL_MUL32 RCC_CFGR_PLLMUL32
  462. #define RCC_PLL_MUL48 RCC_CFGR_PLLMUL48
  463. /**
  464. * @}
  465. */
  466. /** @defgroup RCC_MCO_Index MCO Index
  467. * @{
  468. */
  469. #define RCC_MCO1 ((uint32_t)0x00000000)
  470. #define RCC_MCO2 ((uint32_t)0x00000001)
  471. #if defined(STM32L031xx) || defined(STM32L041xx) || defined(STM32L073xx) || defined(STM32L083xx) \
  472. || defined(STM32L072xx) || defined(STM32L082xx) || defined(STM32L071xx) || defined(STM32L081xx)
  473. #define RCC_MCO3 ((uint32_t)0x00000002)
  474. #endif
  475. /**
  476. * @}
  477. */
  478. /** @defgroup RCC_MCOx_Clock_Prescaler MCO Clock Prescaler
  479. * @{
  480. */
  481. #define RCC_MCODIV_1 RCC_CFGR_MCO_PRE_1
  482. #define RCC_MCODIV_2 RCC_CFGR_MCO_PRE_2
  483. #define RCC_MCODIV_4 RCC_CFGR_MCO_PRE_4
  484. #define RCC_MCODIV_8 RCC_CFGR_MCO_PRE_8
  485. #define RCC_MCODIV_16 RCC_CFGR_MCO_PRE_16
  486. /**
  487. * @}
  488. */
  489. /** @defgroup RCC_MCO1_Clock_Source MCO1 Clock Source
  490. * @{
  491. */
  492. #define RCC_MCO1SOURCE_NOCLOCK RCC_CFGR_MCO_NOCLOCK
  493. #define RCC_MCO1SOURCE_SYSCLK RCC_CFGR_MCO_SYSCLK
  494. #define RCC_MCO1SOURCE_MSI RCC_CFGR_MCO_MSI
  495. #define RCC_MCO1SOURCE_HSI RCC_CFGR_MCO_HSI
  496. #define RCC_MCO1SOURCE_LSE RCC_CFGR_MCO_LSE
  497. #define RCC_MCO1SOURCE_LSI RCC_CFGR_MCO_LSI
  498. #define RCC_MCO1SOURCE_HSE RCC_CFGR_MCO_HSE
  499. #define RCC_MCO1SOURCE_PLLCLK RCC_CFGR_MCO_PLL
  500. #if defined(RCC_CFGR_MCOSEL_HSI48)
  501. #define RCC_MCO1SOURCE_HSI48 RCC_CFGR_MCO_HSI48
  502. #endif /* RCC_CFGR_MCOSEL_HSI48 */
  503. /**
  504. * @}
  505. */
  506. /** @defgroup RCC_Interrupt Interrupts
  507. * @{
  508. */
  509. #define RCC_IT_LSIRDY RCC_CIFR_LSIRDYF /*!< LSI Ready Interrupt flag */
  510. #define RCC_IT_LSERDY RCC_CIFR_LSERDYF /*!< LSE Ready Interrupt flag */
  511. #define RCC_IT_HSIRDY RCC_CIFR_HSIRDYF /*!< HSI Ready Interrupt flag */
  512. #define RCC_IT_HSERDY RCC_CIFR_HSERDYF /*!< HSE Ready Interrupt flag */
  513. #define RCC_IT_PLLRDY RCC_CIFR_PLLRDYF /*!< PLL Ready Interrupt flag */
  514. #define RCC_IT_MSIRDY RCC_CIFR_MSIRDYF /*!< MSI Ready Interrupt flag */
  515. #define RCC_IT_LSECSS RCC_CIFR_CSSLSEF /*!< LSE Clock Security System Interrupt flag */
  516. #if defined(RCC_HSECSS_SUPPORT)
  517. #define RCC_IT_CSS RCC_CIFR_CSSHSEF /*!< Clock Security System Interrupt flag */
  518. #endif /* RCC_HSECSS_SUPPORT */
  519. #if defined(RCC_HSI48_SUPPORT)
  520. #define RCC_IT_HSI48RDY RCC_CIFR_HSI48RDYF /*!< HSI48 Ready Interrupt flag */
  521. #endif /* RCC_HSI48_SUPPORT */
  522. /**
  523. * @}
  524. */
  525. /** @defgroup RCC_Flag Flags
  526. * Elements values convention: XXXYYYYYb
  527. * - YYYYY : Flag position in the register
  528. * - XXX : Register index
  529. * - 001: CR register
  530. * - 010: CSR register
  531. * - 011: CRRCR register (*)
  532. * (*) Applicable only for STM32L052xx, STM32L053xx, (...), STM32L073xx & STM32L082xx
  533. * @{
  534. */
  535. /* Flags in the CR register */
  536. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_HSIRDY_Pos)) /*!< Internal High Speed clock ready flag */
  537. #define RCC_FLAG_HSIDIV ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_HSIDIVF_Pos)) /*!< HSI16 divider flag */
  538. #define RCC_FLAG_MSIRDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_MSIRDY_Pos)) /*!< MSI clock ready flag */
  539. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_HSERDY_Pos)) /*!< External High Speed clock ready flag */
  540. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5) | RCC_CR_PLLRDY_Pos)) /*!< PLL clock ready flag */
  541. /* Flags in the CSR register */
  542. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LSIRDY_Pos)) /*!< Internal Low Speed oscillator Ready */
  543. #define RCC_FLAG_LSERDY ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LSERDY_Pos)) /*!< External Low Speed oscillator Ready */
  544. #define RCC_FLAG_LSECSS ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LSECSSD_Pos)) /*!< CSS on LSE failure Detection */
  545. #define RCC_FLAG_OBLRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_OBLRSTF_Pos)) /*!< Options bytes loading reset flag */
  546. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_PINRSTF_Pos)) /*!< PIN reset flag */
  547. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_PORRSTF_Pos)) /*!< POR/PDR reset flag */
  548. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_SFTRSTF_Pos)) /*!< Software Reset flag */
  549. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_IWDGRSTF_Pos)) /*!< Independent Watchdog reset flag */
  550. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_WWDGRSTF_Pos)) /*!< Window watchdog reset flag */
  551. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_LPWRRSTF_Pos)) /*!< Low-Power reset flag */
  552. #if defined(RCC_CSR_FWRSTF)
  553. #define RCC_FLAG_FWRST ((uint8_t)((CSR_REG_INDEX << 5) | RCC_CSR_FWRSTF_Pos)) /*!< RCC flag FW reset */
  554. #endif /* RCC_CSR_FWRSTF */
  555. /* Flags in the CRRCR register */
  556. #if defined(RCC_HSI48_SUPPORT)
  557. #define RCC_FLAG_HSI48RDY ((uint8_t)((CRRCR_REG_INDEX << 5) | RCC_CRRCR_HSI48RDY_Pos)) /*!< HSI48 clock ready flag */
  558. #endif /* RCC_HSI48_SUPPORT */
  559. /**
  560. * @}
  561. */
  562. /**
  563. * @}
  564. */
  565. /* Exported macro ------------------------------------------------------------*/
  566. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  567. * @{
  568. */
  569. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable AHB Peripheral Clock Enable Disable
  570. * @brief Enable or disable the AHB peripheral clock.
  571. * @note After reset, the peripheral clock (used for registers read/write access)
  572. * is disabled and the application software has to enable this clock before
  573. * using it.
  574. * @{
  575. */
  576. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  577. __IO uint32_t tmpreg; \
  578. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  579. /* Delay after an RCC peripheral clock enabling */ \
  580. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  581. UNUSED(tmpreg); \
  582. } while(0)
  583. #define __HAL_RCC_MIF_CLK_ENABLE() do { \
  584. __IO uint32_t tmpreg; \
  585. SET_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN);\
  586. /* Delay after an RCC peripheral clock enabling */ \
  587. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN);\
  588. UNUSED(tmpreg); \
  589. } while(0)
  590. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  591. __IO uint32_t tmpreg; \
  592. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  593. /* Delay after an RCC peripheral clock enabling */ \
  594. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  595. UNUSED(tmpreg); \
  596. } while(0)
  597. #define __HAL_RCC_DMA1_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN)
  598. #define __HAL_RCC_MIF_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN)
  599. #define __HAL_RCC_CRC_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN)
  600. /**
  601. * @}
  602. */
  603. /** @defgroup RCC_IOPORT_Clock_Enable_Disable IOPORT Peripheral Clock Enable Disable
  604. * @brief Enable or disable the IOPORT peripheral clock.
  605. * @note After reset, the peripheral clock (used for registers read/write access)
  606. * is disabled and the application software has to enable this clock before
  607. * using it.
  608. * @{
  609. */
  610. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  611. __IO uint32_t tmpreg; \
  612. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  613. /* Delay after an RCC peripheral clock enabling */ \
  614. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  615. UNUSED(tmpreg); \
  616. } while(0)
  617. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  618. __IO uint32_t tmpreg; \
  619. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN);\
  620. /* Delay after an RCC peripheral clock enabling */ \
  621. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN);\
  622. UNUSED(tmpreg); \
  623. } while(0)
  624. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  625. __IO uint32_t tmpreg; \
  626. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN);\
  627. /* Delay after an RCC peripheral clock enabling */ \
  628. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN);\
  629. UNUSED(tmpreg); \
  630. } while(0)
  631. #define __HAL_RCC_GPIOH_CLK_ENABLE() do { \
  632. __IO uint32_t tmpreg; \
  633. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN);\
  634. /* Delay after an RCC peripheral clock enabling */ \
  635. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN);\
  636. UNUSED(tmpreg); \
  637. } while(0)
  638. #define __HAL_RCC_GPIOA_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN)
  639. #define __HAL_RCC_GPIOB_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN)
  640. #define __HAL_RCC_GPIOC_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN)
  641. #define __HAL_RCC_GPIOH_CLK_DISABLE() CLEAR_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN)
  642. /**
  643. * @}
  644. */
  645. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Peripheral Clock Enable Disable
  646. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  647. * @note After reset, the peripheral clock (used for registers read/write access)
  648. * is disabled and the application software has to enable this clock before
  649. * using it.
  650. * @{
  651. */
  652. #define __HAL_RCC_WWDG_CLK_ENABLE() SET_BIT(RCC->APB1ENR, (RCC_APB1ENR_WWDGEN))
  653. #define __HAL_RCC_PWR_CLK_ENABLE() SET_BIT(RCC->APB1ENR, (RCC_APB1ENR_PWREN))
  654. #define __HAL_RCC_WWDG_CLK_DISABLE() CLEAR_BIT(RCC->APB1ENR, (RCC_APB1ENR_WWDGEN))
  655. #define __HAL_RCC_PWR_CLK_DISABLE() CLEAR_BIT(RCC->APB1ENR, (RCC_APB1ENR_PWREN))
  656. /**
  657. * @}
  658. */
  659. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Peripheral Clock Enable Disable
  660. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  661. * @note After reset, the peripheral clock (used for registers read/write access)
  662. * is disabled and the application software has to enable this clock before
  663. * using it.
  664. * @{
  665. */
  666. #define __HAL_RCC_SYSCFG_CLK_ENABLE() SET_BIT(RCC->APB2ENR, (RCC_APB2ENR_SYSCFGEN))
  667. #define __HAL_RCC_DBGMCU_CLK_ENABLE() SET_BIT(RCC->APB2ENR, (RCC_APB2ENR_DBGMCUEN))
  668. #define __HAL_RCC_SYSCFG_CLK_DISABLE() CLEAR_BIT(RCC->APB2ENR, (RCC_APB2ENR_SYSCFGEN))
  669. #define __HAL_RCC_DBGMCU_CLK_DISABLE() CLEAR_BIT(RCC->APB2ENR, (RCC_APB2ENR_DBGMCUEN))
  670. /**
  671. * @}
  672. */
  673. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enabled or Disabled Status
  674. * @brief Check whether the AHB peripheral clock is enabled or not.
  675. * @note After reset, the peripheral clock (used for registers read/write access)
  676. * is disabled and the application software has to enable this clock before
  677. * using it.
  678. * @{
  679. */
  680. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN) != 0U)
  681. #define __HAL_RCC_MIF_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN) != 0U)
  682. #define __HAL_RCC_CRC_IS_CLK_ENABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) != 0U)
  683. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN) == 0U)
  684. #define __HAL_RCC_MIF_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_MIFEN) == 0U)
  685. #define __HAL_RCC_CRC_IS_CLK_DISABLED() (READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN) == 0U)
  686. /**
  687. * @}
  688. */
  689. /** @defgroup RCC_IOPORT_Peripheral_Clock_Enable_Disable_Status IOPORT Peripheral Clock Enabled or Disabled Status
  690. * @brief Check whether the IOPORT peripheral clock is enabled or not.
  691. * @note After reset, the peripheral clock (used for registers read/write access)
  692. * is disabled and the application software has to enable this clock before
  693. * using it.
  694. * @{
  695. */
  696. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) != 0U)
  697. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) != 0U)
  698. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN) != 0U)
  699. #define __HAL_RCC_GPIOH_IS_CLK_ENABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN) != 0U)
  700. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN) == 0U)
  701. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN) == 0U)
  702. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOCEN) == 0U)
  703. #define __HAL_RCC_GPIOH_IS_CLK_DISABLED() (READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOHEN) == 0U)
  704. /**
  705. * @}
  706. */
  707. /** @defgroup RCC_APB1_Clock_Enable_Disable_Status APB1 Peripheral Clock Enabled or Disabled Status
  708. * @brief Check whether the APB1 peripheral clock is enabled or not.
  709. * @note After reset, the peripheral clock (used for registers read/write access)
  710. * is disabled and the application software has to enable this clock before
  711. * using it.
  712. * @{
  713. */
  714. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN) != 0U)
  715. #define __HAL_RCC_PWR_IS_CLK_ENABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN) != 0U)
  716. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN) == 0U)
  717. #define __HAL_RCC_PWR_IS_CLK_DISABLED() (READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN) == 0U)
  718. /**
  719. * @}
  720. */
  721. /** @defgroup RCC_APB2_Clock_Enable_Disable_Status APB2 Peripheral Clock Enabled or Disabled Status
  722. * @brief Check whether the APB2 peripheral clock is enabled or not.
  723. * @note After reset, the peripheral clock (used for registers read/write access)
  724. * is disabled and the application software has to enable this clock before
  725. * using it.
  726. * @{
  727. */
  728. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN) != 0U)
  729. #define __HAL_RCC_DBGMCU_IS_CLK_ENABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_DBGMCUEN) != 0U)
  730. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN) == 0U)
  731. #define __HAL_RCC_DBGMCU_IS_CLK_DISABLED() (READ_BIT(RCC->APB2ENR, RCC_APB2ENR_DBGMCUEN) == 0U)
  732. /**
  733. * @}
  734. */
  735. /** @defgroup RCC_AHB_Force_Release_Reset AHB Peripheral Force Release Reset
  736. * @brief Force or release AHB peripheral reset.
  737. * @{
  738. */
  739. #define __HAL_RCC_AHB_FORCE_RESET() (RCC->AHBRSTR = 0xFFFFFFFFU)
  740. #define __HAL_RCC_DMA1_FORCE_RESET() SET_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_DMA1RST))
  741. #define __HAL_RCC_MIF_FORCE_RESET() SET_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_MIFRST))
  742. #define __HAL_RCC_CRC_FORCE_RESET() SET_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_CRCRST))
  743. #define __HAL_RCC_AHB_RELEASE_RESET() (RCC->AHBRSTR = 0x00000000U)
  744. #define __HAL_RCC_CRC_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_CRCRST))
  745. #define __HAL_RCC_DMA1_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_DMA1RST))
  746. #define __HAL_RCC_MIF_RELEASE_RESET() CLEAR_BIT(RCC->AHBRSTR, (RCC_AHBRSTR_MIFRST))
  747. /**
  748. * @}
  749. */
  750. /** @defgroup RCC_IOPORT_Force_Release_Reset IOPORT Peripheral Force Release Reset
  751. * @brief Force or release IOPORT peripheral reset.
  752. * @{
  753. */
  754. #define __HAL_RCC_IOP_FORCE_RESET() (RCC->IOPRSTR = 0xFFFFFFFFU)
  755. #define __HAL_RCC_GPIOA_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOARST))
  756. #define __HAL_RCC_GPIOB_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOBRST))
  757. #define __HAL_RCC_GPIOC_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOCRST))
  758. #define __HAL_RCC_GPIOH_FORCE_RESET() SET_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOHRST))
  759. #define __HAL_RCC_IOP_RELEASE_RESET() (RCC->IOPRSTR = 0x00000000U)
  760. #define __HAL_RCC_GPIOA_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOARST))
  761. #define __HAL_RCC_GPIOB_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOBRST))
  762. #define __HAL_RCC_GPIOC_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOCRST))
  763. #define __HAL_RCC_GPIOH_RELEASE_RESET() CLEAR_BIT(RCC->IOPRSTR, (RCC_IOPRSTR_GPIOHRST))
  764. /**
  765. * @}
  766. */
  767. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Peripheral Force Release Reset
  768. * @brief Force or release APB1 peripheral reset.
  769. * @{
  770. */
  771. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFFU)
  772. #define __HAL_RCC_WWDG_FORCE_RESET() SET_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_WWDGRST))
  773. #define __HAL_RCC_PWR_FORCE_RESET() SET_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_PWRRST))
  774. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00000000U)
  775. #define __HAL_RCC_WWDG_RELEASE_RESET() CLEAR_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_WWDGRST))
  776. #define __HAL_RCC_PWR_RELEASE_RESET() CLEAR_BIT(RCC->APB1RSTR, (RCC_APB1RSTR_PWRRST))
  777. /**
  778. * @}
  779. */
  780. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Peripheral Force Release Reset
  781. * @brief Force or release APB2 peripheral reset.
  782. * @{
  783. */
  784. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  785. #define __HAL_RCC_DBGMCU_FORCE_RESET() SET_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_DBGMCURST))
  786. #define __HAL_RCC_SYSCFG_FORCE_RESET() SET_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_SYSCFGRST))
  787. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00000000U)
  788. #define __HAL_RCC_DBGMCU_RELEASE_RESET() CLEAR_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_DBGMCURST))
  789. #define __HAL_RCC_SYSCFG_RELEASE_RESET() CLEAR_BIT(RCC->APB2RSTR, (RCC_APB2RSTR_SYSCFGRST))
  790. /**
  791. * @}
  792. */
  793. /** @defgroup RCC_AHB_Clock_Sleep_Enable_Disable AHB Peripheral Clock Sleep Enable Disable
  794. * @brief Enable or disable the AHB peripheral clock during Low Power (Sleep) mode.
  795. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  796. * power consumption.
  797. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  798. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  799. * @{
  800. */
  801. #define __HAL_RCC_CRC_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_CRCSMEN))
  802. #define __HAL_RCC_MIF_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_MIFSMEN))
  803. #define __HAL_RCC_SRAM_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_SRAMSMEN))
  804. #define __HAL_RCC_DMA1_CLK_SLEEP_ENABLE() SET_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_DMA1SMEN))
  805. #define __HAL_RCC_CRC_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_CRCSMEN))
  806. #define __HAL_RCC_MIF_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_MIFSMEN))
  807. #define __HAL_RCC_SRAM_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_SRAMSMEN))
  808. #define __HAL_RCC_DMA1_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->AHBSMENR, (RCC_AHBSMENR_DMA1SMEN))
  809. /**
  810. * @}
  811. */
  812. /** @defgroup RCC_IOPORT_Clock_Sleep_Enable_Disable IOPORT Peripheral Clock Sleep Enable Disable
  813. * @brief Enable or disable the IOPORT peripheral clock during Low Power (Sleep) mode.
  814. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  815. * power consumption.
  816. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  817. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  818. * @{
  819. */
  820. #define __HAL_RCC_GPIOA_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOASMEN))
  821. #define __HAL_RCC_GPIOB_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOBSMEN))
  822. #define __HAL_RCC_GPIOC_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOCSMEN))
  823. #define __HAL_RCC_GPIOH_CLK_SLEEP_ENABLE() SET_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOHSMEN))
  824. #define __HAL_RCC_GPIOA_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOASMEN))
  825. #define __HAL_RCC_GPIOB_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOBSMEN))
  826. #define __HAL_RCC_GPIOC_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOCSMEN))
  827. #define __HAL_RCC_GPIOH_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->IOPSMENR, (RCC_IOPSMENR_GPIOHSMEN))
  828. /**
  829. * @}
  830. */
  831. /** @defgroup RCC_APB1_Clock_Sleep_Enable_Disable APB1 Peripheral Clock Sleep Enable Disable
  832. * @brief Enable or disable the APB1 peripheral clock during Low Power (Sleep) mode.
  833. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  834. * power consumption.
  835. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  836. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  837. * @{
  838. */
  839. #define __HAL_RCC_WWDG_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_WWDGSMEN))
  840. #define __HAL_RCC_PWR_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_PWRSMEN))
  841. #define __HAL_RCC_WWDG_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_WWDGSMEN))
  842. #define __HAL_RCC_PWR_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB1SMENR, (RCC_APB1SMENR_PWRSMEN))
  843. /**
  844. * @}
  845. */
  846. /** @defgroup RCC_APB2_Clock_Sleep_Enable_Disable APB2 Peripheral Clock Sleep Enable Disable
  847. * @brief Enable or disable the APB2 peripheral clock during Low Power (Sleep) mode.
  848. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  849. * power consumption.
  850. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  851. * @note By default, all peripheral activated clocks remain enabled during SLEEP mode.
  852. * @{
  853. */
  854. #define __HAL_RCC_SYSCFG_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_SYSCFGSMEN))
  855. #define __HAL_RCC_DBGMCU_CLK_SLEEP_ENABLE() SET_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_DBGMCUSMEN))
  856. #define __HAL_RCC_SYSCFG_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_SYSCFGSMEN))
  857. #define __HAL_RCC_DBGMCU_CLK_SLEEP_DISABLE() CLEAR_BIT(RCC->APB2SMENR, (RCC_APB2SMENR_DBGMCUSMEN))
  858. /**
  859. * @}
  860. */
  861. /** @defgroup RCC_AHB_Clock_Sleep_Enable_Disable_Status AHB Peripheral Clock Sleep Enabled or Disabled Status
  862. * @brief Check whether the AHB peripheral clock during Low Power (Sleep) mode is enabled or not.
  863. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  864. * power consumption.
  865. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  866. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  867. * @{
  868. */
  869. #define __HAL_RCC_CRC_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_CRCSMEN) != 0U)
  870. #define __HAL_RCC_MIF_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_MIFSMEN) != 0U)
  871. #define __HAL_RCC_SRAM_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_SRAMSMEN) != 0U)
  872. #define __HAL_RCC_DMA1_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_DMA1SMEN) != 0U)
  873. #define __HAL_RCC_CRC_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_CRCSMEN) == 0U)
  874. #define __HAL_RCC_MIF_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_MIFSMEN) == 0U)
  875. #define __HAL_RCC_SRAM_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_SRAMSMEN) == 0U)
  876. #define __HAL_RCC_DMA1_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->AHBSMENR, RCC_AHBSMENR_DMA1SMEN) == 0U)
  877. /**
  878. * @}
  879. */
  880. /** @defgroup RCC_IOPORT_Clock_Sleep_Enable_Disable_Status IOPORT Peripheral Clock Sleep Enabled or Disabled Status
  881. * @brief Check whether the IOPORT peripheral clock during Low Power (Sleep) mode is enabled or not.
  882. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  883. * power consumption.
  884. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  885. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  886. * @{
  887. */
  888. #define __HAL_RCC_GPIOA_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOASMEN) != 0U)
  889. #define __HAL_RCC_GPIOB_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOBSMEN) != 0U)
  890. #define __HAL_RCC_GPIOC_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOCSMEN) != 0U)
  891. #define __HAL_RCC_GPIOH_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOHSMEN) != 0U)
  892. #define __HAL_RCC_GPIOA_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOASMEN) == 0U)
  893. #define __HAL_RCC_GPIOB_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOBSMEN) == 0U)
  894. #define __HAL_RCC_GPIOC_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOCSMEN) == 0U)
  895. #define __HAL_RCC_GPIOH_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->IOPSMENR, RCC_IOPSMENR_GPIOHSMEN) == 0U)
  896. /**
  897. * @}
  898. */
  899. /** @defgroup RCC_APB1_Clock_Sleep_Enable_Disable_Status APB1 Peripheral Clock Sleep Enabled or Disabled Status
  900. * @brief Check whether the APB1 peripheral clock during Low Power (Sleep) mode is enabled or not.
  901. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  902. * power consumption.
  903. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  904. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  905. * @{
  906. */
  907. #define __HAL_RCC_WWDG_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_WWDGSMEN) != 0U)
  908. #define __HAL_RCC_PWR_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_PWRSMEN) != 0U)
  909. #define __HAL_RCC_WWDG_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_WWDGSMEN) == 0U)
  910. #define __HAL_RCC_PWR_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB1SMENR, RCC_APB1SMENR_PWRSMEN) == 0U)
  911. /**
  912. * @}
  913. */
  914. /** @defgroup RCC_APB2_Clock_Sleep_Enable_Disable_Status APB2 Peripheral Clock Sleep Enabled or Disabled Status
  915. * @brief Check whether the APB2 peripheral clock during Low Power (Sleep) mode is enabled or not.
  916. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  917. * power consumption.
  918. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  919. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  920. * @{
  921. */
  922. #define __HAL_RCC_SYSCFG_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_SYSCFGSMEN) != 0U)
  923. #define __HAL_RCC_DBGMCU_IS_CLK_SLEEP_ENABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_DBGMCUSMEN) != 0U)
  924. #define __HAL_RCC_SYSCFG_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_SYSCFGSMEN) == 0U)
  925. #define __HAL_RCC_DBGMCU_IS_CLK_SLEEP_DISABLED() (READ_BIT(RCC->APB2SMENR, RCC_APB2SMENR_DBGMCUSMEN) == 0U)
  926. /**
  927. * @}
  928. */
  929. /** @defgroup RCC_HSI_Configuration HSI Configuration
  930. * @{
  931. */
  932. /** @brief Macro to enable or disable the Internal High Speed oscillator (HSI).
  933. * @note After enabling the HSI, the application software should wait on
  934. * HSIRDY flag to be set indicating that HSI clock is stable and can
  935. * be used to clock the PLL and/or system clock.
  936. * @note HSI can not be stopped if it is used directly or through the PLL
  937. * as system clock. In this case, you have to select another source
  938. * of the system clock then stop the HSI.
  939. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  940. * @param __STATE__ specifies the new state of the HSI.
  941. * This parameter can be one of the following values:
  942. * @arg @ref RCC_HSI_OFF turn OFF the HSI oscillator
  943. * @arg @ref RCC_HSI_ON turn ON the HSI oscillator
  944. * @arg @ref RCC_HSI_DIV4 turn ON the HSI oscillator and divide it by 4
  945. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  946. * clock cycles.
  947. */
  948. #define __HAL_RCC_HSI_CONFIG(__STATE__) \
  949. MODIFY_REG(RCC->CR, RCC_CR_HSION | RCC_CR_HSIDIVEN , (uint32_t)(__STATE__))
  950. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  951. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  952. * It is used (enabled by hardware) as system clock source after startup
  953. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  954. * of the HSE used directly or indirectly as system clock (if the Clock
  955. * Security System CSS is enabled).
  956. * @note HSI can not be stopped if it is used as system clock source. In this case,
  957. * you have to select another source of the system clock then stop the HSI.
  958. * @note After enabling the HSI, the application software should wait on HSIRDY
  959. * flag to be set indicating that HSI clock is stable and can be used as
  960. * system clock source.
  961. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  962. * clock cycles.
  963. */
  964. #define __HAL_RCC_HSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_HSION)
  965. #define __HAL_RCC_HSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_HSION)
  966. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  967. * @note The calibration is used to compensate for the variations in voltage
  968. * and temperature that influence the frequency of the internal HSI RC.
  969. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  970. * (default is RCC_HSICALIBRATION_DEFAULT).
  971. * This parameter must be a number between 0 and 0x1F.
  972. */
  973. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  974. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << RCC_ICSCR_HSITRIM_Pos))
  975. /**
  976. * @}
  977. */
  978. /** @defgroup RCC_LSI_Configuration LSI Configuration
  979. * @{
  980. */
  981. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  982. * @note After enabling the LSI, the application software should wait on
  983. * LSIRDY flag to be set indicating that LSI clock is stable and can
  984. * be used to clock the IWDG and/or the RTC.
  985. */
  986. #define __HAL_RCC_LSI_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_LSION)
  987. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  988. * @note LSI can not be disabled if the IWDG is running.
  989. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  990. * clock cycles.
  991. */
  992. #define __HAL_RCC_LSI_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_LSION)
  993. /**
  994. * @}
  995. */
  996. /** @defgroup RCC_HSE_Configuration HSE Configuration
  997. * @{
  998. */
  999. /**
  1000. * @brief Macro to configure the External High Speed oscillator (HSE).
  1001. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  1002. * supported by this macro. User should request a transition to HSE Off
  1003. * first and then HSE On or HSE Bypass.
  1004. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  1005. * software should wait on HSERDY flag to be set indicating that HSE clock
  1006. * is stable and can be used to clock the PLL and/or system clock.
  1007. * @note HSE state can not be changed if it is used directly or through the
  1008. * PLL as system clock. In this case, you have to select another source
  1009. * of the system clock then change the HSE state (ex. disable it).
  1010. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  1011. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  1012. * was previously enabled you have to enable it again after calling this
  1013. * function.
  1014. * @param __STATE__ specifies the new state of the HSE.
  1015. * This parameter can be one of the following values:
  1016. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  1017. * 6 HSE oscillator clock cycles.
  1018. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  1019. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  1020. */
  1021. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  1022. do{ \
  1023. __IO uint32_t tmpreg; \
  1024. if ((__STATE__) == RCC_HSE_ON) \
  1025. { \
  1026. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1027. } \
  1028. else if ((__STATE__) == RCC_HSE_BYPASS) \
  1029. { \
  1030. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1031. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  1032. } \
  1033. else \
  1034. { \
  1035. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  1036. /* Delay after an RCC peripheral clock */ \
  1037. tmpreg = READ_BIT(RCC->CR, RCC_CR_HSEON); \
  1038. UNUSED(tmpreg); \
  1039. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  1040. } \
  1041. }while(0)
  1042. /**
  1043. * @}
  1044. */
  1045. /** @defgroup RCC_LSE_Configuration LSE Configuration
  1046. * @{
  1047. */
  1048. /**
  1049. * @brief Macro to configure the External Low Speed oscillator (LSE).
  1050. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  1051. * @note As the LSE is in the Backup domain and write access is denied to
  1052. * this domain after reset, you have to enable write access using
  1053. * @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  1054. * (to be done once after reset).
  1055. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  1056. * software should wait on LSERDY flag to be set indicating that LSE clock
  1057. * is stable and can be used to clock the RTC.
  1058. * @param __STATE__ specifies the new state of the LSE.
  1059. * This parameter can be one of the following values:
  1060. * @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
  1061. * 6 LSE oscillator clock cycles.
  1062. * @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
  1063. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  1064. */
  1065. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  1066. do{ \
  1067. if ((__STATE__) == RCC_LSE_ON) \
  1068. { \
  1069. SET_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1070. } \
  1071. else if ((__STATE__) == RCC_LSE_OFF) \
  1072. { \
  1073. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1074. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1075. } \
  1076. else if ((__STATE__) == RCC_LSE_BYPASS) \
  1077. { \
  1078. SET_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1079. SET_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1080. } \
  1081. else \
  1082. { \
  1083. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEON); \
  1084. CLEAR_BIT(RCC->CSR, RCC_CSR_LSEBYP); \
  1085. } \
  1086. }while(0)
  1087. /**
  1088. * @}
  1089. */
  1090. /** @defgroup RCC_MSI_Configuration MSI Configuration
  1091. * @{
  1092. */
  1093. /** @brief Macro to enable Internal Multi Speed oscillator (MSI).
  1094. * @note After enabling the MSI, the application software should wait on MSIRDY
  1095. * flag to be set indicating that MSI clock is stable and can be used as
  1096. * system clock source.
  1097. */
  1098. #define __HAL_RCC_MSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_MSION)
  1099. /** @brief Macro to disable the Internal Multi Speed oscillator (MSI).
  1100. * @note The MSI is stopped by hardware when entering STOP and STANDBY modes.
  1101. * It is used (enabled by hardware) as system clock source after startup
  1102. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  1103. * of the HSE used directly or indirectly as system clock (if the Clock
  1104. * Security System CSS is enabled).
  1105. * @note MSI can not be stopped if it is used as system clock source. In this case,
  1106. * you have to select another source of the system clock then stop the MSI.
  1107. * @note When the MSI is stopped, MSIRDY flag goes low after 6 MSI oscillator
  1108. * clock cycles.
  1109. */
  1110. #define __HAL_RCC_MSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_MSION)
  1111. /** @brief Macro adjusts Internal Multi Speed oscillator (MSI) calibration value.
  1112. * @note The calibration is used to compensate for the variations in voltage
  1113. * and temperature that influence the frequency of the internal MSI RC.
  1114. * Refer to the Application Note AN3300 for more details on how to
  1115. * calibrate the MSI.
  1116. * @param _MSICALIBRATIONVALUE_ specifies the calibration trimming value.
  1117. * (default is RCC_MSICALIBRATION_DEFAULT).
  1118. * This parameter must be a number between 0 and 0xFF.
  1119. */
  1120. #define __HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST(_MSICALIBRATIONVALUE_) \
  1121. (MODIFY_REG(RCC->ICSCR, RCC_ICSCR_MSITRIM, (uint32_t)(_MSICALIBRATIONVALUE_) << RCC_ICSCR_MSITRIM_Pos))
  1122. /* @brief Macro to configures the Internal Multi Speed oscillator (MSI) clock range.
  1123. * @note After restart from Reset or wakeup from STANDBY, the MSI clock is
  1124. * around 2.097 MHz. The MSI clock does not change after wake-up from
  1125. * STOP mode.
  1126. * @note The MSI clock range can be modified on the fly.
  1127. * @param _MSIRANGEVALUE_ specifies the MSI Clock range.
  1128. * This parameter must be one of the following values:
  1129. * @arg @ref RCC_MSIRANGE_0 MSI clock is around 65.536 KHz
  1130. * @arg @ref RCC_MSIRANGE_1 MSI clock is around 131.072 KHz
  1131. * @arg @ref RCC_MSIRANGE_2 MSI clock is around 262.144 KHz
  1132. * @arg @ref RCC_MSIRANGE_3 MSI clock is around 524.288 KHz
  1133. * @arg @ref RCC_MSIRANGE_4 MSI clock is around 1.048 MHz
  1134. * @arg @ref RCC_MSIRANGE_5 MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  1135. * @arg @ref RCC_MSIRANGE_6 MSI clock is around 4.194 MHz
  1136. */
  1137. #define __HAL_RCC_MSI_RANGE_CONFIG(_MSIRANGEVALUE_) (MODIFY_REG(RCC->ICSCR, \
  1138. RCC_ICSCR_MSIRANGE, (uint32_t)(_MSIRANGEVALUE_)))
  1139. /** @brief Macro to get the Internal Multi Speed oscillator (MSI) clock range in run mode
  1140. * @retval MSI clock range.
  1141. * This parameter must be one of the following values:
  1142. * @arg @ref RCC_MSIRANGE_0 MSI clock is around 65.536 KHz
  1143. * @arg @ref RCC_MSIRANGE_1 MSI clock is around 131.072 KHz
  1144. * @arg @ref RCC_MSIRANGE_2 MSI clock is around 262.144 KHz
  1145. * @arg @ref RCC_MSIRANGE_3 MSI clock is around 524.288 KHz
  1146. * @arg @ref RCC_MSIRANGE_4 MSI clock is around 1.048 MHz
  1147. * @arg @ref RCC_MSIRANGE_5 MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
  1148. * @arg @ref RCC_MSIRANGE_6 MSI clock is around 4.194 MHz
  1149. */
  1150. #define __HAL_RCC_GET_MSI_RANGE() (uint32_t)(READ_BIT(RCC->ICSCR, RCC_ICSCR_MSIRANGE))
  1151. /**
  1152. * @}
  1153. */
  1154. /** @defgroup RCC_PLL_Configuration PLL Configuration
  1155. * @{
  1156. */
  1157. /** @brief Macro to enable the main PLL.
  1158. * @note After enabling the main PLL, the application software should wait on
  1159. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1160. * be used as system clock source.
  1161. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1162. */
  1163. #define __HAL_RCC_PLL_ENABLE() SET_BIT(RCC->CR, RCC_CR_PLLON)
  1164. /** @brief Macro to disable the main PLL.
  1165. * @note The main PLL can not be disabled if it is used as system clock source
  1166. */
  1167. #define __HAL_RCC_PLL_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLON)
  1168. /** @brief Macro to configure the main PLL clock source, multiplication and division factors.
  1169. * @note This function must be used only when the main PLL is disabled.
  1170. *
  1171. * @param __RCC_PLLSOURCE__ specifies the PLL entry clock source.
  1172. * This parameter can be one of the following values:
  1173. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL clock entry
  1174. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  1175. * @param __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
  1176. * This parameter can be one of the following values:
  1177. * @arg @ref RCC_PLL_MUL3 PLLVCO = PLL clock entry x 3
  1178. * @arg @ref RCC_PLL_MUL4 PLLVCO = PLL clock entry x 4
  1179. * @arg @ref RCC_PLL_MUL6 PLLVCO = PLL clock entry x 6
  1180. * @arg @ref RCC_PLL_MUL8 PLLVCO = PLL clock entry x 8
  1181. * @arg @ref RCC_PLL_MUL12 PLLVCO = PLL clock entry x 12
  1182. * @arg @ref RCC_PLL_MUL16 PLLVCO = PLL clock entry x 16
  1183. * @arg @ref RCC_PLL_MUL24 PLLVCO = PLL clock entry x 24
  1184. * @arg @ref RCC_PLL_MUL32 PLLVCO = PLL clock entry x 32
  1185. * @arg @ref RCC_PLL_MUL48 PLLVCO = PLL clock entry x 48
  1186. * @note The PLL VCO clock frequency must not exceed 96 MHz when the product is in Range 1,
  1187. * 48 MHz when the product is in Range 2and 24 MHz when the product is in Range 3.
  1188. *
  1189. * @param __PLLDIV__ specifies the division factor for PLL VCO input clock
  1190. * This parameter can be one of the following values:
  1191. * @arg @ref RCC_PLL_DIV2 PLL clock output = PLLVCO / 2
  1192. * @arg @ref RCC_PLL_DIV3 PLL clock output = PLLVCO / 3
  1193. * @arg @ref RCC_PLL_DIV4 PLL clock output = PLLVCO / 4
  1194. *
  1195. */
  1196. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__, __PLLDIV__)\
  1197. MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC|RCC_CFGR_PLLMUL|RCC_CFGR_PLLDIV),((__RCC_PLLSOURCE__) | (__PLLMUL__) | (__PLLDIV__)))
  1198. /** @brief Get oscillator clock selected as PLL input clock
  1199. * @retval The clock source used for PLL entry. The returned value can be one
  1200. * of the following:
  1201. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL input clock
  1202. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  1203. */
  1204. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  1205. /**
  1206. * @}
  1207. */
  1208. /** @defgroup RCC_Get_Clock_source Get Clock source
  1209. * @{
  1210. */
  1211. /**
  1212. * @brief Macro to configure the system clock source.
  1213. * @param __SYSCLKSOURCE__ specifies the system clock source.
  1214. * This parameter can be one of the following values:
  1215. * @arg @ref RCC_SYSCLKSOURCE_MSI MSI oscillator is used as system clock source.
  1216. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  1217. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  1218. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  1219. */
  1220. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  1221. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  1222. /** @brief Macro to get the clock source used as system clock.
  1223. * @retval The clock source used as system clock. The returned value can be one
  1224. * of the following:
  1225. * @arg @ref RCC_SYSCLKSOURCE_STATUS_MSI MSI used as system clock
  1226. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  1227. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  1228. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  1229. */
  1230. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  1231. /**
  1232. * @}
  1233. */
  1234. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  1235. * @{
  1236. */
  1237. /** @brief Macro to configure the MCO clock.
  1238. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1239. * This parameter can be one of the following values:
  1240. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1241. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1242. * @arg @ref RCC_MCO1SOURCE_HSI HSI oscillator clock selected as MCO clock
  1243. * @arg @ref RCC_MCO1SOURCE_MSI MSI oscillator clock selected as MCO clock
  1244. * @arg @ref RCC_MCO1SOURCE_HSE HSE oscillator clock selected as MCO clock
  1245. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock selected as MCO clock
  1246. * @arg @ref RCC_MCO1SOURCE_LSI LSI clock selected as MCO clock
  1247. * @arg @ref RCC_MCO1SOURCE_LSE LSE clock selected as MCO clock
  1248. @if STM32L052xx
  1249. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1250. @elseif STM32L053xx
  1251. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1252. @elseif STM32L062xx
  1253. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1254. @elseif STM32L063xx
  1255. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1256. @elseif STM32L072xx
  1257. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1258. @elseif STM32L073xx
  1259. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1260. @elseif STM32L082xx
  1261. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1262. @elseif STM32L083xx
  1263. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  1264. @endif
  1265. * @param __MCODIV__ specifies the MCO clock prescaler.
  1266. * This parameter can be one of the following values:
  1267. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  1268. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  1269. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  1270. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  1271. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  1272. */
  1273. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1274. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCOSEL | RCC_CFGR_MCO_PRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  1275. /**
  1276. * @}
  1277. */
  1278. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  1279. * @{
  1280. */
  1281. /** @brief Macro to configure the RTC clock (RTCCLK).
  1282. * @note As the RTC clock configuration bits are in the Backup domain and write
  1283. * access is denied to this domain after reset, you have to enable write
  1284. * access using the Power Backup Access macro before to configure
  1285. * the RTC clock source (to be done once after reset).
  1286. * @note Once the RTC clock is configured it cannot be changed unless the
  1287. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1288. * a Power On Reset (POR).
  1289. * @note RTC prescaler cannot be modified if HSE is enabled (HSEON = 1).
  1290. *
  1291. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  1292. * This parameter can be one of the following values:
  1293. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1294. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1295. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1296. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV2 HSE divided by 2 selected as RTC clock
  1297. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV4 HSE divided by 4 selected as RTC clock
  1298. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV8 HSE divided by 8 selected as RTC clock
  1299. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV16 HSE divided by 16 selected as RTC clock
  1300. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1301. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1302. * However, when the HSE clock is used as RTC clock source, the RTC
  1303. * cannot be used in STOP and STANDBY modes.
  1304. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1305. * RTC clock source).
  1306. */
  1307. #define __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__) do { \
  1308. if(((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE) \
  1309. { \
  1310. MODIFY_REG(RCC->CR, RCC_CR_RTCPRE, ((__RTC_CLKSOURCE__) & RCC_CR_RTCPRE)); \
  1311. } \
  1312. } while (0)
  1313. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) do { \
  1314. __HAL_RCC_RTC_CLKPRESCALER(__RTC_CLKSOURCE__); \
  1315. RCC->CSR |= ((__RTC_CLKSOURCE__) & RCC_CSR_RTCSEL); \
  1316. } while (0)
  1317. /** @brief Macro to get the RTC clock source.
  1318. * @retval The clock source can be one of the following values:
  1319. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1320. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1321. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1322. * @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()
  1323. */
  1324. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->CSR, RCC_CSR_RTCSEL))
  1325. /**
  1326. * @brief Get the RTC and LCD HSE clock divider (RTCCLK / LCDCLK).
  1327. *
  1328. * @retval Returned value can be one of the following values:
  1329. * @arg @ref RCC_RTC_HSE_DIV_2 HSE divided by 2 selected as RTC clock
  1330. * @arg @ref RCC_RTC_HSE_DIV_4 HSE divided by 4 selected as RTC clock
  1331. * @arg @ref RCC_RTC_HSE_DIV_8 HSE divided by 8 selected as RTC clock
  1332. * @arg @ref RCC_RTC_HSE_DIV_16 HSE divided by 16 selected as RTC clock
  1333. *
  1334. */
  1335. #define __HAL_RCC_GET_RTC_HSE_PRESCALER() ((uint32_t)(READ_BIT(RCC->CR, RCC_CR_RTCPRE)))
  1336. /** @brief Macro to enable the the RTC clock.
  1337. * @note These macros must be used only after the RTC clock source was selected.
  1338. */
  1339. #define __HAL_RCC_RTC_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_RTCEN)
  1340. /** @brief Macro to disable the the RTC clock.
  1341. * @note These macros must be used only after the RTC clock source was selected.
  1342. */
  1343. #define __HAL_RCC_RTC_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_RTCEN)
  1344. /** @brief Macro to force the Backup domain reset.
  1345. * @note This function resets the RTC peripheral (including the backup registers)
  1346. * and the RTC clock source selection in RCC_CSR register.
  1347. * @note The BKPSRAM is not affected by this reset.
  1348. */
  1349. #define __HAL_RCC_BACKUPRESET_FORCE() SET_BIT(RCC->CSR, RCC_CSR_RTCRST)
  1350. /** @brief Macros to release the Backup domain reset.
  1351. */
  1352. #define __HAL_RCC_BACKUPRESET_RELEASE() CLEAR_BIT(RCC->CSR, RCC_CSR_RTCRST)
  1353. /**
  1354. * @}
  1355. */
  1356. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1357. * @brief macros to manage the specified RCC Flags and interrupts.
  1358. * @{
  1359. */
  1360. /** @brief Enable RCC interrupt.
  1361. * @note The CSS interrupt doesn't have an enable bit; once the CSS is enabled
  1362. * and if the HSE clock fails, the CSS interrupt occurs and an NMI is
  1363. * automatically generated. The NMI will be executed indefinitely, and
  1364. * since NMI has higher priority than any other IRQ (and main program)
  1365. * the application will be stacked in the NMI ISR unless the CSS interrupt
  1366. * pending bit is cleared.
  1367. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1368. * This parameter can be any combination of the following values:
  1369. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1370. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1371. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1372. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1373. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1374. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1375. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1376. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt (not available on all devices)
  1377. */
  1378. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) SET_BIT(RCC->CIER, (__INTERRUPT__))
  1379. /** @brief Disable RCC interrupt.
  1380. * @note The CSS interrupt doesn't have an enable bit; once the CSS is enabled
  1381. * and if the HSE clock fails, the CSS interrupt occurs and an NMI is
  1382. * automatically generated. The NMI will be executed indefinitely, and
  1383. * since NMI has higher priority than any other IRQ (and main program)
  1384. * the application will be stacked in the NMI ISR unless the CSS interrupt
  1385. * pending bit is cleared.
  1386. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1387. * This parameter can be any combination of the following values:
  1388. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1389. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1390. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1391. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1392. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1393. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1394. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1395. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt (not available on all devices)
  1396. */
  1397. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(RCC->CIER, (__INTERRUPT__))
  1398. /** @brief Clear the RCC's interrupt pending bits.
  1399. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1400. * This parameter can be any combination of the following values:
  1401. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1402. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1403. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1404. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1405. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1406. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1407. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1408. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt (not available on all devices)
  1409. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1410. */
  1411. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (RCC->CICR = (__INTERRUPT__))
  1412. /** @brief Check the RCC's interrupt has occurred or not.
  1413. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1414. * This parameter can be one of the following values:
  1415. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1416. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1417. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1418. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1419. * @arg @ref RCC_IT_PLLRDY PLL ready interrupt
  1420. * @arg @ref RCC_IT_MSIRDY MSI ready interrupt
  1421. * @arg @ref RCC_IT_LSECSS LSE CSS interrupt
  1422. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1423. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1424. */
  1425. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIFR & (__INTERRUPT__)) == (__INTERRUPT__))
  1426. /** @brief Set RMVF bit to clear the reset flags.
  1427. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1428. * RCC_FLAG_OBLRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1429. */
  1430. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1431. /** @brief Check RCC flag is set or not.
  1432. * @param __FLAG__ specifies the flag to check.
  1433. * This parameter can be one of the following values:
  1434. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready
  1435. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready (not available on all devices)
  1436. * @arg @ref RCC_FLAG_HSIDIV HSI16 divider flag
  1437. * @arg @ref RCC_FLAG_MSIRDY MSI oscillator clock ready
  1438. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready
  1439. * @arg @ref RCC_FLAG_PLLRDY PLL clock ready
  1440. * @arg @ref RCC_FLAG_LSECSS LSE oscillator clock CSS detected
  1441. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready
  1442. * @arg @ref RCC_FLAG_FWRST Firewall reset
  1443. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready
  1444. * @arg @ref RCC_FLAG_OBLRST Option Byte Loader (OBL) reset
  1445. * @arg @ref RCC_FLAG_PINRST Pin reset
  1446. * @arg @ref RCC_FLAG_PORRST POR/PDR reset
  1447. * @arg @ref RCC_FLAG_SFTRST Software reset
  1448. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset
  1449. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset
  1450. * @arg @ref RCC_FLAG_LPWRRST Low Power reset
  1451. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1452. */
  1453. #if defined(RCC_HSI48_SUPPORT)
  1454. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((((__FLAG__) >> 5) == CR_REG_INDEX)? RCC->CR :((((__FLAG__) >> 5) == CSR_REG_INDEX) ? RCC->CSR :RCC->CRRCR)))) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK))) != 0U ) ? 1U : 0U )
  1455. #else
  1456. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((((__FLAG__) >> 5) == CR_REG_INDEX)? RCC->CR : RCC->CSR))) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK))) != 0U ) ? 1U : 0U )
  1457. #endif /* RCC_HSI48_SUPPORT */
  1458. /**
  1459. * @}
  1460. */
  1461. /**
  1462. * @}
  1463. */
  1464. /* Include RCC HAL Extension module */
  1465. #include "stm32l0xx_hal_rcc_ex.h"
  1466. /* Exported functions --------------------------------------------------------*/
  1467. /** @addtogroup RCC_Exported_Functions
  1468. * @{
  1469. */
  1470. /** @addtogroup RCC_Exported_Functions_Group1
  1471. * @{
  1472. */
  1473. /* Initialization and de-initialization functions ******************************/
  1474. HAL_StatusTypeDef HAL_RCC_DeInit(void);
  1475. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1476. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1477. /**
  1478. * @}
  1479. */
  1480. /** @addtogroup RCC_Exported_Functions_Group2
  1481. * @{
  1482. */
  1483. /* Peripheral Control functions ************************************************/
  1484. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1485. #if defined(RCC_HSECSS_SUPPORT)
  1486. void HAL_RCC_EnableCSS(void);
  1487. /* CSS NMI IRQ handler */
  1488. void HAL_RCC_NMI_IRQHandler(void);
  1489. /* User Callbacks in non blocking mode (IT mode) */
  1490. void HAL_RCC_CSSCallback(void);
  1491. #endif /* RCC_HSECSS_SUPPORT */
  1492. uint32_t HAL_RCC_GetSysClockFreq(void);
  1493. uint32_t HAL_RCC_GetHCLKFreq(void);
  1494. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1495. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1496. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1497. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1498. /**
  1499. * @}
  1500. */
  1501. /**
  1502. * @}
  1503. */
  1504. /**
  1505. * @}
  1506. */
  1507. /**
  1508. * @}
  1509. */
  1510. #ifdef __cplusplus
  1511. }
  1512. #endif
  1513. #endif /* __STM32L0xx_HAL_RCC_H */
  1514. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/