py32f0xx_hal_rcc_ex.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_hal_rcc_ex.c
  4. * @author MCU Application Team
  5. * @brief Extended RCC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities RCC extended peripheral:
  8. * + Extended Peripheral Control functions
  9. * + Extended Clock management functions
  10. *
  11. ******************************************************************************
  12. * @attention
  13. *
  14. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  15. * All rights reserved.</center></h2>
  16. *
  17. * This software component is licensed by Puya under BSD 3-Clause license,
  18. * the "License"; You may not use this file except in compliance with the
  19. * License. You may obtain a copy of the License at:
  20. * opensource.org/licenses/BSD-3-Clause
  21. *
  22. ******************************************************************************
  23. * @attention
  24. *
  25. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  26. * All rights reserved.</center></h2>
  27. *
  28. * This software component is licensed by ST under BSD 3-Clause license,
  29. * the "License"; You may not use this file except in compliance with the
  30. * License. You may obtain a copy of the License at:
  31. * opensource.org/licenses/BSD-3-Clause
  32. *
  33. ******************************************************************************
  34. */
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "py32f0xx_hal.h"
  37. /** @addtogroup PY32F0xx_HAL_Driver
  38. * @{
  39. */
  40. /** @defgroup RCCEx RCCEx
  41. * @brief RCC Extended HAL module driver
  42. * @{
  43. */
  44. #ifdef HAL_RCC_MODULE_ENABLED
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* Private defines -----------------------------------------------------------*/
  47. /** @defgroup RCCEx_Private_Constants RCCEx Private Constants
  48. * @{
  49. */
  50. #define PLL_TIMEOUT_VALUE 100U /* 100 ms (minimum Tick + 1) */
  51. /**
  52. * @}
  53. */
  54. /* Private macros ------------------------------------------------------------*/
  55. /* Private variables ---------------------------------------------------------*/
  56. /* Private function prototypes -----------------------------------------------*/
  57. /* Exported functions --------------------------------------------------------*/
  58. /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
  59. * @{
  60. */
  61. /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
  62. * @brief Extended Peripheral Control functions
  63. *
  64. @verbatim
  65. ===============================================================================
  66. ##### Extended Peripheral Control functions #####
  67. ===============================================================================
  68. [..]
  69. This subsection provides a set of functions allowing to control the RCC Clocks
  70. frequencies.
  71. [..]
  72. (@) Important note: Care must be taken when @ref HAL_RCCEx_PeriphCLKConfig() is used to
  73. select the RTC clock source; in this case the Backup domain will be reset in
  74. order to modify the RTC Clock source, as consequence RTC registers (including
  75. the backup registers) and RCC_BDCR register are set to their reset values.
  76. @endverbatim
  77. * @{
  78. */
  79. /**
  80. * @brief Initialize the RCC extended peripherals clocks according to the specified
  81. * parameters in the @ref RCC_PeriphCLKInitTypeDef.
  82. * @param PeriphClkInit pointer to a @ref RCC_PeriphCLKInitTypeDef structure that
  83. * contains a field PeriphClockSelection which can be a combination of the following values:
  84. * @arg @ref RCC_PERIPHCLK_RTC RTC peripheral clock (1)
  85. * @arg @ref RCC_PERIPHCLK_PVD PVD peripheral clock (1)
  86. * @arg @ref RCC_PERIPHCLK_COMP1 COMP1 peripheral clock (1)
  87. * @arg @ref RCC_PERIPHCLK_COMP2 COMP2 peripheral clock (1)
  88. * @arg @ref RCC_PERIPHCLK_LPTIM LPTIM peripheral clock (1)
  89. *
  90. * @note (1) Peripherals maybe not available on some devices
  91. * @note Care must be taken when @ref HAL_RCCEx_PeriphCLKConfig() is used to select
  92. * the RTC clock source: in this case the access to Backup domain is enabled.
  93. *
  94. * @retval HAL status
  95. */
  96. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  97. {
  98. #if defined(RCC_BDCR_RTCSEL)
  99. uint32_t tickstart = 0U, temp_reg = 0U;
  100. FlagStatus pwrclkchanged = RESET;
  101. #endif
  102. /* Check the parameters */
  103. assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
  104. #if defined(RCC_BDCR_RTCSEL)
  105. /*------------------------------- RTC Configuration ------------------------*/
  106. if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
  107. {
  108. /* check for RTC Parameters used to output RTCCLK */
  109. assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
  110. /* As soon as function is called to change RTC clock source, activation of the
  111. power domain is done. */
  112. /* Requires to enable write access to Backup Domain of necessary */
  113. if (__HAL_RCC_PWR_IS_CLK_DISABLED())
  114. {
  115. __HAL_RCC_PWR_CLK_ENABLE();
  116. pwrclkchanged = SET;
  117. }
  118. if (HAL_IS_BIT_CLR(PWR->CR1, PWR_CR1_DBP))
  119. {
  120. /* Enable write access to Backup domain */
  121. SET_BIT(PWR->CR1, PWR_CR1_DBP);
  122. /* Wait for Backup domain Write protection disable */
  123. tickstart = HAL_GetTick();
  124. while (HAL_IS_BIT_CLR(PWR->CR1, PWR_CR1_DBP))
  125. {
  126. if ((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  127. {
  128. return HAL_TIMEOUT;
  129. }
  130. }
  131. }
  132. /* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
  133. temp_reg = (RCC->BDCR & RCC_BDCR_RTCSEL);
  134. if ((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
  135. {
  136. /* Store the content of BDCR register before the reset of Backup Domain */
  137. temp_reg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
  138. /* RTC Clock selection can be changed only if the Backup Domain is reset */
  139. __HAL_RCC_BACKUPRESET_FORCE();
  140. __HAL_RCC_BACKUPRESET_RELEASE();
  141. /* Restore the Content of BDCR register */
  142. RCC->BDCR = temp_reg;
  143. #if defined(RCC_LSE_SUPPORT)
  144. /* Wait for LSERDY if LSE was enabled */
  145. if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON))
  146. {
  147. /* Get Start Tick */
  148. tickstart = HAL_GetTick();
  149. /* Wait till LSE is ready */
  150. while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
  151. {
  152. if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
  153. {
  154. return HAL_TIMEOUT;
  155. }
  156. }
  157. }
  158. #endif
  159. }
  160. __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
  161. /* Require to disable power clock if necessary */
  162. if (pwrclkchanged == SET)
  163. {
  164. __HAL_RCC_PWR_CLK_DISABLE();
  165. }
  166. }
  167. #endif /*RCC_BDCR_RTCSEL*/
  168. #if defined(RCC_CCIPR_PVDSEL)
  169. /*-------------------------- PVD clock source configuration -------------------*/
  170. if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_PVD) == RCC_PERIPHCLK_PVD)
  171. {
  172. /* Check the parameters */
  173. assert_param(IS_RCC_PVDCLKSOURCE(PeriphClkInit->PvdClockSelection));
  174. /* Configure the PVD clock source */
  175. __HAL_RCC_PVD_CONFIG(PeriphClkInit->PvdClockSelection);
  176. }
  177. #endif /* RCC_CCIPR_PVDSEL */
  178. #if defined(RCC_CCIPR_COMP1SEL)
  179. /*-------------------------- COMP1 clock source configuration -------------------*/
  180. if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_COMP1) == RCC_PERIPHCLK_COMP1)
  181. {
  182. /* Check the parameters */
  183. assert_param(IS_RCC_COMP1CLKSOURCE(PeriphClkInit->Comp1ClockSelection));
  184. /* Configure the COMP1 clock source */
  185. __HAL_RCC_COMP1_CONFIG(PeriphClkInit->Comp1ClockSelection);
  186. }
  187. #endif /* RCC_CCIPR_COMP1SEL */
  188. #if defined(RCC_CCIPR_COMP2SEL)
  189. /*-------------------------- COMP2 clock source configuration -------------------*/
  190. if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_COMP2) == RCC_PERIPHCLK_COMP2)
  191. {
  192. /* Check the parameters */
  193. assert_param(IS_RCC_COMP2CLKSOURCE(PeriphClkInit->Comp2ClockSelection));
  194. /* Configure the COMP2 clock source */
  195. __HAL_RCC_COMP2_CONFIG(PeriphClkInit->Comp2ClockSelection);
  196. }
  197. #endif /* RCC_CCIPR_COMP2SEL */
  198. #if defined(RCC_CCIPR_LPTIMSEL)
  199. /*-------------------------- LPTIM clock source configuration -------------------*/
  200. if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM) == (RCC_PERIPHCLK_LPTIM))
  201. {
  202. assert_param(IS_RCC_LPTIM1CLKSOURCE(PeriphClkInit->LptimClockSelection));
  203. __HAL_RCC_LPTIM_CONFIG(PeriphClkInit->LptimClockSelection);
  204. }
  205. #endif /* RCC_CCIPR_LPTIM1SEL */
  206. return HAL_OK;
  207. }
  208. /**
  209. * @brief Get the RCC_ClkInitStruct according to the internal RCC configuration registers.
  210. * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
  211. * returns the configuration information for the Extended Peripherals
  212. * clocks: PVD, COMP1, COMP2, RTC, LPTIM
  213. * @note Depending on devices and packages, some Peripherals may not be available.
  214. * Refer to device datasheet for Peripheral availability.
  215. * @retval None
  216. */
  217. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  218. {
  219. /* Set all possible values for the extended clock type parameter------------*/
  220. #if defined(PY32F002APRE)
  221. PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_LPTIM;
  222. #else
  223. #if defined(RCC_CCIPR_PVDSEL)
  224. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_PVD;
  225. #endif
  226. #if defined(RCC_CCIPR_COMP1SEL)
  227. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_COMP1;
  228. #endif
  229. #if defined(RCC_CCIPR_COMP2SEL)
  230. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_COMP2;
  231. #endif
  232. #if defined(RCC_CCIPR_LPTIMSEL)
  233. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_LPTIM;
  234. #endif
  235. #if defined(RCC_BDCR_RTCSEL)
  236. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_RTC;
  237. #endif
  238. #endif
  239. #if defined(RCC_CCIPR_PVDSEL)
  240. /* Get the PVD clock source ---------------------------------------------*/
  241. PeriphClkInit->PvdClockSelection = __HAL_RCC_GET_PVD_SOURCE();
  242. #endif /* RCC_CCIPR_PVDSEL */
  243. #if defined(RCC_CCIPR_COMP1SEL)
  244. /* Get the COMP1 clock source --------------------------------------------*/
  245. PeriphClkInit->Comp1ClockSelection = __HAL_RCC_GET_COMP1_SOURCE();
  246. #endif /* RCC_CCIPR_COMP1SEL */
  247. #if defined(RCC_CCIPR_COMP2SEL)
  248. /* Get the COMP2 clock source ---------------------------------------------*/
  249. PeriphClkInit->Comp2ClockSelection = __HAL_RCC_GET_COMP2_SOURCE();
  250. #endif /* RCC_CCIPR_COMP2SEL */
  251. #if defined(RCC_CCIPR_LPTIMSEL)
  252. /* Get the LPTIM clock source ---------------------------------------------*/
  253. PeriphClkInit->LptimClockSelection = __HAL_RCC_GET_LPTIM_SOURCE();
  254. #endif /* RCC_CCIPR_LPTIM2SEL */
  255. #if defined(RCC_BDCR_RTCSEL)
  256. /* Get the RTC clock source ------------------------------------------------*/
  257. PeriphClkInit->RTCClockSelection = __HAL_RCC_GET_RTC_SOURCE();
  258. #endif /* RCC_BDCR_RTCSEL */
  259. }
  260. /**
  261. * @brief Return the peripheral clock frequency for peripherals with clock source from PLL
  262. * @note Return 0 if peripheral clock identifier not managed by this API
  263. * @param PeriphClk Peripheral clock identifier
  264. * This parameter can be one of the following values:
  265. * @arg @ref RCC_PERIPHCLK_RTC RTC peripheral clock
  266. * @arg @ref RCC_PERIPHCLK_PVD PVD peripheral clock
  267. * @arg @ref RCC_PERIPHCLK_COMP1 COMP1 peripheral clock
  268. * @arg @ref RCC_PERIPHCLK_COMP2 COMP2 peripheral clock
  269. * @arg @ref RCC_PERIPHCLK_LPTIM LPTIM peripheral clock
  270. * @note Depending on devices and packages, some Peripherals may not be available.
  271. * Refer to device datasheet for Peripheral availability.
  272. * @retval Frequency in Hz
  273. */
  274. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
  275. {
  276. uint32_t frequency = 0U;
  277. uint32_t srcclk;
  278. #if defined(RCC_CCIPR_RNGSEL)
  279. uint32_t rngclk;
  280. uint32_t rngdiv;
  281. #endif
  282. /* Check the parameters */
  283. assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
  284. #if defined(RCC_BDCR_RTCSEL)
  285. if (PeriphClk == RCC_PERIPHCLK_RTC)
  286. {
  287. /* Get the current RTC source */
  288. srcclk = __HAL_RCC_GET_RTC_SOURCE();
  289. /* Check if LSI is ready and if RTC clock selection is LSI */
  290. if ((HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)) && (srcclk == RCC_RTCCLKSOURCE_LSI))
  291. {
  292. frequency = LSI_VALUE;
  293. }
  294. #if defined(RCC_LSE_SUPPORT)
  295. /* Check if LSE is ready and if RTC clock selection is LSE */
  296. else if ((HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY)) && (srcclk == RCC_RTCCLKSOURCE_LSE))
  297. {
  298. frequency = LSE_VALUE;
  299. }
  300. #endif
  301. /* Check if HSE is ready and if RTC clock selection is HSI_DIV32*/
  302. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) &&(srcclk == RCC_RTCCLKSOURCE_HSE_DIV128))
  303. {
  304. frequency = HSE_VALUE / 128U;
  305. }
  306. /* Clock not enabled for RTC*/
  307. else
  308. {
  309. /* Nothing to do as frequency already initialized to 0U */
  310. }
  311. }
  312. else
  313. {
  314. #endif
  315. /* Other external peripheral clock source than RTC */
  316. switch (PeriphClk)
  317. {
  318. #if defined(RCC_CCIPR_PVDSEL)
  319. case RCC_PERIPHCLK_PVD:
  320. /* Get the current PVD source */
  321. srcclk = __HAL_RCC_GET_PVD_SOURCE();
  322. if (srcclk == RCC_PVDCLKSOURCE_PCLK) /* PCLK1 */
  323. {
  324. frequency = HAL_RCC_GetPCLK1Freq();
  325. }
  326. #if defined(RCC_LSE_SUPPORT)
  327. else if ((HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)) && (HAL_IS_BIT_CLR(RCC->BDCR, RCC_BDCR_LSCOSEL)) \
  328. && (srcclk == RCC_PVDCLKSOURCE_LSC))
  329. {
  330. frequency = LSI_VALUE;
  331. }
  332. else if ((HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY)) && (HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSCOSEL)) \
  333. && (srcclk == RCC_PVDCLKSOURCE_LSC))
  334. {
  335. frequency = LSE_VALUE;
  336. }
  337. /* Clock not enabled for PVD */
  338. else
  339. {
  340. /* Nothing to do as frequency already initialized to 0U */
  341. }
  342. #else
  343. else
  344. {
  345. frequency = LSI_VALUE;
  346. }
  347. #endif
  348. break;
  349. #endif
  350. #if defined(RCC_CCIPR_COMP1SEL)
  351. case RCC_PERIPHCLK_COMP1:
  352. /* Get the current COMP1 source */
  353. srcclk = __HAL_RCC_GET_COMP1_SOURCE();
  354. if (srcclk == RCC_COMP1CLKSOURCE_PCLK) /* PCLK1 */
  355. {
  356. frequency = HAL_RCC_GetPCLK1Freq();
  357. }
  358. #if defined(RCC_LSE_SUPPORT)
  359. else if ((HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)) && (HAL_IS_BIT_CLR(RCC->BDCR, RCC_BDCR_LSCOSEL)) \
  360. && (srcclk == RCC_COMP1CLKSOURCE_LSC))
  361. {
  362. frequency = LSI_VALUE;
  363. }
  364. else if ((HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY)) && (HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSCOSEL)) \
  365. && (srcclk == RCC_COMP1CLKSOURCE_LSC))
  366. {
  367. frequency = LSE_VALUE;
  368. }
  369. /* Clock not enabled for COMP1 */
  370. else
  371. {
  372. /* Nothing to do as frequency already initialized to 0U */
  373. }
  374. #else
  375. else
  376. {
  377. frequency = LSI_VALUE;
  378. }
  379. #endif
  380. break;
  381. #endif
  382. #if defined(RCC_CCIPR_COMP2SEL)
  383. case RCC_PERIPHCLK_COMP2:
  384. /* Get the current COMP2 source */
  385. srcclk = __HAL_RCC_GET_COMP2_SOURCE();
  386. if (srcclk == RCC_COMP2CLKSOURCE_PCLK) /* PCLK1 */
  387. {
  388. frequency = HAL_RCC_GetPCLK1Freq();
  389. }
  390. #if defined(RCC_LSE_SUPPORT)
  391. else if ((HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)) && (HAL_IS_BIT_CLR(RCC->BDCR, RCC_BDCR_LSCOSEL)) \
  392. && (srcclk == RCC_COMP2CLKSOURCE_LSC))
  393. {
  394. frequency = LSI_VALUE;
  395. }
  396. else if ((HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY)) && (HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSCOSEL)) \
  397. && (srcclk == RCC_COMP2CLKSOURCE_LSC))
  398. {
  399. frequency = LSE_VALUE;
  400. }
  401. /* Clock not enabled for COMP2 */
  402. else
  403. {
  404. /* Nothing to do as frequency already initialized to 0U */
  405. }
  406. #else
  407. else
  408. {
  409. frequency = LSI_VALUE;
  410. }
  411. #endif
  412. break;
  413. #endif
  414. #if defined(RCC_CCIPR_LPTIMSEL)
  415. case RCC_PERIPHCLK_LPTIM:
  416. /* Get the current LPTIM1 source */
  417. srcclk = __HAL_RCC_GET_LPTIM_SOURCE();
  418. if (srcclk == RCC_LPTIMCLKSOURCE_PCLK)
  419. {
  420. frequency = HAL_RCC_GetPCLK1Freq();
  421. }
  422. else if ((HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)) && (srcclk == RCC_LPTIMCLKSOURCE_LSI))
  423. {
  424. frequency = LSI_VALUE;
  425. }
  426. #if defined(RCC_LSE_SUPPORT)
  427. else if ((HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY)) && (srcclk == RCC_LPTIMCLKSOURCE_LSE))
  428. {
  429. frequency = LSE_VALUE;
  430. }
  431. #endif
  432. /* Clock not enabled for LPTIM1 */
  433. else
  434. {
  435. /* Nothing to do as frequency already initialized to 0U */
  436. }
  437. break;
  438. #endif /* RCC_CCIPR_LPTIM1SEL */
  439. default:
  440. break;
  441. }
  442. #if defined(RCC_BDCR_RTCSEL)
  443. }
  444. #endif
  445. return (frequency);
  446. }
  447. /**
  448. * @}
  449. */
  450. /** @defgroup RCCEx_Exported_Functions_Group2 Extended Clock management functions
  451. * @brief Extended Clock management functions
  452. *
  453. @verbatim
  454. ===============================================================================
  455. ##### Extended clock management functions #####
  456. ===============================================================================
  457. [..]
  458. This subsection provides a set of functions allowing to control the
  459. activation or deactivation of LSE CSS, Low speed clock output and
  460. clock after wake-up from STOP mode.
  461. @endverbatim
  462. * @{
  463. */
  464. /**
  465. * @brief Select the Low Speed clock source.
  466. * @param LSCOSource specifies the Low Speed clock source.
  467. * This parameter can be one of the following values:
  468. * @arg @ref RCC_LSCOSOURCE_LSI LSI clock selected as LSCO source
  469. * @arg @ref RCC_LSCOSOURCE_LSE LSE clock selected as LSCO source
  470. * @retval None
  471. */
  472. void HAL_RCCEx_EnableLSCO(uint32_t LSCOSource)
  473. {
  474. FlagStatus pwrclkchanged = RESET;
  475. FlagStatus backupchanged = RESET;
  476. /* Check the parameters */
  477. assert_param(IS_RCC_LSCOSOURCE(LSCOSource));
  478. /* Update LSCOSEL clock source in Backup Domain control register */
  479. if (__HAL_RCC_PWR_IS_CLK_DISABLED())
  480. {
  481. __HAL_RCC_PWR_CLK_ENABLE();
  482. pwrclkchanged = SET;
  483. }
  484. if (HAL_IS_BIT_CLR(PWR->CR1, PWR_CR1_DBP))
  485. {
  486. HAL_PWR_EnableBkUpAccess();
  487. backupchanged = SET;
  488. }
  489. #if defined(RCC_BDCR_LSCOSEL)
  490. MODIFY_REG(RCC->BDCR, RCC_BDCR_LSCOSEL, LSCOSource);
  491. #endif
  492. if (backupchanged == SET)
  493. {
  494. HAL_PWR_DisableBkUpAccess();
  495. }
  496. if (pwrclkchanged == SET)
  497. {
  498. __HAL_RCC_PWR_CLK_DISABLE();
  499. }
  500. }
  501. /**
  502. * @}
  503. */
  504. /**
  505. * @}
  506. */
  507. #endif /* HAL_RCC_MODULE_ENABLED */
  508. /**
  509. * @}
  510. */
  511. /**
  512. * @}
  513. */
  514. /************************ (C) COPYRIGHT Puya *****END OF FILE****/