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.
 
 
 
 
 
 

1379 lines
65 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_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 __STM32F1xx_HAL_RCC_H
  21. #define __STM32F1xx_HAL_RCC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx_hal_def.h"
  27. /** @addtogroup STM32F1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup RCC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup RCC_Exported_Types RCC Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief RCC PLL configuration structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  43. This parameter can be a value of @ref RCC_PLL_Config */
  44. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  45. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  46. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  47. This parameter must be a value of @ref RCCEx_PLL_Multiplication_Factor */
  48. } RCC_PLLInitTypeDef;
  49. /**
  50. * @brief RCC System, AHB and APB busses clock configuration structure definition
  51. */
  52. typedef struct
  53. {
  54. uint32_t ClockType; /*!< The clock to be configured.
  55. This parameter can be a value of @ref RCC_System_Clock_Type */
  56. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  57. This parameter can be a value of @ref RCC_System_Clock_Source */
  58. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  59. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  60. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  61. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  62. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  63. This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
  64. } RCC_ClkInitTypeDef;
  65. /**
  66. * @}
  67. */
  68. /* Exported constants --------------------------------------------------------*/
  69. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  70. * @{
  71. */
  72. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  73. * @{
  74. */
  75. #define RCC_PLLSOURCE_HSI_DIV2 0x00000000U /*!< HSI clock divided by 2 selected as PLL entry clock source */
  76. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC /*!< HSE clock selected as PLL entry clock source */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup RCC_Oscillator_Type Oscillator Type
  81. * @{
  82. */
  83. #define RCC_OSCILLATORTYPE_NONE 0x00000000U
  84. #define RCC_OSCILLATORTYPE_HSE 0x00000001U
  85. #define RCC_OSCILLATORTYPE_HSI 0x00000002U
  86. #define RCC_OSCILLATORTYPE_LSE 0x00000004U
  87. #define RCC_OSCILLATORTYPE_LSI 0x00000008U
  88. /**
  89. * @}
  90. */
  91. /** @defgroup RCC_HSE_Config HSE Config
  92. * @{
  93. */
  94. #define RCC_HSE_OFF 0x00000000U /*!< HSE clock deactivation */
  95. #define RCC_HSE_ON RCC_CR_HSEON /*!< HSE clock activation */
  96. #define RCC_HSE_BYPASS ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup RCC_LSE_Config LSE Config
  101. * @{
  102. */
  103. #define RCC_LSE_OFF 0x00000000U /*!< LSE clock deactivation */
  104. #define RCC_LSE_ON RCC_BDCR_LSEON /*!< LSE clock activation */
  105. #define RCC_LSE_BYPASS ((uint32_t)(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON)) /*!< External clock source for LSE clock */
  106. /**
  107. * @}
  108. */
  109. /** @defgroup RCC_HSI_Config HSI Config
  110. * @{
  111. */
  112. #define RCC_HSI_OFF 0x00000000U /*!< HSI clock deactivation */
  113. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  114. #define RCC_HSICALIBRATION_DEFAULT 0x10U /* Default HSI calibration trimming value */
  115. /**
  116. * @}
  117. */
  118. /** @defgroup RCC_LSI_Config LSI Config
  119. * @{
  120. */
  121. #define RCC_LSI_OFF 0x00000000U /*!< LSI clock deactivation */
  122. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup RCC_PLL_Config PLL Config
  127. * @{
  128. */
  129. #define RCC_PLL_NONE 0x00000000U /*!< PLL is not configured */
  130. #define RCC_PLL_OFF 0x00000001U /*!< PLL deactivation */
  131. #define RCC_PLL_ON 0x00000002U /*!< PLL activation */
  132. /**
  133. * @}
  134. */
  135. /** @defgroup RCC_System_Clock_Type System Clock Type
  136. * @{
  137. */
  138. #define RCC_CLOCKTYPE_SYSCLK 0x00000001U /*!< SYSCLK to configure */
  139. #define RCC_CLOCKTYPE_HCLK 0x00000002U /*!< HCLK to configure */
  140. #define RCC_CLOCKTYPE_PCLK1 0x00000004U /*!< PCLK1 to configure */
  141. #define RCC_CLOCKTYPE_PCLK2 0x00000008U /*!< PCLK2 to configure */
  142. /**
  143. * @}
  144. */
  145. /** @defgroup RCC_System_Clock_Source System Clock Source
  146. * @{
  147. */
  148. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  149. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  150. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  151. /**
  152. * @}
  153. */
  154. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  155. * @{
  156. */
  157. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  158. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  159. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  160. /**
  161. * @}
  162. */
  163. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  164. * @{
  165. */
  166. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  167. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  168. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  169. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  170. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  171. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  172. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  173. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  174. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  175. /**
  176. * @}
  177. */
  178. /** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
  179. * @{
  180. */
  181. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE1_DIV1 /*!< HCLK not divided */
  182. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE1_DIV2 /*!< HCLK divided by 2 */
  183. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE1_DIV4 /*!< HCLK divided by 4 */
  184. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE1_DIV8 /*!< HCLK divided by 8 */
  185. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup RCC_RTC_Clock_Source RTC Clock Source
  190. * @{
  191. */
  192. #define RCC_RTCCLKSOURCE_NO_CLK 0x00000000U /*!< No clock */
  193. #define RCC_RTCCLKSOURCE_LSE RCC_BDCR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  194. #define RCC_RTCCLKSOURCE_LSI RCC_BDCR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  195. #define RCC_RTCCLKSOURCE_HSE_DIV128 RCC_BDCR_RTCSEL_HSE /*!< HSE oscillator clock divided by 128 used as RTC clock */
  196. /**
  197. * @}
  198. */
  199. /** @defgroup RCC_MCO_Index MCO Index
  200. * @{
  201. */
  202. #define RCC_MCO1 0x00000000U
  203. #define RCC_MCO RCC_MCO1 /*!< MCO1 to be compliant with other families with 2 MCOs*/
  204. /**
  205. * @}
  206. */
  207. /** @defgroup RCC_MCOx_Clock_Prescaler MCO Clock Prescaler
  208. * @{
  209. */
  210. #define RCC_MCODIV_1 0x00000000U
  211. /**
  212. * @}
  213. */
  214. /** @defgroup RCC_Interrupt Interrupts
  215. * @{
  216. */
  217. #define RCC_IT_LSIRDY ((uint8_t)RCC_CIR_LSIRDYF) /*!< LSI Ready Interrupt flag */
  218. #define RCC_IT_LSERDY ((uint8_t)RCC_CIR_LSERDYF) /*!< LSE Ready Interrupt flag */
  219. #define RCC_IT_HSIRDY ((uint8_t)RCC_CIR_HSIRDYF) /*!< HSI Ready Interrupt flag */
  220. #define RCC_IT_HSERDY ((uint8_t)RCC_CIR_HSERDYF) /*!< HSE Ready Interrupt flag */
  221. #define RCC_IT_PLLRDY ((uint8_t)RCC_CIR_PLLRDYF) /*!< PLL Ready Interrupt flag */
  222. #define RCC_IT_CSS ((uint8_t)RCC_CIR_CSSF) /*!< Clock Security System Interrupt flag */
  223. /**
  224. * @}
  225. */
  226. /** @defgroup RCC_Flag Flags
  227. * Elements values convention: XXXYYYYYb
  228. * - YYYYY : Flag position in the register
  229. * - XXX : Register index
  230. * - 001: CR register
  231. * - 010: BDCR register
  232. * - 011: CSR register
  233. * @{
  234. */
  235. /* Flags in the CR register */
  236. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSIRDY_Pos)) /*!< Internal High Speed clock ready flag */
  237. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSERDY_Pos)) /*!< External High Speed clock ready flag */
  238. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_PLLRDY_Pos)) /*!< PLL clock ready flag */
  239. /* Flags in the CSR register */
  240. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LSIRDY_Pos)) /*!< Internal Low Speed oscillator Ready */
  241. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PINRSTF_Pos)) /*!< PIN reset flag */
  242. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PORRSTF_Pos)) /*!< POR/PDR reset flag */
  243. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_SFTRSTF_Pos)) /*!< Software Reset flag */
  244. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_IWDGRSTF_Pos)) /*!< Independent Watchdog reset flag */
  245. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_WWDGRSTF_Pos)) /*!< Window watchdog reset flag */
  246. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LPWRRSTF_Pos)) /*!< Low-Power reset flag */
  247. /* Flags in the BDCR register */
  248. #define RCC_FLAG_LSERDY ((uint8_t)((BDCR_REG_INDEX << 5U) | RCC_BDCR_LSERDY_Pos)) /*!< External Low Speed oscillator Ready */
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @}
  254. */
  255. /* Exported macro ------------------------------------------------------------*/
  256. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  257. * @{
  258. */
  259. /** @defgroup RCC_Peripheral_Clock_Enable_Disable Peripheral Clock Enable Disable
  260. * @brief Enable or disable the AHB1 peripheral clock.
  261. * @note After reset, the peripheral clock (used for registers read/write access)
  262. * is disabled and the application software has to enable this clock before
  263. * using it.
  264. * @{
  265. */
  266. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  267. __IO uint32_t tmpreg; \
  268. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  269. /* Delay after an RCC peripheral clock enabling */\
  270. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  271. UNUSED(tmpreg); \
  272. } while(0U)
  273. #define __HAL_RCC_SRAM_CLK_ENABLE() do { \
  274. __IO uint32_t tmpreg; \
  275. SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  276. /* Delay after an RCC peripheral clock enabling */\
  277. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  278. UNUSED(tmpreg); \
  279. } while(0U)
  280. #define __HAL_RCC_FLITF_CLK_ENABLE() do { \
  281. __IO uint32_t tmpreg; \
  282. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  283. /* Delay after an RCC peripheral clock enabling */\
  284. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  285. UNUSED(tmpreg); \
  286. } while(0U)
  287. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  288. __IO uint32_t tmpreg; \
  289. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  290. /* Delay after an RCC peripheral clock enabling */\
  291. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  292. UNUSED(tmpreg); \
  293. } while(0U)
  294. #define __HAL_RCC_DMA1_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
  295. #define __HAL_RCC_SRAM_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_SRAMEN))
  296. #define __HAL_RCC_FLITF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
  297. #define __HAL_RCC_CRC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
  298. /**
  299. * @}
  300. */
  301. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enable Disable Status
  302. * @brief Get the enable or disable status of the AHB peripheral clock.
  303. * @note After reset, the peripheral clock (used for registers read/write access)
  304. * is disabled and the application software has to enable this clock before
  305. * using it.
  306. * @{
  307. */
  308. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) != RESET)
  309. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) == RESET)
  310. #define __HAL_RCC_SRAM_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) != RESET)
  311. #define __HAL_RCC_SRAM_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) == RESET)
  312. #define __HAL_RCC_FLITF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) != RESET)
  313. #define __HAL_RCC_FLITF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) == RESET)
  314. #define __HAL_RCC_CRC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) != RESET)
  315. #define __HAL_RCC_CRC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) == RESET)
  316. /**
  317. * @}
  318. */
  319. /** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Clock Enable Disable
  320. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  321. * @note After reset, the peripheral clock (used for registers read/write access)
  322. * is disabled and the application software has to enable this clock before
  323. * using it.
  324. * @{
  325. */
  326. #define __HAL_RCC_TIM2_CLK_ENABLE() do { \
  327. __IO uint32_t tmpreg; \
  328. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  329. /* Delay after an RCC peripheral clock enabling */\
  330. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  331. UNUSED(tmpreg); \
  332. } while(0U)
  333. #define __HAL_RCC_TIM3_CLK_ENABLE() do { \
  334. __IO uint32_t tmpreg; \
  335. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  336. /* Delay after an RCC peripheral clock enabling */\
  337. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  338. UNUSED(tmpreg); \
  339. } while(0U)
  340. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  341. __IO uint32_t tmpreg; \
  342. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  343. /* Delay after an RCC peripheral clock enabling */\
  344. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  345. UNUSED(tmpreg); \
  346. } while(0U)
  347. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  348. __IO uint32_t tmpreg; \
  349. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  350. /* Delay after an RCC peripheral clock enabling */\
  351. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  352. UNUSED(tmpreg); \
  353. } while(0U)
  354. #define __HAL_RCC_I2C1_CLK_ENABLE() do { \
  355. __IO uint32_t tmpreg; \
  356. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  357. /* Delay after an RCC peripheral clock enabling */\
  358. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  359. UNUSED(tmpreg); \
  360. } while(0U)
  361. #define __HAL_RCC_BKP_CLK_ENABLE() do { \
  362. __IO uint32_t tmpreg; \
  363. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_BKPEN);\
  364. /* Delay after an RCC peripheral clock enabling */\
  365. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_BKPEN);\
  366. UNUSED(tmpreg); \
  367. } while(0U)
  368. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  369. __IO uint32_t tmpreg; \
  370. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  371. /* Delay after an RCC peripheral clock enabling */\
  372. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  373. UNUSED(tmpreg); \
  374. } while(0U)
  375. #define __HAL_RCC_TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  376. #define __HAL_RCC_TIM3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
  377. #define __HAL_RCC_WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  378. #define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  379. #define __HAL_RCC_I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  380. #define __HAL_RCC_BKP_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_BKPEN))
  381. #define __HAL_RCC_PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  382. /**
  383. * @}
  384. */
  385. /** @defgroup RCC_APB1_Peripheral_Clock_Enable_Disable_Status APB1 Peripheral Clock Enable Disable Status
  386. * @brief Get the enable or disable status of the APB1 peripheral clock.
  387. * @note After reset, the peripheral clock (used for registers read/write access)
  388. * is disabled and the application software has to enable this clock before
  389. * using it.
  390. * @{
  391. */
  392. #define __HAL_RCC_TIM2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) != RESET)
  393. #define __HAL_RCC_TIM2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) == RESET)
  394. #define __HAL_RCC_TIM3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) != RESET)
  395. #define __HAL_RCC_TIM3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) == RESET)
  396. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) != RESET)
  397. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) == RESET)
  398. #define __HAL_RCC_USART2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != RESET)
  399. #define __HAL_RCC_USART2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == RESET)
  400. #define __HAL_RCC_I2C1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) != RESET)
  401. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) == RESET)
  402. #define __HAL_RCC_BKP_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_BKPEN)) != RESET)
  403. #define __HAL_RCC_BKP_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_BKPEN)) == RESET)
  404. #define __HAL_RCC_PWR_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) != RESET)
  405. #define __HAL_RCC_PWR_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) == RESET)
  406. /**
  407. * @}
  408. */
  409. /** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Clock Enable Disable
  410. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  411. * @note After reset, the peripheral clock (used for registers read/write access)
  412. * is disabled and the application software has to enable this clock before
  413. * using it.
  414. * @{
  415. */
  416. #define __HAL_RCC_AFIO_CLK_ENABLE() do { \
  417. __IO uint32_t tmpreg; \
  418. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_AFIOEN);\
  419. /* Delay after an RCC peripheral clock enabling */\
  420. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_AFIOEN);\
  421. UNUSED(tmpreg); \
  422. } while(0U)
  423. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  424. __IO uint32_t tmpreg; \
  425. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);\
  426. /* Delay after an RCC peripheral clock enabling */\
  427. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);\
  428. UNUSED(tmpreg); \
  429. } while(0U)
  430. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  431. __IO uint32_t tmpreg; \
  432. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);\
  433. /* Delay after an RCC peripheral clock enabling */\
  434. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);\
  435. UNUSED(tmpreg); \
  436. } while(0U)
  437. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  438. __IO uint32_t tmpreg; \
  439. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPCEN);\
  440. /* Delay after an RCC peripheral clock enabling */\
  441. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPCEN);\
  442. UNUSED(tmpreg); \
  443. } while(0U)
  444. #define __HAL_RCC_GPIOD_CLK_ENABLE() do { \
  445. __IO uint32_t tmpreg; \
  446. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);\
  447. /* Delay after an RCC peripheral clock enabling */\
  448. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);\
  449. UNUSED(tmpreg); \
  450. } while(0U)
  451. #define __HAL_RCC_ADC1_CLK_ENABLE() do { \
  452. __IO uint32_t tmpreg; \
  453. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  454. /* Delay after an RCC peripheral clock enabling */\
  455. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  456. UNUSED(tmpreg); \
  457. } while(0U)
  458. #define __HAL_RCC_TIM1_CLK_ENABLE() do { \
  459. __IO uint32_t tmpreg; \
  460. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  461. /* Delay after an RCC peripheral clock enabling */\
  462. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  463. UNUSED(tmpreg); \
  464. } while(0U)
  465. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  466. __IO uint32_t tmpreg; \
  467. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  468. /* Delay after an RCC peripheral clock enabling */\
  469. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  470. UNUSED(tmpreg); \
  471. } while(0U)
  472. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  473. __IO uint32_t tmpreg; \
  474. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  475. /* Delay after an RCC peripheral clock enabling */\
  476. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  477. UNUSED(tmpreg); \
  478. } while(0U)
  479. #define __HAL_RCC_AFIO_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_AFIOEN))
  480. #define __HAL_RCC_GPIOA_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPAEN))
  481. #define __HAL_RCC_GPIOB_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPBEN))
  482. #define __HAL_RCC_GPIOC_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPCEN))
  483. #define __HAL_RCC_GPIOD_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPDEN))
  484. #define __HAL_RCC_ADC1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
  485. #define __HAL_RCC_TIM1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
  486. #define __HAL_RCC_SPI1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
  487. #define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  488. /**
  489. * @}
  490. */
  491. /** @defgroup RCC_APB2_Peripheral_Clock_Enable_Disable_Status APB2 Peripheral Clock Enable Disable Status
  492. * @brief Get the enable or disable status of the APB2 peripheral clock.
  493. * @note After reset, the peripheral clock (used for registers read/write access)
  494. * is disabled and the application software has to enable this clock before
  495. * using it.
  496. * @{
  497. */
  498. #define __HAL_RCC_AFIO_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_AFIOEN)) != RESET)
  499. #define __HAL_RCC_AFIO_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_AFIOEN)) == RESET)
  500. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPAEN)) != RESET)
  501. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPAEN)) == RESET)
  502. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPBEN)) != RESET)
  503. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPBEN)) == RESET)
  504. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPCEN)) != RESET)
  505. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPCEN)) == RESET)
  506. #define __HAL_RCC_GPIOD_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPDEN)) != RESET)
  507. #define __HAL_RCC_GPIOD_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_IOPDEN)) == RESET)
  508. #define __HAL_RCC_ADC1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) != RESET)
  509. #define __HAL_RCC_ADC1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) == RESET)
  510. #define __HAL_RCC_TIM1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) != RESET)
  511. #define __HAL_RCC_TIM1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) == RESET)
  512. #define __HAL_RCC_SPI1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) != RESET)
  513. #define __HAL_RCC_SPI1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) == RESET)
  514. #define __HAL_RCC_USART1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) != RESET)
  515. #define __HAL_RCC_USART1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) == RESET)
  516. /**
  517. * @}
  518. */
  519. /** @defgroup RCC_APB1_Force_Release_Reset APB1 Force Release Reset
  520. * @brief Force or release APB1 peripheral reset.
  521. * @{
  522. */
  523. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  524. #define __HAL_RCC_TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  525. #define __HAL_RCC_TIM3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
  526. #define __HAL_RCC_WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  527. #define __HAL_RCC_USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  528. #define __HAL_RCC_I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  529. #define __HAL_RCC_BKP_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_BKPRST))
  530. #define __HAL_RCC_PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  531. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00)
  532. #define __HAL_RCC_TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  533. #define __HAL_RCC_TIM3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
  534. #define __HAL_RCC_WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  535. #define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  536. #define __HAL_RCC_I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  537. #define __HAL_RCC_BKP_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_BKPRST))
  538. #define __HAL_RCC_PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  539. /**
  540. * @}
  541. */
  542. /** @defgroup RCC_APB2_Force_Release_Reset APB2 Force Release Reset
  543. * @brief Force or release APB2 peripheral reset.
  544. * @{
  545. */
  546. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  547. #define __HAL_RCC_AFIO_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_AFIORST))
  548. #define __HAL_RCC_GPIOA_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPARST))
  549. #define __HAL_RCC_GPIOB_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPBRST))
  550. #define __HAL_RCC_GPIOC_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPCRST))
  551. #define __HAL_RCC_GPIOD_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPDRST))
  552. #define __HAL_RCC_ADC1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_ADC1RST))
  553. #define __HAL_RCC_TIM1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM1RST))
  554. #define __HAL_RCC_SPI1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
  555. #define __HAL_RCC_USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  556. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00)
  557. #define __HAL_RCC_AFIO_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_AFIORST))
  558. #define __HAL_RCC_GPIOA_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPARST))
  559. #define __HAL_RCC_GPIOB_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPBRST))
  560. #define __HAL_RCC_GPIOC_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPCRST))
  561. #define __HAL_RCC_GPIOD_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPDRST))
  562. #define __HAL_RCC_ADC1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADC1RST))
  563. #define __HAL_RCC_TIM1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM1RST))
  564. #define __HAL_RCC_SPI1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
  565. #define __HAL_RCC_USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  566. /**
  567. * @}
  568. */
  569. /** @defgroup RCC_HSI_Configuration HSI Configuration
  570. * @{
  571. */
  572. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  573. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  574. * @note HSI can not be stopped if it is used as system clock source. In this case,
  575. * you have to select another source of the system clock then stop the HSI.
  576. * @note After enabling the HSI, the application software should wait on HSIRDY
  577. * flag to be set indicating that HSI clock is stable and can be used as
  578. * system clock source.
  579. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  580. * clock cycles.
  581. */
  582. #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = ENABLE)
  583. #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = DISABLE)
  584. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  585. * @note The calibration is used to compensate for the variations in voltage
  586. * and temperature that influence the frequency of the internal HSI RC.
  587. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  588. * (default is RCC_HSICALIBRATION_DEFAULT).
  589. * This parameter must be a number between 0 and 0x1F.
  590. */
  591. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  592. (MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << RCC_CR_HSITRIM_Pos))
  593. /**
  594. * @}
  595. */
  596. /** @defgroup RCC_LSI_Configuration LSI Configuration
  597. * @{
  598. */
  599. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  600. * @note After enabling the LSI, the application software should wait on
  601. * LSIRDY flag to be set indicating that LSI clock is stable and can
  602. * be used to clock the IWDG and/or the RTC.
  603. */
  604. #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = ENABLE)
  605. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  606. * @note LSI can not be disabled if the IWDG is running.
  607. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  608. * clock cycles.
  609. */
  610. #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = DISABLE)
  611. /**
  612. * @}
  613. */
  614. /** @defgroup RCC_HSE_Configuration HSE Configuration
  615. * @{
  616. */
  617. /**
  618. * @brief Macro to configure the External High Speed oscillator (HSE).
  619. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  620. * supported by this macro. User should request a transition to HSE Off
  621. * first and then HSE On or HSE Bypass.
  622. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  623. * software should wait on HSERDY flag to be set indicating that HSE clock
  624. * is stable and can be used to clock the PLL and/or system clock.
  625. * @note HSE state can not be changed if it is used directly or through the
  626. * PLL as system clock. In this case, you have to select another source
  627. * of the system clock then change the HSE state (ex. disable it).
  628. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  629. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  630. * was previously enabled you have to enable it again after calling this
  631. * function.
  632. * @param __STATE__ specifies the new state of the HSE.
  633. * This parameter can be one of the following values:
  634. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  635. * 6 HSE oscillator clock cycles.
  636. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  637. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  638. */
  639. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  640. do{ \
  641. if ((__STATE__) == RCC_HSE_ON) \
  642. { \
  643. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  644. } \
  645. else if ((__STATE__) == RCC_HSE_OFF) \
  646. { \
  647. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  648. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  649. } \
  650. else if ((__STATE__) == RCC_HSE_BYPASS) \
  651. { \
  652. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  653. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  654. } \
  655. else \
  656. { \
  657. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  658. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  659. } \
  660. }while(0U)
  661. /**
  662. * @}
  663. */
  664. /** @defgroup RCC_LSE_Configuration LSE Configuration
  665. * @{
  666. */
  667. /**
  668. * @brief Macro to configure the External Low Speed oscillator (LSE).
  669. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  670. * @note As the LSE is in the Backup domain and write access is denied to
  671. * this domain after reset, you have to enable write access using
  672. * @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  673. * (to be done once after reset).
  674. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  675. * software should wait on LSERDY flag to be set indicating that LSE clock
  676. * is stable and can be used to clock the RTC.
  677. * @param __STATE__ specifies the new state of the LSE.
  678. * This parameter can be one of the following values:
  679. * @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
  680. * 6 LSE oscillator clock cycles.
  681. * @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
  682. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  683. */
  684. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  685. do{ \
  686. if ((__STATE__) == RCC_LSE_ON) \
  687. { \
  688. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  689. } \
  690. else if ((__STATE__) == RCC_LSE_OFF) \
  691. { \
  692. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  693. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  694. } \
  695. else if ((__STATE__) == RCC_LSE_BYPASS) \
  696. { \
  697. SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  698. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  699. } \
  700. else \
  701. { \
  702. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  703. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  704. } \
  705. }while(0U)
  706. /**
  707. * @}
  708. */
  709. /** @defgroup RCC_PLL_Configuration PLL Configuration
  710. * @{
  711. */
  712. /** @brief Macro to enable the main PLL.
  713. * @note After enabling the main PLL, the application software should wait on
  714. * PLLRDY flag to be set indicating that PLL clock is stable and can
  715. * be used as system clock source.
  716. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  717. */
  718. #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = ENABLE)
  719. /** @brief Macro to disable the main PLL.
  720. * @note The main PLL can not be disabled if it is used as system clock source
  721. */
  722. #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) RCC_CR_PLLON_BB = DISABLE)
  723. /** @brief Macro to configure the main PLL clock source and multiplication factors.
  724. * @note This function must be used only when the main PLL is disabled.
  725. *
  726. * @param __RCC_PLLSOURCE__ specifies the PLL entry clock source.
  727. * This parameter can be one of the following values:
  728. * @arg @ref RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL clock entry
  729. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  730. * @param __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
  731. * This parameter can be one of the following values:
  732. * @arg @ref RCC_PLL_MUL4 PLLVCO = PLL clock entry x 4
  733. * @arg @ref RCC_PLL_MUL6 PLLVCO = PLL clock entry x 6
  734. @if STM32F105xC
  735. * @arg @ref RCC_PLL_MUL6_5 PLLVCO = PLL clock entry x 6.5
  736. @elseif STM32F107xC
  737. * @arg @ref RCC_PLL_MUL6_5 PLLVCO = PLL clock entry x 6.5
  738. @else
  739. * @arg @ref RCC_PLL_MUL2 PLLVCO = PLL clock entry x 2
  740. * @arg @ref RCC_PLL_MUL3 PLLVCO = PLL clock entry x 3
  741. * @arg @ref RCC_PLL_MUL10 PLLVCO = PLL clock entry x 10
  742. * @arg @ref RCC_PLL_MUL11 PLLVCO = PLL clock entry x 11
  743. * @arg @ref RCC_PLL_MUL12 PLLVCO = PLL clock entry x 12
  744. * @arg @ref RCC_PLL_MUL13 PLLVCO = PLL clock entry x 13
  745. * @arg @ref RCC_PLL_MUL14 PLLVCO = PLL clock entry x 14
  746. * @arg @ref RCC_PLL_MUL15 PLLVCO = PLL clock entry x 15
  747. * @arg @ref RCC_PLL_MUL16 PLLVCO = PLL clock entry x 16
  748. @endif
  749. * @arg @ref RCC_PLL_MUL8 PLLVCO = PLL clock entry x 8
  750. * @arg @ref RCC_PLL_MUL9 PLLVCO = PLL clock entry x 9
  751. *
  752. */
  753. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__)\
  754. MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL),((__RCC_PLLSOURCE__) | (__PLLMUL__) ))
  755. /** @brief Get oscillator clock selected as PLL input clock
  756. * @retval The clock source used for PLL entry. The returned value can be one
  757. * of the following:
  758. * @arg @ref RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL input clock
  759. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  760. */
  761. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  762. /**
  763. * @}
  764. */
  765. /** @defgroup RCC_Get_Clock_source Get Clock source
  766. * @{
  767. */
  768. /**
  769. * @brief Macro to configure the system clock source.
  770. * @param __SYSCLKSOURCE__ specifies the system clock source.
  771. * This parameter can be one of the following values:
  772. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  773. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  774. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  775. */
  776. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  777. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  778. /** @brief Macro to get the clock source used as system clock.
  779. * @retval The clock source used as system clock. The returned value can be one
  780. * of the following:
  781. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  782. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  783. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  784. */
  785. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  786. /**
  787. * @}
  788. */
  789. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  790. * @{
  791. */
  792. #if defined(RCC_CFGR_MCO_3)
  793. /** @brief Macro to configure the MCO clock.
  794. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  795. * This parameter can be one of the following values:
  796. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  797. * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock (SYSCLK) selected as MCO clock
  798. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  799. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  800. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO clock
  801. * @arg @ref RCC_MCO1SOURCE_PLL2CLK PLL2 clock selected by 2 selected as MCO clock
  802. * @arg @ref RCC_MCO1SOURCE_PLL3CLK_DIV2 PLL3 clock divided by 2 selected as MCO clock
  803. * @arg @ref RCC_MCO1SOURCE_EXT_HSE XT1 external 3-25 MHz oscillator clock selected (for Ethernet) as MCO clock
  804. * @arg @ref RCC_MCO1SOURCE_PLL3CLK PLL3 clock selected (for Ethernet) as MCO clock
  805. * @param __MCODIV__ specifies the MCO clock prescaler.
  806. * This parameter can be one of the following values:
  807. * @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
  808. */
  809. #else
  810. /** @brief Macro to configure the MCO clock.
  811. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  812. * This parameter can be one of the following values:
  813. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  814. * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock (SYSCLK) selected as MCO clock
  815. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  816. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  817. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO clock
  818. * @param __MCODIV__ specifies the MCO clock prescaler.
  819. * This parameter can be one of the following values:
  820. * @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
  821. */
  822. #endif
  823. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  824. MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, (__MCOCLKSOURCE__))
  825. /**
  826. * @}
  827. */
  828. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  829. * @{
  830. */
  831. /** @brief Macro to configure the RTC clock (RTCCLK).
  832. * @note As the RTC clock configuration bits are in the Backup domain and write
  833. * access is denied to this domain after reset, you have to enable write
  834. * access using the Power Backup Access macro before to configure
  835. * the RTC clock source (to be done once after reset).
  836. * @note Once the RTC clock is configured it can't be changed unless the
  837. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  838. * a Power On Reset (POR).
  839. *
  840. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  841. * This parameter can be one of the following values:
  842. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  843. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  844. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  845. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock
  846. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  847. * work in STOP and STANDBY modes, and can be used as wakeup source.
  848. * However, when the HSE clock is used as RTC clock source, the RTC
  849. * cannot be used in STOP and STANDBY modes.
  850. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  851. * RTC clock source).
  852. */
  853. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, (__RTC_CLKSOURCE__))
  854. /** @brief Macro to get the RTC clock source.
  855. * @retval The clock source can be one of the following values:
  856. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  857. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  858. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  859. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock
  860. */
  861. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL))
  862. /** @brief Macro to enable the the RTC clock.
  863. * @note These macros must be used only after the RTC clock source was selected.
  864. */
  865. #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = ENABLE)
  866. /** @brief Macro to disable the the RTC clock.
  867. * @note These macros must be used only after the RTC clock source was selected.
  868. */
  869. #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = DISABLE)
  870. /** @brief Macro to force the Backup domain reset.
  871. * @note This function resets the RTC peripheral (including the backup registers)
  872. * and the RTC clock source selection in RCC_BDCR register.
  873. */
  874. #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = ENABLE)
  875. /** @brief Macros to release the Backup domain reset.
  876. */
  877. #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = DISABLE)
  878. /**
  879. * @}
  880. */
  881. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  882. * @brief macros to manage the specified RCC Flags and interrupts.
  883. * @{
  884. */
  885. /** @brief Enable RCC interrupt.
  886. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  887. * This parameter can be any combination of the following values:
  888. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  889. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  890. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  891. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  892. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  893. @if STM32F105xx
  894. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  895. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  896. @elsif STM32F107xx
  897. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  898. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  899. @endif
  900. */
  901. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  902. /** @brief Disable RCC interrupt.
  903. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  904. * This parameter can be any combination of the following values:
  905. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  906. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  907. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  908. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  909. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  910. @if STM32F105xx
  911. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  912. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  913. @elsif STM32F107xx
  914. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  915. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  916. @endif
  917. */
  918. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= (uint8_t)(~(__INTERRUPT__)))
  919. /** @brief Clear the RCC's interrupt pending bits.
  920. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  921. * This parameter can be any combination of the following values:
  922. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  923. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  924. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  925. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  926. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  927. @if STM32F105xx
  928. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  929. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  930. @elsif STM32F107xx
  931. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  932. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  933. @endif
  934. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  935. */
  936. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  937. /** @brief Check the RCC's interrupt has occurred or not.
  938. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  939. * This parameter can be one of the following values:
  940. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  941. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  942. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  943. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  944. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  945. @if STM32F105xx
  946. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  947. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  948. @elsif STM32F107xx
  949. * @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
  950. * @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
  951. @endif
  952. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  953. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  954. */
  955. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  956. /** @brief Set RMVF bit to clear the reset flags.
  957. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  958. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  959. */
  960. #define __HAL_RCC_CLEAR_RESET_FLAGS() (*(__IO uint32_t *)RCC_CSR_RMVF_BB = ENABLE)
  961. /** @brief Check RCC flag is set or not.
  962. * @param __FLAG__ specifies the flag to check.
  963. * This parameter can be one of the following values:
  964. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready.
  965. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready.
  966. * @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready.
  967. @if STM32F105xx
  968. * @arg @ref RCC_FLAG_PLL2RDY Main PLL2 clock ready.
  969. * @arg @ref RCC_FLAG_PLLI2SRDY Main PLLI2S clock ready.
  970. @elsif STM32F107xx
  971. * @arg @ref RCC_FLAG_PLL2RDY Main PLL2 clock ready.
  972. * @arg @ref RCC_FLAG_PLLI2SRDY Main PLLI2S clock ready.
  973. @endif
  974. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready.
  975. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready.
  976. * @arg @ref RCC_FLAG_PINRST Pin reset.
  977. * @arg @ref RCC_FLAG_PORRST POR/PDR reset.
  978. * @arg @ref RCC_FLAG_SFTRST Software reset.
  979. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset.
  980. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset.
  981. * @arg @ref RCC_FLAG_LPWRRST Low Power reset.
  982. * @retval The new state of __FLAG__ (TRUE or FALSE).
  983. */
  984. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5U) == CR_REG_INDEX)? RCC->CR : \
  985. ((((__FLAG__) >> 5U) == BDCR_REG_INDEX)? RCC->BDCR : \
  986. RCC->CSR)) & (1U << ((__FLAG__) & RCC_FLAG_MASK)))
  987. /**
  988. * @}
  989. */
  990. /**
  991. * @}
  992. */
  993. /* Include RCC HAL Extension module */
  994. #include "stm32f1xx_hal_rcc_ex.h"
  995. /* Exported functions --------------------------------------------------------*/
  996. /** @addtogroup RCC_Exported_Functions
  997. * @{
  998. */
  999. /** @addtogroup RCC_Exported_Functions_Group1
  1000. * @{
  1001. */
  1002. /* Initialization and de-initialization functions ******************************/
  1003. HAL_StatusTypeDef HAL_RCC_DeInit(void);
  1004. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1005. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1006. /**
  1007. * @}
  1008. */
  1009. /** @addtogroup RCC_Exported_Functions_Group2
  1010. * @{
  1011. */
  1012. /* Peripheral Control functions ************************************************/
  1013. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1014. void HAL_RCC_EnableCSS(void);
  1015. void HAL_RCC_DisableCSS(void);
  1016. uint32_t HAL_RCC_GetSysClockFreq(void);
  1017. uint32_t HAL_RCC_GetHCLKFreq(void);
  1018. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1019. uint32_t HAL_RCC_GetPCLK2Freq(void);
  1020. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1021. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1022. /* CSS NMI IRQ handler */
  1023. void HAL_RCC_NMI_IRQHandler(void);
  1024. /* User Callbacks in non blocking mode (IT mode) */
  1025. void HAL_RCC_CSSCallback(void);
  1026. /**
  1027. * @}
  1028. */
  1029. /**
  1030. * @}
  1031. */
  1032. /** @addtogroup RCC_Private_Constants
  1033. * @{
  1034. */
  1035. /** @defgroup RCC_Timeout RCC Timeout
  1036. * @{
  1037. */
  1038. /* Disable Backup domain write protection state change timeout */
  1039. #define RCC_DBP_TIMEOUT_VALUE 100U /* 100 ms */
  1040. /* LSE state change timeout */
  1041. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  1042. #define CLOCKSWITCH_TIMEOUT_VALUE 5000 /* 5 s */
  1043. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  1044. #define HSI_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
  1045. #define LSI_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
  1046. #define PLL_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
  1047. /**
  1048. * @}
  1049. */
  1050. /** @defgroup RCC_Register_Offset Register offsets
  1051. * @{
  1052. */
  1053. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  1054. #define RCC_CR_OFFSET 0x00U
  1055. #define RCC_CFGR_OFFSET 0x04U
  1056. #define RCC_CIR_OFFSET 0x08U
  1057. #define RCC_BDCR_OFFSET 0x20U
  1058. #define RCC_CSR_OFFSET 0x24U
  1059. /**
  1060. * @}
  1061. */
  1062. /** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
  1063. * @brief RCC registers bit address in the alias region
  1064. * @{
  1065. */
  1066. #define RCC_CR_OFFSET_BB (RCC_OFFSET + RCC_CR_OFFSET)
  1067. #define RCC_CFGR_OFFSET_BB (RCC_OFFSET + RCC_CFGR_OFFSET)
  1068. #define RCC_CIR_OFFSET_BB (RCC_OFFSET + RCC_CIR_OFFSET)
  1069. #define RCC_BDCR_OFFSET_BB (RCC_OFFSET + RCC_BDCR_OFFSET)
  1070. #define RCC_CSR_OFFSET_BB (RCC_OFFSET + RCC_CSR_OFFSET)
  1071. /* --- CR Register ---*/
  1072. /* Alias word address of HSION bit */
  1073. #define RCC_HSION_BIT_NUMBER RCC_CR_HSION_Pos
  1074. #define RCC_CR_HSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSION_BIT_NUMBER * 4U)))
  1075. /* Alias word address of HSEON bit */
  1076. #define RCC_HSEON_BIT_NUMBER RCC_CR_HSEON_Pos
  1077. #define RCC_CR_HSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSEON_BIT_NUMBER * 4U)))
  1078. /* Alias word address of CSSON bit */
  1079. #define RCC_CSSON_BIT_NUMBER RCC_CR_CSSON_Pos
  1080. #define RCC_CR_CSSON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_CSSON_BIT_NUMBER * 4U)))
  1081. /* Alias word address of PLLON bit */
  1082. #define RCC_PLLON_BIT_NUMBER RCC_CR_PLLON_Pos
  1083. #define RCC_CR_PLLON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_PLLON_BIT_NUMBER * 4U)))
  1084. /* --- CSR Register ---*/
  1085. /* Alias word address of LSION bit */
  1086. #define RCC_LSION_BIT_NUMBER RCC_CSR_LSION_Pos
  1087. #define RCC_CSR_LSION_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_LSION_BIT_NUMBER * 4U)))
  1088. /* Alias word address of RMVF bit */
  1089. #define RCC_RMVF_BIT_NUMBER RCC_CSR_RMVF_Pos
  1090. #define RCC_CSR_RMVF_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_RMVF_BIT_NUMBER * 4U)))
  1091. /* --- BDCR Registers ---*/
  1092. /* Alias word address of LSEON bit */
  1093. #define RCC_LSEON_BIT_NUMBER RCC_BDCR_LSEON_Pos
  1094. #define RCC_BDCR_LSEON_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_LSEON_BIT_NUMBER * 4U)))
  1095. /* Alias word address of LSEON bit */
  1096. #define RCC_LSEBYP_BIT_NUMBER RCC_BDCR_LSEBYP_Pos
  1097. #define RCC_BDCR_LSEBYP_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_LSEBYP_BIT_NUMBER * 4U)))
  1098. /* Alias word address of RTCEN bit */
  1099. #define RCC_RTCEN_BIT_NUMBER RCC_BDCR_RTCEN_Pos
  1100. #define RCC_BDCR_RTCEN_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_RTCEN_BIT_NUMBER * 4U)))
  1101. /* Alias word address of BDRST bit */
  1102. #define RCC_BDRST_BIT_NUMBER RCC_BDCR_BDRST_Pos
  1103. #define RCC_BDCR_BDRST_BB ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_BDRST_BIT_NUMBER * 4U)))
  1104. /**
  1105. * @}
  1106. */
  1107. /* CR register byte 2 (Bits[23:16]) base address */
  1108. #define RCC_CR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02U))
  1109. /* CIR register byte 1 (Bits[15:8]) base address */
  1110. #define RCC_CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01U))
  1111. /* CIR register byte 2 (Bits[23:16]) base address */
  1112. #define RCC_CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02U))
  1113. /* Defines used for Flags */
  1114. #define CR_REG_INDEX ((uint8_t)1)
  1115. #define BDCR_REG_INDEX ((uint8_t)2)
  1116. #define CSR_REG_INDEX ((uint8_t)3)
  1117. #define RCC_FLAG_MASK ((uint8_t)0x1F)
  1118. /**
  1119. * @}
  1120. */
  1121. /** @addtogroup RCC_Private_Macros
  1122. * @{
  1123. */
  1124. /** @defgroup RCC_Alias_For_Legacy Alias define maintained for legacy
  1125. * @{
  1126. */
  1127. #define __HAL_RCC_SYSCFG_CLK_DISABLE __HAL_RCC_AFIO_CLK_DISABLE
  1128. #define __HAL_RCC_SYSCFG_CLK_ENABLE __HAL_RCC_AFIO_CLK_ENABLE
  1129. #define __HAL_RCC_SYSCFG_FORCE_RESET __HAL_RCC_AFIO_FORCE_RESET
  1130. #define __HAL_RCC_SYSCFG_RELEASE_RESET __HAL_RCC_AFIO_RELEASE_RESET
  1131. /**
  1132. * @}
  1133. */
  1134. #define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI_DIV2) || \
  1135. ((__SOURCE__) == RCC_PLLSOURCE_HSE))
  1136. #define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE) || \
  1137. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  1138. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  1139. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  1140. (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE))
  1141. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  1142. ((__HSE__) == RCC_HSE_BYPASS))
  1143. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  1144. ((__LSE__) == RCC_LSE_BYPASS))
  1145. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  1146. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
  1147. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  1148. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  1149. ((__PLL__) == RCC_PLL_ON))
  1150. #define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  1151. (((CLK) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  1152. (((CLK) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) || \
  1153. (((CLK) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2))
  1154. #define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
  1155. ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
  1156. ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
  1157. #define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  1158. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  1159. ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  1160. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  1161. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  1162. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  1163. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  1164. ((__HCLK__) == RCC_SYSCLK_DIV512))
  1165. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  1166. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  1167. ((__PCLK__) == RCC_HCLK_DIV16))
  1168. #define IS_RCC_MCO(__MCO__) ((__MCO__) == RCC_MCO)
  1169. #define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1))
  1170. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  1171. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  1172. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  1173. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV128))
  1174. /**
  1175. * @}
  1176. */
  1177. /**
  1178. * @}
  1179. */
  1180. /**
  1181. * @}
  1182. */
  1183. #ifdef __cplusplus
  1184. }
  1185. #endif
  1186. #endif /* __STM32F1xx_HAL_RCC_H */
  1187. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/