stm32h7xx_hal_rcc.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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 Internal High Speed oscillator
  17. (HSI 64MHz) with Flash 0 wait state,and all peripherals are off except
  18. internal SRAM, Flash, JTAG and PWR
  19. (+) There is no pre-scaler on High speed (AHB) and Low speed (APB) buses;
  20. all peripherals mapped on these buses are running at HSI speed.
  21. (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
  22. (+) All GPIOs are in analogue mode , except the JTAG pins which
  23. are assigned to be used for debug purpose.
  24. [..]
  25. Once the device started from reset, the user application has to:
  26. (+) Configure the clock source to be used to drive the System clock
  27. (if the application needs higher frequency/performance)
  28. (+) Configure the System clock frequency and Flash settings
  29. (+) Configure the AHB and APB buses pre-scalers
  30. (+) Enable the clock for the peripheral(s) to be used
  31. (+) Configure the clock kernel source(s) for peripherals which clocks are not
  32. derived from the System clock through :RCC_D1CCIPR,RCC_D2CCIP1R,RCC_D2CCIP2R
  33. and RCC_D3CCIPR registers
  34. ##### RCC Limitations #####
  35. ==============================================================================
  36. [..]
  37. A delay between an RCC peripheral clock enable and the effective peripheral
  38. enabling should be taken into account in order to manage the peripheral read/write
  39. from/to registers.
  40. (+) This delay depends on the peripheral mapping.
  41. (+) If peripheral is mapped on AHB: the delay is 2 AHB clock cycle
  42. after the clock enable bit is set on the hardware register
  43. (+) If peripheral is mapped on APB: the delay is 2 APB clock cycle
  44. after the clock enable bit is set on the hardware register
  45. [..]
  46. Implemented Workaround:
  47. (+) For AHB & APB peripherals, a dummy read to the peripheral register has been
  48. inserted in each __HAL_RCC_PPP_CLK_ENABLE() macro.
  49. @endverbatim
  50. ******************************************************************************
  51. * @attention
  52. *
  53. * Copyright (c) 2017 STMicroelectronics.
  54. * All rights reserved.
  55. *
  56. * This software is licensed under terms that can be found in the LICENSE file in
  57. * the root directory of this software component.
  58. * If no LICENSE file comes with this software, it is provided AS-IS.
  59. ******************************************************************************
  60. */
  61. /* Includes ------------------------------------------------------------------*/
  62. #include "stm32h7xx_hal.h"
  63. /** @addtogroup STM32H7xx_HAL_Driver
  64. * @{
  65. */
  66. /** @defgroup RCC RCC
  67. * @brief RCC HAL module driver
  68. * @{
  69. */
  70. #ifdef HAL_RCC_MODULE_ENABLED
  71. /* Private typedef -----------------------------------------------------------*/
  72. /* Private define ------------------------------------------------------------*/
  73. /* Private macro -------------------------------------------------------------*/
  74. /** @defgroup RCC_Private_Macros RCC Private Macros
  75. * @{
  76. */
  77. #define MCO1_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  78. #define MCO1_GPIO_PORT GPIOA
  79. #define MCO1_PIN GPIO_PIN_8
  80. #define MCO2_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  81. #define MCO2_GPIO_PORT GPIOC
  82. #define MCO2_PIN GPIO_PIN_9
  83. /**
  84. * @}
  85. */
  86. /* Private variables ---------------------------------------------------------*/
  87. /** @defgroup RCC_Private_Variables RCC Private Variables
  88. * @{
  89. */
  90. /**
  91. * @}
  92. */
  93. /* Private function prototypes -----------------------------------------------*/
  94. /* Exported functions --------------------------------------------------------*/
  95. /** @defgroup RCC_Exported_Functions RCC Exported Functions
  96. * @{
  97. */
  98. /** @defgroup RCC_Exported_Functions_Group1 Initialization and de-initialization functions
  99. * @brief Initialization and Configuration functions
  100. *
  101. @verbatim
  102. ===============================================================================
  103. ##### Initialization and de-initialization functions #####
  104. ===============================================================================
  105. [..]
  106. This section provides functions allowing to configure the internal/external oscillators
  107. (HSE, HSI, LSE,CSI, LSI,HSI48, PLL, CSS and MCO) and the System buses clocks (SYSCLK, AHB3, AHB1
  108. AHB2,AHB4,APB3, APB1L, APB1H, APB2, and APB4).
  109. [..] Internal/external clock and PLL configuration
  110. (#) HSI (high-speed internal), 64 MHz factory-trimmed RC used directly or through
  111. the PLL as System clock source.
  112. (#) CSI is a low-power RC oscillator which can be used directly as system clock, peripheral
  113. clock, or PLL input.But even with frequency calibration, is less accurate than an
  114. external crystal oscillator or ceramic resonator.
  115. (#) LSI (low-speed internal), 32 KHz low consumption RC used as IWDG and/or RTC
  116. clock source.
  117. (#) HSE (high-speed external), 4 to 48 MHz crystal oscillator used directly or
  118. through the PLL as System clock source. Can be used also as RTC clock source.
  119. (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
  120. (#) PLL , The RCC features three independent PLLs (clocked by HSI , HSE or CSI),
  121. featuring three different output clocks and able to work either in integer or Fractional mode.
  122. (++) A main PLL, PLL1, which is generally used to provide clocks to the CPU
  123. and to some peripherals.
  124. (++) Two dedicated PLLs, PLL2 and PLL3, which are used to generate the kernel clock for peripherals.
  125. (#) CSS (Clock security system), once enabled and if a HSE clock failure occurs
  126. (HSE used directly or through PLL as System clock source), the System clock
  127. is automatically switched to HSI and an interrupt is generated if enabled.
  128. The interrupt is linked to the Cortex-M NMI (Non-Mask-able Interrupt)
  129. exception vector.
  130. (#) MCO1 (micro controller clock output), used to output HSI, LSE, HSE, PLL1(PLL1_Q)
  131. or HSI48 clock (through a configurable pre-scaler) on PA8 pin.
  132. (#) MCO2 (micro controller clock output), used to output HSE, PLL2(PLL2_P), SYSCLK,
  133. LSI, CSI, or PLL1(PLL1_P) clock (through a configurable pre-scaler) on PC9 pin.
  134. [..] System, AHB and APB buses clocks configuration
  135. (#) Several clock sources can be used to drive the System clock (SYSCLK): CSI,HSI,
  136. HSE and PLL.
  137. The AHB clock (HCLK) is derived from System core clock through configurable
  138. pre-scaler and used to clock the CPU, memory and peripherals mapped
  139. on AHB and APB bus of the 3 Domains (D1, D2, D3)* through configurable pre-scalers
  140. and used to clock the peripherals mapped on these buses. You can use
  141. "HAL_RCC_GetSysClockFreq()" function to retrieve system clock frequency.
  142. -@- All the peripheral clocks are derived from the System clock (SYSCLK) except those
  143. with dual clock domain where kernel source clock could be selected through
  144. RCC_D1CCIPR,RCC_D2CCIP1R,RCC_D2CCIP2R and RCC_D3CCIPR registers.
  145. (*) : 2 Domains (CD and SRD) for stm32h7a3xx and stm32h7b3xx family lines.
  146. @endverbatim
  147. * @{
  148. */
  149. /**
  150. * @brief Resets the RCC clock configuration to the default reset state.
  151. * @note The default reset state of the clock configuration is given below:
  152. * - HSI ON and used as system clock source
  153. * - HSE, PLL1, PLL2 and PLL3 OFF
  154. * - AHB, APB Bus pre-scaler set to 1.
  155. * - CSS, MCO1 and MCO2 OFF
  156. * - All interrupts disabled
  157. * @note This function doesn't modify the configuration of the
  158. * - Peripheral clocks
  159. * - LSI, LSE and RTC clocks
  160. * @retval HAL status
  161. */
  162. HAL_StatusTypeDef HAL_RCC_DeInit(void)
  163. {
  164. uint32_t tickstart;
  165. /* Increasing the CPU frequency */
  166. if (FLASH_LATENCY_DEFAULT > __HAL_FLASH_GET_LATENCY())
  167. {
  168. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  169. __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_DEFAULT);
  170. /* Check that the new number of wait states is taken into account to access the Flash
  171. memory by reading the FLASH_ACR register */
  172. if (__HAL_FLASH_GET_LATENCY() != FLASH_LATENCY_DEFAULT)
  173. {
  174. return HAL_ERROR;
  175. }
  176. }
  177. /* Get Start Tick */
  178. tickstart = HAL_GetTick();
  179. /* Set HSION bit */
  180. SET_BIT(RCC->CR, RCC_CR_HSION);
  181. /* Wait till HSI is ready */
  182. while (READ_BIT(RCC->CR, RCC_CR_HSIRDY) == 0U)
  183. {
  184. if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE)
  185. {
  186. return HAL_TIMEOUT;
  187. }
  188. }
  189. /* Set HSITRIM[6:0] bits to the reset value */
  190. SET_BIT(RCC->HSICFGR, RCC_HSICFGR_HSITRIM_6);
  191. /* Reset CFGR register */
  192. CLEAR_REG(RCC->CFGR);
  193. /* Update the SystemCoreClock and SystemD2Clock global variables */
  194. SystemCoreClock = HSI_VALUE;
  195. SystemD2Clock = HSI_VALUE;
  196. /* Adapt Systick interrupt period */
  197. if (HAL_InitTick(uwTickPrio) != HAL_OK)
  198. {
  199. return HAL_ERROR;
  200. }
  201. /* Get Start Tick */
  202. tickstart = HAL_GetTick();
  203. /* Wait till clock switch is ready */
  204. while (READ_BIT(RCC->CFGR, RCC_CFGR_SWS) != 0U)
  205. {
  206. if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
  207. {
  208. return HAL_TIMEOUT;
  209. }
  210. }
  211. /* Get Start Tick */
  212. tickstart = HAL_GetTick();
  213. /* Reset CSION, CSIKERON, HSEON, HSI48ON, HSECSSON, HSIDIV bits */
  214. CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_HSIKERON | RCC_CR_HSIDIV | RCC_CR_HSIDIVF | RCC_CR_CSION | RCC_CR_CSIKERON \
  215. | RCC_CR_HSI48ON | RCC_CR_CSSHSEON);
  216. /* Wait till HSE is disabled */
  217. while (READ_BIT(RCC->CR, RCC_CR_HSERDY) != 0U)
  218. {
  219. if ((HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
  220. {
  221. return HAL_TIMEOUT;
  222. }
  223. }
  224. /* Get Start Tick */
  225. tickstart = HAL_GetTick();
  226. /* Clear PLLON bit */
  227. CLEAR_BIT(RCC->CR, RCC_CR_PLL1ON);
  228. /* Wait till PLL is disabled */
  229. while (READ_BIT(RCC->CR, RCC_CR_PLL1RDY) != 0U)
  230. {
  231. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  232. {
  233. return HAL_TIMEOUT;
  234. }
  235. }
  236. /* Get Start Tick */
  237. tickstart = HAL_GetTick();
  238. /* Reset PLL2ON bit */
  239. CLEAR_BIT(RCC->CR, RCC_CR_PLL2ON);
  240. /* Wait till PLL2 is disabled */
  241. while (READ_BIT(RCC->CR, RCC_CR_PLL2RDY) != 0U)
  242. {
  243. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  244. {
  245. return HAL_TIMEOUT;
  246. }
  247. }
  248. /* Get Start Tick */
  249. tickstart = HAL_GetTick();
  250. /* Reset PLL3 bit */
  251. CLEAR_BIT(RCC->CR, RCC_CR_PLL3ON);
  252. /* Wait till PLL3 is disabled */
  253. while (READ_BIT(RCC->CR, RCC_CR_PLL3RDY) != 0U)
  254. {
  255. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  256. {
  257. return HAL_TIMEOUT;
  258. }
  259. }
  260. #if defined(RCC_D1CFGR_HPRE)
  261. /* Reset D1CFGR register */
  262. CLEAR_REG(RCC->D1CFGR);
  263. /* Reset D2CFGR register */
  264. CLEAR_REG(RCC->D2CFGR);
  265. /* Reset D3CFGR register */
  266. CLEAR_REG(RCC->D3CFGR);
  267. #else
  268. /* Reset CDCFGR1 register */
  269. CLEAR_REG(RCC->CDCFGR1);
  270. /* Reset CDCFGR2 register */
  271. CLEAR_REG(RCC->CDCFGR2);
  272. /* Reset SRDCFGR register */
  273. CLEAR_REG(RCC->SRDCFGR);
  274. #endif
  275. /* Reset PLLCKSELR register to default value */
  276. RCC->PLLCKSELR = RCC_PLLCKSELR_DIVM1_5 | RCC_PLLCKSELR_DIVM2_5 | RCC_PLLCKSELR_DIVM3_5;
  277. /* Reset PLLCFGR register to default value */
  278. WRITE_REG(RCC->PLLCFGR, 0x01FF0000U);
  279. /* Reset PLL1DIVR register to default value */
  280. WRITE_REG(RCC->PLL1DIVR, 0x01010280U);
  281. /* Reset PLL1FRACR register */
  282. CLEAR_REG(RCC->PLL1FRACR);
  283. /* Reset PLL2DIVR register to default value */
  284. WRITE_REG(RCC->PLL2DIVR, 0x01010280U);
  285. /* Reset PLL2FRACR register */
  286. CLEAR_REG(RCC->PLL2FRACR);
  287. /* Reset PLL3DIVR register to default value */
  288. WRITE_REG(RCC->PLL3DIVR, 0x01010280U);
  289. /* Reset PLL3FRACR register */
  290. CLEAR_REG(RCC->PLL3FRACR);
  291. #if defined(RCC_CR_HSEEXT)
  292. /* Reset HSEEXT */
  293. CLEAR_BIT(RCC->CR, RCC_CR_HSEEXT);
  294. #endif /* RCC_CR_HSEEXT */
  295. /* Reset HSEBYP bit */
  296. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);
  297. /* Disable all interrupts */
  298. CLEAR_REG(RCC->CIER);
  299. /* Clear all interrupts flags */
  300. WRITE_REG(RCC->CICR, 0xFFFFFFFFU);
  301. /* Reset all RSR flags */
  302. SET_BIT(RCC->RSR, RCC_RSR_RMVF);
  303. /* Decreasing the number of wait states because of lower CPU frequency */
  304. if (FLASH_LATENCY_DEFAULT < __HAL_FLASH_GET_LATENCY())
  305. {
  306. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  307. __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_DEFAULT);
  308. /* Check that the new number of wait states is taken into account to access the Flash
  309. memory by reading the FLASH_ACR register */
  310. if (__HAL_FLASH_GET_LATENCY() != FLASH_LATENCY_DEFAULT)
  311. {
  312. return HAL_ERROR;
  313. }
  314. }
  315. return HAL_OK;
  316. }
  317. /**
  318. * @brief Initializes the RCC Oscillators according to the specified parameters in the
  319. * RCC_OscInitTypeDef.
  320. * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that
  321. * contains the configuration information for the RCC Oscillators.
  322. * @note The PLL is not disabled when used as system clock.
  323. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not
  324. * supported by this function. User should request a transition to LSE Off
  325. * first and then LSE On or LSE Bypass.
  326. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  327. * supported by this function. User should request a transition to HSE Off
  328. * first and then HSE On or HSE Bypass.
  329. * @retval HAL status
  330. */
  331. __weak HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
  332. {
  333. uint32_t tickstart;
  334. uint32_t temp1_pllckcfg, temp2_pllckcfg;
  335. /* Check Null pointer */
  336. if (RCC_OscInitStruct == NULL)
  337. {
  338. return HAL_ERROR;
  339. }
  340. /* Check the parameters */
  341. assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
  342. /*------------------------------- HSE Configuration ------------------------*/
  343. if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
  344. {
  345. /* Check the parameters */
  346. assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
  347. const uint32_t temp_sysclksrc = __HAL_RCC_GET_SYSCLK_SOURCE();
  348. const uint32_t temp_pllckselr = RCC->PLLCKSELR;
  349. /* When the HSE is used as system clock or clock source for PLL in these cases HSE will not disabled */
  350. if ((temp_sysclksrc == RCC_CFGR_SWS_HSE) || ((temp_sysclksrc == RCC_CFGR_SWS_PLL1) && ((temp_pllckselr & RCC_PLLCKSELR_PLLSRC) == RCC_PLLCKSELR_PLLSRC_HSE)))
  351. {
  352. if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != 0U) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
  353. {
  354. return HAL_ERROR;
  355. }
  356. }
  357. else
  358. {
  359. /* Set the new HSE configuration ---------------------------------------*/
  360. __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
  361. /* Check the HSE State */
  362. if (RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
  363. {
  364. /* Get Start Tick*/
  365. tickstart = HAL_GetTick();
  366. /* Wait till HSE is ready */
  367. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
  368. {
  369. if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
  370. {
  371. return HAL_TIMEOUT;
  372. }
  373. }
  374. }
  375. else
  376. {
  377. /* Get Start Tick*/
  378. tickstart = HAL_GetTick();
  379. /* Wait till HSE is disabled */
  380. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != 0U)
  381. {
  382. if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
  383. {
  384. return HAL_TIMEOUT;
  385. }
  386. }
  387. }
  388. }
  389. }
  390. /*----------------------------- HSI Configuration --------------------------*/
  391. if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
  392. {
  393. /* Check the parameters */
  394. assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
  395. assert_param(IS_RCC_HSICALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
  396. /* When the HSI is used as system clock it will not be disabled */
  397. const uint32_t temp_sysclksrc = __HAL_RCC_GET_SYSCLK_SOURCE();
  398. const uint32_t temp_pllckselr = RCC->PLLCKSELR;
  399. if ((temp_sysclksrc == RCC_CFGR_SWS_HSI) || ((temp_sysclksrc == RCC_CFGR_SWS_PLL1) && ((temp_pllckselr & RCC_PLLCKSELR_PLLSRC) == RCC_PLLCKSELR_PLLSRC_HSI)))
  400. {
  401. /* When HSI is used as system clock it will not be disabled */
  402. if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != 0U) && (RCC_OscInitStruct->HSIState == RCC_HSI_OFF))
  403. {
  404. return HAL_ERROR;
  405. }
  406. /* Otherwise, only HSI division and calibration are allowed */
  407. else
  408. {
  409. /* Enable the Internal High Speed oscillator (HSI, HSIDIV2, HSIDIV4, or HSIDIV8) */
  410. __HAL_RCC_HSI_CONFIG(RCC_OscInitStruct->HSIState);
  411. /* Get Start Tick*/
  412. tickstart = HAL_GetTick();
  413. /* Wait till HSI is ready */
  414. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == 0U)
  415. {
  416. if ((uint32_t)(HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE)
  417. {
  418. return HAL_TIMEOUT;
  419. }
  420. }
  421. /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
  422. __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
  423. }
  424. }
  425. else
  426. {
  427. /* Check the HSI State */
  428. if ((RCC_OscInitStruct->HSIState) != RCC_HSI_OFF)
  429. {
  430. /* Enable the Internal High Speed oscillator (HSI, HSIDIV2,HSIDIV4, or HSIDIV8) */
  431. __HAL_RCC_HSI_CONFIG(RCC_OscInitStruct->HSIState);
  432. /* Get Start Tick*/
  433. tickstart = HAL_GetTick();
  434. /* Wait till HSI is ready */
  435. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == 0U)
  436. {
  437. if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE)
  438. {
  439. return HAL_TIMEOUT;
  440. }
  441. }
  442. /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
  443. __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
  444. }
  445. else
  446. {
  447. /* Disable the Internal High Speed oscillator (HSI). */
  448. __HAL_RCC_HSI_DISABLE();
  449. /* Get Start Tick*/
  450. tickstart = HAL_GetTick();
  451. /* Wait till HSI is disabled */
  452. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != 0U)
  453. {
  454. if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE)
  455. {
  456. return HAL_TIMEOUT;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. /*----------------------------- CSI Configuration --------------------------*/
  463. if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_CSI) == RCC_OSCILLATORTYPE_CSI)
  464. {
  465. /* Check the parameters */
  466. assert_param(IS_RCC_CSI(RCC_OscInitStruct->CSIState));
  467. assert_param(IS_RCC_CSICALIBRATION_VALUE(RCC_OscInitStruct->CSICalibrationValue));
  468. /* When the CSI is used as system clock it will not disabled */
  469. const uint32_t temp_sysclksrc = __HAL_RCC_GET_SYSCLK_SOURCE();
  470. const uint32_t temp_pllckselr = RCC->PLLCKSELR;
  471. if ((temp_sysclksrc == RCC_CFGR_SWS_CSI) || ((temp_sysclksrc == RCC_CFGR_SWS_PLL1) && ((temp_pllckselr & RCC_PLLCKSELR_PLLSRC) == RCC_PLLCKSELR_PLLSRC_CSI)))
  472. {
  473. /* When CSI is used as system clock it will not disabled */
  474. if ((__HAL_RCC_GET_FLAG(RCC_FLAG_CSIRDY) != 0U) && (RCC_OscInitStruct->CSIState != RCC_CSI_ON))
  475. {
  476. return HAL_ERROR;
  477. }
  478. /* Otherwise, just the calibration is allowed */
  479. else
  480. {
  481. /* Adjusts the Internal High Speed oscillator (CSI) calibration value.*/
  482. __HAL_RCC_CSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->CSICalibrationValue);
  483. }
  484. }
  485. else
  486. {
  487. /* Check the CSI State */
  488. if ((RCC_OscInitStruct->CSIState) != RCC_CSI_OFF)
  489. {
  490. /* Enable the Internal High Speed oscillator (CSI). */
  491. __HAL_RCC_CSI_ENABLE();
  492. /* Get Start Tick*/
  493. tickstart = HAL_GetTick();
  494. /* Wait till CSI is ready */
  495. while (__HAL_RCC_GET_FLAG(RCC_FLAG_CSIRDY) == 0U)
  496. {
  497. if ((HAL_GetTick() - tickstart) > CSI_TIMEOUT_VALUE)
  498. {
  499. return HAL_TIMEOUT;
  500. }
  501. }
  502. /* Adjusts the Internal High Speed oscillator (CSI) calibration value.*/
  503. __HAL_RCC_CSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->CSICalibrationValue);
  504. }
  505. else
  506. {
  507. /* Disable the Internal High Speed oscillator (CSI). */
  508. __HAL_RCC_CSI_DISABLE();
  509. /* Get Start Tick*/
  510. tickstart = HAL_GetTick();
  511. /* Wait till CSI is disabled */
  512. while (__HAL_RCC_GET_FLAG(RCC_FLAG_CSIRDY) != 0U)
  513. {
  514. if ((HAL_GetTick() - tickstart) > CSI_TIMEOUT_VALUE)
  515. {
  516. return HAL_TIMEOUT;
  517. }
  518. }
  519. }
  520. }
  521. }
  522. /*------------------------------ LSI Configuration -------------------------*/
  523. if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
  524. {
  525. /* Check the parameters */
  526. assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
  527. /* Check the LSI State */
  528. if ((RCC_OscInitStruct->LSIState) != RCC_LSI_OFF)
  529. {
  530. /* Enable the Internal Low Speed oscillator (LSI). */
  531. __HAL_RCC_LSI_ENABLE();
  532. /* Get Start Tick*/
  533. tickstart = HAL_GetTick();
  534. /* Wait till LSI is ready */
  535. while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == 0U)
  536. {
  537. if ((HAL_GetTick() - tickstart) > LSI_TIMEOUT_VALUE)
  538. {
  539. return HAL_TIMEOUT;
  540. }
  541. }
  542. }
  543. else
  544. {
  545. /* Disable the Internal Low Speed oscillator (LSI). */
  546. __HAL_RCC_LSI_DISABLE();
  547. /* Get Start Tick*/
  548. tickstart = HAL_GetTick();
  549. /* Wait till LSI is ready */
  550. while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != 0U)
  551. {
  552. if ((HAL_GetTick() - tickstart) > LSI_TIMEOUT_VALUE)
  553. {
  554. return HAL_TIMEOUT;
  555. }
  556. }
  557. }
  558. }
  559. /*------------------------------ HSI48 Configuration -------------------------*/
  560. if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI48) == RCC_OSCILLATORTYPE_HSI48)
  561. {
  562. /* Check the parameters */
  563. assert_param(IS_RCC_HSI48(RCC_OscInitStruct->HSI48State));
  564. /* Check the HSI48 State */
  565. if ((RCC_OscInitStruct->HSI48State) != RCC_HSI48_OFF)
  566. {
  567. /* Enable the Internal Low Speed oscillator (HSI48). */
  568. __HAL_RCC_HSI48_ENABLE();
  569. /* Get time-out */
  570. tickstart = HAL_GetTick();
  571. /* Wait till HSI48 is ready */
  572. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY) == 0U)
  573. {
  574. if ((HAL_GetTick() - tickstart) > HSI48_TIMEOUT_VALUE)
  575. {
  576. return HAL_TIMEOUT;
  577. }
  578. }
  579. }
  580. else
  581. {
  582. /* Disable the Internal Low Speed oscillator (HSI48). */
  583. __HAL_RCC_HSI48_DISABLE();
  584. /* Get time-out */
  585. tickstart = HAL_GetTick();
  586. /* Wait till HSI48 is ready */
  587. while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY) != 0U)
  588. {
  589. if ((HAL_GetTick() - tickstart) > HSI48_TIMEOUT_VALUE)
  590. {
  591. return HAL_TIMEOUT;
  592. }
  593. }
  594. }
  595. }
  596. /*------------------------------ LSE Configuration -------------------------*/
  597. if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
  598. {
  599. /* Check the parameters */
  600. assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
  601. /* Enable write access to Backup domain */
  602. PWR->CR1 |= PWR_CR1_DBP;
  603. /* Wait for Backup domain Write protection disable */
  604. tickstart = HAL_GetTick();
  605. while ((PWR->CR1 & PWR_CR1_DBP) == 0U)
  606. {
  607. if ((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  608. {
  609. return HAL_TIMEOUT;
  610. }
  611. }
  612. /* Set the new LSE configuration -----------------------------------------*/
  613. __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
  614. /* Check the LSE State */
  615. if ((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
  616. {
  617. /* Get Start Tick*/
  618. tickstart = HAL_GetTick();
  619. /* Wait till LSE is ready */
  620. while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == 0U)
  621. {
  622. if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
  623. {
  624. return HAL_TIMEOUT;
  625. }
  626. }
  627. }
  628. else
  629. {
  630. /* Get Start Tick*/
  631. tickstart = HAL_GetTick();
  632. /* Wait till LSE is disabled */
  633. while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != 0U)
  634. {
  635. if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
  636. {
  637. return HAL_TIMEOUT;
  638. }
  639. }
  640. }
  641. }
  642. /*-------------------------------- PLL Configuration -----------------------*/
  643. /* Check the parameters */
  644. assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
  645. if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
  646. {
  647. /* Check if the PLL is used as system clock or not */
  648. if (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL1)
  649. {
  650. if ((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
  651. {
  652. /* Check the parameters */
  653. assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
  654. assert_param(IS_RCC_PLLRGE_VALUE(RCC_OscInitStruct->PLL.PLLRGE));
  655. assert_param(IS_RCC_PLLVCO_VALUE(RCC_OscInitStruct->PLL.PLLVCOSEL));
  656. assert_param(IS_RCC_PLLM_VALUE(RCC_OscInitStruct->PLL.PLLM));
  657. assert_param(IS_RCC_PLLN_VALUE(RCC_OscInitStruct->PLL.PLLN));
  658. assert_param(IS_RCC_PLLP_VALUE(RCC_OscInitStruct->PLL.PLLP));
  659. assert_param(IS_RCC_PLLQ_VALUE(RCC_OscInitStruct->PLL.PLLQ));
  660. assert_param(IS_RCC_PLLR_VALUE(RCC_OscInitStruct->PLL.PLLR));
  661. assert_param(IS_RCC_PLLFRACN_VALUE(RCC_OscInitStruct->PLL.PLLFRACN));
  662. /* Disable the main PLL. */
  663. __HAL_RCC_PLL_DISABLE();
  664. /* Get Start Tick*/
  665. tickstart = HAL_GetTick();
  666. /* Wait till PLL is disabled */
  667. while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != 0U)
  668. {
  669. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  670. {
  671. return HAL_TIMEOUT;
  672. }
  673. }
  674. /* Configure the main PLL clock source, multiplication and division factors. */
  675. __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
  676. RCC_OscInitStruct->PLL.PLLM,
  677. RCC_OscInitStruct->PLL.PLLN,
  678. RCC_OscInitStruct->PLL.PLLP,
  679. RCC_OscInitStruct->PLL.PLLQ,
  680. RCC_OscInitStruct->PLL.PLLR);
  681. /* Disable PLLFRACN . */
  682. __HAL_RCC_PLLFRACN_DISABLE();
  683. /* Configure PLL PLL1FRACN */
  684. __HAL_RCC_PLLFRACN_CONFIG(RCC_OscInitStruct->PLL.PLLFRACN);
  685. /* Select PLL1 input reference frequency range: VCI */
  686. __HAL_RCC_PLL_VCIRANGE(RCC_OscInitStruct->PLL.PLLRGE) ;
  687. /* Select PLL1 output frequency range : VCO */
  688. __HAL_RCC_PLL_VCORANGE(RCC_OscInitStruct->PLL.PLLVCOSEL) ;
  689. /* Enable PLL System Clock output. */
  690. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVP);
  691. /* Enable PLL1Q Clock output. */
  692. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  693. /* Enable PLL1R Clock output. */
  694. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVR);
  695. /* Enable PLL1FRACN . */
  696. __HAL_RCC_PLLFRACN_ENABLE();
  697. /* Enable the main PLL. */
  698. __HAL_RCC_PLL_ENABLE();
  699. /* Get Start Tick*/
  700. tickstart = HAL_GetTick();
  701. /* Wait till PLL is ready */
  702. while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == 0U)
  703. {
  704. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  705. {
  706. return HAL_TIMEOUT;
  707. }
  708. }
  709. }
  710. else
  711. {
  712. /* Disable the main PLL. */
  713. __HAL_RCC_PLL_DISABLE();
  714. /* Get Start Tick*/
  715. tickstart = HAL_GetTick();
  716. /* Wait till PLL is disabled */
  717. while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != 0U)
  718. {
  719. if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
  720. {
  721. return HAL_TIMEOUT;
  722. }
  723. }
  724. }
  725. }
  726. else
  727. {
  728. /* Do not return HAL_ERROR if request repeats the current configuration */
  729. temp1_pllckcfg = RCC->PLLCKSELR;
  730. temp2_pllckcfg = RCC->PLL1DIVR;
  731. if (((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF) ||
  732. (READ_BIT(temp1_pllckcfg, RCC_PLLCKSELR_PLLSRC) != RCC_OscInitStruct->PLL.PLLSource) ||
  733. ((READ_BIT(temp1_pllckcfg, RCC_PLLCKSELR_DIVM1) >> RCC_PLLCKSELR_DIVM1_Pos) != RCC_OscInitStruct->PLL.PLLM) ||
  734. (READ_BIT(temp2_pllckcfg, RCC_PLL1DIVR_N1) != (RCC_OscInitStruct->PLL.PLLN - 1U)) ||
  735. ((READ_BIT(temp2_pllckcfg, RCC_PLL1DIVR_P1) >> RCC_PLL1DIVR_P1_Pos) != (RCC_OscInitStruct->PLL.PLLP - 1U)) ||
  736. ((READ_BIT(temp2_pllckcfg, RCC_PLL1DIVR_Q1) >> RCC_PLL1DIVR_Q1_Pos) != (RCC_OscInitStruct->PLL.PLLQ - 1U)) ||
  737. ((READ_BIT(temp2_pllckcfg, RCC_PLL1DIVR_R1) >> RCC_PLL1DIVR_R1_Pos) != (RCC_OscInitStruct->PLL.PLLR - 1U)))
  738. {
  739. return HAL_ERROR;
  740. }
  741. else
  742. {
  743. /* Check if only fractional part needs to be updated */
  744. temp1_pllckcfg = ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1) >> RCC_PLL1FRACR_FRACN1_Pos);
  745. if (RCC_OscInitStruct->PLL.PLLFRACN != temp1_pllckcfg)
  746. {
  747. assert_param(IS_RCC_PLLFRACN_VALUE(RCC_OscInitStruct->PLL.PLLFRACN));
  748. /* Disable PLL1FRACEN */
  749. __HAL_RCC_PLLFRACN_DISABLE();
  750. /* Get Start Tick*/
  751. tickstart = HAL_GetTick();
  752. /* Wait at least 2 CK_REF (PLL input source divided by M) period to make sure next latched value will be taken into account. */
  753. while ((HAL_GetTick() - tickstart) < PLL_FRAC_TIMEOUT_VALUE)
  754. {
  755. }
  756. /* Configure PLL1 PLL1FRACN */
  757. __HAL_RCC_PLLFRACN_CONFIG(RCC_OscInitStruct->PLL.PLLFRACN);
  758. /* Enable PLL1FRACEN to latch new value. */
  759. __HAL_RCC_PLLFRACN_ENABLE();
  760. }
  761. }
  762. }
  763. }
  764. return HAL_OK;
  765. }
  766. /**
  767. * @brief Initializes the CPU, AHB and APB buses clocks according to the specified
  768. * parameters in the RCC_ClkInitStruct.
  769. * @param RCC_ClkInitStruct: pointer to an RCC_OscInitTypeDef structure that
  770. * contains the configuration information for the RCC peripheral.
  771. * @param FLatency: FLASH Latency, this parameter depend on device selected
  772. *
  773. * @note The SystemCoreClock CMSIS variable is used to store System Core Clock Frequency
  774. * and updated by HAL_InitTick() function called within this function
  775. *
  776. * @note The HSI is used (enabled by hardware) as system clock source after
  777. * start-up from Reset, wake-up from STOP and STANDBY mode, or in case
  778. * of failure of the HSE used directly or indirectly as system clock
  779. * (if the Clock Security System CSS is enabled).
  780. *
  781. * @note A switch from one clock source to another occurs only if the target
  782. * clock source is ready (clock stable after start-up delay or PLL locked).
  783. * If a clock source which is not yet ready is selected, the switch will
  784. * occur when the clock source will be ready.
  785. * You can use HAL_RCC_GetClockConfig() function to know which clock is
  786. * currently used as system clock source.
  787. * @note Depending on the device voltage range, the software has to set correctly
  788. * D1CPRE[3:0] bits to ensure that Domain1 core clock not exceed the maximum allowed frequency
  789. * (for more details refer to section above "Initialization/de-initialization functions")
  790. * @retval None
  791. */
  792. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
  793. {
  794. HAL_StatusTypeDef halstatus;
  795. uint32_t tickstart;
  796. uint32_t common_system_clock;
  797. /* Check Null pointer */
  798. if (RCC_ClkInitStruct == NULL)
  799. {
  800. return HAL_ERROR;
  801. }
  802. /* Check the parameters */
  803. assert_param(IS_RCC_CLOCKTYPE(RCC_ClkInitStruct->ClockType));
  804. assert_param(IS_FLASH_LATENCY(FLatency));
  805. /* To correctly read data from FLASH memory, the number of wait states (LATENCY)
  806. must be correctly programmed according to the frequency of the CPU clock
  807. (HCLK) and the supply voltage of the device. */
  808. /* Increasing the CPU frequency */
  809. if (FLatency > __HAL_FLASH_GET_LATENCY())
  810. {
  811. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  812. __HAL_FLASH_SET_LATENCY(FLatency);
  813. /* Check that the new number of wait states is taken into account to access the Flash
  814. memory by reading the FLASH_ACR register */
  815. if (__HAL_FLASH_GET_LATENCY() != FLatency)
  816. {
  817. return HAL_ERROR;
  818. }
  819. }
  820. /* Increasing the BUS frequency divider */
  821. /*-------------------------- D1PCLK1/CDPCLK1 Configuration ---------------------------*/
  822. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_D1PCLK1) == RCC_CLOCKTYPE_D1PCLK1)
  823. {
  824. #if defined (RCC_D1CFGR_D1PPRE)
  825. if ((RCC_ClkInitStruct->APB3CLKDivider) > (RCC->D1CFGR & RCC_D1CFGR_D1PPRE))
  826. {
  827. assert_param(IS_RCC_D1PCLK1(RCC_ClkInitStruct->APB3CLKDivider));
  828. MODIFY_REG(RCC->D1CFGR, RCC_D1CFGR_D1PPRE, RCC_ClkInitStruct->APB3CLKDivider);
  829. }
  830. #else
  831. if ((RCC_ClkInitStruct->APB3CLKDivider) > (RCC->CDCFGR1 & RCC_CDCFGR1_CDPPRE))
  832. {
  833. assert_param(IS_RCC_CDPCLK1(RCC_ClkInitStruct->APB3CLKDivider));
  834. MODIFY_REG(RCC->CDCFGR1, RCC_CDCFGR1_CDPPRE, RCC_ClkInitStruct->APB3CLKDivider);
  835. }
  836. #endif
  837. }
  838. /*-------------------------- PCLK1 Configuration ---------------------------*/
  839. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
  840. {
  841. #if defined (RCC_D2CFGR_D2PPRE1)
  842. if ((RCC_ClkInitStruct->APB1CLKDivider) > (RCC->D2CFGR & RCC_D2CFGR_D2PPRE1))
  843. {
  844. assert_param(IS_RCC_PCLK1(RCC_ClkInitStruct->APB1CLKDivider));
  845. MODIFY_REG(RCC->D2CFGR, RCC_D2CFGR_D2PPRE1, (RCC_ClkInitStruct->APB1CLKDivider));
  846. }
  847. #else
  848. if ((RCC_ClkInitStruct->APB1CLKDivider) > (RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE1))
  849. {
  850. assert_param(IS_RCC_PCLK1(RCC_ClkInitStruct->APB1CLKDivider));
  851. MODIFY_REG(RCC->CDCFGR2, RCC_CDCFGR2_CDPPRE1, (RCC_ClkInitStruct->APB1CLKDivider));
  852. }
  853. #endif
  854. }
  855. /*-------------------------- PCLK2 Configuration ---------------------------*/
  856. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
  857. {
  858. #if defined(RCC_D2CFGR_D2PPRE2)
  859. if ((RCC_ClkInitStruct->APB2CLKDivider) > (RCC->D2CFGR & RCC_D2CFGR_D2PPRE2))
  860. {
  861. assert_param(IS_RCC_PCLK2(RCC_ClkInitStruct->APB2CLKDivider));
  862. MODIFY_REG(RCC->D2CFGR, RCC_D2CFGR_D2PPRE2, (RCC_ClkInitStruct->APB2CLKDivider));
  863. }
  864. #else
  865. if ((RCC_ClkInitStruct->APB2CLKDivider) > (RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE2))
  866. {
  867. assert_param(IS_RCC_PCLK2(RCC_ClkInitStruct->APB2CLKDivider));
  868. MODIFY_REG(RCC->CDCFGR2, RCC_CDCFGR2_CDPPRE2, (RCC_ClkInitStruct->APB2CLKDivider));
  869. }
  870. #endif
  871. }
  872. /*-------------------------- D3PCLK1 Configuration ---------------------------*/
  873. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_D3PCLK1) == RCC_CLOCKTYPE_D3PCLK1)
  874. {
  875. #if defined(RCC_D3CFGR_D3PPRE)
  876. if ((RCC_ClkInitStruct->APB4CLKDivider) > (RCC->D3CFGR & RCC_D3CFGR_D3PPRE))
  877. {
  878. assert_param(IS_RCC_D3PCLK1(RCC_ClkInitStruct->APB4CLKDivider));
  879. MODIFY_REG(RCC->D3CFGR, RCC_D3CFGR_D3PPRE, (RCC_ClkInitStruct->APB4CLKDivider));
  880. }
  881. #else
  882. if ((RCC_ClkInitStruct->APB4CLKDivider) > (RCC->SRDCFGR & RCC_SRDCFGR_SRDPPRE))
  883. {
  884. assert_param(IS_RCC_D3PCLK1(RCC_ClkInitStruct->APB4CLKDivider));
  885. MODIFY_REG(RCC->SRDCFGR, RCC_SRDCFGR_SRDPPRE, (RCC_ClkInitStruct->APB4CLKDivider));
  886. }
  887. #endif
  888. }
  889. /*-------------------------- HCLK Configuration --------------------------*/
  890. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
  891. {
  892. #if defined (RCC_D1CFGR_HPRE)
  893. if ((RCC_ClkInitStruct->AHBCLKDivider) > (RCC->D1CFGR & RCC_D1CFGR_HPRE))
  894. {
  895. /* Set the new HCLK clock divider */
  896. assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
  897. MODIFY_REG(RCC->D1CFGR, RCC_D1CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
  898. }
  899. #else
  900. if ((RCC_ClkInitStruct->AHBCLKDivider) > (RCC->CDCFGR1 & RCC_CDCFGR1_HPRE))
  901. {
  902. /* Set the new HCLK clock divider */
  903. assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
  904. MODIFY_REG(RCC->CDCFGR1, RCC_CDCFGR1_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
  905. }
  906. #endif
  907. }
  908. /*------------------------- SYSCLK Configuration -------------------------*/
  909. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
  910. {
  911. assert_param(IS_RCC_SYSCLK(RCC_ClkInitStruct->SYSCLKDivider));
  912. assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
  913. #if defined(RCC_D1CFGR_D1CPRE)
  914. MODIFY_REG(RCC->D1CFGR, RCC_D1CFGR_D1CPRE, RCC_ClkInitStruct->SYSCLKDivider);
  915. #else
  916. MODIFY_REG(RCC->CDCFGR1, RCC_CDCFGR1_CDCPRE, RCC_ClkInitStruct->SYSCLKDivider);
  917. #endif
  918. /* HSE is selected as System Clock Source */
  919. if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
  920. {
  921. /* Check the HSE ready flag */
  922. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
  923. {
  924. return HAL_ERROR;
  925. }
  926. }
  927. /* PLL is selected as System Clock Source */
  928. else if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
  929. {
  930. /* Check the PLL ready flag */
  931. if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == 0U)
  932. {
  933. return HAL_ERROR;
  934. }
  935. }
  936. /* CSI is selected as System Clock Source */
  937. else if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_CSI)
  938. {
  939. /* Check the PLL ready flag */
  940. if (__HAL_RCC_GET_FLAG(RCC_FLAG_CSIRDY) == 0U)
  941. {
  942. return HAL_ERROR;
  943. }
  944. }
  945. /* HSI is selected as System Clock Source */
  946. else
  947. {
  948. /* Check the HSI ready flag */
  949. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == 0U)
  950. {
  951. return HAL_ERROR;
  952. }
  953. }
  954. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_ClkInitStruct->SYSCLKSource);
  955. /* Get Start Tick*/
  956. tickstart = HAL_GetTick();
  957. while (__HAL_RCC_GET_SYSCLK_SOURCE() != (RCC_ClkInitStruct->SYSCLKSource << RCC_CFGR_SWS_Pos))
  958. {
  959. if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
  960. {
  961. return HAL_TIMEOUT;
  962. }
  963. }
  964. }
  965. /* Decreasing the BUS frequency divider */
  966. /*-------------------------- HCLK Configuration --------------------------*/
  967. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
  968. {
  969. #if defined(RCC_D1CFGR_HPRE)
  970. if ((RCC_ClkInitStruct->AHBCLKDivider) < (RCC->D1CFGR & RCC_D1CFGR_HPRE))
  971. {
  972. /* Set the new HCLK clock divider */
  973. assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
  974. MODIFY_REG(RCC->D1CFGR, RCC_D1CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
  975. }
  976. #else
  977. if ((RCC_ClkInitStruct->AHBCLKDivider) < (RCC->CDCFGR1 & RCC_CDCFGR1_HPRE))
  978. {
  979. /* Set the new HCLK clock divider */
  980. assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
  981. MODIFY_REG(RCC->CDCFGR1, RCC_CDCFGR1_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
  982. }
  983. #endif
  984. }
  985. /* Decreasing the number of wait states because of lower CPU frequency */
  986. if (FLatency < __HAL_FLASH_GET_LATENCY())
  987. {
  988. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  989. __HAL_FLASH_SET_LATENCY(FLatency);
  990. /* Check that the new number of wait states is taken into account to access the Flash
  991. memory by reading the FLASH_ACR register */
  992. if (__HAL_FLASH_GET_LATENCY() != FLatency)
  993. {
  994. return HAL_ERROR;
  995. }
  996. }
  997. /*-------------------------- D1PCLK1/CDPCLK Configuration ---------------------------*/
  998. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_D1PCLK1) == RCC_CLOCKTYPE_D1PCLK1)
  999. {
  1000. #if defined(RCC_D1CFGR_D1PPRE)
  1001. if ((RCC_ClkInitStruct->APB3CLKDivider) < (RCC->D1CFGR & RCC_D1CFGR_D1PPRE))
  1002. {
  1003. assert_param(IS_RCC_D1PCLK1(RCC_ClkInitStruct->APB3CLKDivider));
  1004. MODIFY_REG(RCC->D1CFGR, RCC_D1CFGR_D1PPRE, RCC_ClkInitStruct->APB3CLKDivider);
  1005. }
  1006. #else
  1007. if ((RCC_ClkInitStruct->APB3CLKDivider) < (RCC->CDCFGR1 & RCC_CDCFGR1_CDPPRE))
  1008. {
  1009. assert_param(IS_RCC_CDPCLK1(RCC_ClkInitStruct->APB3CLKDivider));
  1010. MODIFY_REG(RCC->CDCFGR1, RCC_CDCFGR1_CDPPRE, RCC_ClkInitStruct->APB3CLKDivider);
  1011. }
  1012. #endif
  1013. }
  1014. /*-------------------------- PCLK1 Configuration ---------------------------*/
  1015. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
  1016. {
  1017. #if defined(RCC_D2CFGR_D2PPRE1)
  1018. if ((RCC_ClkInitStruct->APB1CLKDivider) < (RCC->D2CFGR & RCC_D2CFGR_D2PPRE1))
  1019. {
  1020. assert_param(IS_RCC_PCLK1(RCC_ClkInitStruct->APB1CLKDivider));
  1021. MODIFY_REG(RCC->D2CFGR, RCC_D2CFGR_D2PPRE1, (RCC_ClkInitStruct->APB1CLKDivider));
  1022. }
  1023. #else
  1024. if ((RCC_ClkInitStruct->APB1CLKDivider) < (RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE1))
  1025. {
  1026. assert_param(IS_RCC_PCLK1(RCC_ClkInitStruct->APB1CLKDivider));
  1027. MODIFY_REG(RCC->CDCFGR2, RCC_CDCFGR2_CDPPRE1, (RCC_ClkInitStruct->APB1CLKDivider));
  1028. }
  1029. #endif
  1030. }
  1031. /*-------------------------- PCLK2 Configuration ---------------------------*/
  1032. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
  1033. {
  1034. #if defined (RCC_D2CFGR_D2PPRE2)
  1035. if ((RCC_ClkInitStruct->APB2CLKDivider) < (RCC->D2CFGR & RCC_D2CFGR_D2PPRE2))
  1036. {
  1037. assert_param(IS_RCC_PCLK2(RCC_ClkInitStruct->APB2CLKDivider));
  1038. MODIFY_REG(RCC->D2CFGR, RCC_D2CFGR_D2PPRE2, (RCC_ClkInitStruct->APB2CLKDivider));
  1039. }
  1040. #else
  1041. if ((RCC_ClkInitStruct->APB2CLKDivider) < (RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE2))
  1042. {
  1043. assert_param(IS_RCC_PCLK2(RCC_ClkInitStruct->APB2CLKDivider));
  1044. MODIFY_REG(RCC->CDCFGR2, RCC_CDCFGR2_CDPPRE2, (RCC_ClkInitStruct->APB2CLKDivider));
  1045. }
  1046. #endif
  1047. }
  1048. /*-------------------------- D3PCLK1/SRDPCLK1 Configuration ---------------------------*/
  1049. if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_D3PCLK1) == RCC_CLOCKTYPE_D3PCLK1)
  1050. {
  1051. #if defined(RCC_D3CFGR_D3PPRE)
  1052. if ((RCC_ClkInitStruct->APB4CLKDivider) < (RCC->D3CFGR & RCC_D3CFGR_D3PPRE))
  1053. {
  1054. assert_param(IS_RCC_D3PCLK1(RCC_ClkInitStruct->APB4CLKDivider));
  1055. MODIFY_REG(RCC->D3CFGR, RCC_D3CFGR_D3PPRE, (RCC_ClkInitStruct->APB4CLKDivider));
  1056. }
  1057. #else
  1058. if ((RCC_ClkInitStruct->APB4CLKDivider) < (RCC->SRDCFGR & RCC_SRDCFGR_SRDPPRE))
  1059. {
  1060. assert_param(IS_RCC_SRDPCLK1(RCC_ClkInitStruct->APB4CLKDivider));
  1061. MODIFY_REG(RCC->SRDCFGR, RCC_SRDCFGR_SRDPPRE, (RCC_ClkInitStruct->APB4CLKDivider));
  1062. }
  1063. #endif
  1064. }
  1065. /* Update the SystemCoreClock global variable */
  1066. #if defined(RCC_D1CFGR_D1CPRE)
  1067. common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE) >> RCC_D1CFGR_D1CPRE_Pos]) & 0x1FU);
  1068. #else
  1069. common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE) >> RCC_CDCFGR1_CDCPRE_Pos]) & 0x1FU);
  1070. #endif
  1071. #if defined(RCC_D1CFGR_HPRE)
  1072. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE) >> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
  1073. #else
  1074. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE) >> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
  1075. #endif
  1076. #if defined(DUAL_CORE) && defined(CORE_CM4)
  1077. SystemCoreClock = SystemD2Clock;
  1078. #else
  1079. SystemCoreClock = common_system_clock;
  1080. #endif /* DUAL_CORE && CORE_CM4 */
  1081. /* Configure the source of time base considering new system clocks settings*/
  1082. halstatus = HAL_InitTick(uwTickPrio);
  1083. return halstatus;
  1084. }
  1085. /**
  1086. * @}
  1087. */
  1088. /** @defgroup RCC_Exported_Functions_Group2 Peripheral Control functions
  1089. * @brief RCC clocks control functions
  1090. *
  1091. @verbatim
  1092. ===============================================================================
  1093. ##### Peripheral Control functions #####
  1094. ===============================================================================
  1095. [..]
  1096. This subsection provides a set of functions allowing to control the RCC Clocks
  1097. frequencies.
  1098. @endverbatim
  1099. * @{
  1100. */
  1101. /**
  1102. * @brief Selects the clock source to output on MCO1 pin(PA8) or on MCO2 pin(PC9).
  1103. * @note PA8/PC9 should be configured in alternate function mode.
  1104. * @param RCC_MCOx: specifies the output direction for the clock source.
  1105. * This parameter can be one of the following values:
  1106. * @arg RCC_MCO1: Clock source to output on MCO1 pin(PA8).
  1107. * @arg RCC_MCO2: Clock source to output on MCO2 pin(PC9).
  1108. * @param RCC_MCOSource: specifies the clock source to output.
  1109. * This parameter can be one of the following values:
  1110. * @arg RCC_MCO1SOURCE_HSI: HSI clock selected as MCO1 source
  1111. * @arg RCC_MCO1SOURCE_LSE: LSE clock selected as MCO1 source
  1112. * @arg RCC_MCO1SOURCE_HSE: HSE clock selected as MCO1 source
  1113. * @arg RCC_MCO1SOURCE_PLL1QCLK: PLL1Q clock selected as MCO1 source
  1114. * @arg RCC_MCO1SOURCE_HSI48: HSI48 (48MHZ) selected as MCO1 source
  1115. * @arg RCC_MCO2SOURCE_SYSCLK: System clock (SYSCLK) selected as MCO2 source
  1116. * @arg RCC_MCO2SOURCE_PLL2PCLK: PLL2P clock selected as MCO2 source
  1117. * @arg RCC_MCO2SOURCE_HSE: HSE clock selected as MCO2 source
  1118. * @arg RCC_MCO2SOURCE_PLLCLK: PLL1P clock selected as MCO2 source
  1119. * @arg RCC_MCO2SOURCE_CSICLK: CSI clock selected as MCO2 source
  1120. * @arg RCC_MCO2SOURCE_LSICLK: LSI clock selected as MCO2 source
  1121. * @param RCC_MCODiv: specifies the MCOx pre-scaler.
  1122. * This parameter can be one of the following values:
  1123. * @arg RCC_MCODIV_1 up to RCC_MCODIV_15 : divider applied to MCOx clock
  1124. * @retval None
  1125. */
  1126. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
  1127. {
  1128. GPIO_InitTypeDef GPIO_InitStruct;
  1129. /* Check the parameters */
  1130. assert_param(IS_RCC_MCO(RCC_MCOx));
  1131. assert_param(IS_RCC_MCODIV(RCC_MCODiv));
  1132. /* RCC_MCO1 */
  1133. if (RCC_MCOx == RCC_MCO1)
  1134. {
  1135. assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
  1136. /* MCO1 Clock Enable */
  1137. MCO1_CLK_ENABLE();
  1138. /* Configure the MCO1 pin in alternate function mode */
  1139. GPIO_InitStruct.Pin = MCO1_PIN;
  1140. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1141. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1142. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1143. GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
  1144. HAL_GPIO_Init(MCO1_GPIO_PORT, &GPIO_InitStruct);
  1145. /* Mask MCO1 and MCO1PRE[3:0] bits then Select MCO1 clock source and pre-scaler */
  1146. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO1 | RCC_CFGR_MCO1PRE), (RCC_MCOSource | RCC_MCODiv));
  1147. }
  1148. else
  1149. {
  1150. assert_param(IS_RCC_MCO2SOURCE(RCC_MCOSource));
  1151. /* MCO2 Clock Enable */
  1152. MCO2_CLK_ENABLE();
  1153. /* Configure the MCO2 pin in alternate function mode */
  1154. GPIO_InitStruct.Pin = MCO2_PIN;
  1155. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1156. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1157. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1158. GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
  1159. HAL_GPIO_Init(MCO2_GPIO_PORT, &GPIO_InitStruct);
  1160. /* Mask MCO2 and MCO2PRE[3:0] bits then Select MCO2 clock source and pre-scaler */
  1161. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO2 | RCC_CFGR_MCO2PRE), (RCC_MCOSource | (RCC_MCODiv << 7U)));
  1162. }
  1163. }
  1164. /**
  1165. * @brief Enables the Clock Security System.
  1166. * @note If a failure is detected on the HSE oscillator clock, this oscillator
  1167. * is automatically disabled and an interrupt is generated to inform the
  1168. * software about the failure (Clock Security System Interrupt, CSSI),
  1169. * allowing the MCU to perform rescue operations. The CSSI is linked to
  1170. * the Cortex-M NMI (Non-Mask-able Interrupt) exception vector.
  1171. * @retval None
  1172. */
  1173. void HAL_RCC_EnableCSS(void)
  1174. {
  1175. SET_BIT(RCC->CR, RCC_CR_CSSHSEON) ;
  1176. }
  1177. /**
  1178. * @brief Disables the Clock Security System.
  1179. * @retval None
  1180. */
  1181. void HAL_RCC_DisableCSS(void)
  1182. {
  1183. CLEAR_BIT(RCC->CR, RCC_CR_CSSHSEON);
  1184. }
  1185. /**
  1186. * @brief Returns the SYSCLK frequency
  1187. *
  1188. * @note The system frequency computed by this function is not the real
  1189. * frequency in the chip. It is calculated based on the predefined
  1190. * constant and the selected clock source:
  1191. * @note If SYSCLK source is CSI, function returns values based on CSI_VALUE(*)
  1192. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**)
  1193. * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***)
  1194. * @note If SYSCLK source is PLL, function returns values based on CSI_VALUE(*),
  1195. * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
  1196. * @note (*) CSI_VALUE is a constant defined in stm32h7xx_hal_conf.h file (default value
  1197. * 4 MHz) but the real value may vary depending on the variations
  1198. * in voltage and temperature.
  1199. * @note (**) HSI_VALUE is a constant defined in stm32h7xx_hal_conf.h file (default value
  1200. * 64 MHz) but the real value may vary depending on the variations
  1201. * in voltage and temperature.
  1202. * @note (***) HSE_VALUE is a constant defined in stm32h7xx_hal_conf.h file (default value
  1203. * 25 MHz), user has to ensure that HSE_VALUE is same as the real
  1204. * frequency of the crystal used. Otherwise, this function may
  1205. * have wrong result.
  1206. *
  1207. * @note The result of this function could be not correct when using fractional
  1208. * value for HSE crystal.
  1209. *
  1210. * @note This function can be used by the user application to compute the
  1211. * baud rate for the communication peripherals or configure other parameters.
  1212. *
  1213. * @note Each time SYSCLK changes, this function must be called to update the
  1214. * right SYSCLK value. Otherwise, any configuration based on this function will be incorrect.
  1215. *
  1216. *
  1217. * @retval SYSCLK frequency
  1218. */
  1219. uint32_t HAL_RCC_GetSysClockFreq(void)
  1220. {
  1221. uint32_t pllp, pllsource, pllm, pllfracen, hsivalue;
  1222. float_t fracn1, pllvco;
  1223. uint32_t sysclockfreq;
  1224. /* Get SYSCLK source -------------------------------------------------------*/
  1225. switch (RCC->CFGR & RCC_CFGR_SWS)
  1226. {
  1227. case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
  1228. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
  1229. {
  1230. sysclockfreq = (uint32_t)(HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER() >> 3));
  1231. }
  1232. else
  1233. {
  1234. sysclockfreq = (uint32_t) HSI_VALUE;
  1235. }
  1236. break;
  1237. case RCC_CFGR_SWS_CSI: /* CSI used as system clock source */
  1238. sysclockfreq = CSI_VALUE;
  1239. break;
  1240. case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
  1241. sysclockfreq = HSE_VALUE;
  1242. break;
  1243. case RCC_CFGR_SWS_PLL1: /* PLL1 used as system clock source */
  1244. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
  1245. SYSCLK = PLL_VCO / PLLR
  1246. */
  1247. pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  1248. pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1) >> 4) ;
  1249. pllfracen = ((RCC-> PLLCFGR & RCC_PLLCFGR_PLL1FRACEN) >> RCC_PLLCFGR_PLL1FRACEN_Pos);
  1250. fracn1 = (float_t)(uint32_t)(pllfracen * ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1) >> 3));
  1251. if (pllm != 0U)
  1252. {
  1253. switch (pllsource)
  1254. {
  1255. case RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1256. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
  1257. {
  1258. hsivalue = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER() >> 3));
  1259. pllvco = ((float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1 / (float_t)0x2000) + (float_t)1);
  1260. }
  1261. else
  1262. {
  1263. pllvco = ((float_t)HSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1 / (float_t)0x2000) + (float_t)1);
  1264. }
  1265. break;
  1266. case RCC_PLLSOURCE_CSI: /* CSI used as PLL clock source */
  1267. pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1 / (float_t)0x2000) + (float_t)1);
  1268. break;
  1269. case RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1270. pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1 / (float_t)0x2000) + (float_t)1);
  1271. break;
  1272. default:
  1273. pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1 / (float_t)0x2000) + (float_t)1);
  1274. break;
  1275. }
  1276. pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >> 9) + 1U) ;
  1277. sysclockfreq = (uint32_t)(float_t)(pllvco / (float_t)pllp);
  1278. }
  1279. else
  1280. {
  1281. sysclockfreq = 0U;
  1282. }
  1283. break;
  1284. default:
  1285. sysclockfreq = CSI_VALUE;
  1286. break;
  1287. }
  1288. return sysclockfreq;
  1289. }
  1290. /**
  1291. * @brief Returns the HCLK frequency
  1292. * @note Each time HCLK changes, this function must be called to update the
  1293. * right HCLK value. Otherwise, any configuration based on this function will be incorrect.
  1294. *
  1295. * @note The SystemD2Clock CMSIS variable is used to store System domain2 Clock Frequency
  1296. * and updated within this function
  1297. * @retval HCLK frequency
  1298. */
  1299. uint32_t HAL_RCC_GetHCLKFreq(void)
  1300. {
  1301. uint32_t common_system_clock;
  1302. #if defined(RCC_D1CFGR_D1CPRE)
  1303. common_system_clock = HAL_RCC_GetSysClockFreq() >> (D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE) >> RCC_D1CFGR_D1CPRE_Pos] & 0x1FU);
  1304. #else
  1305. common_system_clock = HAL_RCC_GetSysClockFreq() >> (D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE) >> RCC_CDCFGR1_CDCPRE_Pos] & 0x1FU);
  1306. #endif
  1307. #if defined(RCC_D1CFGR_HPRE)
  1308. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE) >> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
  1309. #else
  1310. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE) >> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
  1311. #endif
  1312. #if defined(DUAL_CORE) && defined(CORE_CM4)
  1313. SystemCoreClock = SystemD2Clock;
  1314. #else
  1315. SystemCoreClock = common_system_clock;
  1316. #endif /* DUAL_CORE && CORE_CM4 */
  1317. return SystemD2Clock;
  1318. }
  1319. /**
  1320. * @brief Returns the PCLK1 frequency
  1321. * @note Each time PCLK1 changes, this function must be called to update the
  1322. * right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
  1323. * @retval PCLK1 frequency
  1324. */
  1325. uint32_t HAL_RCC_GetPCLK1Freq(void)
  1326. {
  1327. #if defined (RCC_D2CFGR_D2PPRE1)
  1328. /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
  1329. return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->D2CFGR & RCC_D2CFGR_D2PPRE1) >> RCC_D2CFGR_D2PPRE1_Pos]) & 0x1FU));
  1330. #else
  1331. /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
  1332. return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE1) >> RCC_CDCFGR2_CDPPRE1_Pos]) & 0x1FU));
  1333. #endif
  1334. }
  1335. /**
  1336. * @brief Returns the D2 PCLK2 frequency
  1337. * @note Each time PCLK2 changes, this function must be called to update the
  1338. * right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
  1339. * @retval PCLK1 frequency
  1340. */
  1341. uint32_t HAL_RCC_GetPCLK2Freq(void)
  1342. {
  1343. /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
  1344. #if defined(RCC_D2CFGR_D2PPRE2)
  1345. return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->D2CFGR & RCC_D2CFGR_D2PPRE2) >> RCC_D2CFGR_D2PPRE2_Pos]) & 0x1FU));
  1346. #else
  1347. return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE2) >> RCC_CDCFGR2_CDPPRE2_Pos]) & 0x1FU));
  1348. #endif
  1349. }
  1350. /**
  1351. * @brief Configures the RCC_OscInitStruct according to the internal
  1352. * RCC configuration registers.
  1353. * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that
  1354. * will be configured.
  1355. * @retval None
  1356. */
  1357. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
  1358. {
  1359. /* Set all possible values for the Oscillator type parameter ---------------*/
  1360. RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_CSI | \
  1361. RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSI48;
  1362. /* Get the HSE configuration -----------------------------------------------*/
  1363. #if defined(RCC_CR_HSEEXT)
  1364. if ((RCC->CR & (RCC_CR_HSEBYP | RCC_CR_HSEEXT)) == RCC_CR_HSEBYP)
  1365. {
  1366. RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
  1367. }
  1368. else if ((RCC->CR & (RCC_CR_HSEBYP | RCC_CR_HSEEXT)) == (RCC_CR_HSEBYP | RCC_CR_HSEEXT))
  1369. {
  1370. RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS_DIGITAL;
  1371. }
  1372. else if ((RCC->CR & RCC_CR_HSEON) == RCC_CR_HSEON)
  1373. {
  1374. RCC_OscInitStruct->HSEState = RCC_HSE_ON;
  1375. }
  1376. else
  1377. {
  1378. RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
  1379. }
  1380. #else
  1381. if ((RCC->CR & RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
  1382. {
  1383. RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
  1384. }
  1385. else if ((RCC->CR & RCC_CR_HSEON) == RCC_CR_HSEON)
  1386. {
  1387. RCC_OscInitStruct->HSEState = RCC_HSE_ON;
  1388. }
  1389. else
  1390. {
  1391. RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
  1392. }
  1393. #endif /* RCC_CR_HSEEXT */
  1394. /* Get the CSI configuration -----------------------------------------------*/
  1395. if ((RCC->CR & RCC_CR_CSION) == RCC_CR_CSION)
  1396. {
  1397. RCC_OscInitStruct->CSIState = RCC_CSI_ON;
  1398. }
  1399. else
  1400. {
  1401. RCC_OscInitStruct->CSIState = RCC_CSI_OFF;
  1402. }
  1403. #if defined(RCC_VER_X)
  1404. if (HAL_GetREVID() <= REV_ID_Y)
  1405. {
  1406. RCC_OscInitStruct->CSICalibrationValue = (uint32_t)(READ_BIT(RCC->HSICFGR, HAL_RCC_REV_Y_CSITRIM_Msk) >> HAL_RCC_REV_Y_CSITRIM_Pos);
  1407. }
  1408. else
  1409. {
  1410. RCC_OscInitStruct->CSICalibrationValue = (uint32_t)(READ_BIT(RCC->CSICFGR, RCC_CSICFGR_CSITRIM) >> RCC_CSICFGR_CSITRIM_Pos);
  1411. }
  1412. #else
  1413. RCC_OscInitStruct->CSICalibrationValue = (uint32_t)(READ_BIT(RCC->CSICFGR, RCC_CSICFGR_CSITRIM) >> RCC_CSICFGR_CSITRIM_Pos);
  1414. #endif /*RCC_VER_X*/
  1415. /* Get the HSI configuration -----------------------------------------------*/
  1416. if ((RCC->CR & RCC_CR_HSION) == RCC_CR_HSION)
  1417. {
  1418. RCC_OscInitStruct->HSIState = RCC_HSI_ON;
  1419. }
  1420. else
  1421. {
  1422. RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
  1423. }
  1424. #if defined(RCC_VER_X)
  1425. if (HAL_GetREVID() <= REV_ID_Y)
  1426. {
  1427. RCC_OscInitStruct->HSICalibrationValue = (uint32_t)(READ_BIT(RCC->HSICFGR, HAL_RCC_REV_Y_HSITRIM_Msk) >> HAL_RCC_REV_Y_HSITRIM_Pos);
  1428. }
  1429. else
  1430. {
  1431. RCC_OscInitStruct->HSICalibrationValue = (uint32_t)(READ_BIT(RCC->HSICFGR, RCC_HSICFGR_HSITRIM) >> RCC_HSICFGR_HSITRIM_Pos);
  1432. }
  1433. #else
  1434. RCC_OscInitStruct->HSICalibrationValue = (uint32_t)(READ_BIT(RCC->HSICFGR, RCC_HSICFGR_HSITRIM) >> RCC_HSICFGR_HSITRIM_Pos);
  1435. #endif /*RCC_VER_X*/
  1436. /* Get the LSE configuration -----------------------------------------------*/
  1437. #if defined(RCC_BDCR_LSEEXT)
  1438. if ((RCC->BDCR & (RCC_BDCR_LSEBYP | RCC_BDCR_LSEEXT)) == RCC_BDCR_LSEBYP)
  1439. {
  1440. RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
  1441. }
  1442. else if ((RCC->BDCR & (RCC_BDCR_LSEBYP | RCC_BDCR_LSEEXT)) == (RCC_BDCR_LSEBYP | RCC_BDCR_LSEEXT))
  1443. {
  1444. RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS_DIGITAL;
  1445. }
  1446. else if ((RCC->BDCR & RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
  1447. {
  1448. RCC_OscInitStruct->LSEState = RCC_LSE_ON;
  1449. }
  1450. else
  1451. {
  1452. RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
  1453. }
  1454. #else
  1455. if ((RCC->BDCR & RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
  1456. {
  1457. RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
  1458. }
  1459. else if ((RCC->BDCR & RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
  1460. {
  1461. RCC_OscInitStruct->LSEState = RCC_LSE_ON;
  1462. }
  1463. else
  1464. {
  1465. RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
  1466. }
  1467. #endif /* RCC_BDCR_LSEEXT */
  1468. /* Get the LSI configuration -----------------------------------------------*/
  1469. if ((RCC->CSR & RCC_CSR_LSION) == RCC_CSR_LSION)
  1470. {
  1471. RCC_OscInitStruct->LSIState = RCC_LSI_ON;
  1472. }
  1473. else
  1474. {
  1475. RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
  1476. }
  1477. /* Get the HSI48 configuration ---------------------------------------------*/
  1478. if ((RCC->CR & RCC_CR_HSI48ON) == RCC_CR_HSI48ON)
  1479. {
  1480. RCC_OscInitStruct->HSI48State = RCC_HSI48_ON;
  1481. }
  1482. else
  1483. {
  1484. RCC_OscInitStruct->HSI48State = RCC_HSI48_OFF;
  1485. }
  1486. /* Get the PLL configuration -----------------------------------------------*/
  1487. if ((RCC->CR & RCC_CR_PLLON) == RCC_CR_PLLON)
  1488. {
  1489. RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
  1490. }
  1491. else
  1492. {
  1493. RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
  1494. }
  1495. RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  1496. RCC_OscInitStruct->PLL.PLLM = (uint32_t)((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1) >> RCC_PLLCKSELR_DIVM1_Pos);
  1497. RCC_OscInitStruct->PLL.PLLN = (uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_N1) >> RCC_PLL1DIVR_N1_Pos) + 1U;
  1498. RCC_OscInitStruct->PLL.PLLR = (uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_R1) >> RCC_PLL1DIVR_R1_Pos) + 1U;
  1499. RCC_OscInitStruct->PLL.PLLP = (uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >> RCC_PLL1DIVR_P1_Pos) + 1U;
  1500. RCC_OscInitStruct->PLL.PLLQ = (uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_Q1) >> RCC_PLL1DIVR_Q1_Pos) + 1U;
  1501. RCC_OscInitStruct->PLL.PLLRGE = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLL1RGE));
  1502. RCC_OscInitStruct->PLL.PLLVCOSEL = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLL1VCOSEL) >> RCC_PLLCFGR_PLL1VCOSEL_Pos);
  1503. RCC_OscInitStruct->PLL.PLLFRACN = (uint32_t)(((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1) >> RCC_PLL1FRACR_FRACN1_Pos));
  1504. }
  1505. /**
  1506. * @brief Configures the RCC_ClkInitStruct according to the internal
  1507. * RCC configuration registers.
  1508. * @param RCC_ClkInitStruct: pointer to an RCC_ClkInitTypeDef structure that
  1509. * will be configured.
  1510. * @param pFLatency: Pointer on the Flash Latency.
  1511. * @retval None
  1512. */
  1513. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
  1514. {
  1515. /* Set all possible values for the Clock type parameter --------------------*/
  1516. RCC_ClkInitStruct->ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 |
  1517. RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1 ;
  1518. /* Get the SYSCLK configuration --------------------------------------------*/
  1519. RCC_ClkInitStruct->SYSCLKSource = (uint32_t)(RCC->CFGR & RCC_CFGR_SW);
  1520. #if defined(RCC_D1CFGR_D1CPRE)
  1521. /* Get the SYSCLK configuration ----------------------------------------------*/
  1522. RCC_ClkInitStruct->SYSCLKDivider = (uint32_t)(RCC->D1CFGR & RCC_D1CFGR_D1CPRE);
  1523. /* Get the D1HCLK configuration ----------------------------------------------*/
  1524. RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->D1CFGR & RCC_D1CFGR_HPRE);
  1525. /* Get the APB3 configuration ----------------------------------------------*/
  1526. RCC_ClkInitStruct->APB3CLKDivider = (uint32_t)(RCC->D1CFGR & RCC_D1CFGR_D1PPRE);
  1527. /* Get the APB1 configuration ----------------------------------------------*/
  1528. RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->D2CFGR & RCC_D2CFGR_D2PPRE1);
  1529. /* Get the APB2 configuration ----------------------------------------------*/
  1530. RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)(RCC->D2CFGR & RCC_D2CFGR_D2PPRE2);
  1531. /* Get the APB4 configuration ----------------------------------------------*/
  1532. RCC_ClkInitStruct->APB4CLKDivider = (uint32_t)(RCC->D3CFGR & RCC_D3CFGR_D3PPRE);
  1533. #else
  1534. /* Get the SYSCLK configuration ----------------------------------------------*/
  1535. RCC_ClkInitStruct->SYSCLKDivider = (uint32_t)(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE);
  1536. /* Get the D1HCLK configuration ----------------------------------------------*/
  1537. RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE);
  1538. /* Get the APB3 configuration ----------------------------------------------*/
  1539. RCC_ClkInitStruct->APB3CLKDivider = (uint32_t)(RCC->CDCFGR1 & RCC_CDCFGR1_CDPPRE);
  1540. /* Get the APB1 configuration ----------------------------------------------*/
  1541. RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE1);
  1542. /* Get the APB2 configuration ----------------------------------------------*/
  1543. RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)(RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE2);
  1544. /* Get the APB4 configuration ----------------------------------------------*/
  1545. RCC_ClkInitStruct->APB4CLKDivider = (uint32_t)(RCC->SRDCFGR & RCC_SRDCFGR_SRDPPRE);
  1546. #endif
  1547. /* Get the Flash Wait State (Latency) configuration ------------------------*/
  1548. *pFLatency = (uint32_t)(FLASH->ACR & FLASH_ACR_LATENCY);
  1549. }
  1550. /**
  1551. * @brief This function handles the RCC CSS interrupt request.
  1552. * @note This API should be called under the NMI_Handler().
  1553. * @retval None
  1554. */
  1555. void HAL_RCC_NMI_IRQHandler(void)
  1556. {
  1557. /* Check RCC CSSF flag */
  1558. if (__HAL_RCC_GET_IT(RCC_IT_CSS))
  1559. {
  1560. /* RCC Clock Security System interrupt user callback */
  1561. HAL_RCC_CSSCallback();
  1562. /* Clear RCC CSS pending bit */
  1563. __HAL_RCC_CLEAR_IT(RCC_IT_CSS);
  1564. }
  1565. }
  1566. /**
  1567. * @brief RCC Clock Security System interrupt callback
  1568. * @retval none
  1569. */
  1570. __weak void HAL_RCC_CSSCallback(void)
  1571. {
  1572. /* NOTE : This function Should not be modified, when the callback is needed,
  1573. the HAL_RCC_CSSCallback could be implemented in the user file
  1574. */
  1575. }
  1576. /**
  1577. * @}
  1578. */
  1579. /**
  1580. * @}
  1581. */
  1582. #endif /* HAL_RCC_MODULE_ENABLED */
  1583. /**
  1584. * @}
  1585. */
  1586. /**
  1587. * @}
  1588. */