stm8l15x_clk.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_clk.c
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the clock controller (CLK) peripheral:
  9. * - Internal/external clocks, CSS and CCO configuration
  10. * - System clocks configuration
  11. * - Peripheral clocks configuration
  12. * - CSS on LSE configuration
  13. * - Low power clock configuration
  14. * - Interrupts and flags management
  15. *
  16. * @verbatim
  17. *
  18. * ===================================================================
  19. * CLK specific features
  20. * ===================================================================
  21. *
  22. * After reset the device is running from Internal High Speed oscillator
  23. * divided by 8 (HSI/8 = 2MHz) with all peripherals off.
  24. * - The clock for all peripherals is switched off, except for the BootROM
  25. * clock used for bootloader, in which case, the software should be properly
  26. * written to switch off that clock after the bootloader execution.
  27. *
  28. * Once the device starts from reset, the user application has to:
  29. * - Configure the clock source to be used to drive the System clock
  30. * (if the application needs higher frequency/performance)
  31. * - Configure the System clock frequency
  32. * - Enable the clock for the peripheral(s) to be used
  33. * - Configure the clock source(s) for peripherals which clocks are not
  34. * derived from the System clock (RTC/LCD, BEEP)
  35. *
  36. * @endverbatim
  37. *
  38. ******************************************************************************
  39. * @attention
  40. *
  41. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  42. *
  43. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  44. * You may not use this file except in compliance with the License.
  45. * You may obtain a copy of the License at:
  46. *
  47. * http://www.st.com/software_license_agreement_liberty_v2
  48. *
  49. * Unless required by applicable law or agreed to in writing, software
  50. * distributed under the License is distributed on an "AS IS" BASIS,
  51. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  52. * See the License for the specific language governing permissions and
  53. * limitations under the License.
  54. *
  55. ******************************************************************************
  56. */
  57. /* Includes ------------------------------------------------------------------*/
  58. #include "stm8l15x_clk.h"
  59. /** @addtogroup STM8L15x_StdPeriph_Driver
  60. * @{
  61. */
  62. /** @defgroup CLK
  63. * @brief CLK driver modules
  64. * @{
  65. */
  66. /* Private typedef -----------------------------------------------------------*/
  67. /* Private macro -------------------------------------------------------------*/
  68. /* Private Variables ---------------------------------------------------------*/
  69. /* Private Constant ---------------------------------------------------------*/
  70. CONST uint8_t SYSDivFactor[5] = {1, 2, 4, 8, 16}; /*!< Holds the different Master clock Divider factors */
  71. /* Private function prototypes -----------------------------------------------*/
  72. /* Private functions ---------------------------------------------------------*/
  73. /** @defgroup CLK_Private_Functions
  74. * @{
  75. */
  76. /** @defgroup CLK_Group1 Internal and external clocks, CSS and CCO configuration functions
  77. * @brief Internal and external clocks, CSS and CCO configuration functions
  78. *
  79. @verbatim
  80. ===============================================================================
  81. Internal/external clocks, CSS and CCO configuration functions
  82. ===============================================================================
  83. This section provides functions allowing to configure the internal/external clocks,
  84. CSS and CCO pins.
  85. 1. HSI (high-speed internal), 16 MHz factory-trimmed RC used directly as System
  86. clock source.
  87. 2. LSI (low-speed internal), 32 KHz low consumption RC used as IWDG and/or RTC
  88. and/or BEEP clock source.
  89. 3. HSE (high-speed external), 1 to 16 MHz crystal oscillator used directly as
  90. System clock source. Can be used also as RTC/LCD clock source.
  91. 4. LSE (low-speed external), 32 KHz oscillator used as RTC/LCD and/or BEEP clock source.
  92. 5. CSS (Clock security system), once enabled and if a HSE clock failure occurs
  93. (HSE used as System clock source), the System clock is automatically switched
  94. to HSI and an interrupt is generated if enabled.
  95. 6. CCO (configurable clock output), used to output HSI, LSE, HSE, HSI, LSI
  96. clock (through a configurable prescaler) on PC4 pin.
  97. @endverbatim
  98. * @{
  99. */
  100. /**
  101. * @brief Deinitializes the CLK peripheral registers to their default reset values.
  102. * @param None
  103. * @retval None
  104. */
  105. void CLK_DeInit(void)
  106. {
  107. CLK->ICKCR = CLK_ICKCR_RESET_VALUE;
  108. CLK->ECKCR = CLK_ECKCR_RESET_VALUE;
  109. CLK->CRTCR = CLK_CRTCR_RESET_VALUE;
  110. CLK->CBEEPR = CLK_CBEEPR_RESET_VALUE;
  111. CLK->SWR = CLK_SWR_RESET_VALUE;
  112. CLK->SWCR = CLK_SWCR_RESET_VALUE;
  113. CLK->CKDIVR = CLK_CKDIVR_RESET_VALUE;
  114. CLK->PCKENR1 = CLK_PCKENR1_RESET_VALUE;
  115. CLK->PCKENR2 = CLK_PCKENR2_RESET_VALUE;
  116. CLK->PCKENR3 = CLK_PCKENR3_RESET_VALUE;
  117. CLK->CSSR = CLK_CSSR_RESET_VALUE;
  118. CLK->CCOR = CLK_CCOR_RESET_VALUE;
  119. CLK->HSITRIMR = CLK_HSITRIMR_RESET_VALUE;
  120. CLK->HSICALR = CLK_HSICALR_RESET_VALUE;
  121. CLK->HSIUNLCKR = CLK_HSIUNLCKR_RESET_VALUE;
  122. CLK->REGCSR = CLK_REGCSR_RESET_VALUE;
  123. }
  124. /**
  125. * @brief Enables or disables the Internal High Speed oscillator (HSI).
  126. * @note The HSI is stopped by hardware when entering Halt and active Halt modes.
  127. * It is used (enabled by hardware) as system clock source after startup
  128. * from Reset, wakeup from Halt and active Halt mode when the FHWU bit is
  129. * set in the ICKCR register, or in case of HSE failure used as system clock
  130. * (if the Clock Security System CSS is enabled).
  131. * @note HSI can not be stopped if it is used as active CCO source, as active
  132. * RTC clock, if the safe oscillator (AUX) is enabled or as system clock source,
  133. * In this case, you have to select another source of the system clock
  134. * then stop the HSI.
  135. * @note After enabling the HSI, the application software should wait on HSIRDY
  136. * flag to be set indicating that HSI clock is stable and can be used as
  137. * system clock source.
  138. * @param NewState: new state of the HSI.
  139. * This parameter can be: ENABLE or DISABLE.
  140. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  141. * clock cycles.
  142. * @retval None
  143. */
  144. void CLK_HSICmd(FunctionalState NewState)
  145. {
  146. /* Check the parameters */
  147. assert_param(IS_FUNCTIONAL_STATE(NewState));
  148. if (NewState != DISABLE)
  149. {
  150. /* Set HSION bit */
  151. CLK->ICKCR |= CLK_ICKCR_HSION;
  152. }
  153. else
  154. {
  155. /* Reset HSION bit */
  156. CLK->ICKCR &= (uint8_t)(~CLK_ICKCR_HSION);
  157. }
  158. }
  159. /**
  160. * @brief Adjusts the Internal High Speed oscillator (HSI) calibration value.
  161. * @note The calibration is used to compensate for the variations in voltage
  162. * and temperature that influence the frequency of the internal HSI RC.
  163. * @param CLK_HSICalibrationValue : calibration trimming value.
  164. * This parameter must be a number between [(HSICALR register value) -12]
  165. * and [(HSICALR register value) + 8 ]
  166. * @note Once HSITRIMR register configured, its value is used instead of the HSICALR
  167. * register values.
  168. * @retval None
  169. */
  170. void CLK_AdjustHSICalibrationValue(uint8_t CLK_HSICalibrationValue)
  171. {
  172. /* two consecutive write access to HSIUNLCKR register to unlock HSITRIMR */
  173. CLK->HSIUNLCKR = 0xAC;
  174. CLK->HSIUNLCKR = 0x35;
  175. /* Store the new value */
  176. CLK->HSITRIMR = (uint8_t)CLK_HSICalibrationValue;
  177. }
  178. /**
  179. * @brief Enables or disables the Internal Low Speed oscillator (LSI).
  180. * @note After enabling the LSI, the application software should wait on
  181. * LSIRDY flag to be set indicating that LSI clock is stable and can
  182. * be used to clock the IWDG and/or the RTC.
  183. * @note LSI can not be disabled if used as system clock source, as active CCO
  184. * source, as BEEP clock source while BEEPAHALT bit is set or, as RTC active
  185. * clock source.
  186. * @param NewState: new state of the LSI.
  187. * This parameter can be: ENABLE or DISABLE.
  188. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  189. * clock cycles.
  190. * @retval None
  191. */
  192. void CLK_LSICmd(FunctionalState NewState)
  193. {
  194. /* Check the parameters */
  195. assert_param(IS_FUNCTIONAL_STATE(NewState));
  196. if (NewState != DISABLE)
  197. {
  198. /* Set LSION bit */
  199. CLK->ICKCR |= CLK_ICKCR_LSION;
  200. }
  201. else
  202. {
  203. /* Reset LSION bit */
  204. CLK->ICKCR &= (uint8_t)(~CLK_ICKCR_LSION);
  205. }
  206. }
  207. /**
  208. * @brief Configures the External High Speed oscillator (HSE).
  209. * @note After enabling the HSE (CLK_HSE_ON or CLK_HSE_Bypass), the application
  210. * software should wait on HSERDY flag to be set indicating that HSE clock
  211. * is stable and can be used to clock the system.
  212. * @note HSE state can not be changed if it is used as system clock. In this case,
  213. * you have to select another source of the system clock then change
  214. * the HSE state (ex. disable it).
  215. * @note The HSE is stopped by hardware when entering HALT and active HALT modes.
  216. * @param CLK_HSE: specifies the new state of the HSE.
  217. * This parameter can be one of the following values:
  218. * @arg CLK_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
  219. * 6 HSE oscillator clock cycles.
  220. * @arg CLK_HSE_ON: turn ON the HSE oscillator
  221. * @arg CLK_HSE_Bypass: HSE oscillator bypassed with external clock
  222. * @note In case of Enabling HSE Bypass make sure that the HSE clock source is
  223. * not used by the RTC, output or involved in a switching operation.
  224. * @retval None
  225. */
  226. void CLK_HSEConfig(CLK_HSE_TypeDef CLK_HSE)
  227. {
  228. /* Check the parameters */
  229. assert_param(IS_CLK_HSE(CLK_HSE));
  230. /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
  231. /* Reset HSEON bit */
  232. CLK->ECKCR &= (uint8_t)~CLK_ECKCR_HSEON;
  233. /* Reset HSEBYP bit */
  234. CLK->ECKCR &= (uint8_t)~CLK_ECKCR_HSEBYP;
  235. /* Configure HSE */
  236. CLK->ECKCR |= (uint8_t)CLK_HSE;
  237. }
  238. /**
  239. * @brief Configures the External Low Speed oscillator (LSE).
  240. * @note After enabling the LSE (CLK_LSE_ON or CLK_LSE_Bypass), the application
  241. * software should wait on LSERDY flag to be set indicating that LSE clock
  242. * is stable and can be used to clock the RTC.
  243. * @param CLK_LSE: specifies the new state of the LSE.
  244. * This parameter can be one of the following values:
  245. * @arg CLK_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
  246. * 6 LSE oscillator clock cycles.
  247. * @arg CLK_LSE_ON: turn ON the LSE oscillator
  248. * @arg CLK_LSE_Bypass: LSE oscillator bypassed with external clock
  249. * @note In case of Enabling LSE Bypass make sure that the LSE clock source is
  250. * not used by the RTC, output or involved in a switching operation.
  251. * @retval None
  252. */
  253. void CLK_LSEConfig(CLK_LSE_TypeDef CLK_LSE)
  254. {
  255. /* Check the parameters */
  256. assert_param(IS_CLK_LSE(CLK_LSE));
  257. /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
  258. /* Reset LSEON bit */
  259. CLK->ECKCR &= (uint8_t)~CLK_ECKCR_LSEON;
  260. /* Reset LSEBYP bit */
  261. CLK->ECKCR &= (uint8_t)~CLK_ECKCR_LSEBYP;
  262. /* Configure LSE */
  263. CLK->ECKCR |= (uint8_t)CLK_LSE;
  264. }
  265. /**
  266. * @brief Enables the Clock Security System.
  267. * @note If a failure is detected on the HSE oscillator clock, this oscillator
  268. * is automatically disabled and an interrupt is generated to inform the
  269. * software about the failure allowing the MCU to perform rescue operations.
  270. * @note Once CSS is enabled it cannot be disabled until the next reset.
  271. * @param None
  272. * @retval None
  273. */
  274. void CLK_ClockSecuritySystemEnable(void)
  275. {
  276. /* Set CSSEN bit */
  277. CLK->CSSR |= CLK_CSSR_CSSEN;
  278. }
  279. /**
  280. * @brief Enables the Clock Security System deglitcher system.
  281. * @param None
  282. * @retval None
  283. */
  284. void CLK_ClockSecuritySytemDeglitchCmd(FunctionalState NewState)
  285. {
  286. /* Check the parameters */
  287. assert_param(IS_FUNCTIONAL_STATE(NewState));
  288. if (NewState != DISABLE)
  289. {
  290. /* Set CSSDGON bit */
  291. CLK->CSSR |= CLK_CSSR_CSSDGON;
  292. }
  293. else
  294. {
  295. /* Reset CSSDGON bit */
  296. CLK->CSSR &= (uint8_t)(~CLK_CSSR_CSSDGON);
  297. }
  298. }
  299. /**
  300. * @brief Selects the clock source to output on CCO pin(PC4).
  301. * @note PC4 should be configured output push-pull with the speed that matches
  302. * maximum output speed of the desired clock.
  303. * @param CLK_CCOSource: specifies the clock source to output.
  304. * This parameter can be one of the following values:
  305. * @arg CLK_CCOSource_Off: No clock selected as CCO source
  306. * @arg CLK_CCOSource_HSI: HSI clock selected as CCO source
  307. * @arg CLK_CCOSource_LSI: LSI clock selected as CCO source
  308. * @arg CLK_CCOSource_LSE: LSE clock selected as CCO source
  309. * @arg CLK_CCOSource_HSE: HSE clock selected as CCO source
  310. * @param CLK_CCODiv: specifies the CCO prescaler.
  311. * This parameter can be one of the following values:
  312. * @arg CLK_CCODiv_1: no division applied to CCO clock
  313. * @arg CLK_CCODiv_2: division by 2 applied to CCO clock
  314. * @arg CLK_CCODiv_4: division by 4 applied to CCO clock
  315. * @arg CLK_CCODiv_8: division by 8 applied to CCO clock
  316. * @arg CLK_CCODiv_16: division by 16 applied to CCO clock
  317. * @arg CLK_CCODiv_32: division by 32 applied to CCO clock
  318. * @arg CLK_CCODiv_64: division by 64 applied to CCO clock
  319. * @retval None
  320. */
  321. void CLK_CCOConfig(CLK_CCOSource_TypeDef CLK_CCOSource, CLK_CCODiv_TypeDef CLK_CCODiv)
  322. {
  323. /* check teh parameters */
  324. assert_param(IS_CLK_OUTPUT(CLK_CCOSource));
  325. assert_param(IS_CLK_OUTPUT_DIVIDER(CLK_CCODiv));
  326. /* Selects the source provided on cco_ck output and its divider*/
  327. CLK->CCOR = (uint8_t)((uint8_t)CLK_CCOSource | (uint8_t)CLK_CCODiv);
  328. }
  329. /**
  330. * @}
  331. */
  332. /** @defgroup CLK_Group2 System clock configuration functions
  333. * @brief System clock configuration functions
  334. *
  335. @verbatim
  336. ===============================================================================
  337. System clock configuration functions
  338. ===============================================================================
  339. This section provides functions allowing to configure the System clock.
  340. 1. Several clock sources can be used to drive the System clock (SYSCLK): HSI,
  341. HSE, LSI and LSE.
  342. You can use "CLK_GetClocksFreq()" function to retrieve the frequencies of these clocks.
  343. @note All the peripheral clocks are derived from the System clock (SYSCLK) except:
  344. - BEEP: the Beeper clock can be derived either from a LSE or LSI clock sources.
  345. You have to use CLK_BEEPClockConfig() function to configure this clock.
  346. - RTC: the RTC clock can be derived either from the LSI, LSE, HSI or HSE clock
  347. divided by 1 to 64. You have to use CLK_RTCClockConfig() functions to
  348. configure this clock.
  349. - LCD : LCD clock is the RTC Clock divided by 2.
  350. - IWDG clock which is always the LSI clock.
  351. 2. The maximum frequency of the SYSCLK is 16 MHz.
  352. @endverbatim
  353. * @{
  354. */
  355. /**
  356. * @brief Configures the system clock (SYSCLK).
  357. * @note The HSI is used (enabled by hardware) as system clock source after
  358. * startup from Reset, wake-up from Halt and active Halt modes, or in case
  359. * of failure of the HSE used as system clock (if the Clock Security System CSS is enabled).
  360. * @note A switch from one clock source to another occurs only if the target
  361. * clock source is ready (clock stable after startup delay or PLL locked).
  362. * You can use CLK_GetSYSCLKSource() function to know which clock is
  363. * currently used as system clock source.
  364. * @param CLK_SYSCLKSource: specifies the clock source used as system clock.
  365. * This parameter can be one of the following values:
  366. * @arg CLK_SYSCLKSource_HSI: HSI selected as system clock source
  367. * @arg CLK_SYSCLKSource_HSE: HSE selected as system clock source
  368. * @arg CLK_SYSCLKSource_LSI: LSI selected as system clock source
  369. * @arg CLK_SYSCLKSource_LSE: LSE selected as system clock source
  370. * @retval None
  371. */
  372. void CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_TypeDef CLK_SYSCLKSource)
  373. {
  374. /* check teh parameters */
  375. assert_param(IS_CLK_SOURCE(CLK_SYSCLKSource));
  376. /* Selection of the target clock source */
  377. CLK->SWR = (uint8_t)CLK_SYSCLKSource;
  378. }
  379. /**
  380. * @brief Returns the clock source used as system clock.
  381. * @param None
  382. * @retval Clock used as System clock (SYSCLK) source.
  383. * The returned value can be one of the following:
  384. * - CLK_SYSCLKSource_HSI: HSI used as system clock
  385. * - CLK_SYSCLKSource_LSI: LSI used as system clock
  386. * - CLK_SYSCLKSource_HSE: HSE used as system clock
  387. * - CLK_SYSCLKSource_LSE: LSE used as system clock
  388. */
  389. CLK_SYSCLKSource_TypeDef CLK_GetSYSCLKSource(void)
  390. {
  391. return ((CLK_SYSCLKSource_TypeDef)(CLK->SCSR));
  392. }
  393. /**
  394. * @brief Returns the frequencies of different the SYSCLK
  395. *
  396. * @note The system frequency computed by this function is not the real
  397. * frequency in the chip. It is calculated based on the predefined
  398. * constant and the selected clock source:
  399. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
  400. * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
  401. * @note If SYSCLK source is LSE, function returns values based on LSE_VALUE(***)
  402. * @note If SYSCLK source is LSI, function returns values based on LSI_VALUE(****)
  403. * @note (*) HSI_VALUE is a constant defined in stm8l15x.h file (default value
  404. * 16 MHz) but the real value may vary depending on the variations
  405. * in voltage and temperature.
  406. * @note (**) HSE_VALUE is a constant defined in stm8l15x.h file (default value
  407. * 16 MHz), user has to ensure that HSE_VALUE is same as the real
  408. * frequency of the crystal used. Otherwise, this function may
  409. * have wrong result.
  410. * @note (***) LSI_VALUE is a constant defined in stm8l15x.h file (default value
  411. * 38 KHz) but the real value may vary depending on the variations
  412. * in voltage and temperature.
  413. * @note (****) LSE_VALUE is a constant defined in stm8l15x.h file (default value
  414. * 32,768 KHz), user has to ensure that LSE_VALUE is same as the real
  415. * frequency of the crystal used. Otherwise, this function may
  416. * have wrong result.
  417. *
  418. * @note The result of this function could be not correct when using fractional
  419. * value for HSE crystal.
  420. *
  421. * @param None
  422. *
  423. * @note This function can be used by the user application to compute the
  424. * baudrate for the communication peripherals or configure other parameters.
  425. * @note Each time SYSCLK clock changes, this function must be called to update
  426. * the returned value. Otherwise, any configuration based on this
  427. * function will be incorrect.
  428. *
  429. * @retval System Clock frequency value
  430. */
  431. uint32_t CLK_GetClockFreq(void)
  432. {
  433. uint32_t clockfrequency = 0;
  434. uint32_t sourcefrequency = 0;
  435. CLK_SYSCLKSource_TypeDef clocksource = CLK_SYSCLKSource_HSI;
  436. uint8_t tmp = 0, presc = 0;
  437. /* Get SYSCLK source. */
  438. clocksource = (CLK_SYSCLKSource_TypeDef)CLK->SCSR;
  439. if ( clocksource == CLK_SYSCLKSource_HSI)
  440. {
  441. sourcefrequency = HSI_VALUE;
  442. }
  443. else if ( clocksource == CLK_SYSCLKSource_LSI)
  444. {
  445. sourcefrequency = LSI_VALUE;
  446. }
  447. else if ( clocksource == CLK_SYSCLKSource_HSE)
  448. {
  449. sourcefrequency = HSE_VALUE;
  450. }
  451. else
  452. {
  453. clockfrequency = LSE_VALUE;
  454. }
  455. /* Get System clock divider factor*/
  456. tmp = (uint8_t)(CLK->CKDIVR & CLK_CKDIVR_CKM);
  457. presc = SYSDivFactor[tmp];
  458. /* Get System clock frequency */
  459. clockfrequency = sourcefrequency / presc;
  460. return((uint32_t)clockfrequency);
  461. }
  462. /**
  463. * @brief Configures the System clock (SYSCLK) dividers.
  464. * @param CLK_SYSCLKDiv : Specifies the system clock divider to apply.
  465. * This parameter can be one of the following values:
  466. * @arg CLK_SYSCLKDiv_1
  467. * @arg CLK_SYSCLKDiv_2
  468. * @arg CLK_SYSCLKDiv_4
  469. * @arg CLK_SYSCLKDiv_8
  470. * @arg CLK_SYSCLKDiv_16
  471. * @arg CLK_SYSCLKDiv_64
  472. * @arg CLK_SYSCLKDiv_128
  473. * @retval None
  474. */
  475. void CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_TypeDef CLK_SYSCLKDiv)
  476. {
  477. /* check the parameters */
  478. assert_param(IS_CLK_SYSTEM_DIVIDER(CLK_SYSCLKDiv));
  479. CLK->CKDIVR = (uint8_t)(CLK_SYSCLKDiv);
  480. }
  481. /**
  482. * @brief Enables or disables the clock switch execution.
  483. * @param NewState : new state of clock switch, value accepted ENABLE, DISABLE.
  484. * @retval None
  485. */
  486. void CLK_SYSCLKSourceSwitchCmd(FunctionalState NewState)
  487. {
  488. /* Check the parameters */
  489. assert_param(IS_FUNCTIONAL_STATE(NewState));
  490. if (NewState != DISABLE)
  491. {
  492. /* Set SWEN bit */
  493. CLK->SWCR |= CLK_SWCR_SWEN;
  494. }
  495. else
  496. {
  497. /* Reset SWEN bit */
  498. CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWEN);
  499. }
  500. }
  501. /**
  502. * @}
  503. */
  504. /** @defgroup CLK_Group3 Peripheral clocks configuration functions
  505. * @brief Peripheral clocks configuration functions
  506. *
  507. @verbatim
  508. ===============================================================================
  509. Peripheral clocks configuration functions
  510. ===============================================================================
  511. This section provides functions allowing to configure the Peripheral clocks.
  512. 1. The RTC clock which is derived from the LSI, LSE, HSI or HSE clock divided by 1 to 64.
  513. 2. The BEEP clock which is derived from the LSI or LSE clocks.
  514. 3. After restart from Reset or wakeup from HALT, all peripherals are off
  515. Before to start using a peripheral you have to enable its interface clock.
  516. You can do this using CLK_AHBPeriphClockCmd()
  517. , CLK_APB2PeriphClockCmd() and CLK_APB1PeriphClockCmd() functions.
  518. 4. To reset the peripherals configuration (to the default state after device reset)
  519. you can use CLK_PeripheralClockConfig() function.
  520. @endverbatim
  521. * @{
  522. */
  523. /**
  524. * @brief Configures the RTC clock (RTCCLK).
  525. * @param CLK_RTCCLKSource: specifies the RTC clock source.
  526. * This parameter can be one of the following values:
  527. * @arg CLK_RTCCLKSource_Off: RTC clock Off
  528. * @arg CLK_RTCCLKSource_LSE: LSE selected as RTC clock
  529. * @arg CLK_RTCCLKSource_LSI: LSI selected as RTC clock
  530. * @arg CLK_RTCCLKSource_HSE: HSE selected as RTC clock
  531. * @arg CLK_RTCCLKSource_HSI: HSI selected as RTC clock
  532. *
  533. * @param CLK_RTCCLKDiv: specifies the RTC clock source divider.
  534. * This parameter can be one of the following values:
  535. * @arg CLK_RTCCLKDiv_1: Clock RTC Div 1
  536. * @arg CLK_RTCCLKDiv_2: Clock RTC Div 2
  537. * @arg CLK_RTCCLKDiv_4: Clock RTC Div 4
  538. * @arg CLK_RTCCLKDiv_8: Clock RTC Div 8
  539. * @arg CLK_RTCCLKDiv_16: Clock RTC Div 16
  540. * @arg CLK_RTCCLKDiv_32: Clock RTC Div 32
  541. * @arg CLK_RTCCLKDiv_64: Clock RTC Div 64
  542. *
  543. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  544. * work in HALT and Active HALT modes, and can be used as wakeup source.
  545. * However, when the HSE clock is used as RTC clock source.
  546. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE/HSI as
  547. * RTC clock source).
  548. *
  549. * @retval None
  550. */
  551. void CLK_RTCClockConfig(CLK_RTCCLKSource_TypeDef CLK_RTCCLKSource, CLK_RTCCLKDiv_TypeDef CLK_RTCCLKDiv)
  552. {
  553. /* check the parameters */
  554. assert_param(IS_CLK_CLOCK_RTC(CLK_RTCCLKSource));
  555. assert_param(IS_CLK_CLOCK_RTC_DIV(CLK_RTCCLKDiv));
  556. /* Selects the source provided on to RTC and its divider*/
  557. CLK->CRTCR = (uint8_t)((uint8_t)CLK_RTCCLKSource | (uint8_t)CLK_RTCCLKDiv);
  558. }
  559. /**
  560. * @brief Configures the BEEP clock (BEEPCLK).
  561. * @param CLK_BEEPCLKSource: specifies the BEEP clock source.
  562. * This parameter can be one of the following values:
  563. * @arg CLK_BEEPCLKSource_Off: BEEP clock Off
  564. * @arg CLK_BEEPCLKSource_LSE: LSE selected as BEEP clock
  565. * @arg CLK_BEEPCLKSource_LSI: LSI selected as BEEP clock
  566. * @retval None
  567. */
  568. void CLK_BEEPClockConfig(CLK_BEEPCLKSource_TypeDef CLK_BEEPCLKSource)
  569. {
  570. /* check the parameters */
  571. assert_param(IS_CLK_CLOCK_BEEP(CLK_BEEPCLKSource));
  572. /* Selects the source provided to BEEP*/
  573. CLK->CBEEPR = (uint8_t)(CLK_BEEPCLKSource);
  574. }
  575. /**
  576. * @brief Enables or disables the specified peripheral clock.
  577. * @note After reset, the peripheral clock (used for registers read/write access)
  578. * is disabled and the application software has to enable this clock before
  579. * using it.
  580. * @param CLK_Peripheral: specifies the peripheral to gate its clock.
  581. * This parameter can be any combination of the following values:
  582. * @arg CLK_Peripheral_TIM2: TIM2 clock
  583. * @arg CLK_Peripheral_TIM3: TIM3 clock
  584. * @arg CLK_Peripheral_TIM4: TIM4 clock
  585. * @arg CLK_Peripheral_I2C1: I2C1 clock
  586. * @arg CLK_Peripheral_SPI1: SPI1 clock
  587. * @arg CLK_Peripheral_USART1: USART1 clock
  588. * @arg CLK_Peripheral_BEEP: BEEP clock
  589. * @arg CLK_Peripheral_DAC: DAC clock
  590. * @arg CLK_Peripheral_ADC1: ADC1 clock
  591. * @arg CLK_Peripheral_TIM1: TIM1 clock
  592. * @arg CLK_Peripheral_RTC: RTC clock
  593. * @arg CLK_Peripheral_LCD: LCD clock
  594. * @arg CLK_Peripheral_DMA1: DMA1 clock
  595. * @arg CLK_Peripheral_COMP: COMP clock
  596. * @arg CLK_Peripheral_BOOTROM: BOOTROM clock
  597. * @arg CLK_Peripheral_AES: AES clock
  598. * @arg CLK_Peripheral_TIM5: TIM5 clock
  599. * @arg CLK_Peripheral_SPI2: SPI2 clock
  600. * @arg CLK_Peripheral_USART2: USART2 clock
  601. * @arg CLK_Peripheral_USART3: USART3 clock
  602. * @arg CLK_Peripheral_CSSLSE: CSS on LSE clock
  603. * @param NewState: new state of the specified peripheral clock.
  604. * This parameter can be: ENABLE or DISABLE.
  605. * @retval None
  606. */
  607. void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral, FunctionalState NewState)
  608. {
  609. uint8_t reg = 0;
  610. /* Check the parameters */
  611. assert_param(IS_CLK_PERIPHERAL(CLK_Peripheral));
  612. assert_param(IS_FUNCTIONAL_STATE(NewState));
  613. /* get flag register */
  614. reg = (uint8_t)((uint8_t)CLK_Peripheral & (uint8_t)0xF0);
  615. if ( reg == 0x00)
  616. {
  617. if (NewState != DISABLE)
  618. {
  619. /* Enable the peripheral Clock */
  620. CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F));
  621. }
  622. else
  623. {
  624. /* Disable the peripheral Clock */
  625. CLK->PCKENR1 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F))));
  626. }
  627. }
  628. else if (reg == 0x10)
  629. {
  630. if (NewState != DISABLE)
  631. {
  632. /* Enable the peripheral Clock */
  633. CLK->PCKENR2 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F));
  634. }
  635. else
  636. {
  637. /* Disable the peripheral Clock */
  638. CLK->PCKENR2 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F))));
  639. }
  640. }
  641. else
  642. {
  643. if (NewState != DISABLE)
  644. {
  645. /* Enable the peripheral Clock */
  646. CLK->PCKENR3 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F));
  647. }
  648. else
  649. {
  650. /* Disable the peripheral Clock */
  651. CLK->PCKENR3 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F))));
  652. }
  653. }
  654. }
  655. /**
  656. * @}
  657. */
  658. /** @defgroup CLK_Group4 CSS on LSE configuration functions
  659. * @brief CSS on LSE configuration functions
  660. *
  661. @verbatim
  662. ===============================================================================
  663. CSS on LSE configuration functions
  664. ===============================================================================
  665. This section provides functions allowing to configure the CSS on LSE capability.
  666. 1. The LSE crystal clock source failures can be monitored when used as RTC clock
  667. by the mean of the LSI oscillator.
  668. 2. The CSS on LSE is a feature implemented externally to RTC peripheral and though
  669. has no impact the clock controller registers.
  670. 3. To enable the CSS on LSE you can use CLK_LSEClockSecuritySystemEnable() function
  671. 4. To configure the action to perform at RTC clock failure you can use
  672. CLK_RTCCLKSwitchOnLSEFailureEnable() function that allows to switch the RTC clock
  673. from LSE to LSI.
  674. @endverbatim
  675. * @{
  676. */
  677. /**
  678. * @brief Enables the clock CSS on LSE.
  679. * @note Once Enabled, only POR can Disable it.
  680. * @param None
  681. * @retval None
  682. */
  683. void CLK_LSEClockSecuritySystemEnable(void)
  684. {
  685. /* Set CSSEN bit */
  686. CSSLSE->CSR |= CSSLSE_CSR_CSSEN;
  687. }
  688. /**
  689. * @brief Enables RTC clock switch to LSI in case of LSE failure.
  690. * @note Once Enabled, only POR can Disable it.
  691. * @param None
  692. * @retval None
  693. */
  694. void CLK_RTCCLKSwitchOnLSEFailureEnable(void)
  695. {
  696. /* Set SWITCHEN bit */
  697. CSSLSE->CSR |= CSSLSE_CSR_SWITCHEN;
  698. }
  699. /**
  700. * @}
  701. */
  702. /** @defgroup CLK_Group5 Low power clock configuration functions
  703. * @brief Low power clock configuration functions
  704. *
  705. @verbatim
  706. ===============================================================================
  707. Low power clock configuration functions
  708. ===============================================================================
  709. @endverbatim
  710. * @{
  711. */
  712. /**
  713. * @brief Configures clock during halt and active halt modes.
  714. * @param CLK_Halt : Specifies the clock state and wake-up mode from halt way.
  715. * This parameter can be a value of @ref CLK_Halt_TypeDef.
  716. * @param NewState : Specifies the System clock (SYSCLK) state in active halt mode.
  717. * This parameter can be ENABLE or DISABLE.
  718. * @retval None
  719. */
  720. void CLK_HaltConfig(CLK_Halt_TypeDef CLK_Halt, FunctionalState NewState)
  721. {
  722. /* check the parameters */
  723. assert_param(IS_CLK_HALT(CLK_Halt));
  724. assert_param(IS_FUNCTIONAL_STATE(NewState));
  725. if (NewState != DISABLE)
  726. {
  727. CLK->ICKCR |= (uint8_t)(CLK_Halt);
  728. }
  729. else
  730. {
  731. CLK->ICKCR &= (uint8_t)(~CLK_Halt);
  732. }
  733. }
  734. /**
  735. * @brief Configures the main voltage regulator
  736. * @param NewState: specifies the MVR state.
  737. * This parameter can be one of the following values:
  738. * - DISABLE: MVR disabled;
  739. * - ENABLE: MVR enabled.
  740. * @retval None
  741. */
  742. void CLK_MainRegulatorCmd(FunctionalState NewState)
  743. {
  744. /* check the parameters */
  745. assert_param(IS_FUNCTIONAL_STATE(NewState));
  746. if (NewState != DISABLE)
  747. {
  748. /* Reset REGUOFF bit */
  749. CLK->REGCSR &= (uint8_t)(~CLK_REGCSR_REGOFF);
  750. }
  751. else
  752. {
  753. /* Set REGUOFF bit */
  754. CLK->REGCSR |= CLK_REGCSR_REGOFF;
  755. }
  756. }
  757. /**
  758. * @}
  759. */
  760. /** @defgroup CLK_Group6 Interrupts and flags management functions
  761. * @brief Interrupts and flags management functions
  762. *
  763. @verbatim
  764. ===============================================================================
  765. Interrupts and flags management functions
  766. ===============================================================================
  767. @endverbatim
  768. * @{
  769. */
  770. /**
  771. * @brief Enables or disables the specified CLK interrupts.
  772. * @param CLK_IT: specifies the CLK interrupt sources to be enabled or disabled.
  773. * This parameter can be any combination of the following values:
  774. * @arg CLK_IT_CSSD: Clock security system detection interrupt
  775. * @arg CLK_IT_SWIF: Clock switch interrupt
  776. * @arg CLK_IT_LSECSSF: LSE Clock security system detection interrupt
  777. * @param NewState: new state of the specified CLK interrupts.
  778. * This parameter can be: ENABLE or DISABLE.
  779. * @retval None
  780. */
  781. void CLK_ITConfig(CLK_IT_TypeDef CLK_IT, FunctionalState NewState)
  782. {
  783. /* check the parameters */
  784. assert_param(IS_CLK_IT(CLK_IT));
  785. assert_param(IS_FUNCTIONAL_STATE(NewState));
  786. if (NewState != DISABLE)
  787. {
  788. if (CLK_IT == CLK_IT_SWIF)
  789. {
  790. /* Enable the clock switch interrupt */
  791. CLK->SWCR |= CLK_SWCR_SWIEN;
  792. }
  793. else if (CLK_IT == CLK_IT_LSECSSF)
  794. {
  795. /* Enable the CSS on LSE interrupt */
  796. CSSLSE->CSR |= CSSLSE_CSR_CSSIE;
  797. }
  798. else
  799. {
  800. /* Enable the clock security system detection interrupt */
  801. CLK->CSSR |= CLK_CSSR_CSSDIE;
  802. }
  803. }
  804. else /*(NewState == DISABLE)*/
  805. {
  806. if (CLK_IT == CLK_IT_SWIF)
  807. {
  808. /* Disable the clock switch interrupt */
  809. CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWIEN);
  810. }
  811. else if (CLK_IT == CLK_IT_LSECSSF)
  812. {
  813. /* Disable the CSS on LSE interrupt */
  814. CSSLSE->CSR &= (uint8_t)(~CSSLSE_CSR_CSSIE);
  815. }
  816. else
  817. {
  818. /* Disable the clock security system detection interrupt */
  819. CLK->CSSR &= (uint8_t)(~CLK_CSSR_CSSDIE);
  820. }
  821. }
  822. }
  823. /**
  824. * @brief Checks whether the specified CLK flag is set or not.
  825. * @param CLK_FLAG: specifies the flag to check.
  826. * This parameter can be one of the following values:
  827. * @arg CLK_FLAG_LSIRDY: LSI oscillator clock ready
  828. * @arg CLK_FLAG_HSIRDY: HSI oscillator clock ready
  829. * @arg CLK_FLAG_HSERDY: HSE oscillator clock ready
  830. * @arg CLK_FLAG_SWBSY: Switch busy
  831. * @arg CLK_FLAG_CSSD: Clock security system detection
  832. * @arg CLK_FLAG_AUX: Auxiliary oscillator connected to master clock
  833. * @arg CLK_FLAG_LSERDY: LSE oscillator clock ready
  834. * @arg CLK_FLAG_CCOBSY: Configurable clock output busy
  835. * @arg CLK_FLAG_RTCSWBSY: RTC clock busy in switch
  836. * @arg CLK_FLAG_EEREADY: Flash program memory and Data EEPROM ready
  837. * @arg CLK_FLAG_EEBUSY: Flash program memory and Data EEPROM busy
  838. * @arg CLK_FLAG_LSEPD: LSE power-down
  839. * @arg CLK_FLAG_LSIPD: LSI power-down
  840. * @arg CLK_FLAG_HSEPD: HSE power-down
  841. * @arg CLK_FLAG_HSIPD: HSI power-down
  842. * @arg CLK_FLAG_REGREADY: REGREADY
  843. * @arg CLK_FLAG_BEEPSWBSY: BEEP clock busy in switch
  844. * @arg CLK_FLAG_LSECSSF: CSS on LSE detection
  845. * @arg CLK_FLAG_RTCCLKSWF: RTCCLK switch completed on LSE failure
  846. * @retval The new state of CLK_FLAG (SET or RESET).
  847. */
  848. FlagStatus CLK_GetFlagStatus(CLK_FLAG_TypeDef CLK_FLAG)
  849. {
  850. uint8_t reg = 0;
  851. uint8_t pos = 0;
  852. FlagStatus bitstatus = RESET;
  853. /* check the parameters */
  854. assert_param(IS_CLK_FLAGS(CLK_FLAG));
  855. /* get flag register */
  856. reg = (uint8_t)((uint8_t)CLK_FLAG & (uint8_t)0xF0);
  857. /* get flag position */
  858. pos = (uint8_t)((uint8_t)CLK_FLAG & (uint8_t)0x0F);
  859. if (reg == 0x00) /* The flag to check is in CRTC Rregister */
  860. {
  861. reg = CLK->CRTCR;
  862. }
  863. else if (reg == 0x10) /* The flag to check is in ICKCR register */
  864. {
  865. reg = CLK->ICKCR;
  866. }
  867. else if (reg == 0x20) /* The flag to check is in CCOR register */
  868. {
  869. reg = CLK->CCOR;
  870. }
  871. else if (reg == 0x30) /* The flag to check is in ECKCR register */
  872. {
  873. reg = CLK->ECKCR;
  874. }
  875. else if (reg == 0x40) /* The flag to check is in SWCR register */
  876. {
  877. reg = CLK->SWCR;
  878. }
  879. else if (reg == 0x50) /* The flag to check is in CSSR register */
  880. {
  881. reg = CLK->CSSR;
  882. }
  883. else if (reg == 0x70) /* The flag to check is in REGCSR register */
  884. {
  885. reg = CLK->REGCSR;
  886. }
  887. else if (reg == 0x80) /* The flag to check is in CSSLSE_CSRregister */
  888. {
  889. reg = CSSLSE->CSR;
  890. }
  891. else /* The flag to check is in CBEEPR register */
  892. {
  893. reg = CLK->CBEEPR;
  894. }
  895. if ((reg & (uint8_t)((uint8_t)1 << (uint8_t)pos)) != (uint8_t)RESET)
  896. {
  897. bitstatus = SET;
  898. }
  899. else
  900. {
  901. bitstatus = RESET;
  902. }
  903. /* Return the flag status */
  904. return((FlagStatus)bitstatus);
  905. }
  906. /**
  907. * @brief Clears the CSS LSE Flag.
  908. * @param None
  909. * @retval None
  910. */
  911. void CLK_ClearFlag(void)
  912. {
  913. /* Clear the clock security system on LSE detection Flag */
  914. CSSLSE->CSR &= (uint8_t)(~CSSLSE_CSR_CSSF);
  915. }
  916. /**
  917. * @brief Checks whether the specified CLK interrupt has occurred or not.
  918. * @param CLK_IT: specifies the CLK interrupt source to check.
  919. * This parameter can be one of the following values:
  920. * @arg CLK_IT_SWIF: LSI ready interrupt
  921. * @arg CLK_IT_LSECSSF: LSE ready interrupt
  922. * @arg CLK_IT_CSSD: HSI ready interrupt
  923. * @retval The new state of CLK_IT (SET or RESET).
  924. */
  925. ITStatus CLK_GetITStatus(CLK_IT_TypeDef CLK_IT)
  926. {
  927. ITStatus bitstatus = RESET;
  928. /* check the parameters */
  929. assert_param(IS_CLK_IT(CLK_IT));
  930. if (CLK_IT == CLK_IT_SWIF)
  931. {
  932. /* Check the status of the clock switch interrupt */
  933. if ((CLK->SWCR & (uint8_t)CLK_IT) == (uint8_t)0x0C)
  934. {
  935. bitstatus = SET;
  936. }
  937. else
  938. {
  939. bitstatus = RESET;
  940. }
  941. }
  942. else if (CLK_IT == CLK_IT_LSECSSF)
  943. {
  944. /* Check the status of the clock security system on LSE interrupt */
  945. if ((CSSLSE->CSR & (uint8_t)CLK_IT) == (uint8_t)0x0C)
  946. {
  947. bitstatus = SET;
  948. }
  949. else
  950. {
  951. bitstatus = RESET;
  952. }
  953. }
  954. else /* CLK_IT == CLK_IT_CSSD */
  955. {
  956. /* Check the status of the security system detection interrupt */
  957. if ((CLK->CSSR & (uint8_t)CLK_IT) == (uint8_t)0x0C)
  958. {
  959. bitstatus = SET;
  960. }
  961. else
  962. {
  963. bitstatus = RESET;
  964. }
  965. }
  966. /* Return the CLK_IT status */
  967. return bitstatus;
  968. }
  969. /**
  970. * @brief Clears the CLK's interrupt pending bits.
  971. * @param CLK_IT: specifies the interrupt pending bit to clear.
  972. * This parameter can be any combination of the following values:
  973. * @arg CLK_IT_SWIF: Clock switch interrupt
  974. * @arg CLK_IT_LSECSSF: LSE Clock security system detection interrupt
  975. * @retval None
  976. */
  977. void CLK_ClearITPendingBit(CLK_IT_TypeDef CLK_IT)
  978. {
  979. /* check the parameters */
  980. assert_param(IS_CLK_CLEAR_IT(CLK_IT));
  981. if ((uint8_t)((uint8_t)CLK_IT & (uint8_t)0xF0) == (uint8_t)0x20)
  982. {
  983. /* Clear the status of the clock security system on LSE interrupt */
  984. CSSLSE->CSR &= (uint8_t)(~CSSLSE_CSR_CSSF);
  985. }
  986. else
  987. {
  988. /* Clear the status of the clock switch interrupt */
  989. CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWIF);
  990. }
  991. }
  992. /**
  993. * @}
  994. */
  995. /**
  996. * @}
  997. */
  998. /**
  999. * @}
  1000. */
  1001. /**
  1002. * @}
  1003. */
  1004. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/