• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_rcc.c
4   * @author  MCD Application Team
5   * @version V1.4.0
6   * @date    04-August-2014
7   * @brief   This file provides firmware functions to manage the following
8   *          functionalities of the Reset and clock control (RCC) peripheral:
9   *           + Internal/external clocks, PLL, CSS and MCO configuration
10   *           + System, AHB and APB busses clocks configuration
11   *           + Peripheral clocks configuration
12   *           + Interrupts and flags management
13   *
14  @verbatim
15  ===============================================================================
16                       ##### RCC specific features #####
17  ===============================================================================
18     [..]
19       After reset the device is running from Internal High Speed oscillator
20       (HSI 16MHz) with Flash 0 wait state, Flash prefetch buffer, D-Cache
21       and I-Cache are disabled, and all peripherals are off except internal
22       SRAM, Flash and JTAG.
23       (+) There is no prescaler on High speed (AHB) and Low speed (APB) busses;
24           all peripherals mapped on these busses are running at HSI speed.
25       (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
26       (+) All GPIOs are in input floating state, except the JTAG pins which
27           are assigned to be used for debug purpose.
28     [..]
29       Once the device started from reset, the user application has to:
30       (+) Configure the clock source to be used to drive the System clock
31           (if the application needs higher frequency/performance)
32       (+) Configure the System clock frequency and Flash settings
33       (+) Configure the AHB and APB busses prescalers
34       (+) Enable the clock for the peripheral(s) to be used
35       (+) Configure the clock source(s) for peripherals which clocks are not
36           derived from the System clock (I2S, RTC, ADC, USB OTG FS/SDIO/RNG)
37  @endverbatim
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 
58 /* Includes ------------------------------------------------------------------*/
59 #include "stm32f4xx_rcc.h"
60 #include "stm32f4xx_conf.h"
61 
62 /** @addtogroup STM32F4xx_StdPeriph_Driver
63   * @{
64   */
65 
66 /** @defgroup RCC
67   * @brief RCC driver modules
68   * @{
69   */
70 
71 /* Private typedef -----------------------------------------------------------*/
72 /* Private define ------------------------------------------------------------*/
73 /* ------------ RCC registers bit address in the alias region ----------- */
74 #define RCC_OFFSET                (RCC_BASE - PERIPH_BASE)
75 /* --- CR Register ---*/
76 /* Alias word address of HSION bit */
77 #define CR_OFFSET                 (RCC_OFFSET + 0x00)
78 #define HSION_BitNumber           0x00
79 #define CR_HSION_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))
80 /* Alias word address of CSSON bit */
81 #define CSSON_BitNumber           0x13
82 #define CR_CSSON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))
83 /* Alias word address of PLLON bit */
84 #define PLLON_BitNumber           0x18
85 #define CR_PLLON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))
86 /* Alias word address of PLLI2SON bit */
87 #define PLLI2SON_BitNumber        0x1A
88 #define CR_PLLI2SON_BB            (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLI2SON_BitNumber * 4))
89 
90 /* Alias word address of PLLSAION bit */
91 #define PLLSAION_BitNumber        0x1C
92 #define CR_PLLSAION_BB            (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLSAION_BitNumber * 4))
93 
94 /* --- CFGR Register ---*/
95 /* Alias word address of I2SSRC bit */
96 #define CFGR_OFFSET               (RCC_OFFSET + 0x08)
97 #define I2SSRC_BitNumber          0x17
98 #define CFGR_I2SSRC_BB            (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (I2SSRC_BitNumber * 4))
99 
100 /* --- BDCR Register ---*/
101 /* Alias word address of RTCEN bit */
102 #define BDCR_OFFSET               (RCC_OFFSET + 0x70)
103 #define RTCEN_BitNumber           0x0F
104 #define BDCR_RTCEN_BB             (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))
105 /* Alias word address of BDRST bit */
106 #define BDRST_BitNumber           0x10
107 #define BDCR_BDRST_BB             (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))
108 
109 /* --- CSR Register ---*/
110 /* Alias word address of LSION bit */
111 #define CSR_OFFSET                (RCC_OFFSET + 0x74)
112 #define LSION_BitNumber           0x00
113 #define CSR_LSION_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))
114 
115 /* --- DCKCFGR Register ---*/
116 /* Alias word address of TIMPRE bit */
117 #define DCKCFGR_OFFSET            (RCC_OFFSET + 0x8C)
118 #define TIMPRE_BitNumber          0x18
119 #define DCKCFGR_TIMPRE_BB         (PERIPH_BB_BASE + (DCKCFGR_OFFSET * 32) + (TIMPRE_BitNumber * 4))
120 /* ---------------------- RCC registers bit mask ------------------------ */
121 /* CFGR register bit mask */
122 #define CFGR_MCO2_RESET_MASK      ((uint32_t)0x07FFFFFF)
123 #define CFGR_MCO1_RESET_MASK      ((uint32_t)0xF89FFFFF)
124 
125 /* RCC Flag Mask */
126 #define FLAG_MASK                 ((uint8_t)0x1F)
127 
128 /* CR register byte 3 (Bits[23:16]) base address */
129 #define CR_BYTE3_ADDRESS          ((uint32_t)0x40023802)
130 
131 /* CIR register byte 2 (Bits[15:8]) base address */
132 #define CIR_BYTE2_ADDRESS         ((uint32_t)(RCC_BASE + 0x0C + 0x01))
133 
134 /* CIR register byte 3 (Bits[23:16]) base address */
135 #define CIR_BYTE3_ADDRESS         ((uint32_t)(RCC_BASE + 0x0C + 0x02))
136 
137 /* BDCR register base address */
138 #define BDCR_ADDRESS              (PERIPH_BASE + BDCR_OFFSET)
139 
140 /* Private macro -------------------------------------------------------------*/
141 /* Private variables ---------------------------------------------------------*/
142 static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
143 
144 /* Private function prototypes -----------------------------------------------*/
145 /* Private functions ---------------------------------------------------------*/
146 
147 /** @defgroup RCC_Private_Functions
148   * @{
149   */
150 
151 /** @defgroup RCC_Group1 Internal and external clocks, PLL, CSS and MCO configuration functions
152  *  @brief   Internal and external clocks, PLL, CSS and MCO configuration functions
153  *
154 @verbatim
155  ===================================================================================
156  ##### Internal and  external clocks, PLL, CSS and MCO configuration functions #####
157  ===================================================================================
158     [..]
159       This section provide functions allowing to configure the internal/external clocks,
160       PLLs, CSS and MCO pins.
161 
162       (#) HSI (high-speed internal), 16 MHz factory-trimmed RC used directly or through
163           the PLL as System clock source.
164 
165       (#) LSI (low-speed internal), 32 KHz low consumption RC used as IWDG and/or RTC
166           clock source.
167 
168       (#) HSE (high-speed external), 4 to 26 MHz crystal oscillator used directly or
169           through the PLL as System clock source. Can be used also as RTC clock source.
170 
171       (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
172 
173       (#) PLL (clocked by HSI or HSE), featuring two different output clocks:
174         (++) The first output is used to generate the high speed system clock (up to 168 MHz)
175         (++) The second output is used to generate the clock for the USB OTG FS (48 MHz),
176              the random analog generator (<=48 MHz) and the SDIO (<= 48 MHz).
177 
178       (#) PLLI2S (clocked by HSI or HSE), used to generate an accurate clock to achieve
179           high-quality audio performance on the I2S interface or SAI interface in case
180           of STM32F429x/439x devices.
181 
182       (#) PLLSAI clocked by (HSI or HSE), used to generate an accurate clock to SAI
183           interface and LCD TFT controller available only for STM32F42xxx/43xxx devices.
184 
185       (#) CSS (Clock security system), once enable and if a HSE clock failure occurs
186          (HSE used directly or through PLL as System clock source), the System clock
187          is automatically switched to HSI and an interrupt is generated if enabled.
188          The interrupt is linked to the Cortex-M4 NMI (Non-Maskable Interrupt)
189          exception vector.
190 
191       (#) MCO1 (microcontroller clock output), used to output HSI, LSE, HSE or PLL
192           clock (through a configurable prescaler) on PA8 pin.
193 
194       (#) MCO2 (microcontroller clock output), used to output HSE, PLL, SYSCLK or PLLI2S
195           clock (through a configurable prescaler) on PC9 pin.
196  @endverbatim
197   * @{
198   */
199 
200 /**
201   * @brief  Resets the RCC clock configuration to the default reset state.
202   * @note   The default reset state of the clock configuration is given below:
203   *            - HSI ON and used as system clock source
204   *            - HSE, PLL and PLLI2S OFF
205   *            - AHB, APB1 and APB2 prescaler set to 1.
206   *            - CSS, MCO1 and MCO2 OFF
207   *            - All interrupts disabled
208   * @note   This function doesn't modify the configuration of the
209   *            - Peripheral clocks
210   *            - LSI, LSE and RTC clocks
211   * @param  None
212   * @retval None
213   */
RCC_DeInit(void)214 void RCC_DeInit(void)
215 {
216   /* Set HSION bit */
217   RCC->CR |= (uint32_t)0x00000001;
218 
219   /* Reset CFGR register */
220   RCC->CFGR = 0x00000000;
221 
222   /* Reset HSEON, CSSON, PLLON, PLLI2S and PLLSAI(STM32F42/43xxx devices) bits */
223   RCC->CR &= (uint32_t)0xEAF6FFFF;
224 
225   /* Reset PLLCFGR register */
226   RCC->PLLCFGR = 0x24003010;
227 
228   /* Reset PLLI2SCFGR register */
229   RCC->PLLI2SCFGR = 0x20003000;
230 
231   /* Reset PLLSAICFGR register, only available for STM32F42/43xxx devices */
232   RCC->PLLSAICFGR = 0x24003000;
233 
234   /* Reset HSEBYP bit */
235   RCC->CR &= (uint32_t)0xFFFBFFFF;
236 
237   /* Disable all interrupts */
238   RCC->CIR = 0x00000000;
239 
240   /* Disable Timers clock prescalers selection, only available for STM32F42/43xxx devices */
241   RCC->DCKCFGR = 0x00000000;
242 }
243 
244 /**
245   * @brief  Configures the External High Speed oscillator (HSE).
246   * @note   After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
247   *         software should wait on HSERDY flag to be set indicating that HSE clock
248   *         is stable and can be used to clock the PLL and/or system clock.
249   * @note   HSE state can not be changed if it is used directly or through the
250   *         PLL as system clock. In this case, you have to select another source
251   *         of the system clock then change the HSE state (ex. disable it).
252   * @note   The HSE is stopped by hardware when entering STOP and STANDBY modes.
253   * @note   This function reset the CSSON bit, so if the Clock security system(CSS)
254   *         was previously enabled you have to enable it again after calling this
255   *         function.
256   * @param  RCC_HSE: specifies the new state of the HSE.
257   *          This parameter can be one of the following values:
258   *            @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
259   *                              6 HSE oscillator clock cycles.
260   *            @arg RCC_HSE_ON: turn ON the HSE oscillator
261   *            @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock
262   * @retval None
263   */
RCC_HSEConfig(uint8_t RCC_HSE)264 void RCC_HSEConfig(uint8_t RCC_HSE)
265 {
266   /* Check the parameters */
267   assert_param(IS_RCC_HSE(RCC_HSE));
268 
269   /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
270   *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE_OFF;
271 
272   /* Set the new HSE configuration -------------------------------------------*/
273   *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE;
274 }
275 
276 /**
277   * @brief  Waits for HSE start-up.
278   * @note   This functions waits on HSERDY flag to be set and return SUCCESS if
279   *         this flag is set, otherwise returns ERROR if the timeout is reached
280   *         and this flag is not set. The timeout value is defined by the constant
281   *         HSE_STARTUP_TIMEOUT in stm32f4xx.h file. You can tailor it depending
282   *         on the HSE crystal used in your application.
283   * @param  None
284   * @retval An ErrorStatus enumeration value:
285   *          - SUCCESS: HSE oscillator is stable and ready to use
286   *          - ERROR: HSE oscillator not yet ready
287   */
RCC_WaitForHSEStartUp(void)288 ErrorStatus RCC_WaitForHSEStartUp(void)
289 {
290   __IO uint32_t startupcounter = 0;
291   ErrorStatus status = ERROR;
292   FlagStatus hsestatus = RESET;
293   /* Wait till HSE is ready and if Time out is reached exit */
294   do
295   {
296     hsestatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);
297     startupcounter++;
298   } while((startupcounter != HSE_STARTUP_TIMEOUT) && (hsestatus == RESET));
299 
300   if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)
301   {
302     status = SUCCESS;
303   }
304   else
305   {
306     status = ERROR;
307   }
308   return (status);
309 }
310 
311 /**
312   * @brief  Adjusts the Internal High Speed oscillator (HSI) calibration value.
313   * @note   The calibration is used to compensate for the variations in voltage
314   *         and temperature that influence the frequency of the internal HSI RC.
315   * @param  HSICalibrationValue: specifies the calibration trimming value.
316   *         This parameter must be a number between 0 and 0x1F.
317   * @retval None
318   */
RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)319 void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)
320 {
321   uint32_t tmpreg = 0;
322   /* Check the parameters */
323   assert_param(IS_RCC_CALIBRATION_VALUE(HSICalibrationValue));
324 
325   tmpreg = RCC->CR;
326 
327   /* Clear HSITRIM[4:0] bits */
328   tmpreg &= ~RCC_CR_HSITRIM;
329 
330   /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */
331   tmpreg |= (uint32_t)HSICalibrationValue << 3;
332 
333   /* Store the new value */
334   RCC->CR = tmpreg;
335 }
336 
337 /**
338   * @brief  Enables or disables the Internal High Speed oscillator (HSI).
339   * @note   The HSI is stopped by hardware when entering STOP and STANDBY modes.
340   *         It is used (enabled by hardware) as system clock source after startup
341   *         from Reset, wakeup from STOP and STANDBY mode, or in case of failure
342   *         of the HSE used directly or indirectly as system clock (if the Clock
343   *         Security System CSS is enabled).
344   * @note   HSI can not be stopped if it is used as system clock source. In this case,
345   *         you have to select another source of the system clock then stop the HSI.
346   * @note   After enabling the HSI, the application software should wait on HSIRDY
347   *         flag to be set indicating that HSI clock is stable and can be used as
348   *         system clock source.
349   * @param  NewState: new state of the HSI.
350   *          This parameter can be: ENABLE or DISABLE.
351   * @note   When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
352   *         clock cycles.
353   * @retval None
354   */
RCC_HSICmd(FunctionalState NewState)355 void RCC_HSICmd(FunctionalState NewState)
356 {
357   /* Check the parameters */
358   assert_param(IS_FUNCTIONAL_STATE(NewState));
359 
360   *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;
361 }
362 
363 /**
364   * @brief  Configures the External Low Speed oscillator (LSE).
365   * @note   As the LSE is in the Backup domain and write access is denied to
366   *         this domain after reset, you have to enable write access using
367   *         PWR_BackupAccessCmd(ENABLE) function before to configure the LSE
368   *         (to be done once after reset).
369   * @note   After enabling the LSE (RCC_LSE_ON or RCC_LSE_Bypass), the application
370   *         software should wait on LSERDY flag to be set indicating that LSE clock
371   *         is stable and can be used to clock the RTC.
372   * @param  RCC_LSE: specifies the new state of the LSE.
373   *          This parameter can be one of the following values:
374   *            @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
375   *                              6 LSE oscillator clock cycles.
376   *            @arg RCC_LSE_ON: turn ON the LSE oscillator
377   *            @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock
378   * @retval None
379   */
RCC_LSEConfig(uint8_t RCC_LSE)380 void RCC_LSEConfig(uint8_t RCC_LSE)
381 {
382   /* Check the parameters */
383   assert_param(IS_RCC_LSE(RCC_LSE));
384 
385   /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
386   /* Reset LSEON bit */
387   *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
388 
389   /* Reset LSEBYP bit */
390   *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
391 
392   /* Configure LSE (RCC_LSE_OFF is already covered by the code section above) */
393   switch (RCC_LSE)
394   {
395     case RCC_LSE_ON:
396       /* Set LSEON bit */
397       *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_ON;
398       break;
399     case RCC_LSE_Bypass:
400       /* Set LSEBYP and LSEON bits */
401       *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_Bypass | RCC_LSE_ON;
402       break;
403     default:
404       break;
405   }
406 }
407 
408 /**
409   * @brief  Enables or disables the Internal Low Speed oscillator (LSI).
410   * @note   After enabling the LSI, the application software should wait on
411   *         LSIRDY flag to be set indicating that LSI clock is stable and can
412   *         be used to clock the IWDG and/or the RTC.
413   * @note   LSI can not be disabled if the IWDG is running.
414   * @param  NewState: new state of the LSI.
415   *          This parameter can be: ENABLE or DISABLE.
416   * @note   When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
417   *         clock cycles.
418   * @retval None
419   */
RCC_LSICmd(FunctionalState NewState)420 void RCC_LSICmd(FunctionalState NewState)
421 {
422   /* Check the parameters */
423   assert_param(IS_FUNCTIONAL_STATE(NewState));
424 
425   *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;
426 }
427 
428 /**
429   * @brief  Configures the main PLL clock source, multiplication and division factors.
430   * @note   This function must be used only when the main PLL is disabled.
431   *
432   * @param  RCC_PLLSource: specifies the PLL entry clock source.
433   *          This parameter can be one of the following values:
434   *            @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry
435   *            @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry
436   * @note   This clock source (RCC_PLLSource) is common for the main PLL and PLLI2S.
437   *
438   * @param  PLLM: specifies the division factor for PLL VCO input clock
439   *          This parameter must be a number between 0 and 63.
440   * @note   You have to set the PLLM parameter correctly to ensure that the VCO input
441   *         frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
442   *         of 2 MHz to limit PLL jitter.
443   *
444   * @param  PLLN: specifies the multiplication factor for PLL VCO output clock
445   *          This parameter must be a number between 192 and 432.
446   * @note   You have to set the PLLN parameter correctly to ensure that the VCO
447   *         output frequency is between 192 and 432 MHz.
448   *
449   * @param  PLLP: specifies the division factor for main system clock (SYSCLK)
450   *          This parameter must be a number in the range {2, 4, 6, or 8}.
451   * @note   You have to set the PLLP parameter correctly to not exceed 168 MHz on
452   *         the System clock frequency.
453   *
454   * @param  PLLQ: specifies the division factor for OTG FS, SDIO and RNG clocks
455   *          This parameter must be a number between 4 and 15.
456   * @note   If the USB OTG FS is used in your application, you have to set the
457   *         PLLQ parameter correctly to have 48 MHz clock for the USB. However,
458   *         the SDIO and RNG need a frequency lower than or equal to 48 MHz to work
459   *         correctly.
460   *
461   * @retval None
462   */
RCC_PLLConfig(uint32_t RCC_PLLSource,uint32_t PLLM,uint32_t PLLN,uint32_t PLLP,uint32_t PLLQ)463 void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
464 {
465   /* Check the parameters */
466   assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));
467   assert_param(IS_RCC_PLLM_VALUE(PLLM));
468   assert_param(IS_RCC_PLLN_VALUE(PLLN));
469   assert_param(IS_RCC_PLLP_VALUE(PLLP));
470   assert_param(IS_RCC_PLLQ_VALUE(PLLQ));
471 
472   RCC->PLLCFGR = PLLM | (PLLN << 6) | (((PLLP >> 1) -1) << 16) | (RCC_PLLSource) |
473                  (PLLQ << 24);
474 }
475 
476 /**
477   * @brief  Enables or disables the main PLL.
478   * @note   After enabling the main PLL, the application software should wait on
479   *         PLLRDY flag to be set indicating that PLL clock is stable and can
480   *         be used as system clock source.
481   * @note   The main PLL can not be disabled if it is used as system clock source
482   * @note   The main PLL is disabled by hardware when entering STOP and STANDBY modes.
483   * @param  NewState: new state of the main PLL. This parameter can be: ENABLE or DISABLE.
484   * @retval None
485   */
RCC_PLLCmd(FunctionalState NewState)486 void RCC_PLLCmd(FunctionalState NewState)
487 {
488   /* Check the parameters */
489   assert_param(IS_FUNCTIONAL_STATE(NewState));
490   *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;
491 }
492 
493 #if defined (STM32F40_41xxx) || defined (STM32F401xx)
494 /**
495   * @brief  Configures the PLLI2S clock multiplication and division factors.
496   *
497   * @note   This function can be used only for STM32F405xx/407xx, STM32F415xx/417xx
498   *         or STM32F401xx devices.
499   *
500   * @note   This function must be used only when the PLLI2S is disabled.
501   * @note   PLLI2S clock source is common with the main PLL (configured in
502   *         RCC_PLLConfig function )
503   *
504   * @param  PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
505   *          This parameter must be a number between 192 and 432.
506   * @note   You have to set the PLLI2SN parameter correctly to ensure that the VCO
507   *         output frequency is between 192 and 432 MHz.
508   *
509   * @param  PLLI2SR: specifies the division factor for I2S clock
510   *          This parameter must be a number between 2 and 7.
511   * @note   You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
512   *         on the I2S clock frequency.
513   *
514   * @retval None
515   */
RCC_PLLI2SConfig(uint32_t PLLI2SN,uint32_t PLLI2SR)516 void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SR)
517 {
518   /* Check the parameters */
519   assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
520   assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
521 
522   RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SR << 28);
523 }
524 
525 #elif defined (STM32F411xE)
526 /**
527   * @brief  Configures the PLLI2S clock multiplication and division factors.
528   *
529   * @note   This function can be used only for STM32F411xE devices.
530   *
531   * @note   This function must be used only when the PLLI2S is disabled.
532   * @note   PLLI2S clock source is common with the main PLL (configured in
533   *         RCC_PLLConfig function )
534   *
535   * @param  PLLI2SM: specifies the division factor for PLLI2S VCO input clock
536   *         This parameter must be a number between Min_Data = 2 and Max_Data = 63.
537   * @note   You have to set the PLLI2SM parameter correctly to ensure that the VCO input
538   *         frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
539   *         of 2 MHz to limit PLLI2S jitter.
540   *
541   * @param  PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
542   *          This parameter must be a number between 192 and 432.
543   * @note   You have to set the PLLI2SN parameter correctly to ensure that the VCO
544   *         output frequency is between 192 and 432 MHz.
545   *
546   * @param  PLLI2SR: specifies the division factor for I2S clock
547   *          This parameter must be a number between 2 and 7.
548   * @note   You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
549   *         on the I2S clock frequency.
550   *
551   * @retval None
552   */
RCC_PLLI2SConfig(uint32_t PLLI2SN,uint32_t PLLI2SR,uint32_t PLLI2SM)553 void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SR, uint32_t PLLI2SM)
554 {
555   /* Check the parameters */
556   assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
557   assert_param(IS_RCC_PLLI2SM_VALUE(PLLI2SM));
558   assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
559 
560   RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SR << 28) | PLLI2SM;
561 }
562 
563 #elif defined (STM32F427_437xx) || defined (STM32F429_439xx)
564 /**
565   * @brief  Configures the PLLI2S clock multiplication and division factors.
566   *
567   * @note   This function can be used only for STM32F42xxx/43xxx devices
568   *
569   * @note   This function must be used only when the PLLI2S is disabled.
570   * @note   PLLI2S clock source is common with the main PLL (configured in
571   *         RCC_PLLConfig function )
572   *
573   * @param  PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
574   *          This parameter must be a number between 192 and 432.
575   * @note   You have to set the PLLI2SN parameter correctly to ensure that the VCO
576   *         output frequency is between 192 and 432 MHz.
577   *
578   * @param  PLLI2SQ: specifies the division factor for SAI1 clock
579   *          This parameter must be a number between 2 and 15.
580   *
581   * @param  PLLI2SR: specifies the division factor for I2S clock
582   *          This parameter must be a number between 2 and 7.
583   * @note   You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
584   *         on the I2S clock frequency.
585   * @note   the PLLI2SR parameter is only available with STM32F42xxx/43xxx devices.
586   *
587   * @retval None
588   */
RCC_PLLI2SConfig(uint32_t PLLI2SN,uint32_t PLLI2SQ,uint32_t PLLI2SR)589 void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SQ, uint32_t PLLI2SR)
590 {
591   /* Check the parameters */
592   assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
593   assert_param(IS_RCC_PLLI2SQ_VALUE(PLLI2SQ));
594   assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
595 
596   RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SQ << 24) | (PLLI2SR << 28);
597 }
598 #else
599 #endif /* STM32F40_41xxx || STM32F401xx */
600 
601 /**
602   * @brief  Enables or disables the PLLI2S.
603   * @note   The PLLI2S is disabled by hardware when entering STOP and STANDBY modes.
604   * @param  NewState: new state of the PLLI2S. This parameter can be: ENABLE or DISABLE.
605   * @retval None
606   */
RCC_PLLI2SCmd(FunctionalState NewState)607 void RCC_PLLI2SCmd(FunctionalState NewState)
608 {
609   /* Check the parameters */
610   assert_param(IS_FUNCTIONAL_STATE(NewState));
611   *(__IO uint32_t *) CR_PLLI2SON_BB = (uint32_t)NewState;
612 }
613 
614 /**
615   * @brief  Configures the PLLSAI clock multiplication and division factors.
616   *
617   * @note   This function can be used only for STM32F42xxx/43xxx devices
618   *
619   * @note   This function must be used only when the PLLSAI is disabled.
620   * @note   PLLSAI clock source is common with the main PLL (configured in
621   *         RCC_PLLConfig function )
622   *
623   * @param  PLLSAIN: specifies the multiplication factor for PLLSAI VCO output clock
624   *          This parameter must be a number between 192 and 432.
625   * @note   You have to set the PLLSAIN parameter correctly to ensure that the VCO
626   *         output frequency is between 192 and 432 MHz.
627   *
628   * @param  PLLSAIQ: specifies the division factor for SAI1 clock
629   *          This parameter must be a number between 2 and 15.
630   *
631   * @param  PLLSAIR: specifies the division factor for LTDC clock
632   *          This parameter must be a number between 2 and 7.
633   *
634   * @retval None
635   */
RCC_PLLSAIConfig(uint32_t PLLSAIN,uint32_t PLLSAIQ,uint32_t PLLSAIR)636 void RCC_PLLSAIConfig(uint32_t PLLSAIN, uint32_t PLLSAIQ, uint32_t PLLSAIR)
637 {
638   /* Check the parameters */
639   assert_param(IS_RCC_PLLSAIN_VALUE(PLLSAIN));
640   assert_param(IS_RCC_PLLSAIR_VALUE(PLLSAIR));
641 
642   RCC->PLLSAICFGR = (PLLSAIN << 6) | (PLLSAIQ << 24) | (PLLSAIR << 28);
643 }
644 
645 /**
646   * @brief  Enables or disables the PLLSAI.
647   *
648   * @note   This function can be used only for STM32F42xxx/43xxx devices
649   *
650   * @note   The PLLSAI is disabled by hardware when entering STOP and STANDBY modes.
651   * @param  NewState: new state of the PLLSAI. This parameter can be: ENABLE or DISABLE.
652   * @retval None
653   */
RCC_PLLSAICmd(FunctionalState NewState)654 void RCC_PLLSAICmd(FunctionalState NewState)
655 {
656   /* Check the parameters */
657   assert_param(IS_FUNCTIONAL_STATE(NewState));
658   *(__IO uint32_t *) CR_PLLSAION_BB = (uint32_t)NewState;
659 }
660 
661 /**
662   * @brief  Enables or disables the Clock Security System.
663   * @note   If a failure is detected on the HSE oscillator clock, this oscillator
664   *         is automatically disabled and an interrupt is generated to inform the
665   *         software about the failure (Clock Security System Interrupt, CSSI),
666   *         allowing the MCU to perform rescue operations. The CSSI is linked to
667   *         the Cortex-M4 NMI (Non-Maskable Interrupt) exception vector.
668   * @param  NewState: new state of the Clock Security System.
669   *         This parameter can be: ENABLE or DISABLE.
670   * @retval None
671   */
RCC_ClockSecuritySystemCmd(FunctionalState NewState)672 void RCC_ClockSecuritySystemCmd(FunctionalState NewState)
673 {
674   /* Check the parameters */
675   assert_param(IS_FUNCTIONAL_STATE(NewState));
676   *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;
677 }
678 
679 /**
680   * @brief  Selects the clock source to output on MCO1 pin(PA8).
681   * @note   PA8 should be configured in alternate function mode.
682   * @param  RCC_MCO1Source: specifies the clock source to output.
683   *          This parameter can be one of the following values:
684   *            @arg RCC_MCO1Source_HSI: HSI clock selected as MCO1 source
685   *            @arg RCC_MCO1Source_LSE: LSE clock selected as MCO1 source
686   *            @arg RCC_MCO1Source_HSE: HSE clock selected as MCO1 source
687   *            @arg RCC_MCO1Source_PLLCLK: main PLL clock selected as MCO1 source
688   * @param  RCC_MCO1Div: specifies the MCO1 prescaler.
689   *          This parameter can be one of the following values:
690   *            @arg RCC_MCO1Div_1: no division applied to MCO1 clock
691   *            @arg RCC_MCO1Div_2: division by 2 applied to MCO1 clock
692   *            @arg RCC_MCO1Div_3: division by 3 applied to MCO1 clock
693   *            @arg RCC_MCO1Div_4: division by 4 applied to MCO1 clock
694   *            @arg RCC_MCO1Div_5: division by 5 applied to MCO1 clock
695   * @retval None
696   */
RCC_MCO1Config(uint32_t RCC_MCO1Source,uint32_t RCC_MCO1Div)697 void RCC_MCO1Config(uint32_t RCC_MCO1Source, uint32_t RCC_MCO1Div)
698 {
699   uint32_t tmpreg = 0;
700 
701   /* Check the parameters */
702   assert_param(IS_RCC_MCO1SOURCE(RCC_MCO1Source));
703   assert_param(IS_RCC_MCO1DIV(RCC_MCO1Div));
704 
705   tmpreg = RCC->CFGR;
706 
707   /* Clear MCO1[1:0] and MCO1PRE[2:0] bits */
708   tmpreg &= CFGR_MCO1_RESET_MASK;
709 
710   /* Select MCO1 clock source and prescaler */
711   tmpreg |= RCC_MCO1Source | RCC_MCO1Div;
712 
713   /* Store the new value */
714   RCC->CFGR = tmpreg;
715 }
716 
717 /**
718   * @brief  Selects the clock source to output on MCO2 pin(PC9).
719   * @note   PC9 should be configured in alternate function mode.
720   * @param  RCC_MCO2Source: specifies the clock source to output.
721   *          This parameter can be one of the following values:
722   *            @arg RCC_MCO2Source_SYSCLK: System clock (SYSCLK) selected as MCO2 source
723   *            @arg RCC_MCO2Source_PLLI2SCLK: PLLI2S clock selected as MCO2 source
724   *            @arg RCC_MCO2Source_HSE: HSE clock selected as MCO2 source
725   *            @arg RCC_MCO2Source_PLLCLK: main PLL clock selected as MCO2 source
726   * @param  RCC_MCO2Div: specifies the MCO2 prescaler.
727   *          This parameter can be one of the following values:
728   *            @arg RCC_MCO2Div_1: no division applied to MCO2 clock
729   *            @arg RCC_MCO2Div_2: division by 2 applied to MCO2 clock
730   *            @arg RCC_MCO2Div_3: division by 3 applied to MCO2 clock
731   *            @arg RCC_MCO2Div_4: division by 4 applied to MCO2 clock
732   *            @arg RCC_MCO2Div_5: division by 5 applied to MCO2 clock
733   * @retval None
734   */
RCC_MCO2Config(uint32_t RCC_MCO2Source,uint32_t RCC_MCO2Div)735 void RCC_MCO2Config(uint32_t RCC_MCO2Source, uint32_t RCC_MCO2Div)
736 {
737   uint32_t tmpreg = 0;
738 
739   /* Check the parameters */
740   assert_param(IS_RCC_MCO2SOURCE(RCC_MCO2Source));
741   assert_param(IS_RCC_MCO2DIV(RCC_MCO2Div));
742 
743   tmpreg = RCC->CFGR;
744 
745   /* Clear MCO2 and MCO2PRE[2:0] bits */
746   tmpreg &= CFGR_MCO2_RESET_MASK;
747 
748   /* Select MCO2 clock source and prescaler */
749   tmpreg |= RCC_MCO2Source | RCC_MCO2Div;
750 
751   /* Store the new value */
752   RCC->CFGR = tmpreg;
753 }
754 
755 /**
756   * @}
757   */
758 
759 /** @defgroup RCC_Group2 System AHB and APB busses clocks configuration functions
760  *  @brief   System, AHB and APB busses clocks configuration functions
761  *
762 @verbatim
763  ===============================================================================
764       ##### System, AHB and APB busses clocks configuration functions #####
765  ===============================================================================
766     [..]
767       This section provide functions allowing to configure the System, AHB, APB1 and
768       APB2 busses clocks.
769 
770       (#) Several clock sources can be used to drive the System clock (SYSCLK): HSI,
771           HSE and PLL.
772           The AHB clock (HCLK) is derived from System clock through configurable
773           prescaler and used to clock the CPU, memory and peripherals mapped
774           on AHB bus (DMA, GPIO...). APB1 (PCLK1) and APB2 (PCLK2) clocks are derived
775           from AHB clock through configurable prescalers and used to clock
776           the peripherals mapped on these busses. You can use
777           "RCC_GetClocksFreq()" function to retrieve the frequencies of these clocks.
778 
779       -@- All the peripheral clocks are derived from the System clock (SYSCLK) except:
780         (+@) I2S: the I2S clock can be derived either from a specific PLL (PLLI2S) or
781              from an external clock mapped on the I2S_CKIN pin.
782              You have to use RCC_I2SCLKConfig() function to configure this clock.
783         (+@) RTC: the RTC clock can be derived either from the LSI, LSE or HSE clock
784              divided by 2 to 31. You have to use RCC_RTCCLKConfig() and RCC_RTCCLKCmd()
785              functions to configure this clock.
786         (+@) USB OTG FS, SDIO and RTC: USB OTG FS require a frequency equal to 48 MHz
787              to work correctly, while the SDIO require a frequency equal or lower than
788              to 48. This clock is derived of the main PLL through PLLQ divider.
789         (+@) IWDG clock which is always the LSI clock.
790 
791       (#) For STM32F405xx/407xx and STM32F415xx/417xx devices, the maximum frequency
792          of the SYSCLK and HCLK is 168 MHz, PCLK2 84 MHz and PCLK1 42 MHz. Depending
793          on the device voltage range, the maximum frequency should be adapted accordingly:
794  +-------------------------------------------------------------------------------------+
795  | Latency       |                HCLK clock frequency (MHz)                           |
796  |               |---------------------------------------------------------------------|
797  |               | voltage range  | voltage range  | voltage range   | voltage range   |
798  |               | 2.7 V - 3.6 V  | 2.4 V - 2.7 V  | 2.1 V - 2.4 V   | 1.8 V - 2.1 V   |
799  |---------------|----------------|----------------|-----------------|-----------------|
800  |0WS(1CPU cycle)|0 < HCLK <= 30  |0 < HCLK <= 24  |0 < HCLK <= 22   |0 < HCLK <= 20   |
801  |---------------|----------------|----------------|-----------------|-----------------|
802  |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44  |20 < HCLK <= 40  |
803  |---------------|----------------|----------------|-----------------|-----------------|
804  |2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |44 < HCLK <= 66  |40 < HCLK <= 60  |
805  |---------------|----------------|----------------|-----------------|-----------------|
806  |3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |66 < HCLK <= 88  |60 < HCLK <= 80  |
807  |---------------|----------------|----------------|-----------------|-----------------|
808  |4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|88 < HCLK <= 110 |80 < HCLK <= 100 |
809  |---------------|----------------|----------------|-----------------|-----------------|
810  |5WS(6CPU cycle)|150< HCLK <= 168|120< HCLK <= 144|110 < HCLK <= 132|100 < HCLK <= 120|
811  |---------------|----------------|----------------|-----------------|-----------------|
812  |6WS(7CPU cycle)|      NA        |144< HCLK <= 168|132 < HCLK <= 154|120 < HCLK <= 140|
813  |---------------|----------------|----------------|-----------------|-----------------|
814  |7WS(8CPU cycle)|      NA        |      NA        |154 < HCLK <= 168|140 < HCLK <= 160|
815  +---------------|----------------|----------------|-----------------|-----------------+
816       (#) For STM32F42xxx/43xxx devices, the maximum frequency of the SYSCLK and HCLK is 180 MHz,
817           PCLK2 90 MHz and PCLK1 45 MHz. Depending on the device voltage range, the maximum
818           frequency should be adapted accordingly:
819  +-------------------------------------------------------------------------------------+
820  | Latency       |                HCLK clock frequency (MHz)                           |
821  |               |---------------------------------------------------------------------|
822  |               | voltage range  | voltage range  | voltage range   | voltage range   |
823  |               | 2.7 V - 3.6 V  | 2.4 V - 2.7 V  | 2.1 V - 2.4 V   | 1.8 V - 2.1 V   |
824  |---------------|----------------|----------------|-----------------|-----------------|
825  |0WS(1CPU cycle)|0 < HCLK <= 30  |0 < HCLK <= 24  |0 < HCLK <= 22   |0 < HCLK <= 20   |
826  |---------------|----------------|----------------|-----------------|-----------------|
827  |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44  |20 < HCLK <= 40  |
828  |---------------|----------------|----------------|-----------------|-----------------|
829  |2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |44 < HCLK <= 66  |40 < HCLK <= 60  |
830  |---------------|----------------|----------------|-----------------|-----------------|
831  |3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |66 < HCLK <= 88  |60 < HCLK <= 80  |
832  |---------------|----------------|----------------|-----------------|-----------------|
833  |4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|88 < HCLK <= 110 |80 < HCLK <= 100 |
834  |---------------|----------------|----------------|-----------------|-----------------|
835  |5WS(6CPU cycle)|120< HCLK <= 180|120< HCLK <= 144|110 < HCLK <= 132|100 < HCLK <= 120|
836  |---------------|----------------|----------------|-----------------|-----------------|
837  |6WS(7CPU cycle)|      NA        |144< HCLK <= 168|132 < HCLK <= 154|120 < HCLK <= 140|
838  |---------------|----------------|----------------|-----------------|-----------------|
839  |7WS(8CPU cycle)|      NA        |168< HCLK <= 180|154 < HCLK <= 176|140 < HCLK <= 160|
840  |---------------|----------------|----------------|-----------------|-----------------|
841  |8WS(9CPU cycle)|      NA        |      NA        |176 < HCLK <= 180|160 < HCLK <= 168|
842  +-------------------------------------------------------------------------------------+
843 
844       (#) For STM32F401xx devices, the maximum frequency of the SYSCLK and HCLK is 84 MHz,
845           PCLK2 84 MHz and PCLK1 42 MHz. Depending on the device voltage range, the maximum
846           frequency should be adapted accordingly:
847  +-------------------------------------------------------------------------------------+
848  | Latency       |                HCLK clock frequency (MHz)                           |
849  |               |---------------------------------------------------------------------|
850  |               | voltage range  | voltage range  | voltage range   | voltage range   |
851  |               | 2.7 V - 3.6 V  | 2.4 V - 2.7 V  | 2.1 V - 2.4 V   | 1.8 V - 2.1 V   |
852  |---------------|----------------|----------------|-----------------|-----------------|
853  |0WS(1CPU cycle)|0 < HCLK <= 30  |0 < HCLK <= 24  |0 < HCLK <= 22   |0 < HCLK <= 20   |
854  |---------------|----------------|----------------|-----------------|-----------------|
855  |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44  |20 < HCLK <= 40  |
856  |---------------|----------------|----------------|-----------------|-----------------|
857  |2WS(3CPU cycle)|60 < HCLK <= 84 |48 < HCLK <= 72 |44 < HCLK <= 66  |40 < HCLK <= 60  |
858  |---------------|----------------|----------------|-----------------|-----------------|
859  |3WS(4CPU cycle)|      NA        |72 < HCLK <= 84 |66 < HCLK <= 84  |60 < HCLK <= 80  |
860  |---------------|----------------|----------------|-----------------|-----------------|
861  |4WS(5CPU cycle)|      NA        |      NA        |      NA         |80 < HCLK <= 84  |
862  +-------------------------------------------------------------------------------------+
863 
864       (#) For STM32F411xE devices, the maximum frequency of the SYSCLK and HCLK is 100 MHz,
865           PCLK2 100 MHz and PCLK1 50 MHz. Depending on the device voltage range, the maximum
866           frequency should be adapted accordingly:
867  +-------------------------------------------------------------------------------------+
868  | Latency       |                HCLK clock frequency (MHz)                           |
869  |               |---------------------------------------------------------------------|
870  |               | voltage range  | voltage range  | voltage range   | voltage range   |
871  |               | 2.7 V - 3.6 V  | 2.4 V - 2.7 V  | 2.1 V - 2.4 V   | 1.8 V - 2.1 V   |
872  |---------------|----------------|----------------|-----------------|-----------------|
873  |0WS(1CPU cycle)|0 < HCLK <= 30  |0 < HCLK <= 24  |0 < HCLK <= 18   |0 < HCLK <= 16   |
874  |---------------|----------------|----------------|-----------------|-----------------|
875  |1WS(2CPU cycle)|30 < HCLK <= 64 |24 < HCLK <= 48 |18 < HCLK <= 36  |16 < HCLK <= 32  |
876  |---------------|----------------|----------------|-----------------|-----------------|
877  |2WS(3CPU cycle)|64 < HCLK <= 90 |48 < HCLK <= 72 |36 < HCLK <= 54  |32 < HCLK <= 48  |
878  |---------------|----------------|----------------|-----------------|-----------------|
879  |3WS(4CPU cycle)|90 < HCLK <= 100|72 < HCLK <= 96 |54 < HCLK <= 72  |48 < HCLK <= 64  |
880  |---------------|----------------|----------------|-----------------|-----------------|
881  |4WS(5CPU cycle)|      NA        |96 < HCLK <= 100|72 < HCLK <= 90  |64 < HCLK <= 80  |
882  |---------------|----------------|----------------|-----------------|-----------------|
883  |5WS(6CPU cycle)|      NA        |       NA       |90 < HCLK <= 100 |80 < HCLK <= 96  |
884  |---------------|----------------|----------------|-----------------|-----------------|
885  |6WS(7CPU cycle)|      NA        |       NA       |        NA       |96 < HCLK <= 100 |
886  +-------------------------------------------------------------------------------------+
887 
888       -@- On STM32F405xx/407xx and STM32F415xx/417xx devices:
889            (++) when VOS = '0', the maximum value of fHCLK = 144MHz.
890            (++) when VOS = '1', the maximum value of fHCLK = 168MHz.
891           [..]
892           On STM32F42xxx/43xxx devices:
893            (++) when VOS[1:0] = '0x01', the maximum value of fHCLK is 120MHz.
894            (++) when VOS[1:0] = '0x10', the maximum value of fHCLK is 144MHz.
895            (++) when VOS[1:0] = '0x11', the maximum value of f  is 168MHz
896           [..]
897           On STM32F401x devices:
898            (++) when VOS[1:0] = '0x01', the maximum value of fHCLK is 64MHz.
899            (++) when VOS[1:0] = '0x10', the maximum value of fHCLK is 84MHz.
900           On STM32F411xE devices:
901            (++) when VOS[1:0] = '0x01' the maximum value of fHCLK is 64MHz.
902            (++) when VOS[1:0] = '0x10' the maximum value of fHCLK is 84MHz.
903            (++) when VOS[1:0] = '0x11' the maximum value of fHCLK is 100MHz.
904 
905        You can use PWR_MainRegulatorModeConfig() function to control VOS bits.
906 
907 @endverbatim
908   * @{
909   */
910 
911 /**
912   * @brief  Configures the system clock (SYSCLK).
913   * @note   The HSI is used (enabled by hardware) as system clock source after
914   *         startup from Reset, wake-up from STOP and STANDBY mode, or in case
915   *         of failure of the HSE used directly or indirectly as system clock
916   *         (if the Clock Security System CSS is enabled).
917   * @note   A switch from one clock source to another occurs only if the target
918   *         clock source is ready (clock stable after startup delay or PLL locked).
919   *         If a clock source which is not yet ready is selected, the switch will
920   *         occur when the clock source will be ready.
921   *         You can use RCC_GetSYSCLKSource() function to know which clock is
922   *         currently used as system clock source.
923   * @param  RCC_SYSCLKSource: specifies the clock source used as system clock.
924   *          This parameter can be one of the following values:
925   *            @arg RCC_SYSCLKSource_HSI:    HSI selected as system clock source
926   *            @arg RCC_SYSCLKSource_HSE:    HSE selected as system clock source
927   *            @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock source
928   * @retval None
929   */
RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)930 void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)
931 {
932   uint32_t tmpreg = 0;
933 
934   /* Check the parameters */
935   assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));
936 
937   tmpreg = RCC->CFGR;
938 
939   /* Clear SW[1:0] bits */
940   tmpreg &= ~RCC_CFGR_SW;
941 
942   /* Set SW[1:0] bits according to RCC_SYSCLKSource value */
943   tmpreg |= RCC_SYSCLKSource;
944 
945   /* Store the new value */
946   RCC->CFGR = tmpreg;
947 }
948 
949 /**
950   * @brief  Returns the clock source used as system clock.
951   * @param  None
952   * @retval The clock source used as system clock. The returned value can be one
953   *         of the following:
954   *              - 0x00: HSI used as system clock
955   *              - 0x04: HSE used as system clock
956   *              - 0x08: PLL used as system clock
957   */
RCC_GetSYSCLKSource(void)958 uint8_t RCC_GetSYSCLKSource(void)
959 {
960   return ((uint8_t)(RCC->CFGR & RCC_CFGR_SWS));
961 }
962 
963 /**
964   * @brief  Configures the AHB clock (HCLK).
965   * @note   Depending on the device voltage range, the software has to set correctly
966   *         these bits to ensure that HCLK not exceed the maximum allowed frequency
967   *         (for more details refer to section above
968   *           "CPU, AHB and APB busses clocks configuration functions")
969   * @param  RCC_SYSCLK: defines the AHB clock divider. This clock is derived from
970   *         the system clock (SYSCLK).
971   *          This parameter can be one of the following values:
972   *            @arg RCC_SYSCLK_Div1: AHB clock = SYSCLK
973   *            @arg RCC_SYSCLK_Div2: AHB clock = SYSCLK/2
974   *            @arg RCC_SYSCLK_Div4: AHB clock = SYSCLK/4
975   *            @arg RCC_SYSCLK_Div8: AHB clock = SYSCLK/8
976   *            @arg RCC_SYSCLK_Div16: AHB clock = SYSCLK/16
977   *            @arg RCC_SYSCLK_Div64: AHB clock = SYSCLK/64
978   *            @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128
979   *            @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256
980   *            @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512
981   * @retval None
982   */
RCC_HCLKConfig(uint32_t RCC_SYSCLK)983 void RCC_HCLKConfig(uint32_t RCC_SYSCLK)
984 {
985   uint32_t tmpreg = 0;
986 
987   /* Check the parameters */
988   assert_param(IS_RCC_HCLK(RCC_SYSCLK));
989 
990   tmpreg = RCC->CFGR;
991 
992   /* Clear HPRE[3:0] bits */
993   tmpreg &= ~RCC_CFGR_HPRE;
994 
995   /* Set HPRE[3:0] bits according to RCC_SYSCLK value */
996   tmpreg |= RCC_SYSCLK;
997 
998   /* Store the new value */
999   RCC->CFGR = tmpreg;
1000 }
1001 
1002 
1003 /**
1004   * @brief  Configures the Low Speed APB clock (PCLK1).
1005   * @param  RCC_HCLK: defines the APB1 clock divider. This clock is derived from
1006   *         the AHB clock (HCLK).
1007   *          This parameter can be one of the following values:
1008   *            @arg RCC_HCLK_Div1:  APB1 clock = HCLK
1009   *            @arg RCC_HCLK_Div2:  APB1 clock = HCLK/2
1010   *            @arg RCC_HCLK_Div4:  APB1 clock = HCLK/4
1011   *            @arg RCC_HCLK_Div8:  APB1 clock = HCLK/8
1012   *            @arg RCC_HCLK_Div16: APB1 clock = HCLK/16
1013   * @retval None
1014   */
RCC_PCLK1Config(uint32_t RCC_HCLK)1015 void RCC_PCLK1Config(uint32_t RCC_HCLK)
1016 {
1017   uint32_t tmpreg = 0;
1018 
1019   /* Check the parameters */
1020   assert_param(IS_RCC_PCLK(RCC_HCLK));
1021 
1022   tmpreg = RCC->CFGR;
1023 
1024   /* Clear PPRE1[2:0] bits */
1025   tmpreg &= ~RCC_CFGR_PPRE1;
1026 
1027   /* Set PPRE1[2:0] bits according to RCC_HCLK value */
1028   tmpreg |= RCC_HCLK;
1029 
1030   /* Store the new value */
1031   RCC->CFGR = tmpreg;
1032 }
1033 
1034 /**
1035   * @brief  Configures the High Speed APB clock (PCLK2).
1036   * @param  RCC_HCLK: defines the APB2 clock divider. This clock is derived from
1037   *         the AHB clock (HCLK).
1038   *          This parameter can be one of the following values:
1039   *            @arg RCC_HCLK_Div1:  APB2 clock = HCLK
1040   *            @arg RCC_HCLK_Div2:  APB2 clock = HCLK/2
1041   *            @arg RCC_HCLK_Div4:  APB2 clock = HCLK/4
1042   *            @arg RCC_HCLK_Div8:  APB2 clock = HCLK/8
1043   *            @arg RCC_HCLK_Div16: APB2 clock = HCLK/16
1044   * @retval None
1045   */
RCC_PCLK2Config(uint32_t RCC_HCLK)1046 void RCC_PCLK2Config(uint32_t RCC_HCLK)
1047 {
1048   uint32_t tmpreg = 0;
1049 
1050   /* Check the parameters */
1051   assert_param(IS_RCC_PCLK(RCC_HCLK));
1052 
1053   tmpreg = RCC->CFGR;
1054 
1055   /* Clear PPRE2[2:0] bits */
1056   tmpreg &= ~RCC_CFGR_PPRE2;
1057 
1058   /* Set PPRE2[2:0] bits according to RCC_HCLK value */
1059   tmpreg |= RCC_HCLK << 3;
1060 
1061   /* Store the new value */
1062   RCC->CFGR = tmpreg;
1063 }
1064 
1065 /**
1066   * @brief  Returns the frequencies of different on chip clocks; SYSCLK, HCLK,
1067   *         PCLK1 and PCLK2.
1068   *
1069   * @note   The system frequency computed by this function is not the real
1070   *         frequency in the chip. It is calculated based on the predefined
1071   *         constant and the selected clock source:
1072   * @note     If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
1073   * @note     If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
1074   * @note     If SYSCLK source is PLL, function returns values based on HSE_VALUE(**)
1075   *           or HSI_VALUE(*) multiplied/divided by the PLL factors.
1076   * @note     (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value
1077   *               16 MHz) but the real value may vary depending on the variations
1078   *               in voltage and temperature.
1079   * @note     (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value
1080   *                25 MHz), user has to ensure that HSE_VALUE is same as the real
1081   *                frequency of the crystal used. Otherwise, this function may
1082   *                have wrong result.
1083   *
1084   * @note   The result of this function could be not correct when using fractional
1085   *         value for HSE crystal.
1086   *
1087   * @param  RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold
1088   *          the clocks frequencies.
1089   *
1090   * @note   This function can be used by the user application to compute the
1091   *         baudrate for the communication peripherals or configure other parameters.
1092   * @note   Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function
1093   *         must be called to update the structure's field. Otherwise, any
1094   *         configuration based on this function will be incorrect.
1095   *
1096   * @retval None
1097   */
RCC_GetClocksFreq(RCC_ClocksTypeDef * RCC_Clocks)1098 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)
1099 {
1100   uint32_t tmp = 0, presc = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
1101 
1102   /* Get SYSCLK source -------------------------------------------------------*/
1103   tmp = RCC->CFGR & RCC_CFGR_SWS;
1104 
1105   switch (tmp)
1106   {
1107     case 0x00:  /* HSI used as system clock source */
1108       RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
1109       break;
1110     case 0x04:  /* HSE used as system clock  source */
1111       RCC_Clocks->SYSCLK_Frequency = HSE_VALUE;
1112       break;
1113     case 0x08:  /* PLL used as system clock  source */
1114 
1115       /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
1116          SYSCLK = PLL_VCO / PLLP
1117          */
1118       pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
1119       pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
1120 
1121       if (pllsource != 0)
1122       {
1123         /* HSE used as PLL clock source */
1124         pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
1125       }
1126       else
1127       {
1128         /* HSI used as PLL clock source */
1129         pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
1130       }
1131 
1132       pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
1133       RCC_Clocks->SYSCLK_Frequency = pllvco/pllp;
1134       break;
1135     default:
1136       RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
1137       break;
1138   }
1139   /* Compute HCLK, PCLK1 and PCLK2 clocks frequencies ------------------------*/
1140 
1141   /* Get HCLK prescaler */
1142   tmp = RCC->CFGR & RCC_CFGR_HPRE;
1143   tmp = tmp >> 4;
1144   presc = APBAHBPrescTable[tmp];
1145   /* HCLK clock frequency */
1146   RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;
1147 
1148   /* Get PCLK1 prescaler */
1149   tmp = RCC->CFGR & RCC_CFGR_PPRE1;
1150   tmp = tmp >> 10;
1151   presc = APBAHBPrescTable[tmp];
1152   /* PCLK1 clock frequency */
1153   RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
1154 
1155   /* Get PCLK2 prescaler */
1156   tmp = RCC->CFGR & RCC_CFGR_PPRE2;
1157   tmp = tmp >> 13;
1158   presc = APBAHBPrescTable[tmp];
1159   /* PCLK2 clock frequency */
1160   RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
1161 }
1162 
1163 /**
1164   * @}
1165   */
1166 
1167 /** @defgroup RCC_Group3 Peripheral clocks configuration functions
1168  *  @brief   Peripheral clocks configuration functions
1169  *
1170 @verbatim
1171  ===============================================================================
1172               ##### Peripheral clocks configuration functions #####
1173  ===============================================================================
1174     [..] This section provide functions allowing to configure the Peripheral clocks.
1175 
1176       (#) The RTC clock which is derived from the LSI, LSE or HSE clock divided
1177           by 2 to 31.
1178 
1179       (#) After restart from Reset or wakeup from STANDBY, all peripherals are off
1180           except internal SRAM, Flash and JTAG. Before to start using a peripheral
1181           you have to enable its interface clock. You can do this using
1182           RCC_AHBPeriphClockCmd(), RCC_APB2PeriphClockCmd() and RCC_APB1PeriphClockCmd() functions.
1183 
1184       (#) To reset the peripherals configuration (to the default state after device reset)
1185           you can use RCC_AHBPeriphResetCmd(), RCC_APB2PeriphResetCmd() and
1186           RCC_APB1PeriphResetCmd() functions.
1187 
1188       (#) To further reduce power consumption in SLEEP mode the peripheral clocks
1189           can be disabled prior to executing the WFI or WFE instructions.
1190           You can do this using RCC_AHBPeriphClockLPModeCmd(),
1191           RCC_APB2PeriphClockLPModeCmd() and RCC_APB1PeriphClockLPModeCmd() functions.
1192 
1193 @endverbatim
1194   * @{
1195   */
1196 
1197 /**
1198   * @brief  Configures the RTC clock (RTCCLK).
1199   * @note   As the RTC clock configuration bits are in the Backup domain and write
1200   *         access is denied to this domain after reset, you have to enable write
1201   *         access using PWR_BackupAccessCmd(ENABLE) function before to configure
1202   *         the RTC clock source (to be done once after reset).
1203   * @note   Once the RTC clock is configured it can't be changed unless the
1204   *         Backup domain is reset using RCC_BackupResetCmd() function, or by
1205   *         a Power On Reset (POR).
1206   *
1207   * @param  RCC_RTCCLKSource: specifies the RTC clock source.
1208   *          This parameter can be one of the following values:
1209   *            @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock
1210   *            @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock
1211   *            @arg RCC_RTCCLKSource_HSE_Divx: HSE clock divided by x selected
1212   *                                            as RTC clock, where x:[2,31]
1213   *
1214   * @note   If the LSE or LSI is used as RTC clock source, the RTC continues to
1215   *         work in STOP and STANDBY modes, and can be used as wakeup source.
1216   *         However, when the HSE clock is used as RTC clock source, the RTC
1217   *         cannot be used in STOP and STANDBY modes.
1218   * @note   The maximum input clock frequency for RTC is 1MHz (when using HSE as
1219   *         RTC clock source).
1220   *
1221   * @retval None
1222   */
RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)1223 void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)
1224 {
1225   uint32_t tmpreg = 0;
1226 
1227   /* Check the parameters */
1228   assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));
1229 
1230   if ((RCC_RTCCLKSource & 0x00000300) == 0x00000300)
1231   { /* If HSE is selected as RTC clock source, configure HSE division factor for RTC clock */
1232     tmpreg = RCC->CFGR;
1233 
1234     /* Clear RTCPRE[4:0] bits */
1235     tmpreg &= ~RCC_CFGR_RTCPRE;
1236 
1237     /* Configure HSE division factor for RTC clock */
1238     tmpreg |= (RCC_RTCCLKSource & 0xFFFFCFF);
1239 
1240     /* Store the new value */
1241     RCC->CFGR = tmpreg;
1242   }
1243 
1244   /* Select the RTC clock source */
1245   RCC->BDCR |= (RCC_RTCCLKSource & 0x00000FFF);
1246 }
1247 
1248 /**
1249   * @brief  Enables or disables the RTC clock.
1250   * @note   This function must be used only after the RTC clock source was selected
1251   *         using the RCC_RTCCLKConfig function.
1252   * @param  NewState: new state of the RTC clock. This parameter can be: ENABLE or DISABLE.
1253   * @retval None
1254   */
RCC_RTCCLKCmd(FunctionalState NewState)1255 void RCC_RTCCLKCmd(FunctionalState NewState)
1256 {
1257   /* Check the parameters */
1258   assert_param(IS_FUNCTIONAL_STATE(NewState));
1259 
1260   *(__IO uint32_t *) BDCR_RTCEN_BB = (uint32_t)NewState;
1261 }
1262 
1263 /**
1264   * @brief  Forces or releases the Backup domain reset.
1265   * @note   This function resets the RTC peripheral (including the backup registers)
1266   *         and the RTC clock source selection in RCC_CSR register.
1267   * @note   The BKPSRAM is not affected by this reset.
1268   * @param  NewState: new state of the Backup domain reset.
1269   *          This parameter can be: ENABLE or DISABLE.
1270   * @retval None
1271   */
RCC_BackupResetCmd(FunctionalState NewState)1272 void RCC_BackupResetCmd(FunctionalState NewState)
1273 {
1274   /* Check the parameters */
1275   assert_param(IS_FUNCTIONAL_STATE(NewState));
1276   *(__IO uint32_t *) BDCR_BDRST_BB = (uint32_t)NewState;
1277 }
1278 
1279 /**
1280   * @brief  Configures the I2S clock source (I2SCLK).
1281   * @note   This function must be called before enabling the I2S APB clock.
1282   * @param  RCC_I2SCLKSource: specifies the I2S clock source.
1283   *          This parameter can be one of the following values:
1284   *            @arg RCC_I2S2CLKSource_PLLI2S: PLLI2S clock used as I2S clock source
1285   *            @arg RCC_I2S2CLKSource_Ext: External clock mapped on the I2S_CKIN pin
1286   *                                        used as I2S clock source
1287   * @retval None
1288   */
RCC_I2SCLKConfig(uint32_t RCC_I2SCLKSource)1289 void RCC_I2SCLKConfig(uint32_t RCC_I2SCLKSource)
1290 {
1291   /* Check the parameters */
1292   assert_param(IS_RCC_I2SCLK_SOURCE(RCC_I2SCLKSource));
1293 
1294   *(__IO uint32_t *) CFGR_I2SSRC_BB = RCC_I2SCLKSource;
1295 }
1296 
1297 /**
1298   * @brief  Configures the SAI clock Divider coming from PLLI2S.
1299   *
1300   * @note   This function can be used only for STM32F42xxx/43xxx devices.
1301   *
1302   * @note   This function must be called before enabling the PLLI2S.
1303   *
1304   * @param  RCC_PLLI2SDivQ: specifies the PLLI2S division factor for SAI1 clock .
1305   *          This parameter must be a number between 1 and 32.
1306   *          SAI1 clock frequency = f(PLLI2S_Q) / RCC_PLLI2SDivQ
1307   *
1308   * @retval None
1309   */
RCC_SAIPLLI2SClkDivConfig(uint32_t RCC_PLLI2SDivQ)1310 void RCC_SAIPLLI2SClkDivConfig(uint32_t RCC_PLLI2SDivQ)
1311 {
1312   uint32_t tmpreg = 0;
1313 
1314   /* Check the parameters */
1315   assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(RCC_PLLI2SDivQ));
1316 
1317   tmpreg = RCC->DCKCFGR;
1318 
1319   /* Clear PLLI2SDIVQ[4:0] bits */
1320   tmpreg &= ~(RCC_DCKCFGR_PLLI2SDIVQ);
1321 
1322   /* Set PLLI2SDIVQ values */
1323   tmpreg |= (RCC_PLLI2SDivQ - 1);
1324 
1325   /* Store the new value */
1326   RCC->DCKCFGR = tmpreg;
1327 }
1328 
1329 /**
1330   * @brief  Configures the SAI clock Divider coming from PLLSAI.
1331   *
1332   * @note   This function can be used only for STM32F42xxx/43xxx devices.
1333   *
1334   * @note   This function must be called before enabling the PLLSAI.
1335   *
1336   * @param  RCC_PLLSAIDivQ: specifies the PLLSAI division factor for SAI1 clock .
1337   *          This parameter must be a number between 1 and 32.
1338   *          SAI1 clock frequency = f(PLLSAI_Q) / RCC_PLLSAIDivQ
1339   *
1340   * @retval None
1341   */
RCC_SAIPLLSAIClkDivConfig(uint32_t RCC_PLLSAIDivQ)1342 void RCC_SAIPLLSAIClkDivConfig(uint32_t RCC_PLLSAIDivQ)
1343 {
1344   uint32_t tmpreg = 0;
1345 
1346   /* Check the parameters */
1347   assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(RCC_PLLSAIDivQ));
1348 
1349   tmpreg = RCC->DCKCFGR;
1350 
1351   /* Clear PLLI2SDIVQ[4:0] and PLLSAIDIVQ[4:0] bits */
1352   tmpreg &= ~(RCC_DCKCFGR_PLLSAIDIVQ);
1353 
1354   /* Set PLLSAIDIVQ values */
1355   tmpreg |= ((RCC_PLLSAIDivQ - 1) << 8);
1356 
1357   /* Store the new value */
1358   RCC->DCKCFGR = tmpreg;
1359 }
1360 
1361 /**
1362   * @brief  Configures SAI1BlockA clock source selection.
1363   *
1364   * @note   This function can be used only for STM32F42xxx/43xxx devices.
1365   *
1366   * @note   This function must be called before enabling PLLSAI, PLLI2S and
1367   *         the SAI clock.
1368   * @param  RCC_SAIBlockACLKSource: specifies the SAI Block A clock source.
1369   *          This parameter can be one of the following values:
1370   *            @arg RCC_SAIACLKSource_PLLI2S: PLLI2S_Q clock divided by PLLI2SDIVQ used
1371   *                                           as SAI1 Block A clock
1372   *            @arg RCC_SAIACLKSource_PLLSAI: PLLISAI_Q clock divided by PLLSAIDIVQ used
1373   *                                           as SAI1 Block A clock
1374   *            @arg RCC_SAIACLKSource_Ext: External clock mapped on the I2S_CKIN pin
1375   *                                        used as SAI1 Block A clock
1376   * @retval None
1377   */
RCC_SAIBlockACLKConfig(uint32_t RCC_SAIBlockACLKSource)1378 void RCC_SAIBlockACLKConfig(uint32_t RCC_SAIBlockACLKSource)
1379 {
1380   uint32_t tmpreg = 0;
1381 
1382   /* Check the parameters */
1383   assert_param(IS_RCC_SAIACLK_SOURCE(RCC_SAIBlockACLKSource));
1384 
1385   tmpreg = RCC->DCKCFGR;
1386 
1387   /* Clear RCC_DCKCFGR_SAI1ASRC[1:0] bits */
1388   tmpreg &= ~RCC_DCKCFGR_SAI1ASRC;
1389 
1390   /* Set SAI Block A source selection value */
1391   tmpreg |= RCC_SAIBlockACLKSource;
1392 
1393   /* Store the new value */
1394   RCC->DCKCFGR = tmpreg;
1395 }
1396 
1397 /**
1398   * @brief  Configures SAI1BlockB clock source selection.
1399   *
1400   * @note   This function can be used only for STM32F42xxx/43xxx devices.
1401   *
1402   * @note   This function must be called before enabling PLLSAI, PLLI2S and
1403   *         the SAI clock.
1404   * @param  RCC_SAIBlockBCLKSource: specifies the SAI Block B clock source.
1405   *          This parameter can be one of the following values:
1406   *            @arg RCC_SAIBCLKSource_PLLI2S: PLLI2S_Q clock divided by PLLI2SDIVQ used
1407   *                                           as SAI1 Block B clock
1408   *            @arg RCC_SAIBCLKSource_PLLSAI: PLLISAI_Q clock divided by PLLSAIDIVQ used
1409   *                                           as SAI1 Block B clock
1410   *            @arg RCC_SAIBCLKSource_Ext: External clock mapped on the I2S_CKIN pin
1411   *                                        used as SAI1 Block B clock
1412   * @retval None
1413   */
RCC_SAIBlockBCLKConfig(uint32_t RCC_SAIBlockBCLKSource)1414 void RCC_SAIBlockBCLKConfig(uint32_t RCC_SAIBlockBCLKSource)
1415 {
1416   uint32_t tmpreg = 0;
1417 
1418   /* Check the parameters */
1419   assert_param(IS_RCC_SAIBCLK_SOURCE(RCC_SAIBlockBCLKSource));
1420 
1421   tmpreg = RCC->DCKCFGR;
1422 
1423   /* Clear RCC_DCKCFGR_SAI1BSRC[1:0] bits */
1424   tmpreg &= ~RCC_DCKCFGR_SAI1BSRC;
1425 
1426   /* Set SAI Block B source selection value */
1427   tmpreg |= RCC_SAIBlockBCLKSource;
1428 
1429   /* Store the new value */
1430   RCC->DCKCFGR = tmpreg;
1431 }
1432 
1433 
1434 /**
1435   * @brief  Configures the LTDC clock Divider coming from PLLSAI.
1436   *
1437   * @note   The LTDC peripheral is only available with STM32F429xx/439xx Devices.
1438   *
1439   * @note   This function must be called before enabling the PLLSAI.
1440   *
1441   * @param  RCC_PLLSAIDivR: specifies the PLLSAI division factor for LTDC clock .
1442   *          This parameter must be a number between 2 and 16.
1443   *          LTDC clock frequency = f(PLLSAI_R) / RCC_PLLSAIDivR
1444   *
1445   * @retval None
1446   */
RCC_LTDCCLKDivConfig(uint32_t RCC_PLLSAIDivR)1447 void RCC_LTDCCLKDivConfig(uint32_t RCC_PLLSAIDivR)
1448 {
1449   uint32_t tmpreg = 0;
1450 
1451   /* Check the parameters */
1452   assert_param(IS_RCC_PLLSAI_DIVR_VALUE(RCC_PLLSAIDivR));
1453 
1454   tmpreg = RCC->DCKCFGR;
1455 
1456   /* Clear PLLSAIDIVR[2:0] bits */
1457   tmpreg &= ~RCC_DCKCFGR_PLLSAIDIVR;
1458 
1459   /* Set PLLSAIDIVR values */
1460   tmpreg |= RCC_PLLSAIDivR;
1461 
1462   /* Store the new value */
1463   RCC->DCKCFGR = tmpreg;
1464 }
1465 
1466 /**
1467   * @brief  Configures the Timers clocks prescalers selection.
1468   *
1469   * @note   This function can be used only for STM32F42xxx/43xxx and STM32F401xx/411xE devices.
1470   *
1471   * @param  RCC_TIMCLKPrescaler : specifies the Timers clocks prescalers selection
1472   *         This parameter can be one of the following values:
1473   *            @arg RCC_TIMPrescDesactivated: The Timers kernels clocks prescaler is
1474   *                 equal to HPRE if PPREx is corresponding to division by 1 or 2,
1475   *                 else it is equal to [(HPRE * PPREx) / 2] if PPREx is corresponding to
1476   *                 division by 4 or more.
1477   *
1478   *            @arg RCC_TIMPrescActivated: The Timers kernels clocks prescaler is
1479   *                 equal to HPRE if PPREx is corresponding to division by 1, 2 or 4,
1480   *                 else it is equal to [(HPRE * PPREx) / 4] if PPREx is corresponding
1481   *                 to division by 8 or more.
1482   * @retval None
1483   */
RCC_TIMCLKPresConfig(uint32_t RCC_TIMCLKPrescaler)1484 void RCC_TIMCLKPresConfig(uint32_t RCC_TIMCLKPrescaler)
1485 {
1486   /* Check the parameters */
1487   assert_param(IS_RCC_TIMCLK_PRESCALER(RCC_TIMCLKPrescaler));
1488 
1489   *(__IO uint32_t *) DCKCFGR_TIMPRE_BB = RCC_TIMCLKPrescaler;
1490 
1491 }
1492 
1493 /**
1494   * @brief  Enables or disables the AHB1 peripheral clock.
1495   * @note   After reset, the peripheral clock (used for registers read/write access)
1496   *         is disabled and the application software has to enable this clock before
1497   *         using it.
1498   * @param  RCC_AHBPeriph: specifies the AHB1 peripheral to gates its clock.
1499   *          This parameter can be any combination of the following values:
1500   *            @arg RCC_AHB1Periph_GPIOA:       GPIOA clock
1501   *            @arg RCC_AHB1Periph_GPIOB:       GPIOB clock
1502   *            @arg RCC_AHB1Periph_GPIOC:       GPIOC clock
1503   *            @arg RCC_AHB1Periph_GPIOD:       GPIOD clock
1504   *            @arg RCC_AHB1Periph_GPIOE:       GPIOE clock
1505   *            @arg RCC_AHB1Periph_GPIOF:       GPIOF clock
1506   *            @arg RCC_AHB1Periph_GPIOG:       GPIOG clock
1507   *            @arg RCC_AHB1Periph_GPIOG:       GPIOG clock
1508   *            @arg RCC_AHB1Periph_GPIOI:       GPIOI clock
1509   *            @arg RCC_AHB1Periph_GPIOJ:       GPIOJ clock (STM32F42xxx/43xxx devices)
1510   *            @arg RCC_AHB1Periph_GPIOK:       GPIOK clock (STM32F42xxx/43xxx devices)
1511   *            @arg RCC_AHB1Periph_CRC:         CRC clock
1512   *            @arg RCC_AHB1Periph_BKPSRAM:     BKPSRAM interface clock
1513   *            @arg RCC_AHB1Periph_CCMDATARAMEN CCM data RAM interface clock
1514   *            @arg RCC_AHB1Periph_DMA1:        DMA1 clock
1515   *            @arg RCC_AHB1Periph_DMA2:        DMA2 clock
1516   *            @arg RCC_AHB1Periph_DMA2D:       DMA2D clock (STM32F429xx/439xx devices)
1517   *            @arg RCC_AHB1Periph_ETH_MAC:     Ethernet MAC clock
1518   *            @arg RCC_AHB1Periph_ETH_MAC_Tx:  Ethernet Transmission clock
1519   *            @arg RCC_AHB1Periph_ETH_MAC_Rx:  Ethernet Reception clock
1520   *            @arg RCC_AHB1Periph_ETH_MAC_PTP: Ethernet PTP clock
1521   *            @arg RCC_AHB1Periph_OTG_HS:      USB OTG HS clock
1522   *            @arg RCC_AHB1Periph_OTG_HS_ULPI: USB OTG HS ULPI clock
1523   * @param  NewState: new state of the specified peripheral clock.
1524   *          This parameter can be: ENABLE or DISABLE.
1525   * @retval None
1526   */
RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph,FunctionalState NewState)1527 void RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
1528 {
1529   /* Check the parameters */
1530   assert_param(IS_RCC_AHB1_CLOCK_PERIPH(RCC_AHB1Periph));
1531 
1532   assert_param(IS_FUNCTIONAL_STATE(NewState));
1533   if (NewState != DISABLE)
1534   {
1535     RCC->AHB1ENR |= RCC_AHB1Periph;
1536   }
1537   else
1538   {
1539     RCC->AHB1ENR &= ~RCC_AHB1Periph;
1540   }
1541 }
1542 
1543 /**
1544   * @brief  Enables or disables the AHB2 peripheral clock.
1545   * @note   After reset, the peripheral clock (used for registers read/write access)
1546   *         is disabled and the application software has to enable this clock before
1547   *         using it.
1548   * @param  RCC_AHBPeriph: specifies the AHB2 peripheral to gates its clock.
1549   *          This parameter can be any combination of the following values:
1550   *            @arg RCC_AHB2Periph_DCMI:   DCMI clock
1551   *            @arg RCC_AHB2Periph_CRYP:   CRYP clock
1552   *            @arg RCC_AHB2Periph_HASH:   HASH clock
1553   *            @arg RCC_AHB2Periph_RNG:    RNG clock
1554   *            @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
1555   * @param  NewState: new state of the specified peripheral clock.
1556   *          This parameter can be: ENABLE or DISABLE.
1557   * @retval None
1558   */
RCC_AHB2PeriphClockCmd(uint32_t RCC_AHB2Periph,FunctionalState NewState)1559 void RCC_AHB2PeriphClockCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
1560 {
1561   /* Check the parameters */
1562   assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
1563   assert_param(IS_FUNCTIONAL_STATE(NewState));
1564 
1565   if (NewState != DISABLE)
1566   {
1567     RCC->AHB2ENR |= RCC_AHB2Periph;
1568   }
1569   else
1570   {
1571     RCC->AHB2ENR &= ~RCC_AHB2Periph;
1572   }
1573 }
1574 
1575 /**
1576   * @brief  Enables or disables the AHB3 peripheral clock.
1577   * @note   After reset, the peripheral clock (used for registers read/write access)
1578   *         is disabled and the application software has to enable this clock before
1579   *         using it.
1580   * @param  RCC_AHBPeriph: specifies the AHB3 peripheral to gates its clock.
1581   *          This parameter must be: RCC_AHB3Periph_FSMC
1582   *                                  or RCC_AHB3Periph_FMC (STM32F42xxx/43xxx devices)
1583   * @param  NewState: new state of the specified peripheral clock.
1584   *          This parameter can be: ENABLE or DISABLE.
1585   * @retval None
1586   */
RCC_AHB3PeriphClockCmd(uint32_t RCC_AHB3Periph,FunctionalState NewState)1587 void RCC_AHB3PeriphClockCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState)
1588 {
1589   /* Check the parameters */
1590   assert_param(IS_RCC_AHB3_PERIPH(RCC_AHB3Periph));
1591   assert_param(IS_FUNCTIONAL_STATE(NewState));
1592 
1593   if (NewState != DISABLE)
1594   {
1595     RCC->AHB3ENR |= RCC_AHB3Periph;
1596   }
1597   else
1598   {
1599     RCC->AHB3ENR &= ~RCC_AHB3Periph;
1600   }
1601 }
1602 
1603 /**
1604   * @brief  Enables or disables the Low Speed APB (APB1) peripheral clock.
1605   * @note   After reset, the peripheral clock (used for registers read/write access)
1606   *         is disabled and the application software has to enable this clock before
1607   *         using it.
1608   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
1609   *          This parameter can be any combination of the following values:
1610   *            @arg RCC_APB1Periph_TIM2:   TIM2 clock
1611   *            @arg RCC_APB1Periph_TIM3:   TIM3 clock
1612   *            @arg RCC_APB1Periph_TIM4:   TIM4 clock
1613   *            @arg RCC_APB1Periph_TIM5:   TIM5 clock
1614   *            @arg RCC_APB1Periph_TIM6:   TIM6 clock
1615   *            @arg RCC_APB1Periph_TIM7:   TIM7 clock
1616   *            @arg RCC_APB1Periph_TIM12:  TIM12 clock
1617   *            @arg RCC_APB1Periph_TIM13:  TIM13 clock
1618   *            @arg RCC_APB1Periph_TIM14:  TIM14 clock
1619   *            @arg RCC_APB1Periph_WWDG:   WWDG clock
1620   *            @arg RCC_APB1Periph_SPI2:   SPI2 clock
1621   *            @arg RCC_APB1Periph_SPI3:   SPI3 clock
1622   *            @arg RCC_APB1Periph_USART2: USART2 clock
1623   *            @arg RCC_APB1Periph_USART3: USART3 clock
1624   *            @arg RCC_APB1Periph_UART4:  UART4 clock
1625   *            @arg RCC_APB1Periph_UART5:  UART5 clock
1626   *            @arg RCC_APB1Periph_I2C1:   I2C1 clock
1627   *            @arg RCC_APB1Periph_I2C2:   I2C2 clock
1628   *            @arg RCC_APB1Periph_I2C3:   I2C3 clock
1629   *            @arg RCC_APB1Periph_CAN1:   CAN1 clock
1630   *            @arg RCC_APB1Periph_CAN2:   CAN2 clock
1631   *            @arg RCC_APB1Periph_PWR:    PWR clock
1632   *            @arg RCC_APB1Periph_DAC:    DAC clock
1633   *            @arg RCC_APB1Periph_UART7:  UART7 clock
1634   *            @arg RCC_APB1Periph_UART8:  UART8 clock
1635   * @param  NewState: new state of the specified peripheral clock.
1636   *          This parameter can be: ENABLE or DISABLE.
1637   * @retval None
1638   */
RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph,FunctionalState NewState)1639 void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
1640 {
1641   /* Check the parameters */
1642   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
1643   assert_param(IS_FUNCTIONAL_STATE(NewState));
1644 
1645   if (NewState != DISABLE)
1646   {
1647     RCC->APB1ENR |= RCC_APB1Periph;
1648   }
1649   else
1650   {
1651     RCC->APB1ENR &= ~RCC_APB1Periph;
1652   }
1653 }
1654 
1655 /**
1656   * @brief  Enables or disables the High Speed APB (APB2) peripheral clock.
1657   * @note   After reset, the peripheral clock (used for registers read/write access)
1658   *         is disabled and the application software has to enable this clock before
1659   *         using it.
1660   * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
1661   *          This parameter can be any combination of the following values:
1662   *            @arg RCC_APB2Periph_TIM1:   TIM1 clock
1663   *            @arg RCC_APB2Periph_TIM8:   TIM8 clock
1664   *            @arg RCC_APB2Periph_USART1: USART1 clock
1665   *            @arg RCC_APB2Periph_USART6: USART6 clock
1666   *            @arg RCC_APB2Periph_ADC1:   ADC1 clock
1667   *            @arg RCC_APB2Periph_ADC2:   ADC2 clock
1668   *            @arg RCC_APB2Periph_ADC3:   ADC3 clock
1669   *            @arg RCC_APB2Periph_SDIO:   SDIO clock
1670   *            @arg RCC_APB2Periph_SPI1:   SPI1 clock
1671   *            @arg RCC_APB2Periph_SPI4:   SPI4 clock
1672   *            @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
1673   *            @arg RCC_APB2Periph_TIM9:   TIM9 clock
1674   *            @arg RCC_APB2Periph_TIM10:  TIM10 clock
1675   *            @arg RCC_APB2Periph_TIM11:  TIM11 clock
1676   *            @arg RCC_APB2Periph_SPI5:   SPI5 clock
1677   *            @arg RCC_APB2Periph_SPI6:   SPI6 clock
1678   *            @arg RCC_APB2Periph_SAI1:   SAI1 clock (STM32F42xxx/43xxx devices)
1679   *            @arg RCC_APB2Periph_LTDC:   LTDC clock (STM32F429xx/439xx devices)
1680   * @param  NewState: new state of the specified peripheral clock.
1681   *          This parameter can be: ENABLE or DISABLE.
1682   * @retval None
1683   */
RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph,FunctionalState NewState)1684 void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
1685 {
1686   /* Check the parameters */
1687   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
1688   assert_param(IS_FUNCTIONAL_STATE(NewState));
1689 
1690   if (NewState != DISABLE)
1691   {
1692     RCC->APB2ENR |= RCC_APB2Periph;
1693   }
1694   else
1695   {
1696     RCC->APB2ENR &= ~RCC_APB2Periph;
1697   }
1698 }
1699 
1700 /**
1701   * @brief  Forces or releases AHB1 peripheral reset.
1702   * @param  RCC_AHB1Periph: specifies the AHB1 peripheral to reset.
1703   *          This parameter can be any combination of the following values:
1704   *            @arg RCC_AHB1Periph_GPIOA:   GPIOA clock
1705   *            @arg RCC_AHB1Periph_GPIOB:   GPIOB clock
1706   *            @arg RCC_AHB1Periph_GPIOC:   GPIOC clock
1707   *            @arg RCC_AHB1Periph_GPIOD:   GPIOD clock
1708   *            @arg RCC_AHB1Periph_GPIOE:   GPIOE clock
1709   *            @arg RCC_AHB1Periph_GPIOF:   GPIOF clock
1710   *            @arg RCC_AHB1Periph_GPIOG:   GPIOG clock
1711   *            @arg RCC_AHB1Periph_GPIOG:   GPIOG clock
1712   *            @arg RCC_AHB1Periph_GPIOI:   GPIOI clock
1713   *            @arg RCC_AHB1Periph_GPIOJ:   GPIOJ clock (STM32F42xxx/43xxx devices)
1714   *            @arg RCC_AHB1Periph_GPIOK:   GPIOK clock (STM32F42xxx/43xxxdevices)
1715   *            @arg RCC_AHB1Periph_CRC:     CRC clock
1716   *            @arg RCC_AHB1Periph_DMA1:    DMA1 clock
1717   *            @arg RCC_AHB1Periph_DMA2:    DMA2 clock
1718   *            @arg RCC_AHB1Periph_DMA2D:   DMA2D clock (STM32F429xx/439xx devices)
1719   *            @arg RCC_AHB1Periph_ETH_MAC: Ethernet MAC clock
1720   *            @arg RCC_AHB1Periph_OTG_HS:  USB OTG HS clock
1721   *
1722   * @param  NewState: new state of the specified peripheral reset.
1723   *          This parameter can be: ENABLE or DISABLE.
1724   * @retval None
1725   */
RCC_AHB1PeriphResetCmd(uint32_t RCC_AHB1Periph,FunctionalState NewState)1726 void RCC_AHB1PeriphResetCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
1727 {
1728   /* Check the parameters */
1729   assert_param(IS_RCC_AHB1_RESET_PERIPH(RCC_AHB1Periph));
1730   assert_param(IS_FUNCTIONAL_STATE(NewState));
1731 
1732   if (NewState != DISABLE)
1733   {
1734     RCC->AHB1RSTR |= RCC_AHB1Periph;
1735   }
1736   else
1737   {
1738     RCC->AHB1RSTR &= ~RCC_AHB1Periph;
1739   }
1740 }
1741 
1742 /**
1743   * @brief  Forces or releases AHB2 peripheral reset.
1744   * @param  RCC_AHB2Periph: specifies the AHB2 peripheral to reset.
1745   *          This parameter can be any combination of the following values:
1746   *            @arg RCC_AHB2Periph_DCMI:   DCMI clock
1747   *            @arg RCC_AHB2Periph_CRYP:   CRYP clock
1748   *            @arg RCC_AHB2Periph_HASH:   HASH clock
1749   *            @arg RCC_AHB2Periph_RNG:    RNG clock
1750   *            @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
1751   * @param  NewState: new state of the specified peripheral reset.
1752   *          This parameter can be: ENABLE or DISABLE.
1753   * @retval None
1754   */
RCC_AHB2PeriphResetCmd(uint32_t RCC_AHB2Periph,FunctionalState NewState)1755 void RCC_AHB2PeriphResetCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
1756 {
1757   /* Check the parameters */
1758   assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
1759   assert_param(IS_FUNCTIONAL_STATE(NewState));
1760 
1761   if (NewState != DISABLE)
1762   {
1763     RCC->AHB2RSTR |= RCC_AHB2Periph;
1764   }
1765   else
1766   {
1767     RCC->AHB2RSTR &= ~RCC_AHB2Periph;
1768   }
1769 }
1770 
1771 /**
1772   * @brief  Forces or releases AHB3 peripheral reset.
1773   * @param  RCC_AHB3Periph: specifies the AHB3 peripheral to reset.
1774   *          This parameter must be: RCC_AHB3Periph_FSMC
1775   *                                  or RCC_AHB3Periph_FMC (STM32F42xxx/43xxx devices)
1776   * @param  NewState: new state of the specified peripheral reset.
1777   *          This parameter can be: ENABLE or DISABLE.
1778   * @retval None
1779   */
RCC_AHB3PeriphResetCmd(uint32_t RCC_AHB3Periph,FunctionalState NewState)1780 void RCC_AHB3PeriphResetCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState)
1781 {
1782   /* Check the parameters */
1783   assert_param(IS_RCC_AHB3_PERIPH(RCC_AHB3Periph));
1784   assert_param(IS_FUNCTIONAL_STATE(NewState));
1785 
1786   if (NewState != DISABLE)
1787   {
1788     RCC->AHB3RSTR |= RCC_AHB3Periph;
1789   }
1790   else
1791   {
1792     RCC->AHB3RSTR &= ~RCC_AHB3Periph;
1793   }
1794 }
1795 
1796 /**
1797   * @brief  Forces or releases Low Speed APB (APB1) peripheral reset.
1798   * @param  RCC_APB1Periph: specifies the APB1 peripheral to reset.
1799   *          This parameter can be any combination of the following values:
1800   *            @arg RCC_APB1Periph_TIM2:   TIM2 clock
1801   *            @arg RCC_APB1Periph_TIM3:   TIM3 clock
1802   *            @arg RCC_APB1Periph_TIM4:   TIM4 clock
1803   *            @arg RCC_APB1Periph_TIM5:   TIM5 clock
1804   *            @arg RCC_APB1Periph_TIM6:   TIM6 clock
1805   *            @arg RCC_APB1Periph_TIM7:   TIM7 clock
1806   *            @arg RCC_APB1Periph_TIM12:  TIM12 clock
1807   *            @arg RCC_APB1Periph_TIM13:  TIM13 clock
1808   *            @arg RCC_APB1Periph_TIM14:  TIM14 clock
1809   *            @arg RCC_APB1Periph_WWDG:   WWDG clock
1810   *            @arg RCC_APB1Periph_SPI2:   SPI2 clock
1811   *            @arg RCC_APB1Periph_SPI3:   SPI3 clock
1812   *            @arg RCC_APB1Periph_USART2: USART2 clock
1813   *            @arg RCC_APB1Periph_USART3: USART3 clock
1814   *            @arg RCC_APB1Periph_UART4:  UART4 clock
1815   *            @arg RCC_APB1Periph_UART5:  UART5 clock
1816   *            @arg RCC_APB1Periph_I2C1:   I2C1 clock
1817   *            @arg RCC_APB1Periph_I2C2:   I2C2 clock
1818   *            @arg RCC_APB1Periph_I2C3:   I2C3 clock
1819   *            @arg RCC_APB1Periph_CAN1:   CAN1 clock
1820   *            @arg RCC_APB1Periph_CAN2:   CAN2 clock
1821   *            @arg RCC_APB1Periph_PWR:    PWR clock
1822   *            @arg RCC_APB1Periph_DAC:    DAC clock
1823   *            @arg RCC_APB1Periph_UART7:  UART7 clock
1824   *            @arg RCC_APB1Periph_UART8:  UART8 clock
1825   * @param  NewState: new state of the specified peripheral reset.
1826   *          This parameter can be: ENABLE or DISABLE.
1827   * @retval None
1828   */
RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph,FunctionalState NewState)1829 void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
1830 {
1831   /* Check the parameters */
1832   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
1833   assert_param(IS_FUNCTIONAL_STATE(NewState));
1834   if (NewState != DISABLE)
1835   {
1836     RCC->APB1RSTR |= RCC_APB1Periph;
1837   }
1838   else
1839   {
1840     RCC->APB1RSTR &= ~RCC_APB1Periph;
1841   }
1842 }
1843 
1844 /**
1845   * @brief  Forces or releases High Speed APB (APB2) peripheral reset.
1846   * @param  RCC_APB2Periph: specifies the APB2 peripheral to reset.
1847   *          This parameter can be any combination of the following values:
1848   *            @arg RCC_APB2Periph_TIM1:   TIM1 clock
1849   *            @arg RCC_APB2Periph_TIM8:   TIM8 clock
1850   *            @arg RCC_APB2Periph_USART1: USART1 clock
1851   *            @arg RCC_APB2Periph_USART6: USART6 clock
1852   *            @arg RCC_APB2Periph_ADC1:   ADC1 clock
1853   *            @arg RCC_APB2Periph_ADC2:   ADC2 clock
1854   *            @arg RCC_APB2Periph_ADC3:   ADC3 clock
1855   *            @arg RCC_APB2Periph_SDIO:   SDIO clock
1856   *            @arg RCC_APB2Periph_SPI1:   SPI1 clock
1857   *            @arg RCC_APB2Periph_SPI4:   SPI4 clock
1858   *            @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
1859   *            @arg RCC_APB2Periph_TIM9:   TIM9 clock
1860   *            @arg RCC_APB2Periph_TIM10:  TIM10 clock
1861   *            @arg RCC_APB2Periph_TIM11:  TIM11 clock
1862   *            @arg RCC_APB2Periph_SPI5:   SPI5 clock
1863   *            @arg RCC_APB2Periph_SPI6:   SPI6 clock
1864   *            @arg RCC_APB2Periph_SAI1:   SAI1 clock (STM32F42xxx/43xxx devices)
1865   *            @arg RCC_APB2Periph_LTDC:   LTDC clock (STM32F429xx/439xx devices)
1866   * @param  NewState: new state of the specified peripheral reset.
1867   *          This parameter can be: ENABLE or DISABLE.
1868   * @retval None
1869   */
RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph,FunctionalState NewState)1870 void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
1871 {
1872   /* Check the parameters */
1873   assert_param(IS_RCC_APB2_RESET_PERIPH(RCC_APB2Periph));
1874   assert_param(IS_FUNCTIONAL_STATE(NewState));
1875   if (NewState != DISABLE)
1876   {
1877     RCC->APB2RSTR |= RCC_APB2Periph;
1878   }
1879   else
1880   {
1881     RCC->APB2RSTR &= ~RCC_APB2Periph;
1882   }
1883 }
1884 
1885 /**
1886   * @brief  Enables or disables the AHB1 peripheral clock during Low Power (Sleep) mode.
1887   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
1888   *         power consumption.
1889   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
1890   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
1891   * @param  RCC_AHBPeriph: specifies the AHB1 peripheral to gates its clock.
1892   *          This parameter can be any combination of the following values:
1893   *            @arg RCC_AHB1Periph_GPIOA:       GPIOA clock
1894   *            @arg RCC_AHB1Periph_GPIOB:       GPIOB clock
1895   *            @arg RCC_AHB1Periph_GPIOC:       GPIOC clock
1896   *            @arg RCC_AHB1Periph_GPIOD:       GPIOD clock
1897   *            @arg RCC_AHB1Periph_GPIOE:       GPIOE clock
1898   *            @arg RCC_AHB1Periph_GPIOF:       GPIOF clock
1899   *            @arg RCC_AHB1Periph_GPIOG:       GPIOG clock
1900   *            @arg RCC_AHB1Periph_GPIOG:       GPIOG clock
1901   *            @arg RCC_AHB1Periph_GPIOI:       GPIOI clock
1902   *            @arg RCC_AHB1Periph_GPIOJ:       GPIOJ clock (STM32F42xxx/43xxx devices)
1903   *            @arg RCC_AHB1Periph_GPIOK:       GPIOK clock (STM32F42xxx/43xxx devices)
1904   *            @arg RCC_AHB1Periph_CRC:         CRC clock
1905   *            @arg RCC_AHB1Periph_BKPSRAM:     BKPSRAM interface clock
1906   *            @arg RCC_AHB1Periph_DMA1:        DMA1 clock
1907   *            @arg RCC_AHB1Periph_DMA2:        DMA2 clock
1908   *            @arg RCC_AHB1Periph_DMA2D:       DMA2D clock (STM32F429xx/439xx devices)
1909   *            @arg RCC_AHB1Periph_ETH_MAC:     Ethernet MAC clock
1910   *            @arg RCC_AHB1Periph_ETH_MAC_Tx:  Ethernet Transmission clock
1911   *            @arg RCC_AHB1Periph_ETH_MAC_Rx:  Ethernet Reception clock
1912   *            @arg RCC_AHB1Periph_ETH_MAC_PTP: Ethernet PTP clock
1913   *            @arg RCC_AHB1Periph_OTG_HS:      USB OTG HS clock
1914   *            @arg RCC_AHB1Periph_OTG_HS_ULPI: USB OTG HS ULPI clock
1915   * @param  NewState: new state of the specified peripheral clock.
1916   *          This parameter can be: ENABLE or DISABLE.
1917   * @retval None
1918   */
RCC_AHB1PeriphClockLPModeCmd(uint32_t RCC_AHB1Periph,FunctionalState NewState)1919 void RCC_AHB1PeriphClockLPModeCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
1920 {
1921   /* Check the parameters */
1922   assert_param(IS_RCC_AHB1_LPMODE_PERIPH(RCC_AHB1Periph));
1923   assert_param(IS_FUNCTIONAL_STATE(NewState));
1924   if (NewState != DISABLE)
1925   {
1926     RCC->AHB1LPENR |= RCC_AHB1Periph;
1927   }
1928   else
1929   {
1930     RCC->AHB1LPENR &= ~RCC_AHB1Periph;
1931   }
1932 }
1933 
1934 /**
1935   * @brief  Enables or disables the AHB2 peripheral clock during Low Power (Sleep) mode.
1936   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
1937   *           power consumption.
1938   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
1939   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
1940   * @param  RCC_AHBPeriph: specifies the AHB2 peripheral to gates its clock.
1941   *          This parameter can be any combination of the following values:
1942   *            @arg RCC_AHB2Periph_DCMI:   DCMI clock
1943   *            @arg RCC_AHB2Periph_CRYP:   CRYP clock
1944   *            @arg RCC_AHB2Periph_HASH:   HASH clock
1945   *            @arg RCC_AHB2Periph_RNG:    RNG clock
1946   *            @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
1947   * @param  NewState: new state of the specified peripheral clock.
1948   *          This parameter can be: ENABLE or DISABLE.
1949   * @retval None
1950   */
RCC_AHB2PeriphClockLPModeCmd(uint32_t RCC_AHB2Periph,FunctionalState NewState)1951 void RCC_AHB2PeriphClockLPModeCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
1952 {
1953   /* Check the parameters */
1954   assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
1955   assert_param(IS_FUNCTIONAL_STATE(NewState));
1956   if (NewState != DISABLE)
1957   {
1958     RCC->AHB2LPENR |= RCC_AHB2Periph;
1959   }
1960   else
1961   {
1962     RCC->AHB2LPENR &= ~RCC_AHB2Periph;
1963   }
1964 }
1965 
1966 /**
1967   * @brief  Enables or disables the AHB3 peripheral clock during Low Power (Sleep) mode.
1968   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
1969   *         power consumption.
1970   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
1971   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
1972   * @param  RCC_AHBPeriph: specifies the AHB3 peripheral to gates its clock.
1973   *          This parameter must be: RCC_AHB3Periph_FSMC
1974   *                                  or RCC_AHB3Periph_FMC (STM32F429x/439x devices)
1975   * @param  NewState: new state of the specified peripheral clock.
1976   *          This parameter can be: ENABLE or DISABLE.
1977   * @retval None
1978   */
RCC_AHB3PeriphClockLPModeCmd(uint32_t RCC_AHB3Periph,FunctionalState NewState)1979 void RCC_AHB3PeriphClockLPModeCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState)
1980 {
1981   /* Check the parameters */
1982   assert_param(IS_RCC_AHB3_PERIPH(RCC_AHB3Periph));
1983   assert_param(IS_FUNCTIONAL_STATE(NewState));
1984   if (NewState != DISABLE)
1985   {
1986     RCC->AHB3LPENR |= RCC_AHB3Periph;
1987   }
1988   else
1989   {
1990     RCC->AHB3LPENR &= ~RCC_AHB3Periph;
1991   }
1992 }
1993 
1994 /**
1995   * @brief  Enables or disables the APB1 peripheral clock during Low Power (Sleep) mode.
1996   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
1997   *         power consumption.
1998   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
1999   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
2000   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
2001   *          This parameter can be any combination of the following values:
2002   *            @arg RCC_APB1Periph_TIM2:   TIM2 clock
2003   *            @arg RCC_APB1Periph_TIM3:   TIM3 clock
2004   *            @arg RCC_APB1Periph_TIM4:   TIM4 clock
2005   *            @arg RCC_APB1Periph_TIM5:   TIM5 clock
2006   *            @arg RCC_APB1Periph_TIM6:   TIM6 clock
2007   *            @arg RCC_APB1Periph_TIM7:   TIM7 clock
2008   *            @arg RCC_APB1Periph_TIM12:  TIM12 clock
2009   *            @arg RCC_APB1Periph_TIM13:  TIM13 clock
2010   *            @arg RCC_APB1Periph_TIM14:  TIM14 clock
2011   *            @arg RCC_APB1Periph_WWDG:   WWDG clock
2012   *            @arg RCC_APB1Periph_SPI2:   SPI2 clock
2013   *            @arg RCC_APB1Periph_SPI3:   SPI3 clock
2014   *            @arg RCC_APB1Periph_USART2: USART2 clock
2015   *            @arg RCC_APB1Periph_USART3: USART3 clock
2016   *            @arg RCC_APB1Periph_UART4:  UART4 clock
2017   *            @arg RCC_APB1Periph_UART5:  UART5 clock
2018   *            @arg RCC_APB1Periph_I2C1:   I2C1 clock
2019   *            @arg RCC_APB1Periph_I2C2:   I2C2 clock
2020   *            @arg RCC_APB1Periph_I2C3:   I2C3 clock
2021   *            @arg RCC_APB1Periph_CAN1:   CAN1 clock
2022   *            @arg RCC_APB1Periph_CAN2:   CAN2 clock
2023   *            @arg RCC_APB1Periph_PWR:    PWR clock
2024   *            @arg RCC_APB1Periph_DAC:    DAC clock
2025   *            @arg RCC_APB1Periph_UART7:  UART7 clock
2026   *            @arg RCC_APB1Periph_UART8:  UART8 clock
2027   * @param  NewState: new state of the specified peripheral clock.
2028   *          This parameter can be: ENABLE or DISABLE.
2029   * @retval None
2030   */
RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph,FunctionalState NewState)2031 void RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
2032 {
2033   /* Check the parameters */
2034   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
2035   assert_param(IS_FUNCTIONAL_STATE(NewState));
2036   if (NewState != DISABLE)
2037   {
2038     RCC->APB1LPENR |= RCC_APB1Periph;
2039   }
2040   else
2041   {
2042     RCC->APB1LPENR &= ~RCC_APB1Periph;
2043   }
2044 }
2045 
2046 /**
2047   * @brief  Enables or disables the APB2 peripheral clock during Low Power (Sleep) mode.
2048   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
2049   *         power consumption.
2050   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
2051   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
2052   * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
2053   *          This parameter can be any combination of the following values:
2054   *            @arg RCC_APB2Periph_TIM1:   TIM1 clock
2055   *            @arg RCC_APB2Periph_TIM8:   TIM8 clock
2056   *            @arg RCC_APB2Periph_USART1: USART1 clock
2057   *            @arg RCC_APB2Periph_USART6: USART6 clock
2058   *            @arg RCC_APB2Periph_ADC1:   ADC1 clock
2059   *            @arg RCC_APB2Periph_ADC2:   ADC2 clock
2060   *            @arg RCC_APB2Periph_ADC3:   ADC3 clock
2061   *            @arg RCC_APB2Periph_SDIO:   SDIO clock
2062   *            @arg RCC_APB2Periph_SPI1:   SPI1 clock
2063   *            @arg RCC_APB2Periph_SPI4:   SPI4 clock
2064   *            @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
2065   *            @arg RCC_APB2Periph_TIM9:   TIM9 clock
2066   *            @arg RCC_APB2Periph_TIM10:  TIM10 clock
2067   *            @arg RCC_APB2Periph_TIM11:  TIM11 clock
2068   *            @arg RCC_APB2Periph_SPI5:   SPI5 clock
2069   *            @arg RCC_APB2Periph_SPI6:   SPI6 clock
2070   *            @arg RCC_APB2Periph_SAI1:   SAI1 clock (STM32F42xxx/43xxx devices)
2071   *            @arg RCC_APB2Periph_LTDC:   LTDC clock (STM32F429xx/439xx devices)
2072   * @param  NewState: new state of the specified peripheral clock.
2073   *          This parameter can be: ENABLE or DISABLE.
2074   * @retval None
2075   */
RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph,FunctionalState NewState)2076 void RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
2077 {
2078   /* Check the parameters */
2079   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
2080   assert_param(IS_FUNCTIONAL_STATE(NewState));
2081   if (NewState != DISABLE)
2082   {
2083     RCC->APB2LPENR |= RCC_APB2Periph;
2084   }
2085   else
2086   {
2087     RCC->APB2LPENR &= ~RCC_APB2Periph;
2088   }
2089 }
2090 
2091 /**
2092   * @brief Configures the External Low Speed oscillator mode (LSE mode).
2093   * @note This mode is only available for STM32F411xx devices.
2094   * @param  Mode: specifies the LSE mode.
2095   *          This parameter can be one of the following values:
2096   *            @arg RCC_LSE_LOWPOWER_MODE:  LSE oscillator in low power mode.
2097   *            @arg RCC_LSE_HIGHDRIVE_MODE: LSE oscillator in High Drive mode.
2098   * @retval None
2099   */
RCC_LSEModeConfig(uint8_t Mode)2100 void RCC_LSEModeConfig(uint8_t Mode)
2101 {
2102   /* Check the parameters */
2103   assert_param(IS_RCC_LSE_MODE(Mode));
2104 
2105   if(Mode == RCC_LSE_HIGHDRIVE_MODE)
2106   {
2107     SET_BIT(RCC->BDCR, RCC_BDCR_LSEMOD);
2108   }
2109   else
2110   {
2111     CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEMOD);
2112   }
2113 }
2114 
2115 /**
2116   * @}
2117   */
2118 
2119 /** @defgroup RCC_Group4 Interrupts and flags management functions
2120  *  @brief   Interrupts and flags management functions
2121  *
2122 @verbatim
2123  ===============================================================================
2124                 ##### Interrupts and flags management functions #####
2125  ===============================================================================
2126 
2127 @endverbatim
2128   * @{
2129   */
2130 
2131 /**
2132   * @brief  Enables or disables the specified RCC interrupts.
2133   * @param  RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.
2134   *          This parameter can be any combination of the following values:
2135   *            @arg RCC_IT_LSIRDY: LSI ready interrupt
2136   *            @arg RCC_IT_LSERDY: LSE ready interrupt
2137   *            @arg RCC_IT_HSIRDY: HSI ready interrupt
2138   *            @arg RCC_IT_HSERDY: HSE ready interrupt
2139   *            @arg RCC_IT_PLLRDY: main PLL ready interrupt
2140   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt
2141   *            @arg RCC_IT_PLLSAIRDY: PLLSAI ready interrupt (only for STM32F42xxx/43xxx devices)
2142   * @param  NewState: new state of the specified RCC interrupts.
2143   *          This parameter can be: ENABLE or DISABLE.
2144   * @retval None
2145   */
RCC_ITConfig(uint8_t RCC_IT,FunctionalState NewState)2146 void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)
2147 {
2148   /* Check the parameters */
2149   assert_param(IS_RCC_IT(RCC_IT));
2150   assert_param(IS_FUNCTIONAL_STATE(NewState));
2151   if (NewState != DISABLE)
2152   {
2153     /* Perform Byte access to RCC_CIR[14:8] bits to enable the selected interrupts */
2154     *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;
2155   }
2156   else
2157   {
2158     /* Perform Byte access to RCC_CIR[14:8] bits to disable the selected interrupts */
2159     *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;
2160   }
2161 }
2162 
2163 /**
2164   * @brief  Checks whether the specified RCC flag is set or not.
2165   * @param  RCC_FLAG: specifies the flag to check.
2166   *          This parameter can be one of the following values:
2167   *            @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
2168   *            @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
2169   *            @arg RCC_FLAG_PLLRDY: main PLL clock ready
2170   *            @arg RCC_FLAG_PLLI2SRDY: PLLI2S clock ready
2171   *            @arg RCC_FLAG_PLLSAIRDY: PLLSAI clock ready (only for STM32F42xxx/43xxx devices)
2172   *            @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
2173   *            @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
2174   *            @arg RCC_FLAG_BORRST: POR/PDR or BOR reset
2175   *            @arg RCC_FLAG_PINRST: Pin reset
2176   *            @arg RCC_FLAG_PORRST: POR/PDR reset
2177   *            @arg RCC_FLAG_SFTRST: Software reset
2178   *            @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
2179   *            @arg RCC_FLAG_WWDGRST: Window Watchdog reset
2180   *            @arg RCC_FLAG_LPWRRST: Low Power reset
2181   * @retval The new state of RCC_FLAG (SET or RESET).
2182   */
RCC_GetFlagStatus(uint8_t RCC_FLAG)2183 FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
2184 {
2185   uint32_t tmp = 0;
2186   uint32_t statusreg = 0;
2187   FlagStatus bitstatus = RESET;
2188 
2189   /* Check the parameters */
2190   assert_param(IS_RCC_FLAG(RCC_FLAG));
2191 
2192   /* Get the RCC register index */
2193   tmp = RCC_FLAG >> 5;
2194   if (tmp == 1)               /* The flag to check is in CR register */
2195   {
2196     statusreg = RCC->CR;
2197   }
2198   else if (tmp == 2)          /* The flag to check is in BDCR register */
2199   {
2200     statusreg = RCC->BDCR;
2201   }
2202   else                       /* The flag to check is in CSR register */
2203   {
2204     statusreg = RCC->CSR;
2205   }
2206 
2207   /* Get the flag position */
2208   tmp = RCC_FLAG & FLAG_MASK;
2209   if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
2210   {
2211     bitstatus = SET;
2212   }
2213   else
2214   {
2215     bitstatus = RESET;
2216   }
2217   /* Return the flag status */
2218   return bitstatus;
2219 }
2220 
2221 /**
2222   * @brief  Clears the RCC reset flags.
2223   *         The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST,  RCC_FLAG_SFTRST,
2224   *         RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
2225   * @param  None
2226   * @retval None
2227   */
RCC_ClearFlag(void)2228 void RCC_ClearFlag(void)
2229 {
2230   /* Set RMVF bit to clear the reset flags */
2231   RCC->CSR |= RCC_CSR_RMVF;
2232 }
2233 
2234 /**
2235   * @brief  Checks whether the specified RCC interrupt has occurred or not.
2236   * @param  RCC_IT: specifies the RCC interrupt source to check.
2237   *          This parameter can be one of the following values:
2238   *            @arg RCC_IT_LSIRDY: LSI ready interrupt
2239   *            @arg RCC_IT_LSERDY: LSE ready interrupt
2240   *            @arg RCC_IT_HSIRDY: HSI ready interrupt
2241   *            @arg RCC_IT_HSERDY: HSE ready interrupt
2242   *            @arg RCC_IT_PLLRDY: main PLL ready interrupt
2243   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt
2244   *            @arg RCC_IT_PLLSAIRDY: PLLSAI clock ready interrupt (only for STM32F42xxx/43xxx devices)
2245   *            @arg RCC_IT_CSS: Clock Security System interrupt
2246   * @retval The new state of RCC_IT (SET or RESET).
2247   */
RCC_GetITStatus(uint8_t RCC_IT)2248 ITStatus RCC_GetITStatus(uint8_t RCC_IT)
2249 {
2250   ITStatus bitstatus = RESET;
2251 
2252   /* Check the parameters */
2253   assert_param(IS_RCC_GET_IT(RCC_IT));
2254 
2255   /* Check the status of the specified RCC interrupt */
2256   if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)
2257   {
2258     bitstatus = SET;
2259   }
2260   else
2261   {
2262     bitstatus = RESET;
2263   }
2264   /* Return the RCC_IT status */
2265   return  bitstatus;
2266 }
2267 
2268 /**
2269   * @brief  Clears the RCC's interrupt pending bits.
2270   * @param  RCC_IT: specifies the interrupt pending bit to clear.
2271   *          This parameter can be any combination of the following values:
2272   *            @arg RCC_IT_LSIRDY: LSI ready interrupt
2273   *            @arg RCC_IT_LSERDY: LSE ready interrupt
2274   *            @arg RCC_IT_HSIRDY: HSI ready interrupt
2275   *            @arg RCC_IT_HSERDY: HSE ready interrupt
2276   *            @arg RCC_IT_PLLRDY: main PLL ready interrupt
2277   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt
2278   *            @arg RCC_IT_PLLSAIRDY: PLLSAI ready interrupt (only for STM32F42xxx/43xxx devices)
2279   *            @arg RCC_IT_CSS: Clock Security System interrupt
2280   * @retval None
2281   */
RCC_ClearITPendingBit(uint8_t RCC_IT)2282 void RCC_ClearITPendingBit(uint8_t RCC_IT)
2283 {
2284   /* Check the parameters */
2285   assert_param(IS_RCC_CLEAR_IT(RCC_IT));
2286 
2287   /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt
2288      pending bits */
2289   *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;
2290 }
2291 
2292 /**
2293   * @}
2294   */
2295 
2296 /**
2297   * @}
2298   */
2299 
2300 /**
2301   * @}
2302   */
2303 
2304 /**
2305   * @}
2306   */
2307 
2308 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2309