py32f0xx_hal_rcc_ex.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_hal_rcc_ex.h
  4. * @author MCU Application Team
  5. * @brief Header file of RCC HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya 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. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F0xx_HAL_RCC_EX_H
  32. #define __PY32F0xx_HAL_RCC_EX_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx_hal_def.h"
  38. /** @addtogroup PY32F0xx_HAL_Driver
  39. * @{
  40. */
  41. /** @addtogroup RCCEx
  42. * @{
  43. */
  44. /* Exported types ------------------------------------------------------------*/
  45. /** @defgroup RCCEx_Exported_Types RCCEx Exported Types
  46. * @{
  47. */
  48. /**
  49. * @brief RCC extended clocks structure definition
  50. */
  51. typedef struct
  52. {
  53. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  54. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  55. #if defined(RCC_CCIPR_PVDSEL)
  56. uint32_t PvdClockSelection; /*!< Specifies PVD clock source.
  57. This parameter can be a value of @ref RCCEx_PVD_Clock_Source */
  58. #endif
  59. #if defined(RCC_CCIPR_COMP1SEL)
  60. uint32_t Comp1ClockSelection; /*!< Specifies COMP1 clock source.
  61. This parameter can be a value of @ref RCCEx_COMP1_Clock_Source */
  62. #endif
  63. #if defined(RCC_CCIPR_COMP2SEL)
  64. uint32_t Comp2ClockSelection; /*!< Specifies COMP2 clock source.
  65. This parameter can be a value of @ref RCCEx_COMP2_Clock_Source */
  66. #endif
  67. #if defined(RCC_CCIPR_LPTIMSEL)
  68. uint32_t LptimClockSelection; /*!< Specifies LPTIM1 clock source
  69. This parameter can be a value of @ref RCCEx_LPTIM1_Clock_Source */
  70. #endif
  71. #if defined(RCC_BDCR_RTCSEL)
  72. uint32_t RTCClockSelection; /*!< Specifies RTC clock source.
  73. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  74. #endif
  75. } RCC_PeriphCLKInitTypeDef;
  76. /**
  77. * @}
  78. */
  79. /* Exported constants --------------------------------------------------------*/
  80. /** @defgroup RCCEx_Exported_Constants RCCEx Exported Constants
  81. * @{
  82. */
  83. /** @defgroup RCCEx_LSCO_Clock_Source Low Speed Clock Source
  84. * @{
  85. */
  86. #define RCC_LSCOSOURCE_LSI 0x00000000U /*!< LSI selection for low speed clock output */
  87. #if defined(RCC_LSE_SUPPORT)
  88. #define RCC_LSCOSOURCE_LSE RCC_BDCR_LSCOSEL /*!< LSE selection for low speed clock output */
  89. #endif
  90. /**
  91. * @}
  92. */
  93. /** @defgroup RCCEx_Periph_Clock_Selection Periph Clock Selection
  94. * @{
  95. */
  96. #if defined(RCC_CCIPR_PVDSEL)
  97. #define RCC_PERIPHCLK_PVD 0x00000001U
  98. #endif /* RCC_CCIPR_PVDSEL */
  99. #if defined(RCC_CCIPR_COMP1SEL)
  100. #define RCC_PERIPHCLK_COMP1 0x00000002U
  101. #endif /* RCC_CCIPR_COMP1SEL */
  102. #if defined(RCC_CCIPR_COMP2SEL)
  103. #define RCC_PERIPHCLK_COMP2 0x00000020U
  104. #endif /* RCC_CCIPR_COMP2SEL */
  105. #if defined(RCC_CCIPR_LPTIMSEL)
  106. #define RCC_PERIPHCLK_LPTIM 0x00000200U
  107. #endif /* RCC_CCIPR_LPTIM1SEL */
  108. #if defined(RCC_CCIPR_ADCSEL)
  109. #define RCC_PERIPHCLK_ADC 0x00004000U
  110. #endif /* RCC_CCIPR_ADCSEL */
  111. #if defined(RCC_BDCR_RTCSEL)
  112. #define RCC_PERIPHCLK_RTC 0x00020000U
  113. #endif /* RCC_BDCR_RTCSEL */
  114. /**
  115. * @}
  116. */
  117. #if defined(RCC_CCIPR_PVDSEL)
  118. /** @defgroup RCCEx_PVD_Clock_Source RCC PVD Clock Source
  119. * @{
  120. */
  121. #define RCC_PVDCLKSOURCE_PCLK 0x00000000U /*!< APB clock selected as PVD clock */
  122. #define RCC_PVDCLKSOURCE_LSC RCC_CCIPR_PVDSEL /*!< LSC clock selected as PVD clock */
  123. /**
  124. * @}
  125. */
  126. #endif
  127. #if defined(RCC_CCIPR_COMP1SEL)
  128. /** @defgroup RCCEx_COMP1_Clock_Source RCC COMP1 Clock Source
  129. * @{
  130. */
  131. #define RCC_COMP1CLKSOURCE_PCLK 0x00000000U /*!< APB clock selected as COMP1 clock */
  132. #define RCC_COMP1CLKSOURCE_LSC RCC_CCIPR_COMP1SEL /*!< LSC clock selected as COMP1 clock */
  133. /**
  134. * @}
  135. */
  136. #endif /* RCC_CCIPR_COMP1SEL */
  137. #if defined(RCC_CCIPR_COMP2SEL)
  138. /** @defgroup RCCEx_COMP2_Clock_Source RCC COMP2 Clock Source
  139. * @{
  140. */
  141. #define RCC_COMP2CLKSOURCE_PCLK 0x00000000U /*!< APB clock selected as COMP2 clock */
  142. #define RCC_COMP2CLKSOURCE_LSC RCC_CCIPR_COMP2SEL /*!< LSC clock selected as COMP2 clock */
  143. /**
  144. * @}
  145. */
  146. #endif /* RCC_CCIPR_COMP1SEL */
  147. #if defined(RCC_CCIPR_LPTIMSEL)
  148. /** @defgroup RCCEx_LPTIM1_Clock_Source RCC LPTIM1 Clock Source
  149. * @{
  150. */
  151. #define RCC_LPTIMCLKSOURCE_PCLK 0x00000000U /*!< APB clock selected as LPTimer 1 clock */
  152. #define RCC_LPTIMCLKSOURCE_LSI RCC_CCIPR_LPTIMSEL_0 /*!< LSI clock selected as LPTimer 1 clock */
  153. #if defined(RCC_LSE_SUPPORT)
  154. #define RCC_LPTIMCLKSOURCE_LSE RCC_CCIPR_LPTIMSEL /*!< LSE clock selected as LPTimer 1 clock */
  155. #endif
  156. /**
  157. * @}
  158. */
  159. #endif /* RCC_CCIPR_LPTIM1SEL */
  160. /**
  161. * @}
  162. */
  163. /* Exported macros -----------------------------------------------------------*/
  164. /** @defgroup RCCEx_Exported_Macros RCCEx Exported Macros
  165. * @{
  166. */
  167. #if defined(RCC_CCIPR_PVDSEL)
  168. /** @brief Macro to configure the PVD clock (PVDCLK).
  169. *
  170. * @param __PVD_CLKSOURCE__ specifies the PVD clock source.
  171. * This parameter can be one of the following values:
  172. * @arg @ref RCC_PVDCLKSOURCE_PCLK PCLK selected as PVD clock
  173. * @arg @ref RCC_PVDCLKSOURCE_LSC LSC selected as PVD clock
  174. */
  175. #define __HAL_RCC_PVD_CONFIG(__PVD_CLKSOURCE__) \
  176. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_PVDSEL, (uint32_t)(__PVD_CLKSOURCE__))
  177. /** @brief Macro to get the PVD clock source.
  178. * @retval The clock source can be one of the following values:
  179. * @arg @ref RCC_PVDCLKSOURCE_PCLK PCLK selected as PVD clock
  180. * @arg @ref RCC_PVDCLKSOURCE_LSC LSC selected as PVD clock
  181. */
  182. #define __HAL_RCC_GET_PVD_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_PVDSEL)))
  183. #endif /* RCC_CCIPR_PVDSEL */
  184. #if defined(RCC_CCIPR_COMP1SEL)
  185. /** @brief Macro to configure the COMP1 clock (COMP1CLK).
  186. *
  187. * @param __COMP1_CLKSOURCE__ specifies the COMP1 clock source.
  188. * This parameter can be one of the following values:
  189. * @arg @ref RCC_COMP1CLKSOURCE_PCLK PCLK selected as COMP1 clock
  190. * @arg @ref RCC_COMP1CLKSOURCE_LSC LSC selected as COMP1 clock
  191. */
  192. #define __HAL_RCC_COMP1_CONFIG(__COMP1_CLKSOURCE__) \
  193. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_COMP1SEL, (uint32_t)(__COMP1_CLKSOURCE__))
  194. /** @brief Macro to get the COMP1 clock source.
  195. * @retval The clock source can be one of the following values:
  196. * @arg @ref RCC_COMP1CLKSOURCE_PCLK PCLK selected as COMP1 clock
  197. * @arg @ref RCC_COMP1CLKSOURCE_LSC LSC selected as COMP1 clock
  198. */
  199. #define __HAL_RCC_GET_COMP1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_COMP1SEL)))
  200. #endif /* RCC_CCIPR_COMP1SEL */
  201. #if defined(RCC_CCIPR_COMP2SEL)
  202. /** @brief Macro to configure the COMP2 clock (COMP2CLK).
  203. *
  204. * @param __COMP2_CLKSOURCE__ specifies the COMP2 clock source.
  205. * This parameter can be one of the following values:
  206. * @arg @ref RCC_COMP2CLKSOURCE_PCLK PCLK selected as COMP2 clock
  207. * @arg @ref RCC_COMP2CLKSOURCE_LSC LSC selected as COMP2 clock
  208. */
  209. #define __HAL_RCC_COMP2_CONFIG(__COMP2_CLKSOURCE__) \
  210. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_COMP2SEL, (uint32_t)(__COMP2_CLKSOURCE__))
  211. /** @brief Macro to get the COMP2 clock source.
  212. * @retval The clock source can be one of the following values:
  213. * @arg @ref RCC_COMP2CLKSOURCE_PCLK PCLK selected as COMP2 clock
  214. * @arg @ref RCC_COMP2CLKSOURCE_LSC LSC selected as COMP2 clock
  215. */
  216. #define __HAL_RCC_GET_COMP2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_COMP2SEL)))
  217. #endif /* RCC_CCIPR_COMP2SEL */
  218. #if defined(RCC_CCIPR_LPTIMSEL)
  219. /** @brief Macro to configure the LPTIM1 clock (LPTIM1CLK).
  220. *
  221. * @param __LPTIM1_CLKSOURCE__ specifies the LPTIM1 clock source.
  222. * This parameter can be one of the following values:
  223. * @arg @ref RCC_LPTIMCLKSOURCE_PCLK PCLK1 selected as LPTIM1 clock
  224. * @arg @ref RCC_LPTIMCLKSOURCE_LSI LSI selected as LPTIM1 clock
  225. * @arg @ref RCC_LPTIMCLKSOURCE_LSE LSE selected as LPTIM1 clock
  226. * @note Depending on devices and packages, some clocks may not be available.
  227. * Refer to device datasheet for clocks availability.
  228. */
  229. #define __HAL_RCC_LPTIM_CONFIG(__LPTIM1_CLKSOURCE__) \
  230. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPTIMSEL, (uint32_t)(__LPTIM1_CLKSOURCE__))
  231. /** @brief Macro to get the LPTIM clock source.
  232. * @retval The clock source can be one of the following values:
  233. * @arg @ref RCC_LPTIMCLKSOURCE_PCLK PCLK1 selected as LPTIM1 clock
  234. * @arg @ref RCC_LPTIMCLKSOURCE_LSI HSI selected as LPTIM1 clock
  235. * @arg @ref RCC_LPTIMCLKSOURCE_LSE LSE selected as LPTIM1 clock
  236. * @note Depending on devices and packages, some clocks may not be available.
  237. * Refer to device datasheet for clocks availability.
  238. */
  239. #define __HAL_RCC_GET_LPTIM_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPTIMSEL)))
  240. #endif /* RCC_CCIPR_LPTIM1SEL */
  241. #if defined(RCC_CCIPR_TIM1SEL)
  242. /** @brief Macro to configure the TIM1 interface clock
  243. * @param __TIM1_CLKSOURCE__ specifies the TIM1 digital interface clock source.
  244. * This parameter can be one of the following values:
  245. * @arg @ref RCC_TIM1CLKSOURCE_PLL PLLQ Output Clock selected as TIM1 clock
  246. * @arg @ref RCC_TIM1CLKSOURCE_PCLK1 System Clock selected as TIM1 clock
  247. */
  248. #define __HAL_RCC_TIM1_CONFIG(__TIM1_CLKSOURCE__) \
  249. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_TIM1SEL, (uint32_t)(__TIM1_CLKSOURCE__))
  250. /** @brief Macro to get the TIM1 clock source.
  251. * @retval The clock source can be one of the following values:
  252. * @arg @ref RCC_TIM1CLKSOURCE_PLL PLLQ Output Clock selected as TIM1 clock
  253. * @arg @ref RCC_TIM1CLKSOURCE_PCLK1 System Clock selected as TIM1 clock
  254. */
  255. #define __HAL_RCC_GET_TIM1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_TIM1SEL)))
  256. #endif /* RCC_CCIPR_TIM1SEL */
  257. #if defined(RCC_CCIPR_TIM15SEL)
  258. /** @brief Macro to configure the TIM15 interface clock
  259. * @param __TIM15_CLKSOURCE__ specifies the TIM15 digital interface clock source.
  260. * This parameter can be one of the following values:
  261. * @arg RCC_TIM15CLKSOURCE_PLL PLLQ Output Clock selected as TIM15 clock
  262. * @arg RCC_TIM15CLKSOURCE_PCLK1 System Clock selected as TIM15 clock
  263. */
  264. #define __HAL_RCC_TIM15_CONFIG(__TIM15_CLKSOURCE__) \
  265. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_TIM15SEL, (uint32_t)(__TIM15_CLKSOURCE__))
  266. /** @brief Macro to get the TIM15 clock source.
  267. * @retval The clock source can be one of the following values:
  268. * @arg @ref RCC_TIM15CLKSOURCE_PLL PLLQ Output Clock selected as TIM15 clock
  269. * @arg @ref RCC_TIM15CLKSOURCE_PCLK1 System Clock selected as TIM15 clock
  270. */
  271. #define __HAL_RCC_GET_TIM15_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_TIM15SEL)))
  272. #endif /* RCC_CCIPR_TIM15SEL */
  273. /** @defgroup RCCEx_Flags_Interrupts_Management Flags Interrupts Management
  274. * @brief macros to manage the specified RCC Flags and interrupts.
  275. * @{
  276. */
  277. /**
  278. * @}
  279. */
  280. /**
  281. * @}
  282. */
  283. /* Exported functions --------------------------------------------------------*/
  284. /** @addtogroup RCCEx_Exported_Functions
  285. * @{
  286. */
  287. /** @addtogroup RCCEx_Exported_Functions_Group1
  288. * @{
  289. */
  290. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  291. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  292. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk);
  293. /**
  294. * @}
  295. */
  296. /** @addtogroup RCCEx_Exported_Functions_Group2
  297. * @{
  298. */
  299. void HAL_RCCEx_EnableLSCO(uint32_t LSCOSource);
  300. #define HAL_RCCEx_DisableLSCO()
  301. /**
  302. * @}
  303. */
  304. /**
  305. * @}
  306. */
  307. /* Private macros ------------------------------------------------------------*/
  308. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  309. * @{
  310. */
  311. #if defined(RCC_LSE_SUPPORT)
  312. #define IS_RCC_LSCOSOURCE(__SOURCE__) (((__SOURCE__) == RCC_LSCOSOURCE_LSI) || \
  313. ((__SOURCE__) == RCC_LSCOSOURCE_LSE))
  314. #else
  315. #define IS_RCC_LSCOSOURCE(__SOURCE__) (((__SOURCE__) == RCC_LSCOSOURCE_LSI))
  316. #endif
  317. #if defined(RCC_LSE_SUPPORT)
  318. #define IS_RCC_USART1CLKSOURCE(__SOURCE__) \
  319. (((__SOURCE__) == RCC_USART1CLKSOURCE_PCLK1) || \
  320. ((__SOURCE__) == RCC_USART1CLKSOURCE_SYSCLK) || \
  321. ((__SOURCE__) == RCC_USART1CLKSOURCE_LSE) || \
  322. ((__SOURCE__) == RCC_USART1CLKSOURCE_HSI))
  323. #else
  324. #define IS_RCC_USART1CLKSOURCE(__SOURCE__) \
  325. (((__SOURCE__) == RCC_USART1CLKSOURCE_PCLK1) || \
  326. ((__SOURCE__) == RCC_USART1CLKSOURCE_SYSCLK) || \
  327. ((__SOURCE__) == RCC_USART1CLKSOURCE_HSI))
  328. #endif
  329. #if defined(RCC_CCIPR_PVDSEL)
  330. #define IS_RCC_PVDCLKSOURCE(__SOURCE__) \
  331. (((__SOURCE__) == RCC_PVDCLKSOURCE_PCLK) || \
  332. ((__SOURCE__) == RCC_PVDCLKSOURCE_LSC))
  333. #endif /* RCC_CCIPR_PVDSEL */
  334. #if defined(RCC_CCIPR_COMP1SEL)
  335. #define IS_RCC_COMP1CLKSOURCE(__SOURCE__) \
  336. (((__SOURCE__) == RCC_COMP1CLKSOURCE_PCLK) || \
  337. ((__SOURCE__) == RCC_COMP1CLKSOURCE_LSC))
  338. #endif /* RCC_CCIPR_COMP1SEL */
  339. #if defined(RCC_CCIPR_COMP2SEL)
  340. #define IS_RCC_COMP2CLKSOURCE(__SOURCE__) \
  341. (((__SOURCE__) == RCC_COMP2CLKSOURCE_PCLK) || \
  342. ((__SOURCE__) == RCC_COMP2CLKSOURCE_LSC))
  343. #endif /* RCC_CCIPR_COMP2SEL */
  344. #if defined(RCC_CCIPR_LPTIMSEL)
  345. #if defined(RCC_LSE_SUPPORT)
  346. #define IS_RCC_LPTIM1CLKSOURCE(__SOURCE__) \
  347. (((__SOURCE__) == RCC_LPTIMCLKSOURCE_PCLK)|| \
  348. ((__SOURCE__) == RCC_LPTIMCLKSOURCE_LSI) || \
  349. ((__SOURCE__) == RCC_LPTIMCLKSOURCE_LSE))
  350. #else
  351. #define IS_RCC_LPTIM1CLKSOURCE(__SOURCE__) \
  352. (((__SOURCE__) == RCC_LPTIMCLKSOURCE_PCLK)|| \
  353. ((__SOURCE__) == RCC_LPTIMCLKSOURCE_LSI))
  354. #endif
  355. #endif /* RCC_CCIPR_LPTIM1SEL */
  356. #if defined(PY32F002APRE)
  357. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  358. ((((__SELECTION__) & RCC_PERIPHCLK_LPTIM) == RCC_PERIPHCLK_LPTIM))
  359. #else
  360. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  361. ((((__SELECTION__) & RCC_PERIPHCLK_COMP1) == RCC_PERIPHCLK_COMP1) || \
  362. (((__SELECTION__) & RCC_PERIPHCLK_COMP2) == RCC_PERIPHCLK_COMP2) || \
  363. (((__SELECTION__) & RCC_PERIPHCLK_PVD) == RCC_PERIPHCLK_PVD) || \
  364. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM) == RCC_PERIPHCLK_LPTIM) || \
  365. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
  366. #endif
  367. /**
  368. * @}
  369. */
  370. /**
  371. * @}
  372. */
  373. /**
  374. * @}
  375. */
  376. #ifdef __cplusplus
  377. }
  378. #endif
  379. #endif /* __PY32F0xx_HAL_RCC_EX_H */
  380. /************************ (C) COPYRIGHT Puya *****END OF FILE****/