stm32l0xx_hal_rcc.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_rcc.c
  4. * @author MCD Application Team
  5. * @brief RCC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Reset and Clock Control (RCC) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + Peripheral Control functions
  10. *
  11. @verbatim
  12. ==============================================================================
  13. ##### RCC specific features #####
  14. ==============================================================================
  15. [..]
  16. After reset the device is running from multispeed internal oscillator clock
  17. (MSI 2.097MHz) with Flash 0 wait state and Flash prefetch buffer is disabled,
  18. and all peripherals are off except internal SRAM, Flash and JTAG.
  19. (+) There is no prescaler on High speed (AHB) and Low speed (APB) buses;
  20. all peripherals mapped on these buses are running at MSI speed.
  21. (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
  22. (+) All GPIOs are in input floating state, except the JTAG pins which
  23. are assigned to be used for debug purpose.
  24. [..] Once the device started from reset, the user application has to:
  25. (+) Configure the clock source to be used to drive the System clock
  26. (if the application needs higher frequency/performance)
  27. (+) Configure the System clock frequency and Flash settings
  28. (+) Configure the AHB and APB buses prescalers
  29. (+) Enable the clock for the peripheral(s) to be used
  30. (+) Configure the clock source(s) for peripherals whose clocks are not
  31. derived from the System clock (I2S, RTC, ADC, USB OTG FS/SDIO/RNG)
  32. (*) SDIO only for STM32L0xxxD devices
  33. ##### RCC Limitations #####
  34. ==============================================================================
  35. [..]
  36. A delay between an RCC peripheral clock enable and the effective peripheral
  37. enabling should be taken into account in order to manage the peripheral read/write
  38. from/to registers.
  39. (+) This delay depends on the peripheral mapping.
  40. (++) AHB & APB peripherals, 1 dummy read is necessary
  41. [..]
  42. Workarounds:
  43. (#) For AHB & APB peripherals, a dummy read to the peripheral register has been
  44. inserted in each __HAL_RCC_PPP_CLK_ENABLE() macro.
  45. @endverbatim
  46. ******************************************************************************
  47. * @attention
  48. *
  49. * Copyright (c) 2016 STMicroelectronics.
  50. * All rights reserved.
  51. *
  52. * This software is licensed under terms that can be found in the LICENSE file in
  53. * the root directory of this software component.
  54. * If no LICENSE file comes with this software, it is provided AS-IS.
  55. ******************************************************************************
  56. */
  57. /* Includes ------------------------------------------------------------------*/
  58. #include "stm32l0xx_hal.h"
  59. /** @addtogroup STM32L0xx_HAL_Driver
  60. * @{
  61. */
  62. /** @defgroup RCC RCC
  63. * @brief RCC HAL module driver
  64. * @{
  65. */
  66. #ifdef HAL_RCC_MODULE_ENABLED
  67. /* Private typedef -----------------------------------------------------------*/
  68. /* Private define ------------------------------------------------------------*/
  69. /* Private macro -------------------------------------------------------------*/
  70. /** @defgroup RCC_Private_Macros RCC Private Macros
  71. * @{
  72. */
  73. #define MCO1_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  74. #define MCO1_GPIO_PORT GPIOA
  75. #define MCO1_PIN GPIO_PIN_8
  76. #define MCO2_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  77. #define MCO2_GPIO_PORT GPIOA
  78. #define MCO2_PIN GPIO_PIN_9
  79. #if defined(RCC_MCO3_SUPPORT)
  80. #define MCO3_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  81. #define MCO3_GPIO_PORT GPIOB
  82. #define MCO3_PIN GPIO_PIN_13
  83. #endif /* RCC_MCO3_SUPPORT */
  84. /**
  85. * @}
  86. */
  87. /* Private variables ---------------------------------------------------------*/
  88. /* Private function prototypes -----------------------------------------------*/
  89. /* Exported functions ---------------------------------------------------------*/
  90. /** @defgroup RCC_Exported_Functions RCC Exported Functions
  91. * @{
  92. */
  93. /** @defgroup RCC_Exported_Functions_Group1 Initialization and de-initialization functions
  94. * @brief Initialization and Configuration functions
  95. *
  96. @verbatim
  97. ===============================================================================
  98. ##### Initialization and de-initialization functions #####
  99. ===============================================================================
  100. [..]
  101. This section provides functions allowing to configure the internal/external oscillators
  102. (MSI, HSE, HSI, LSE, LSI, PLL, CSS and MCO) and the System buses clocks (SYSCLK, AHB, APB1
  103. and APB2).
  104. [..] Internal/external clock and PLL configuration
  105. (#) MSI (Multispeed internal), Seven frequency ranges are available: 65.536 kHz,
  106. 131.072 kHz, 262.144 kHz, 524.288 kHz, 1.048 MHz, 2.097 MHz (default value) and 4.194 MHz.
  107. (#) HSI (high-speed internal), 16 MHz factory-trimmed RC used directly or through
  108. the PLL as System clock source.
  109. (#) LSI (low-speed internal), ~37 KHz low consumption RC used as IWDG and/or RTC
  110. clock source.
  111. (#) HSE (high-speed external), 1 to 24 MHz crystal oscillator used directly or
  112. through the PLL as System clock source. Can be used also as RTC clock source.
  113. (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
  114. (#) PLL (clocked by HSI or HSE), featuring different output clocks:
  115. (++) The first output is used to generate the high speed system clock (up to 32 MHz)
  116. (++) The second output is used to generate the clock for the USB OTG FS (48 MHz)
  117. (#) CSS (Clock security system), once enable using the macro __HAL_RCC_CSS_ENABLE()
  118. and if a HSE clock failure occurs(HSE used directly or through PLL as System
  119. clock source), the System clocks automatically switched to MSI and an interrupt
  120. is generated if enabled. The interrupt is linked to the Cortex-M0+ NMI
  121. (Non-Maskable Interrupt) exception vector.
  122. (#) MCO1/MCO2/MCO3 (microcontroller clock output), used to output SYSCLK, HSI, LSI, MSI, LSE,
  123. HSE, HSI48 or PLL clock (through a configurable prescaler) on PA8/PA9/PB13 pins.
  124. [..] System, AHB and APB buses clocks configuration
  125. (#) Several clock sources can be used to drive the System clock (SYSCLK): MSI, HSI,
  126. HSE and PLL.
  127. The AHB clock (HCLK) is derived from System clock through configurable
  128. prescaler and used to clock the CPU, memory and peripherals mapped
  129. on AHB bus (DMA, GPIO...). APB1 (PCLK1) and APB2 (PCLK2) clocks are derived
  130. from AHB clock through configurable prescalers and used to clock
  131. the peripherals mapped on these buses. You can use
  132. "HAL_RCC_GetSysClockFreq()" function to retrieve the frequencies of these clocks.
  133. -@- All the peripheral clocks are derived from the System clock (SYSCLK) except:
  134. (+@) RTC: RTC clock can be derived either from the LSI, LSE or HSE clock
  135. divided by 2 to 16. You have to use __HAL_RCC_RTC_CONFIG() and __HAL_RCC_RTC_ENABLE()
  136. macros to configure this clock.
  137. (+@) LCD: LCD clock can be derived either from the LSI, LSE or HSE clock
  138. divided by 2 to 16. You have to use __HAL_RCC_LCD_CONFIG()
  139. macros to configure this clock.
  140. (+@) USB FS and RNG: USB FS require a frequency equal to 48 MHz to work correctly.
  141. This clock is derived of the main PLL through PLL Multiplier or HSI48 RC oscillator.
  142. (+@) IWDG clock which is always the LSI clock.
  143. (#) The maximum frequency of the SYSCLK and HCLK is 32 MHz, PCLK2 32 MHz
  144. and PCLK1 32 MHz. Depending on the device voltage range, the maximum
  145. frequency should be adapted accordingly.
  146. @endverbatim
  147. * @{
  148. */
  149. /*
  150. Additional consideration on the HCLK based on Latency settings:
  151. +----------------------------------------------------------------------+
  152. | Latency | HCLK clock frequency (MHz) |
  153. | |------------------------------------------------------|
  154. | | voltage range 1 | voltage range 2 | voltage range 3 |
  155. | | 1.8 V | 1.5 V | 1.2 V |
  156. |---------------|------------------|-----------------|-----------------|
  157. |0WS(1CPU cycle)| 0 < HCLK <= 16 | 0 < HCLK <= 8 | 0 < HCLK <= 4.2 |
  158. |---------------|------------------|-----------------|-----------------|
  159. |1WS(2CPU cycle)| 16 < HCLK <= 32 | 8 < HCLK <= 16 | |
  160. +----------------------------------------------------------------------+
  161. The following table gives the different clock source frequencies depending on the product
  162. voltage range:
  163. +------------------------------------------------------------------------------------------+
  164. | Product voltage | Clock frequency |
  165. | |------------------|-----------------------------|-----------------------|
  166. | range | MSI | HSI | HSE | PLL |
  167. |-----------------|---------|--------|-----------------------------|-----------------------|
  168. | Range 1 (1.8 V) | 4.2 MHz | 16 MHz | HSE 32 MHz (external clock) | 32 MHz |
  169. | | | | or 24 MHz (crystal) | (PLLVCO max = 96 MHz) |
  170. |-----------------|---------|--------|-----------------------------|-----------------------|
  171. | Range 2 (1.5 V) | 4.2 MHz | 16 MHz | 16 MHz | 16 MHz |
  172. | | | | | (PLLVCO max = 48 MHz) |
  173. |-----------------|---------|--------|-----------------------------|-----------------------|
  174. | Range 3 (1.2 V) | 4.2 MHz | NA | 8 MHz | 4 MHz |
  175. | | | | | (PLLVCO max = 24 MHz) |
  176. +------------------------------------------------------------------------------------------+
  177. */
  178. /**
  179. * @brief Resets the RCC clock configuration to the default reset state.
  180. * @note The default reset state of the clock configuration is given below:
  181. * - MSI ON and used as system clock source
  182. * - HSI, HSE and PLL OFF
  183. * - AHB, APB1 and APB2 prescaler set to 1.
  184. * - CSS and MCO1/MCO2/MCO3 OFF
  185. * - All interrupts disabled
  186. * @note This function does not modify the configuration of the
  187. * - Peripheral clocks
  188. * - LSI, LSE and RTC clocks
  189. * - HSI48 clock
  190. * @retval None
  191. */
  192. HAL_StatusTypeDef HAL_RCC_DeInit(void)
  193. {
  194. __IO uint32_t tmpreg;
  195. uint32_t tickstart;
  196. uint32_t vl_mask;
  197. HAL_StatusTypeDef status;
  198. /* Set MSIClockRange, HSITRIM and MSITRIM bits to the reset values */
  199. MODIFY_REG(RCC->ICSCR, (RCC_ICSCR_MSITRIM | RCC_ICSCR_HSITRIM | RCC_ICSCR_MSIRANGE), \
  200. ((RCC_MSICALIBRATION_DEFAULT << RCC_ICSCR_MSITRIM_Pos) | (RCC_HSICALIBRATION_DEFAULT << RCC_ICSCR_HSITRIM_Pos) | RCC_ICSCR_MSIRANGE_5));
  201. /* Set MSION bit */
  202. SET_BIT(RCC->CR, RCC_CR_MSION);
  203. /* Get Start Tick*/
  204. tickstart = HAL_GetTick();
  205. /* Wait till MSI is ready */
  206. while (READ_BIT(RCC->CR, RCC_CR_MSIRDY) == 0U)
  207. {
  208. if ((HAL_GetTick() - tickstart) > MSI_TIMEOUT_VALUE)
  209. {
  210. return HAL_TIMEOUT;
  211. }
  212. }
  213. /* Switch SYSCLK to MSI*/
  214. CLEAR_BIT(RCC->CFGR, RCC_CFGR_SW);
  215. /* Wait till MSI as SYSCLK status is ready */
  216. while (READ_BIT(RCC->CFGR, RCC_CFGR_SWS) != 0U)
  217. {
  218. if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
  219. {
  220. return HAL_TIMEOUT;
  221. }
  222. }
  223. /* Update the SystemCoreClock global variable for MSI as system clock source */
  224. SystemCoreClock = MSI_VALUE;
  225. /* Configure the source of time base considering new system clock settings */
  226. status = HAL_InitTick(uwTickPrio);
  227. if(status != HAL_OK)
  228. {
  229. return status;
  230. }
  231. /* Reset HSE, HSI, CSS, PLL */
  232. #if defined(RCC_CR_CSSHSEON) && defined(RCC_CR_HSIOUTEN)
  233. CLEAR_BIT(RCC->CR, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | RCC_CR_HSIOUTEN | \
  234. RCC_CR_HSEON | RCC_CR_CSSHSEON | RCC_CR_PLLON);
  235. #elif !defined(RCC_CR_CSSHSEON) && defined(RCC_CR_HSIOUTEN)
  236. CLEAR_BIT(RCC->CR, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | RCC_CR_HSIOUTEN | \
  237. RCC_CR_HSEON | RCC_CR_PLLON);
  238. #elif defined(RCC_CR_CSSHSEON) && !defined(RCC_CR_HSIOUTEN)
  239. CLEAR_BIT(RCC->CR, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | \
  240. RCC_CR_HSEON | RCC_CR_CSSHSEON | RCC_CR_PLLON);
  241. #endif
  242. /* Delay after an RCC peripheral clock */ \
  243. tmpreg = READ_BIT(RCC->CR, RCC_CR_HSEON); \
  244. UNUSED(tmpreg);
  245. /* Reset HSEBYP bit */
  246. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);
  247. /* Get Start Tick*/
  248. tickstart = HAL_GetTick();
  249. /* Wait till PLL is not ready */
  250. while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != 0U)
  251. {
  252. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  253. {
  254. return HAL_TIMEOUT;
  255. }
  256. }
  257. /* Reset CFGR register */
  258. CLEAR_REG(RCC->CFGR);
  259. /* Disable all interrupts */
  260. CLEAR_REG(RCC->CIER);
  261. /* Clear all flags */
  262. vl_mask = RCC_CICR_LSIRDYC | RCC_CICR_LSERDYC | RCC_CICR_HSIRDYC | RCC_CICR_HSERDYC | RCC_CICR_PLLRDYC | RCC_CICR_MSIRDYC | RCC_CICR_CSSLSEC;
  263. #if defined(RCC_HSI48_SUPPORT)
  264. vl_mask |= RCC_CICR_HSI48RDYC;
  265. #endif
  266. #if defined(RCC_HSECSS_SUPPORT)
  267. vl_mask |= RCC_CICR_CSSHSEC;
  268. #endif
  269. WRITE_REG(RCC->CICR, vl_mask);
  270. /* Clear all reset flags */
  271. SET_BIT(RCC->CSR, RCC_CSR_RMVF);
  272. return HAL_OK;
  273. }
  274. /**
  275. * @brief Initializes the RCC Oscillators according to the specified parameters in the
  276. * RCC_OscInitTypeDef.
  277. * @param RCC_OscInitStruct pointer to an RCC_OscInitTypeDef structure that
  278. * contains the configuration information for the RCC Oscillators.
  279. * @note The PLL is not disabled when used as system clock.
  280. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not
  281. * supported by this macro. User should request a transition to LSE Off
  282. * first and then LSE On or LSE Bypass.
  283. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  284. * supported by this macro. User should request a transition to HSE Off
  285. * first and then HSE On or HSE Bypass.
  286. * @retval HAL status
  287. */
  288. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
  289. {
  290. uint32_t tickstart;
  291. uint32_t hsi_state;
  292. HAL_StatusTypeDef status;
  293. uint32_t sysclk_source, pll_config;
  294. /* Check Null pointer */
  295. if(RCC_OscInitStruct == NULL)
  296. {
  297. return HAL_ERROR;
  298. }
  299. /* Check the parameters */
  300. assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
  301. sysclk_source = __HAL_RCC_GET_SYSCLK_SOURCE();
  302. pll_config = __HAL_RCC_GET_PLL_OSCSOURCE();
  303. /*------------------------------- HSE Configuration ------------------------*/
  304. if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
  305. {
  306. /* Check the parameters */
  307. assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
  308. /* When the HSE is used as system clock or clock source for PLL in these cases it is not allowed to be disabled */
  309. if((sysclk_source == RCC_SYSCLKSOURCE_STATUS_HSE)
  310. || ((sysclk_source == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (pll_config == RCC_PLLSOURCE_HSE)))
  311. {
  312. if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != 0U) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
  313. {
  314. return HAL_ERROR;
  315. }
  316. }
  317. else
  318. {
  319. /* Set the new HSE configuration ---------------------------------------*/
  320. __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
  321. /* Check the HSE State */
  322. if(RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
  323. {
  324. /* Get Start Tick */
  325. tickstart = HAL_GetTick();
  326. /* Wait till HSE is ready */
  327. while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
  328. {
  329. if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
  330. {
  331. return HAL_TIMEOUT;
  332. }
  333. }
  334. }
  335. else
  336. {
  337. /* Get Start Tick */
  338. tickstart = HAL_GetTick();
  339. /* Wait till HSE is disabled */
  340. while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != 0U)
  341. {
  342. if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
  343. {
  344. return HAL_TIMEOUT;
  345. }
  346. }
  347. }
  348. }
  349. }
  350. /*----------------------------- HSI Configuration --------------------------*/
  351. if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
  352. {
  353. /* Check the parameters */
  354. assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
  355. assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
  356. hsi_state = RCC_OscInitStruct->HSIState;
  357. #if defined(RCC_CR_HSIOUTEN)
  358. if((hsi_state & RCC_HSI_OUTEN) != 0U)
  359. {
  360. /* HSI Output enable for timer requested */
  361. SET_BIT(RCC->CR, RCC_CR_HSIOUTEN);
  362. hsi_state &= ~RCC_CR_HSIOUTEN;
  363. }
  364. #endif
  365. /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
  366. if((sysclk_source == RCC_SYSCLKSOURCE_STATUS_HSI)
  367. || ((sysclk_source == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (pll_config == RCC_PLLSOURCE_HSI)))
  368. {
  369. /* When HSI is used as system clock it will not disabled */
  370. if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != 0U) && (hsi_state == RCC_HSI_OFF))
  371. {
  372. return HAL_ERROR;
  373. }
  374. /* Otherwise, just the calibration and HSI or HSIdiv4 are allowed */
  375. else
  376. {
  377. /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
  378. __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
  379. /* Enable the Internal High Speed oscillator (HSI or HSIdiv4) */
  380. __HAL_RCC_HSI_CONFIG(hsi_state);
  381. }
  382. /* Update the SystemCoreClock global variable */
  383. SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE)>> RCC_CFGR_HPRE_Pos];
  384. /* Configure the source of time base considering new system clocks settings*/
  385. status = HAL_InitTick (uwTickPrio);
  386. if(status != HAL_OK)
  387. {
  388. return status;
  389. }
  390. }
  391. else
  392. {
  393. /* Check the HSI State */
  394. if(hsi_state != RCC_HSI_OFF)
  395. {
  396. /* Enable the Internal High Speed oscillator (HSI or HSIdiv4) */
  397. __HAL_RCC_HSI_CONFIG(hsi_state);
  398. /* Get Start Tick */
  399. tickstart = HAL_GetTick();
  400. /* Wait till HSI is ready */
  401. while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == 0U)
  402. {
  403. if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
  404. {
  405. return HAL_TIMEOUT;
  406. }
  407. }
  408. /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
  409. __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
  410. }
  411. else
  412. {
  413. /* Disable the Internal High Speed oscillator (HSI). */
  414. __HAL_RCC_HSI_DISABLE();
  415. /* Get Start Tick */
  416. tickstart = HAL_GetTick();
  417. /* Wait till HSI is disabled */
  418. while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != 0U)
  419. {
  420. if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
  421. {
  422. return HAL_TIMEOUT;
  423. }
  424. }
  425. }
  426. }
  427. }
  428. /*----------------------------- MSI Configuration --------------------------*/
  429. if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_MSI) == RCC_OSCILLATORTYPE_MSI)
  430. {
  431. /* When the MSI is used as system clock it will not be disabled */
  432. if(sysclk_source == RCC_CFGR_SWS_MSI)
  433. {
  434. if((__HAL_RCC_GET_FLAG(RCC_FLAG_MSIRDY) != 0U) && (RCC_OscInitStruct->MSIState == RCC_MSI_OFF))
  435. {
  436. return HAL_ERROR;
  437. }
  438. /* Otherwise, just the calibration and MSI range change are allowed */
  439. else
  440. {
  441. /* Check MSICalibrationValue and MSIClockRange input parameters */
  442. assert_param(IS_RCC_MSICALIBRATION_VALUE(RCC_OscInitStruct->MSICalibrationValue));
  443. assert_param(IS_RCC_MSI_CLOCK_RANGE(RCC_OscInitStruct->MSIClockRange));
  444. /* Selects the Multiple Speed oscillator (MSI) clock range .*/
  445. __HAL_RCC_MSI_RANGE_CONFIG(RCC_OscInitStruct->MSIClockRange);
  446. /* Adjusts the Multiple Speed oscillator (MSI) calibration value.*/
  447. __HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->MSICalibrationValue);
  448. /* Update the SystemCoreClock global variable */
  449. SystemCoreClock = (32768U * (1UL << ((RCC_OscInitStruct->MSIClockRange >> RCC_ICSCR_MSIRANGE_Pos) + 1U)))
  450. >> AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)];
  451. /* Configure the source of time base considering new system clocks settings*/
  452. status = HAL_InitTick (uwTickPrio);
  453. if(status != HAL_OK)
  454. {
  455. return status;
  456. }
  457. }
  458. }
  459. else
  460. {
  461. /* Check MSI State */
  462. assert_param(IS_RCC_MSI(RCC_OscInitStruct->MSIState));
  463. /* Check the MSI State */
  464. if(RCC_OscInitStruct->MSIState != RCC_MSI_OFF)
  465. {
  466. /* Enable the Multi Speed oscillator (MSI). */
  467. __HAL_RCC_MSI_ENABLE();
  468. /* Get Start Tick */
  469. tickstart = HAL_GetTick();
  470. /* Wait till MSI is ready */
  471. while(__HAL_RCC_GET_FLAG(RCC_FLAG_MSIRDY) == 0U)
  472. {
  473. if((HAL_GetTick() - tickstart) > MSI_TIMEOUT_VALUE)
  474. {
  475. return HAL_TIMEOUT;
  476. }
  477. }
  478. /* Check MSICalibrationValue and MSIClockRange input parameters */
  479. assert_param(IS_RCC_MSICALIBRATION_VALUE(RCC_OscInitStruct->MSICalibrationValue));
  480. assert_param(IS_RCC_MSI_CLOCK_RANGE(RCC_OscInitStruct->MSIClockRange));
  481. /* Selects the Multiple Speed oscillator (MSI) clock range .*/
  482. __HAL_RCC_MSI_RANGE_CONFIG(RCC_OscInitStruct->MSIClockRange);
  483. /* Adjusts the Multiple Speed oscillator (MSI) calibration value.*/
  484. __HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->MSICalibrationValue);
  485. }
  486. else
  487. {
  488. /* Disable the Multi Speed oscillator (MSI). */
  489. __HAL_RCC_MSI_DISABLE();
  490. /* Get Start Tick */
  491. tickstart = HAL_GetTick();
  492. /* Wait till MSI is ready */
  493. while(__HAL_RCC_GET_FLAG(RCC_FLAG_MSIRDY) != 0U)
  494. {
  495. if((HAL_GetTick() - tickstart) > MSI_TIMEOUT_VALUE)
  496. {
  497. return HAL_TIMEOUT;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. /*------------------------------ LSI Configuration -------------------------*/
  504. if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
  505. {
  506. /* Check the parameters */
  507. assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
  508. /* Check the LSI State */
  509. if(RCC_OscInitStruct->LSIState != RCC_LSI_OFF)
  510. {
  511. /* Enable the Internal Low Speed oscillator (LSI). */
  512. __HAL_RCC_LSI_ENABLE();
  513. /* Get Start Tick */
  514. tickstart = HAL_GetTick();
  515. /* Wait till LSI is ready */
  516. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == 0U)
  517. {
  518. if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
  519. {
  520. return HAL_TIMEOUT;
  521. }
  522. }
  523. }
  524. else
  525. {
  526. /* Disable the Internal Low Speed oscillator (LSI). */
  527. __HAL_RCC_LSI_DISABLE();
  528. /* Get Start Tick */
  529. tickstart = HAL_GetTick();
  530. /* Wait till LSI is disabled */
  531. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != 0U)
  532. {
  533. if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
  534. {
  535. return HAL_TIMEOUT;
  536. }
  537. }
  538. }
  539. }
  540. /*------------------------------ LSE Configuration -------------------------*/
  541. if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
  542. {
  543. FlagStatus pwrclkchanged = RESET;
  544. /* Check the parameters */
  545. assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
  546. /* Update LSE configuration in Backup Domain control register */
  547. /* Requires to enable write access to Backup Domain of necessary */
  548. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  549. {
  550. __HAL_RCC_PWR_CLK_ENABLE();
  551. pwrclkchanged = SET;
  552. }
  553. if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
  554. {
  555. /* Enable write access to Backup domain */
  556. SET_BIT(PWR->CR, PWR_CR_DBP);
  557. /* Wait for Backup domain Write protection disable */
  558. tickstart = HAL_GetTick();
  559. while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
  560. {
  561. if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  562. {
  563. return HAL_TIMEOUT;
  564. }
  565. }
  566. }
  567. /* Set the new LSE configuration -----------------------------------------*/
  568. __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
  569. /* Check the LSE State */
  570. if(RCC_OscInitStruct->LSEState != RCC_LSE_OFF)
  571. {
  572. /* Get Start Tick */
  573. tickstart = HAL_GetTick();
  574. /* Wait till LSE is ready */
  575. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == 0U)
  576. {
  577. if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
  578. {
  579. return HAL_TIMEOUT;
  580. }
  581. }
  582. }
  583. else
  584. {
  585. /* Get Start Tick */
  586. tickstart = HAL_GetTick();
  587. /* Wait till LSE is disabled */
  588. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != 0U)
  589. {
  590. if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
  591. {
  592. return HAL_TIMEOUT;
  593. }
  594. }
  595. }
  596. /* Require to disable power clock if necessary */
  597. if(pwrclkchanged == SET)
  598. {
  599. __HAL_RCC_PWR_CLK_DISABLE();
  600. }
  601. }
  602. #if defined(RCC_HSI48_SUPPORT)
  603. /*----------------------------- HSI48 Configuration --------------------------*/
  604. if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI48) == RCC_OSCILLATORTYPE_HSI48)
  605. {
  606. /* Check the parameters */
  607. assert_param(IS_RCC_HSI48(RCC_OscInitStruct->HSI48State));
  608. /* Check the HSI48 State */
  609. if(RCC_OscInitStruct->HSI48State != RCC_HSI48_OFF)
  610. {
  611. /* Enable the Internal High Speed oscillator (HSI48). */
  612. __HAL_RCC_HSI48_ENABLE();
  613. /* Get Start Tick */
  614. tickstart = HAL_GetTick();
  615. /* Wait till HSI48 is ready */
  616. while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY) == 0U)
  617. {
  618. if((HAL_GetTick() - tickstart) > HSI48_TIMEOUT_VALUE)
  619. {
  620. return HAL_TIMEOUT;
  621. }
  622. }
  623. }
  624. else
  625. {
  626. /* Disable the Internal High Speed oscillator (HSI48). */
  627. __HAL_RCC_HSI48_DISABLE();
  628. /* Get Start Tick */
  629. tickstart = HAL_GetTick();
  630. /* Wait till HSI48 is ready */
  631. while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY) != 0U)
  632. {
  633. if((HAL_GetTick() - tickstart) > HSI48_TIMEOUT_VALUE)
  634. {
  635. return HAL_TIMEOUT;
  636. }
  637. }
  638. }
  639. }
  640. #endif /* RCC_HSI48_SUPPORT */
  641. /*-------------------------------- PLL Configuration -----------------------*/
  642. /* Check the parameters */
  643. assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
  644. if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
  645. {
  646. /* Check if the PLL is used as system clock or not */
  647. if(sysclk_source != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
  648. {
  649. if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
  650. {
  651. /* Check the parameters */
  652. assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
  653. assert_param(IS_RCC_PLL_MUL(RCC_OscInitStruct->PLL.PLLMUL));
  654. assert_param(IS_RCC_PLL_DIV(RCC_OscInitStruct->PLL.PLLDIV));
  655. /* Disable the main PLL. */
  656. __HAL_RCC_PLL_DISABLE();
  657. /* Get Start Tick */
  658. tickstart = HAL_GetTick();
  659. /* Wait till PLL is ready */
  660. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != 0U)
  661. {
  662. if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
  663. {
  664. return HAL_TIMEOUT;
  665. }
  666. }
  667. /* Configure the main PLL clock source, multiplication and division factors. */
  668. __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
  669. RCC_OscInitStruct->PLL.PLLMUL,
  670. RCC_OscInitStruct->PLL.PLLDIV);
  671. /* Enable the main PLL. */
  672. __HAL_RCC_PLL_ENABLE();
  673. /* Get Start Tick */
  674. tickstart = HAL_GetTick();
  675. /* Wait till PLL is ready */
  676. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == 0U)
  677. {
  678. if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
  679. {
  680. return HAL_TIMEOUT;
  681. }
  682. }
  683. }
  684. else
  685. {
  686. /* Disable the main PLL. */
  687. __HAL_RCC_PLL_DISABLE();
  688. /* Get Start Tick */
  689. tickstart = HAL_GetTick();
  690. /* Wait till PLL is disabled */
  691. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != 0U)
  692. {
  693. if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
  694. {
  695. return HAL_TIMEOUT;
  696. }
  697. }
  698. }
  699. }
  700. else
  701. {
  702. /* Check if there is a request to disable the PLL used as System clock source */
  703. if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF)
  704. {
  705. return HAL_ERROR;
  706. }
  707. else
  708. {
  709. /* Do not return HAL_ERROR if request repeats the current configuration */
  710. pll_config = RCC->CFGR;
  711. if((READ_BIT(pll_config, RCC_CFGR_PLLSRC) != RCC_OscInitStruct->PLL.PLLSource) ||
  712. (READ_BIT(pll_config, RCC_CFGR_PLLMUL) != RCC_OscInitStruct->PLL.PLLMUL) ||
  713. (READ_BIT(pll_config, RCC_CFGR_PLLDIV) != RCC_OscInitStruct->PLL.PLLDIV))
  714. {
  715. return HAL_ERROR;
  716. }
  717. }
  718. }
  719. }
  720. return HAL_OK;
  721. }
  722. /**
  723. * @brief Initializes the CPU, AHB and APB buses clocks according to the specified
  724. * parameters in the RCC_ClkInitStruct.
  725. * @param RCC_ClkInitStruct pointer to an RCC_OscInitTypeDef structure that
  726. * contains the configuration information for the RCC peripheral.
  727. * @param FLatency FLASH Latency
  728. * The value of this parameter depend on device used within the same series
  729. * @note The SystemCoreClock CMSIS variable is used to store System Clock Frequency
  730. * and updated by @ref HAL_RCC_GetHCLKFreq() function called within this function
  731. *
  732. * @note The MSI is used (enabled by hardware) as system clock source after
  733. * start-up from Reset, wake-up from STOP and STANDBY mode, or in case
  734. * of failure of the HSE used directly or indirectly as system clock
  735. * (if the Clock Security System CSS is enabled).
  736. *
  737. * @note A switch from one clock source to another occurs only if the target
  738. * clock source is ready (clock stable after start-up delay or PLL locked).
  739. * If a clock source which is not yet ready is selected, the switch will
  740. * occur when the clock source will be ready.
  741. * You can use @ref HAL_RCC_GetClockConfig() function to know which clock is
  742. * currently used as system clock source.
  743. * @note Depending on the device voltage range, the software has to set correctly
  744. * HPRE[3:0] bits to ensure that HCLK not exceed the maximum allowed frequency
  745. * (for more details refer to section above "Initialization/de-initialization functions")
  746. * @retval HAL status
  747. */
  748. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
  749. {
  750. uint32_t tickstart;
  751. HAL_StatusTypeDef status;
  752. /* Check Null pointer */
  753. if(RCC_ClkInitStruct == NULL)
  754. {
  755. return HAL_ERROR;
  756. }
  757. /* Check the parameters */
  758. assert_param(IS_RCC_CLOCKTYPE(RCC_ClkInitStruct->ClockType));
  759. assert_param(IS_FLASH_LATENCY(FLatency));
  760. /* To correctly read data from FLASH memory, the number of wait states (LATENCY)
  761. must be correctly programmed according to the frequency of the CPU clock
  762. (HCLK) and the supply voltage of the device. */
  763. /* Increasing the number of wait states because of higher CPU frequency */
  764. if(FLatency > __HAL_FLASH_GET_LATENCY())
  765. {
  766. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  767. __HAL_FLASH_SET_LATENCY(FLatency);
  768. /* Check that the new number of wait states is taken into account to access the Flash
  769. memory by polling the FLASH_ACR register */
  770. tickstart = HAL_GetTick();
  771. while (__HAL_FLASH_GET_LATENCY() != FLatency)
  772. {
  773. if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
  774. {
  775. return HAL_TIMEOUT;
  776. }
  777. }
  778. }
  779. /*-------------------------- HCLK Configuration --------------------------*/
  780. if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
  781. {
  782. assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
  783. MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
  784. }
  785. /*------------------------- SYSCLK Configuration ---------------------------*/
  786. if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
  787. {
  788. assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
  789. /* HSE is selected as System Clock Source */
  790. if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
  791. {
  792. /* Check the HSE ready flag */
  793. if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
  794. {
  795. return HAL_ERROR;
  796. }
  797. }
  798. /* PLL is selected as System Clock Source */
  799. else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
  800. {
  801. /* Check the PLL ready flag */
  802. if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == 0U)
  803. {
  804. return HAL_ERROR;
  805. }
  806. }
  807. /* HSI is selected as System Clock Source */
  808. else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSI)
  809. {
  810. /* Check the HSI ready flag */
  811. if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == 0U)
  812. {
  813. return HAL_ERROR;
  814. }
  815. }
  816. /* MSI is selected as System Clock Source */
  817. else
  818. {
  819. /* Check the MSI ready flag */
  820. if(__HAL_RCC_GET_FLAG(RCC_FLAG_MSIRDY) == 0U)
  821. {
  822. return HAL_ERROR;
  823. }
  824. }
  825. __HAL_RCC_SYSCLK_CONFIG(RCC_ClkInitStruct->SYSCLKSource);
  826. /* Get Start Tick */
  827. tickstart = HAL_GetTick();
  828. if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
  829. {
  830. while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSE)
  831. {
  832. if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
  833. {
  834. return HAL_TIMEOUT;
  835. }
  836. }
  837. }
  838. else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
  839. {
  840. while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
  841. {
  842. if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
  843. {
  844. return HAL_TIMEOUT;
  845. }
  846. }
  847. }
  848. else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSI)
  849. {
  850. while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSI)
  851. {
  852. if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
  853. {
  854. return HAL_TIMEOUT;
  855. }
  856. }
  857. }
  858. else
  859. {
  860. while(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_MSI)
  861. {
  862. if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
  863. {
  864. return HAL_TIMEOUT;
  865. }
  866. }
  867. }
  868. }
  869. /* Decreasing the number of wait states because of lower CPU frequency */
  870. if(FLatency < __HAL_FLASH_GET_LATENCY())
  871. {
  872. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  873. __HAL_FLASH_SET_LATENCY(FLatency);
  874. /* Check that the new number of wait states is taken into account to access the Flash
  875. memory by polling the FLASH_ACR register */
  876. tickstart = HAL_GetTick();
  877. while (__HAL_FLASH_GET_LATENCY() != FLatency)
  878. {
  879. if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
  880. {
  881. return HAL_TIMEOUT;
  882. }
  883. }
  884. }
  885. /*-------------------------- PCLK1 Configuration ---------------------------*/
  886. if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
  887. {
  888. assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
  889. MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
  890. }
  891. /*-------------------------- PCLK2 Configuration ---------------------------*/
  892. if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
  893. {
  894. assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
  895. MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
  896. }
  897. /* Update the SystemCoreClock global variable */
  898. SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE)>> RCC_CFGR_HPRE_Pos];
  899. /* Configure the source of time base considering new system clocks settings*/
  900. status = HAL_InitTick(uwTickPrio);
  901. if(status != HAL_OK)
  902. {
  903. return status;
  904. }
  905. return HAL_OK;
  906. }
  907. /**
  908. * @}
  909. */
  910. /** @defgroup RCC_Exported_Functions_Group2 Peripheral Control functions
  911. * @brief RCC clocks control functions
  912. *
  913. @verbatim
  914. ===============================================================================
  915. ##### Peripheral Control functions #####
  916. ===============================================================================
  917. [..]
  918. This subsection provides a set of functions allowing to control the RCC Clocks
  919. frequencies.
  920. @endverbatim
  921. * @{
  922. */
  923. /**
  924. * @brief Selects the clock source to output on MCO pin.
  925. * @note MCO pin should be configured in alternate function mode.
  926. * @param RCC_MCOx specifies the output direction for the clock source.
  927. * This parameter can be one of the following values:
  928. * @arg @ref RCC_MCO1 Clock source to output on MCO1 pin(PA8).
  929. * @arg @ref RCC_MCO2 Clock source to output on MCO2 pin(PA9).
  930. @if STM32L031xx
  931. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  932. @elseif STM32L041xx
  933. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  934. @elseif STM32L073xx
  935. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  936. @elseif STM32L083xx
  937. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  938. @elseif STM32L072xx
  939. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  940. @elseif STM32L082xx
  941. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  942. @elseif STM32L071xx
  943. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  944. @elseif STM32L081xx
  945. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  946. @elseif STM32L051xx
  947. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  948. @elseif STM32L053xx
  949. * @arg @ref RCC_MCO3 Clock source to output on MCO3 pin(PB13)
  950. @endif
  951. * @param RCC_MCOSource specifies the clock source to output.
  952. * This parameter can be one of the following values:
  953. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  954. * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock selected as MCO clock
  955. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  956. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  957. * @arg @ref RCC_MCO1SOURCE_MSI MSI oscillator clock selected as MCO clock
  958. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock selected as MCO clock
  959. * @arg @ref RCC_MCO1SOURCE_LSI LSI clock selected as MCO clock
  960. * @arg @ref RCC_MCO1SOURCE_LSE LSE clock selected as MCO clock
  961. @if STM32L052xx
  962. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  963. @elseif STM32L053xx
  964. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  965. @elseif STM32L062xx
  966. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  967. @elseif STM32L063xx
  968. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  969. @elseif STM32L072xx
  970. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  971. @elseif STM32L073xx
  972. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  973. @elseif STM32L082xx
  974. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  975. @elseif STM32L083xx
  976. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 clock selected as MCO clock
  977. @endif
  978. * @param RCC_MCODiv specifies the MCO DIV.
  979. * This parameter can be one of the following values:
  980. * @arg @ref RCC_MCODIV_1 no division applied to MCO clock
  981. * @arg @ref RCC_MCODIV_2 division by 2 applied to MCO clock
  982. * @arg @ref RCC_MCODIV_4 division by 4 applied to MCO clock
  983. * @arg @ref RCC_MCODIV_8 division by 8 applied to MCO clock
  984. * @arg @ref RCC_MCODIV_16 division by 16 applied to MCO clock
  985. * @retval None
  986. */
  987. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
  988. {
  989. GPIO_InitTypeDef gpio = {0};
  990. /* Check the parameters */
  991. assert_param(IS_RCC_MCO(RCC_MCOx));
  992. assert_param(IS_RCC_MCODIV(RCC_MCODiv));
  993. assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
  994. /* Configure the MCO1 pin in alternate function mode */
  995. gpio.Mode = GPIO_MODE_AF_PP;
  996. gpio.Speed = GPIO_SPEED_FREQ_HIGH;
  997. gpio.Pull = GPIO_NOPULL;
  998. if(RCC_MCOx == RCC_MCO1)
  999. {
  1000. gpio.Pin = MCO1_PIN;
  1001. gpio.Alternate = GPIO_AF0_MCO;
  1002. /* MCO1 Clock Enable */
  1003. MCO1_CLK_ENABLE();
  1004. HAL_GPIO_Init(MCO1_GPIO_PORT, &gpio);
  1005. }
  1006. #if defined(RCC_MCO3_SUPPORT)
  1007. else if (RCC_MCOx == RCC_MCO3)
  1008. {
  1009. gpio.Pin = MCO3_PIN;
  1010. gpio.Alternate = MCO3_GPIO_AF;
  1011. /* MCO3 Clock Enable */
  1012. MCO3_CLK_ENABLE();
  1013. HAL_GPIO_Init(MCO3_GPIO_PORT, &gpio);
  1014. }
  1015. #endif /* RCC_MCO3_SUPPORT */
  1016. else
  1017. {
  1018. gpio.Pin = MCO2_PIN;
  1019. gpio.Alternate = GPIO_AF0_MCO;
  1020. /* MCO2 Clock Enable */
  1021. MCO2_CLK_ENABLE();
  1022. HAL_GPIO_Init(MCO2_GPIO_PORT, &gpio);
  1023. }
  1024. /* Configure the MCO clock source */
  1025. __HAL_RCC_MCO1_CONFIG(RCC_MCOSource, RCC_MCODiv);
  1026. }
  1027. #if defined(RCC_HSECSS_SUPPORT)
  1028. /**
  1029. * @brief Enables the Clock Security System.
  1030. * @note If a failure is detected on the HSE oscillator clock, this oscillator
  1031. * is automatically disabled and an interrupt is generated to inform the
  1032. * software about the failure (Clock Security System Interrupt, CSSI),
  1033. * allowing the MCU to perform rescue operations. The CSSI is linked to
  1034. * the Cortex-M0+ NMI (Non-Maskable Interrupt) exception vector.
  1035. * @retval None
  1036. */
  1037. void HAL_RCC_EnableCSS(void)
  1038. {
  1039. SET_BIT(RCC->CR, RCC_CR_CSSON) ;
  1040. }
  1041. #endif /* RCC_HSECSS_SUPPORT */
  1042. /**
  1043. * @brief Returns the SYSCLK frequency
  1044. * @note The system frequency computed by this function is not the real
  1045. * frequency in the chip. It is calculated based on the predefined
  1046. * constant and the selected clock source:
  1047. * @note If SYSCLK source is MSI, function returns a value based on MSI
  1048. * Value as defined by the MSI range.
  1049. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
  1050. * @note If SYSCLK source is HSE, function returns a value based on HSE_VALUE(**)
  1051. * @note If SYSCLK source is PLL, function returns a value based on HSE_VALUE(**)
  1052. * or HSI_VALUE(*) multiplied/divided by the PLL factors.
  1053. * @note (*) HSI_VALUE is a constant defined in stm32l0xx_hal_conf.h file (default value
  1054. * 16 MHz) but the real value may vary depending on the variations
  1055. * in voltage and temperature.
  1056. * @note (**) HSE_VALUE is a constant defined in stm32l0xx_hal_conf.h file (default value
  1057. * 8 MHz), user has to ensure that HSE_VALUE is same as the real
  1058. * frequency of the crystal used. Otherwise, this function may
  1059. * have wrong result.
  1060. *
  1061. * @note The result of this function could be not correct when using fractional
  1062. * value for HSE crystal.
  1063. *
  1064. * @note This function can be used by the user application to compute the
  1065. * baud-rate for the communication peripherals or configure other parameters.
  1066. *
  1067. * @note Each time SYSCLK changes, this function must be called to update the
  1068. * right SYSCLK value. Otherwise, any configuration based on this function will be incorrect.
  1069. *
  1070. * @retval SYSCLK frequency
  1071. */
  1072. uint32_t HAL_RCC_GetSysClockFreq(void)
  1073. {
  1074. uint32_t tmpreg, pllm, plld, pllvco, msiclkrange; /* no init needed */
  1075. uint32_t sysclockfreq;
  1076. tmpreg = RCC->CFGR;
  1077. /* Get SYSCLK source -------------------------------------------------------*/
  1078. switch (tmpreg & RCC_CFGR_SWS)
  1079. {
  1080. case RCC_SYSCLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
  1081. {
  1082. if ((RCC->CR & RCC_CR_HSIDIVF) != 0U)
  1083. {
  1084. sysclockfreq = (HSI_VALUE >> 2);
  1085. }
  1086. else
  1087. {
  1088. sysclockfreq = HSI_VALUE;
  1089. }
  1090. break;
  1091. }
  1092. case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock */
  1093. {
  1094. sysclockfreq = HSE_VALUE;
  1095. break;
  1096. }
  1097. case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock */
  1098. {
  1099. pllm = PLLMulTable[(uint32_t)(tmpreg & RCC_CFGR_PLLMUL) >> RCC_CFGR_PLLMUL_Pos];
  1100. plld = ((uint32_t)(tmpreg & RCC_CFGR_PLLDIV) >> RCC_CFGR_PLLDIV_Pos) + 1U;
  1101. if (__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI)
  1102. {
  1103. /* HSE used as PLL clock source */
  1104. pllvco = (uint32_t)(((uint64_t)HSE_VALUE * (uint64_t)pllm) / (uint64_t)plld);
  1105. }
  1106. else
  1107. {
  1108. if ((RCC->CR & RCC_CR_HSIDIVF) != 0U)
  1109. {
  1110. pllvco = (uint32_t)((((uint64_t)(HSI_VALUE >> 2)) * (uint64_t)pllm) / (uint64_t)plld);
  1111. }
  1112. else
  1113. {
  1114. pllvco = (uint32_t)(((uint64_t)HSI_VALUE * (uint64_t)pllm) / (uint64_t)plld);
  1115. }
  1116. }
  1117. sysclockfreq = pllvco;
  1118. break;
  1119. }
  1120. case RCC_SYSCLKSOURCE_STATUS_MSI: /* MSI used as system clock source */
  1121. default: /* MSI used as system clock */
  1122. {
  1123. msiclkrange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> RCC_ICSCR_MSIRANGE_Pos;
  1124. sysclockfreq = (32768U * (1UL << (msiclkrange + 1U)));
  1125. break;
  1126. }
  1127. }
  1128. return sysclockfreq;
  1129. }
  1130. /**
  1131. * @brief Returns the HCLK frequency
  1132. * @note Each time HCLK changes, this function must be called to update the
  1133. * right HCLK value. Otherwise, any configuration based on this function will be incorrect.
  1134. *
  1135. * @note The SystemCoreClock CMSIS variable is used to store System Clock Frequency
  1136. * and updated within this function
  1137. * @retval HCLK frequency
  1138. */
  1139. uint32_t HAL_RCC_GetHCLKFreq(void)
  1140. {
  1141. return SystemCoreClock;
  1142. }
  1143. /**
  1144. * @brief Returns the PCLK1 frequency
  1145. * @note Each time PCLK1 changes, this function must be called to update the
  1146. * right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
  1147. * @retval PCLK1 frequency
  1148. */
  1149. uint32_t HAL_RCC_GetPCLK1Freq(void)
  1150. {
  1151. /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
  1152. return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1) >> RCC_CFGR_PPRE1_Pos]);
  1153. }
  1154. /**
  1155. * @brief Returns the PCLK2 frequency
  1156. * @note Each time PCLK2 changes, this function must be called to update the
  1157. * right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
  1158. * @retval PCLK2 frequency
  1159. */
  1160. uint32_t HAL_RCC_GetPCLK2Freq(void)
  1161. {
  1162. /* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
  1163. return (HAL_RCC_GetHCLKFreq()>> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2) >> RCC_CFGR_PPRE2_Pos]);
  1164. }
  1165. /**
  1166. * @brief Configures the RCC_OscInitStruct according to the internal
  1167. * RCC configuration registers.
  1168. * @param RCC_OscInitStruct pointer to an RCC_OscInitTypeDef structure that
  1169. * will be configured.
  1170. * @retval None
  1171. */
  1172. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
  1173. {
  1174. /* Check the parameters */
  1175. assert_param(RCC_OscInitStruct != (void *)NULL);
  1176. /* Set all possible values for the Oscillator type parameter ---------------*/
  1177. RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI \
  1178. | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_MSI;
  1179. #if defined(RCC_HSI48_SUPPORT)
  1180. RCC_OscInitStruct->OscillatorType |= RCC_OSCILLATORTYPE_HSI48;
  1181. #endif /* RCC_HSI48_SUPPORT */
  1182. /* Get the HSE configuration -----------------------------------------------*/
  1183. if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
  1184. {
  1185. RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
  1186. }
  1187. else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
  1188. {
  1189. RCC_OscInitStruct->HSEState = RCC_HSE_ON;
  1190. }
  1191. else
  1192. {
  1193. RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
  1194. }
  1195. /* Get the HSI configuration -----------------------------------------------*/
  1196. if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
  1197. {
  1198. RCC_OscInitStruct->HSIState = RCC_HSI_ON;
  1199. }
  1200. else
  1201. {
  1202. RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
  1203. }
  1204. RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->ICSCR & RCC_ICSCR_HSITRIM) >> 8);
  1205. /* Get the MSI configuration -----------------------------------------------*/
  1206. if((RCC->CR &RCC_CR_MSION) == RCC_CR_MSION)
  1207. {
  1208. RCC_OscInitStruct->MSIState = RCC_MSI_ON;
  1209. }
  1210. else
  1211. {
  1212. RCC_OscInitStruct->MSIState = RCC_MSI_OFF;
  1213. }
  1214. RCC_OscInitStruct->MSICalibrationValue = (uint32_t)((RCC->ICSCR & RCC_ICSCR_MSITRIM) >> RCC_ICSCR_MSITRIM_Pos);
  1215. RCC_OscInitStruct->MSIClockRange = (uint32_t)((RCC->ICSCR & RCC_ICSCR_MSIRANGE));
  1216. /* Get the LSE configuration -----------------------------------------------*/
  1217. if((RCC->CSR &RCC_CSR_LSEBYP) == RCC_CSR_LSEBYP)
  1218. {
  1219. RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
  1220. }
  1221. else if((RCC->CSR &RCC_CSR_LSEON) == RCC_CSR_LSEON)
  1222. {
  1223. RCC_OscInitStruct->LSEState = RCC_LSE_ON;
  1224. }
  1225. else
  1226. {
  1227. RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
  1228. }
  1229. /* Get the LSI configuration -----------------------------------------------*/
  1230. if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
  1231. {
  1232. RCC_OscInitStruct->LSIState = RCC_LSI_ON;
  1233. }
  1234. else
  1235. {
  1236. RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
  1237. }
  1238. #if defined(RCC_HSI48_SUPPORT)
  1239. /* Get the HSI48 configuration if any-----------------------------------------*/
  1240. RCC_OscInitStruct->HSI48State = __HAL_RCC_GET_HSI48_STATE();
  1241. #endif /* RCC_HSI48_SUPPORT */
  1242. /* Get the PLL configuration -----------------------------------------------*/
  1243. if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
  1244. {
  1245. RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
  1246. }
  1247. else
  1248. {
  1249. RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
  1250. }
  1251. RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLSRC);
  1252. RCC_OscInitStruct->PLL.PLLMUL = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLMUL);
  1253. RCC_OscInitStruct->PLL.PLLDIV = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLDIV);
  1254. }
  1255. /**
  1256. * @brief Get the RCC_ClkInitStruct according to the internal
  1257. * RCC configuration registers.
  1258. * @param RCC_ClkInitStruct pointer to an RCC_ClkInitTypeDef structure that
  1259. * contains the current clock configuration.
  1260. * @param pFLatency Pointer on the Flash Latency.
  1261. * @retval None
  1262. */
  1263. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
  1264. {
  1265. /* Check the parameters */
  1266. assert_param(RCC_ClkInitStruct != (void *)NULL);
  1267. assert_param(pFLatency != (void *)NULL);
  1268. /* Set all possible values for the Clock type parameter --------------------*/
  1269. RCC_ClkInitStruct->ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  1270. /* Get the SYSCLK configuration --------------------------------------------*/
  1271. RCC_ClkInitStruct->SYSCLKSource = (uint32_t)(RCC->CFGR & RCC_CFGR_SW);
  1272. /* Get the HCLK configuration ----------------------------------------------*/
  1273. RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_HPRE);
  1274. /* Get the APB1 configuration ----------------------------------------------*/
  1275. RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_PPRE1);
  1276. /* Get the APB2 configuration ----------------------------------------------*/
  1277. RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3);
  1278. /* Get the Flash Wait State (Latency) configuration ------------------------*/
  1279. *pFLatency = __HAL_FLASH_GET_LATENCY();
  1280. }
  1281. #if defined(RCC_HSECSS_SUPPORT)
  1282. /**
  1283. * @brief This function handles the RCC CSS interrupt request.
  1284. * @note This API should be called under the NMI_Handler().
  1285. * @retval None
  1286. */
  1287. void HAL_RCC_NMI_IRQHandler(void)
  1288. {
  1289. /* Check RCC CSSF flag */
  1290. if(__HAL_RCC_GET_IT(RCC_IT_CSS))
  1291. {
  1292. /* RCC Clock Security System interrupt user callback */
  1293. HAL_RCC_CSSCallback();
  1294. /* Clear RCC CSS pending bit */
  1295. __HAL_RCC_CLEAR_IT(RCC_IT_CSS);
  1296. }
  1297. }
  1298. /**
  1299. * @brief RCC Clock Security System interrupt callback
  1300. * @retval none
  1301. */
  1302. __weak void HAL_RCC_CSSCallback(void)
  1303. {
  1304. /* NOTE : This function Should not be modified, when the callback is needed,
  1305. the HAL_RCC_CSSCallback could be implemented in the user file
  1306. */
  1307. }
  1308. #endif /* RCC_HSECSS_SUPPORT */
  1309. /**
  1310. * @}
  1311. */
  1312. /**
  1313. * @}
  1314. */
  1315. /* Private function prototypes -----------------------------------------------*/
  1316. /** @addtogroup RCC_Private_Functions
  1317. * @{
  1318. */
  1319. /**
  1320. * @}
  1321. */
  1322. #endif /* HAL_RCC_MODULE_ENABLED */
  1323. /**
  1324. * @}
  1325. */
  1326. /**
  1327. * @}
  1328. */