2 ******************************************************************************
\r
3 * @file stm32l1xx_rcc.c
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the Reset and clock control (RCC) peripheral:
\r
9 * + Internal/external clocks, PLL, CSS and MCO configuration
\r
10 * + System, AHB and APB busses clocks configuration
\r
11 * + Peripheral clocks configuration
\r
12 * + Interrupts and flags management
\r
16 ===============================================================================
\r
17 ##### RCC specific features #####
\r
18 ===============================================================================
\r
19 [..] After reset the device is running from MSI (2 MHz) with Flash 0 WS,
\r
20 all peripherals are off except internal SRAM, Flash and JTAG.
\r
21 (#) There is no prescaler on High speed (AHB) and Low speed (APB) busses;
\r
22 all peripherals mapped on these busses are running at MSI speed.
\r
23 (#) The clock for all peripherals is switched off, except the SRAM and
\r
25 (#) All GPIOs are in input floating state, except the JTAG pins which
\r
26 are assigned to be used for debug purpose.
\r
27 [..] Once the device started from reset, the user application has to:
\r
28 (#) Configure the clock source to be used to drive the System clock
\r
29 (if the application needs higher frequency/performance)
\r
30 (#) Configure the System clock frequency and Flash settings
\r
31 (#) Configure the AHB and APB busses prescalers
\r
32 (#) Enable the clock for the peripheral(s) to be used
\r
33 (#) Configure the clock source(s) for peripherals whose clocks are not
\r
34 derived from the System clock (ADC, RTC/LCD and IWDG)
\r
38 ******************************************************************************
\r
41 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
43 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
44 * You may not use this file except in compliance with the License.
\r
45 * You may obtain a copy of the License at:
\r
47 * http://www.st.com/software_license_agreement_liberty_v2
\r
49 * Unless required by applicable law or agreed to in writing, software
\r
50 * distributed under the License is distributed on an "AS IS" BASIS,
\r
51 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
52 * See the License for the specific language governing permissions and
\r
53 * limitations under the License.
\r
55 ******************************************************************************
\r
58 /* Includes ------------------------------------------------------------------*/
\r
59 #include "stm32l1xx_rcc.h"
\r
61 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
66 * @brief RCC driver modules
\r
70 /* Private typedef -----------------------------------------------------------*/
\r
71 /* Private define ------------------------------------------------------------*/
\r
73 /* ------------ RCC registers bit address in the alias region ----------- */
\r
74 #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
\r
76 /* --- CR Register ---*/
\r
78 /* Alias word address of HSION bit */
\r
79 #define CR_OFFSET (RCC_OFFSET + 0x00)
\r
80 #define HSION_BitNumber 0x00
\r
81 #define CR_HSION_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))
\r
83 /* Alias word address of MSION bit */
\r
84 #define MSION_BitNumber 0x08
\r
85 #define CR_MSION_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (MSION_BitNumber * 4))
\r
87 /* Alias word address of PLLON bit */
\r
88 #define PLLON_BitNumber 0x18
\r
89 #define CR_PLLON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))
\r
91 /* Alias word address of CSSON bit */
\r
92 #define CSSON_BitNumber 0x1C
\r
93 #define CR_CSSON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))
\r
95 /* --- CSR Register ---*/
\r
97 /* Alias word address of LSION bit */
\r
98 #define CSR_OFFSET (RCC_OFFSET + 0x34)
\r
99 #define LSION_BitNumber 0x00
\r
100 #define CSR_LSION_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))
\r
102 /* Alias word address of LSECSSON bit */
\r
103 #define LSECSSON_BitNumber 0x0B
\r
104 #define CSR_LSECSSON_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSECSSON_BitNumber * 4))
\r
106 /* Alias word address of RTCEN bit */
\r
107 #define RTCEN_BitNumber 0x16
\r
108 #define CSR_RTCEN_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (RTCEN_BitNumber * 4))
\r
110 /* Alias word address of RTCRST bit */
\r
111 #define RTCRST_BitNumber 0x17
\r
112 #define CSR_RTCRST_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (RTCRST_BitNumber * 4))
\r
115 /* ---------------------- RCC registers mask -------------------------------- */
\r
116 /* RCC Flag Mask */
\r
117 #define FLAG_MASK ((uint8_t)0x1F)
\r
119 /* CR register byte 3 (Bits[23:16]) base address */
\r
120 #define CR_BYTE3_ADDRESS ((uint32_t)0x40023802)
\r
122 /* ICSCR register byte 4 (Bits[31:24]) base address */
\r
123 #define ICSCR_BYTE4_ADDRESS ((uint32_t)0x40023807)
\r
125 /* CFGR register byte 3 (Bits[23:16]) base address */
\r
126 #define CFGR_BYTE3_ADDRESS ((uint32_t)0x4002380A)
\r
128 /* CFGR register byte 4 (Bits[31:24]) base address */
\r
129 #define CFGR_BYTE4_ADDRESS ((uint32_t)0x4002380B)
\r
131 /* CIR register byte 2 (Bits[15:8]) base address */
\r
132 #define CIR_BYTE2_ADDRESS ((uint32_t)0x4002380D)
\r
134 /* CIR register byte 3 (Bits[23:16]) base address */
\r
135 #define CIR_BYTE3_ADDRESS ((uint32_t)0x4002380E)
\r
137 /* CSR register byte 2 (Bits[15:8]) base address */
\r
138 #define CSR_BYTE2_ADDRESS ((uint32_t)0x40023835)
\r
140 /* Private macro -------------------------------------------------------------*/
\r
141 /* Private variables ---------------------------------------------------------*/
\r
143 static __I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};
\r
144 static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
\r
146 /* Private function prototypes -----------------------------------------------*/
\r
147 /* Private functions ---------------------------------------------------------*/
\r
149 /** @defgroup RCC_Private_Functions
\r
153 /** @defgroup RCC_Group1 Internal and external clocks, PLL, CSS and MCO configuration functions
\r
154 * @brief Internal and external clocks, PLL, CSS and MCO configuration functions
\r
157 ===============================================================================
\r
158 ##### Internal-external clocks, PLL, CSS and MCO configuration functions #####
\r
159 ===============================================================================
\r
160 [..] This section provide functions allowing to configure the internal/external
\r
161 clocks, PLL, CSS and MCO.
\r
162 (#) HSI (high-speed internal), 16 MHz factory-trimmed RC used directly
\r
163 or through the PLL as System clock source.
\r
164 (#) MSI (multi-speed internal), multispeed low power RC
\r
165 (65.536 KHz to 4.194 MHz) MHz used as System clock source.
\r
166 (#) LSI (low-speed internal), 37 KHz low consumption RC used as IWDG
\r
167 and/or RTC clock source.
\r
168 (#) HSE (high-speed external), 1 to 24 MHz crystal oscillator used
\r
169 directly or through the PLL as System clock source. Can be used
\r
170 also as RTC clock source.
\r
171 (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
\r
172 (#) PLL (clocked by HSI or HSE), for System clock and USB (48 MHz).
\r
173 (#) CSS (Clock security system), once enable and if a HSE clock failure
\r
174 occurs (HSE used directly or through PLL as System clock source),
\r
175 the System clock is automatically switched to MSI and an interrupt
\r
176 is generated if enabled.
\r
177 The interrupt is linked to the Cortex-M3 NMI (Non-Maskable Interrupt)
\r
179 (#) MCO (microcontroller clock output), used to output SYSCLK, HSI, MSI,
\r
180 HSE, PLL, LSI or LSE clock (through a configurable prescaler) on
\r
188 * @brief Resets the RCC clock configuration to the default reset state.
\r
189 * @note The default reset state of the clock configuration is given below:
\r
190 * @note MSI ON and used as system clock source (MSI range is not modified
\r
191 * by this function, it keep the value configured by user application)
\r
192 * @note HSI, HSE and PLL OFF
\r
193 * @note AHB, APB1 and APB2 prescaler set to 1.
\r
194 * @note CSS and MCO OFF
\r
195 * @note All interrupts disabled
\r
196 * @note However, this function doesn't modify the configuration of the
\r
197 * @note Peripheral clocks
\r
198 * @note LSI, LSE and RTC clocks
\r
202 void RCC_DeInit(void)
\r
205 /* Set MSION bit */
\r
206 RCC->CR |= (uint32_t)0x00000100;
\r
208 /* Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */
\r
209 RCC->CFGR &= (uint32_t)0x88FFC00C;
\r
211 /* Reset HSION, HSEON, CSSON and PLLON bits */
\r
212 RCC->CR &= (uint32_t)0xEEFEFFFE;
\r
214 /* Reset HSEBYP bit */
\r
215 RCC->CR &= (uint32_t)0xFFFBFFFF;
\r
217 /* Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */
\r
218 RCC->CFGR &= (uint32_t)0xFF02FFFF;
\r
220 /* Disable all interrupts */
\r
221 RCC->CIR = 0x00000000;
\r
225 * @brief Configures the External High Speed oscillator (HSE).
\r
226 * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
\r
227 * software should wait on HSERDY flag to be set indicating that HSE clock
\r
228 * is stable and can be used to clock the PLL and/or system clock.
\r
229 * @note HSE state can not be changed if it is used directly or through the
\r
230 * PLL as system clock. In this case, you have to select another source
\r
231 * of the system clock then change the HSE state (ex. disable it).
\r
232 * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
\r
233 * @note This function reset the CSSON bit, so if the Clock security system(CSS)
\r
234 * was previously enabled you have to enable it again after calling this
\r
236 * @param RCC_HSE: specifies the new state of the HSE.
\r
237 * This parameter can be one of the following values:
\r
238 * @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
\r
239 * 6 HSE oscillator clock cycles.
\r
240 * @arg RCC_HSE_ON: turn ON the HSE oscillator
\r
241 * @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock
\r
244 void RCC_HSEConfig(uint8_t RCC_HSE)
\r
246 /* Check the parameters */
\r
247 assert_param(IS_RCC_HSE(RCC_HSE));
\r
249 /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
\r
250 *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE_OFF;
\r
252 /* Set the new HSE configuration -------------------------------------------*/
\r
253 *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE;
\r
258 * @brief Waits for HSE start-up.
\r
259 * @note This functions waits on HSERDY flag to be set and return SUCCESS if
\r
260 * this flag is set, otherwise returns ERROR if the timeout is reached
\r
261 * and this flag is not set. The timeout value is defined by the constant
\r
262 * HSE_STARTUP_TIMEOUT in stm32l1xx.h file. You can tailor it depending
\r
263 * on the HSE crystal used in your application.
\r
265 * @retval An ErrorStatus enumeration value:
\r
266 * - SUCCESS: HSE oscillator is stable and ready to use
\r
267 * - ERROR: HSE oscillator not yet ready
\r
269 ErrorStatus RCC_WaitForHSEStartUp(void)
\r
271 __IO uint32_t StartUpCounter = 0;
\r
272 ErrorStatus status = ERROR;
\r
273 FlagStatus HSEStatus = RESET;
\r
275 /* Wait till HSE is ready and if timeout is reached exit */
\r
278 HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);
\r
280 } while((StartUpCounter != HSE_STARTUP_TIMEOUT) && (HSEStatus == RESET));
\r
282 if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)
\r
294 * @brief Adjusts the Internal Multi Speed oscillator (MSI) calibration value.
\r
295 * @note The calibration is used to compensate for the variations in voltage
\r
296 * and temperature that influence the frequency of the internal MSI RC.
\r
297 * Refer to the Application Note AN3300 for more details on how to
\r
298 * calibrate the MSI.
\r
299 * @param MSICalibrationValue: specifies the MSI calibration trimming value.
\r
300 * This parameter must be a number between 0 and 0xFF.
\r
303 void RCC_AdjustMSICalibrationValue(uint8_t MSICalibrationValue)
\r
306 /* Check the parameters */
\r
307 assert_param(IS_RCC_MSI_CALIBRATION_VALUE(MSICalibrationValue));
\r
309 *(__IO uint8_t *) ICSCR_BYTE4_ADDRESS = MSICalibrationValue;
\r
313 * @brief Configures the Internal Multi Speed oscillator (MSI) clock range.
\r
314 * @note After restart from Reset or wakeup from STANDBY, the MSI clock is
\r
315 * around 2.097 MHz. The MSI clock does not change after wake-up from
\r
317 * @note The MSI clock range can be modified on the fly.
\r
318 * @param RCC_MSIRange: specifies the MSI Clock range.
\r
319 * This parameter must be one of the following values:
\r
320 * @arg RCC_MSIRange_0: MSI clock is around 65.536 KHz
\r
321 * @arg RCC_MSIRange_1: MSI clock is around 131.072 KHz
\r
322 * @arg RCC_MSIRange_2: MSI clock is around 262.144 KHz
\r
323 * @arg RCC_MSIRange_3: MSI clock is around 524.288 KHz
\r
324 * @arg RCC_MSIRange_4: MSI clock is around 1.048 MHz
\r
325 * @arg RCC_MSIRange_5: MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)
\r
326 * @arg RCC_MSIRange_6: MSI clock is around 4.194 MHz
\r
330 void RCC_MSIRangeConfig(uint32_t RCC_MSIRange)
\r
332 uint32_t tmpreg = 0;
\r
334 /* Check the parameters */
\r
335 assert_param(IS_RCC_MSI_CLOCK_RANGE(RCC_MSIRange));
\r
337 tmpreg = RCC->ICSCR;
\r
339 /* Clear MSIRANGE[2:0] bits */
\r
340 tmpreg &= ~RCC_ICSCR_MSIRANGE;
\r
342 /* Set the MSIRANGE[2:0] bits according to RCC_MSIRange value */
\r
343 tmpreg |= (uint32_t)RCC_MSIRange;
\r
345 /* Store the new value */
\r
346 RCC->ICSCR = tmpreg;
\r
350 * @brief Enables or disables the Internal Multi Speed oscillator (MSI).
\r
351 * @note The MSI is stopped by hardware when entering STOP and STANDBY modes.
\r
352 * It is used (enabled by hardware) as system clock source after
\r
353 * startup from Reset, wakeup from STOP and STANDBY mode, or in case
\r
354 * of failure of the HSE used directly or indirectly as system clock
\r
355 * (if the Clock Security System CSS is enabled).
\r
356 * @note MSI can not be stopped if it is used as system clock source.
\r
357 * In this case, you have to select another source of the system
\r
358 * clock then stop the MSI.
\r
359 * @note After enabling the MSI, the application software should wait on
\r
360 * MSIRDY flag to be set indicating that MSI clock is stable and can
\r
361 * be used as system clock source.
\r
362 * @param NewState: new state of the MSI.
\r
363 * This parameter can be: ENABLE or DISABLE.
\r
364 * @note When the MSI is stopped, MSIRDY flag goes low after 6 MSI oscillator
\r
368 void RCC_MSICmd(FunctionalState NewState)
\r
370 /* Check the parameters */
\r
371 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
373 *(__IO uint32_t *) CR_MSION_BB = (uint32_t)NewState;
\r
377 * @brief Adjusts the Internal High Speed oscillator (HSI) calibration value.
\r
378 * @note The calibration is used to compensate for the variations in voltage
\r
379 * and temperature that influence the frequency of the internal HSI RC.
\r
380 * Refer to the Application Note AN3300 for more details on how to
\r
381 * calibrate the HSI.
\r
382 * @param HSICalibrationValue: specifies the HSI calibration trimming value.
\r
383 * This parameter must be a number between 0 and 0x1F.
\r
386 void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)
\r
388 uint32_t tmpreg = 0;
\r
390 /* Check the parameters */
\r
391 assert_param(IS_RCC_HSI_CALIBRATION_VALUE(HSICalibrationValue));
\r
393 tmpreg = RCC->ICSCR;
\r
395 /* Clear HSITRIM[4:0] bits */
\r
396 tmpreg &= ~RCC_ICSCR_HSITRIM;
\r
398 /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */
\r
399 tmpreg |= (uint32_t)HSICalibrationValue << 8;
\r
401 /* Store the new value */
\r
402 RCC->ICSCR = tmpreg;
\r
406 * @brief Enables or disables the Internal High Speed oscillator (HSI).
\r
407 * @note After enabling the HSI, the application software should wait on
\r
408 * HSIRDY flag to be set indicating that HSI clock is stable and can
\r
409 * be used to clock the PLL and/or system clock.
\r
410 * @note HSI can not be stopped if it is used directly or through the PLL
\r
411 * as system clock. In this case, you have to select another source
\r
412 * of the system clock then stop the HSI.
\r
413 * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
\r
414 * @param NewState: new state of the HSI.
\r
415 * This parameter can be: ENABLE or DISABLE.
\r
416 * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
\r
420 void RCC_HSICmd(FunctionalState NewState)
\r
422 /* Check the parameters */
\r
423 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
425 *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;
\r
429 * @brief Configures the External Low Speed oscillator (LSE).
\r
430 * @note As the LSE is in the RTC domain and write access is denied to this
\r
431 * domain after reset, you have to enable write access using
\r
432 * PWR_RTCAccessCmd(ENABLE) function before to configure the LSE
\r
433 * (to be done once after reset).
\r
434 * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_Bypass), the application
\r
435 * software should wait on LSERDY flag to be set indicating that LSE clock
\r
436 * is stable and can be used to clock the RTC.
\r
437 * @param RCC_LSE: specifies the new state of the LSE.
\r
438 * This parameter can be one of the following values:
\r
439 * @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
\r
440 * 6 LSE oscillator clock cycles.
\r
441 * @arg RCC_LSE_ON: turn ON the LSE oscillator
\r
442 * @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock
\r
445 void RCC_LSEConfig(uint8_t RCC_LSE)
\r
447 /* Check the parameters */
\r
448 assert_param(IS_RCC_LSE(RCC_LSE));
\r
450 /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
\r
451 *(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE_OFF;
\r
453 /* Set the new LSE configuration -------------------------------------------*/
\r
454 *(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE;
\r
458 * @brief Enables or disables the Internal Low Speed oscillator (LSI).
\r
459 * @note After enabling the LSI, the application software should wait on
\r
460 * LSIRDY flag to be set indicating that LSI clock is stable and can
\r
461 * be used to clock the IWDG and/or the RTC.
\r
462 * @note LSI can not be disabled if the IWDG is running.
\r
463 * @param NewState: new state of the LSI.
\r
464 * This parameter can be: ENABLE or DISABLE.
\r
465 * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
\r
469 void RCC_LSICmd(FunctionalState NewState)
\r
471 /* Check the parameters */
\r
472 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
474 *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;
\r
478 * @brief Configures the PLL clock source and multiplication factor.
\r
479 * @note This function must be used only when the PLL is disabled.
\r
481 * @param RCC_PLLSource: specifies the PLL entry clock source.
\r
482 * This parameter can be one of the following values:
\r
483 * @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock source
\r
484 * @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock source
\r
485 * @note The minimum input clock frequency for PLL is 2 MHz (when using HSE as
\r
488 * @param RCC_PLLMul: specifies the PLL multiplication factor, which drive the PLLVCO clock
\r
489 * This parameter can be:
\r
490 * @arg RCC_PLLMul_3: PLL clock source multiplied by 3
\r
491 * @arg RCC_PLLMul_4: PLL clock source multiplied by 4
\r
492 * @arg RCC_PLLMul_6: PLL clock source multiplied by 6
\r
493 * @arg RCC_PLLMul_8: PLL clock source multiplied by 8
\r
494 * @arg RCC_PLLMul_12: PLL clock source multiplied by 12
\r
495 * @arg RCC_PLLMul_16: PLL clock source multiplied by 16
\r
496 * @arg RCC_PLLMul_24: PLL clock source multiplied by 24
\r
497 * @arg RCC_PLLMul_32: PLL clock source multiplied by 32
\r
498 * @arg RCC_PLLMul_48: PLL clock source multiplied by 48
\r
499 * @note The application software must set correctly the PLL multiplication
\r
500 * factor to avoid exceeding:
\r
501 * - 96 MHz as PLLVCO when the product is in range 1
\r
502 * - 48 MHz as PLLVCO when the product is in range 2
\r
503 * - 24 MHz when the product is in range 3
\r
504 * @note When using the USB the PLLVCO should be 96MHz
\r
506 * @param RCC_PLLDiv: specifies the PLL division factor.
\r
507 * This parameter can be:
\r
508 * @arg RCC_PLLDiv_2: PLL Clock output divided by 2
\r
509 * @arg RCC_PLLDiv_3: PLL Clock output divided by 3
\r
510 * @arg RCC_PLLDiv_4: PLL Clock output divided by 4
\r
511 * @note The application software must set correctly the output division to avoid
\r
512 * exceeding 32 MHz as SYSCLK.
\r
516 void RCC_PLLConfig(uint8_t RCC_PLLSource, uint8_t RCC_PLLMul, uint8_t RCC_PLLDiv)
\r
518 /* Check the parameters */
\r
519 assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));
\r
520 assert_param(IS_RCC_PLL_MUL(RCC_PLLMul));
\r
521 assert_param(IS_RCC_PLL_DIV(RCC_PLLDiv));
\r
523 *(__IO uint8_t *) CFGR_BYTE3_ADDRESS = (uint8_t)(RCC_PLLSource | ((uint8_t)(RCC_PLLMul | (uint8_t)(RCC_PLLDiv))));
\r
527 * @brief Enables or disables the PLL.
\r
528 * @note After enabling the PLL, the application software should wait on
\r
529 * PLLRDY flag to be set indicating that PLL clock is stable and can
\r
530 * be used as system clock source.
\r
531 * @note The PLL can not be disabled if it is used as system clock source
\r
532 * @note The PLL is disabled by hardware when entering STOP and STANDBY modes.
\r
533 * @param NewState: new state of the PLL.
\r
534 * This parameter can be: ENABLE or DISABLE.
\r
537 void RCC_PLLCmd(FunctionalState NewState)
\r
539 /* Check the parameters */
\r
540 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
542 *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;
\r
546 * @brief Enables or disables the Clock Security System.
\r
547 * @note If a failure is detected on the HSE oscillator clock, this oscillator
\r
548 * is automatically disabled and an interrupt is generated to inform the
\r
549 * software about the failure (Clock Security System Interrupt, CSSI),
\r
550 * allowing the MCU to perform rescue operations. The CSSI is linked to
\r
551 * the Cortex-M3 NMI (Non-Maskable Interrupt) exception vector.
\r
552 * @param NewState: new state of the Clock Security System.
\r
553 * This parameter can be: ENABLE or DISABLE.
\r
556 void RCC_ClockSecuritySystemCmd(FunctionalState NewState)
\r
558 /* Check the parameters */
\r
559 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
561 *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;
\r
565 * @brief Enables or disables the LSE Clock Security System.
\r
566 * @param NewState: new state of the Clock Security System.
\r
567 * This parameter can be: ENABLE or DISABLE.
\r
570 void RCC_LSEClockSecuritySystemCmd(FunctionalState NewState)
\r
572 /* Check the parameters */
\r
573 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
575 *(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)NewState;
\r
579 * @brief Selects the clock source to output on MCO pin (PA8).
\r
580 * @note PA8 should be configured in alternate function mode.
\r
581 * @param RCC_MCOSource: specifies the clock source to output.
\r
582 * This parameter can be one of the following values:
\r
583 * @arg RCC_MCOSource_NoClock: No clock selected
\r
584 * @arg RCC_MCOSource_SYSCLK: System clock selected
\r
585 * @arg RCC_MCOSource_HSI: HSI oscillator clock selected
\r
586 * @arg RCC_MCOSource_MSI: MSI oscillator clock selected
\r
587 * @arg RCC_MCOSource_HSE: HSE oscillator clock selected
\r
588 * @arg RCC_MCOSource_PLLCLK: PLL clock selected
\r
589 * @arg RCC_MCOSource_LSI: LSI clock selected
\r
590 * @arg RCC_MCOSource_LSE: LSE clock selected
\r
591 * @param RCC_MCODiv: specifies the MCO prescaler.
\r
592 * This parameter can be one of the following values:
\r
593 * @arg RCC_MCODiv_1: no division applied to MCO clock
\r
594 * @arg RCC_MCODiv_2: division by 2 applied to MCO clock
\r
595 * @arg RCC_MCODiv_4: division by 4 applied to MCO clock
\r
596 * @arg RCC_MCODiv_8: division by 8 applied to MCO clock
\r
597 * @arg RCC_MCODiv_16: division by 16 applied to MCO clock
\r
600 void RCC_MCOConfig(uint8_t RCC_MCOSource, uint8_t RCC_MCODiv)
\r
602 /* Check the parameters */
\r
603 assert_param(IS_RCC_MCO_SOURCE(RCC_MCOSource));
\r
604 assert_param(IS_RCC_MCO_DIV(RCC_MCODiv));
\r
606 /* Select MCO clock source and prescaler */
\r
607 *(__IO uint8_t *) CFGR_BYTE4_ADDRESS = RCC_MCOSource | RCC_MCODiv;
\r
614 /** @defgroup RCC_Group2 System AHB and APB busses clocks configuration functions
\r
615 * @brief System, AHB and APB busses clocks configuration functions
\r
618 ===============================================================================
\r
619 ##### System, AHB and APB busses clocks configuration functions #####
\r
620 ===============================================================================
\r
621 [..] This section provide functions allowing to configure the System, AHB,
\r
622 APB1 and APB2 busses clocks.
\r
623 (#) Several clock sources can be used to drive the System clock (SYSCLK):
\r
624 MSI, HSI, HSE and PLL.
\r
625 The AHB clock (HCLK) is derived from System clock through configurable
\r
626 prescaler and used to clock the CPU, memory and peripherals mapped
\r
627 on AHB bus (DMA and GPIO).APB1 (PCLK1) and APB2 (PCLK2) clocks are
\r
628 derived from AHB clock through configurable prescalers and used to
\r
629 clock the peripherals mapped on these busses. You can use
\r
630 "RCC_GetClocksFreq()" function to retrieve the frequencies of these
\r
633 -@- All the peripheral clocks are derived from the System clock (SYSCLK)
\r
635 (+@) The USB 48 MHz clock which is derived from the PLL VCO clock.
\r
636 (+@) The ADC clock which is always the HSI clock. A divider by 1, 2
\r
637 or 4 allows to adapt the clock frequency to the device operating
\r
639 (+@) The RTC/LCD clock which is derived from the LSE, LSI or 1 MHz
\r
640 HSE_RTC (HSE divided by a programmable prescaler).
\r
641 The System clock (SYSCLK) frequency must be higher or equal to
\r
642 the RTC/LCD clock frequency.
\r
643 (+@) IWDG clock which is always the LSI clock.
\r
645 (#) The maximum frequency of the SYSCLK, HCLK, PCLK1 and PCLK2 is 32 MHz.
\r
646 Depending on the device voltage range, the maximum frequency should
\r
647 be adapted accordingly:
\r
649 +----------------------------------------------------------------+
\r
650 | Wait states | HCLK clock frequency (MHz) |
\r
651 | |------------------------------------------------|
\r
652 | (Latency) | voltage range | voltage range |
\r
653 | | 1.65 V - 3.6 V | 2.0 V - 3.6 V |
\r
654 | |----------------|---------------|---------------|
\r
655 | | VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V |
\r
656 |-------------- |----------------|---------------|---------------|
\r
657 |0WS(1CPU cycle)|0 < HCLK <= 2 |0 < HCLK <= 8 |0 < HCLK <= 16 |
\r
658 |---------------|----------------|---------------|---------------|
\r
659 |1WS(2CPU cycle)|2 < HCLK <= 4 |8 < HCLK <= 16 |16 < HCLK <= 32|
\r
660 +----------------------------------------------------------------+
\r
662 (#) After reset, the System clock source is the MSI (2 MHz) with 0 WS,
\r
663 Flash 32-bit access is enabled and prefetch is disabled.
\r
664 [..] It is recommended to use the following software sequences to tune the
\r
665 number of wait states needed to access the Flash memory with the CPU
\r
667 (+) Increasing the CPU frequency (in the same voltage range)
\r
668 (+) Program the Flash 64-bit access, using "FLASH_ReadAccess64Cmd(ENABLE)"
\r
670 (+) Check that 64-bit access is taken into account by reading FLASH_ACR
\r
671 (+) Program Flash WS to 1, using "FLASH_SetLatency(FLASH_Latency_1)"
\r
673 (+) Check that the new number of WS is taken into account by reading
\r
675 (+) Modify the CPU clock source, using "RCC_SYSCLKConfig()" function
\r
676 (+) If needed, modify the CPU clock prescaler by using "RCC_HCLKConfig()"
\r
678 (+) Check that the new CPU clock source is taken into account by reading
\r
679 the clock source status, using "RCC_GetSYSCLKSource()" function
\r
680 (+) Decreasing the CPU frequency (in the same voltage range)
\r
681 (+) Modify the CPU clock source, using "RCC_SYSCLKConfig()" function
\r
682 (+) If needed, modify the CPU clock prescaler by using "RCC_HCLKConfig()"
\r
684 (+) Check that the new CPU clock source is taken into account by reading
\r
685 the clock source status, using "RCC_GetSYSCLKSource()" function
\r
686 (+) Program the new number of WS, using "FLASH_SetLatency()" function
\r
687 (+) Check that the new number of WS is taken into account by reading
\r
689 (+) Enable the Flash 32-bit access, using "FLASH_ReadAccess64Cmd(DISABLE)"
\r
691 (+) Check that 32-bit access is taken into account by reading FLASH_ACR
\r
698 * @brief Configures the system clock (SYSCLK).
\r
699 * @note The MSI is used (enabled by hardware) as system clock source after
\r
700 * startup from Reset, wake-up from STOP and STANDBY mode, or in case
\r
701 * of failure of the HSE used directly or indirectly as system clock
\r
702 * (if the Clock Security System CSS is enabled).
\r
703 * @note A switch from one clock source to another occurs only if the target
\r
704 * clock source is ready (clock stable after startup delay or PLL locked).
\r
705 * If a clock source which is not yet ready is selected, the switch will
\r
706 * occur when the clock source will be ready.
\r
707 * You can use RCC_GetSYSCLKSource() function to know which clock is
\r
708 * currently used as system clock source.
\r
709 * @param RCC_SYSCLKSource: specifies the clock source used as system clock source
\r
710 * This parameter can be one of the following values:
\r
711 * @arg RCC_SYSCLKSource_MSI: MSI selected as system clock source
\r
712 * @arg RCC_SYSCLKSource_HSI: HSI selected as system clock source
\r
713 * @arg RCC_SYSCLKSource_HSE: HSE selected as system clock source
\r
714 * @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock source
\r
717 void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)
\r
719 uint32_t tmpreg = 0;
\r
721 /* Check the parameters */
\r
722 assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));
\r
724 tmpreg = RCC->CFGR;
\r
726 /* Clear SW[1:0] bits */
\r
727 tmpreg &= ~RCC_CFGR_SW;
\r
729 /* Set SW[1:0] bits according to RCC_SYSCLKSource value */
\r
730 tmpreg |= RCC_SYSCLKSource;
\r
732 /* Store the new value */
\r
733 RCC->CFGR = tmpreg;
\r
737 * @brief Returns the clock source used as system clock.
\r
739 * @retval The clock source used as system clock. The returned value can be one
\r
740 * of the following values:
\r
741 * - 0x00: MSI used as system clock
\r
742 * - 0x04: HSI used as system clock
\r
743 * - 0x08: HSE used as system clock
\r
744 * - 0x0C: PLL used as system clock
\r
746 uint8_t RCC_GetSYSCLKSource(void)
\r
748 return ((uint8_t)(RCC->CFGR & RCC_CFGR_SWS));
\r
752 * @brief Configures the AHB clock (HCLK).
\r
753 * @note Depending on the device voltage range, the software has to set correctly
\r
754 * these bits to ensure that the system frequency does not exceed the
\r
755 * maximum allowed frequency (for more details refer to section above
\r
756 * "CPU, AHB and APB busses clocks configuration functions")
\r
757 * @param RCC_SYSCLK: defines the AHB clock divider. This clock is derived from
\r
758 * the system clock (SYSCLK).
\r
759 * This parameter can be one of the following values:
\r
760 * @arg RCC_SYSCLK_Div1: AHB clock = SYSCLK
\r
761 * @arg RCC_SYSCLK_Div2: AHB clock = SYSCLK/2
\r
762 * @arg RCC_SYSCLK_Div4: AHB clock = SYSCLK/4
\r
763 * @arg RCC_SYSCLK_Div8: AHB clock = SYSCLK/8
\r
764 * @arg RCC_SYSCLK_Div16: AHB clock = SYSCLK/16
\r
765 * @arg RCC_SYSCLK_Div64: AHB clock = SYSCLK/64
\r
766 * @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128
\r
767 * @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256
\r
768 * @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512
\r
771 void RCC_HCLKConfig(uint32_t RCC_SYSCLK)
\r
773 uint32_t tmpreg = 0;
\r
775 /* Check the parameters */
\r
776 assert_param(IS_RCC_HCLK(RCC_SYSCLK));
\r
778 tmpreg = RCC->CFGR;
\r
780 /* Clear HPRE[3:0] bits */
\r
781 tmpreg &= ~RCC_CFGR_HPRE;
\r
783 /* Set HPRE[3:0] bits according to RCC_SYSCLK value */
\r
784 tmpreg |= RCC_SYSCLK;
\r
786 /* Store the new value */
\r
787 RCC->CFGR = tmpreg;
\r
791 * @brief Configures the Low Speed APB clock (PCLK1).
\r
792 * @param RCC_HCLK: defines the APB1 clock divider. This clock is derived from
\r
793 * the AHB clock (HCLK).
\r
794 * This parameter can be one of the following values:
\r
795 * @arg RCC_HCLK_Div1: APB1 clock = HCLK
\r
796 * @arg RCC_HCLK_Div2: APB1 clock = HCLK/2
\r
797 * @arg RCC_HCLK_Div4: APB1 clock = HCLK/4
\r
798 * @arg RCC_HCLK_Div8: APB1 clock = HCLK/8
\r
799 * @arg RCC_HCLK_Div16: APB1 clock = HCLK/16
\r
802 void RCC_PCLK1Config(uint32_t RCC_HCLK)
\r
804 uint32_t tmpreg = 0;
\r
806 /* Check the parameters */
\r
807 assert_param(IS_RCC_PCLK(RCC_HCLK));
\r
809 tmpreg = RCC->CFGR;
\r
811 /* Clear PPRE1[2:0] bits */
\r
812 tmpreg &= ~RCC_CFGR_PPRE1;
\r
814 /* Set PPRE1[2:0] bits according to RCC_HCLK value */
\r
815 tmpreg |= RCC_HCLK;
\r
817 /* Store the new value */
\r
818 RCC->CFGR = tmpreg;
\r
822 * @brief Configures the High Speed APB clock (PCLK2).
\r
823 * @param RCC_HCLK: defines the APB2 clock divider. This clock is derived from
\r
824 * the AHB clock (HCLK).
\r
825 * This parameter can be one of the following values:
\r
826 * @arg RCC_HCLK_Div1: APB2 clock = HCLK
\r
827 * @arg RCC_HCLK_Div2: APB2 clock = HCLK/2
\r
828 * @arg RCC_HCLK_Div4: APB2 clock = HCLK/4
\r
829 * @arg RCC_HCLK_Div8: APB2 clock = HCLK/8
\r
830 * @arg RCC_HCLK_Div16: APB2 clock = HCLK/16
\r
833 void RCC_PCLK2Config(uint32_t RCC_HCLK)
\r
835 uint32_t tmpreg = 0;
\r
837 /* Check the parameters */
\r
838 assert_param(IS_RCC_PCLK(RCC_HCLK));
\r
840 tmpreg = RCC->CFGR;
\r
842 /* Clear PPRE2[2:0] bits */
\r
843 tmpreg &= ~RCC_CFGR_PPRE2;
\r
845 /* Set PPRE2[2:0] bits according to RCC_HCLK value */
\r
846 tmpreg |= RCC_HCLK << 3;
\r
848 /* Store the new value */
\r
849 RCC->CFGR = tmpreg;
\r
853 * @brief Returns the frequencies of the System, AHB and APB busses clocks.
\r
854 * @note The frequency returned by this function is not the real frequency
\r
855 * in the chip. It is calculated based on the predefined constant and
\r
856 * the source selected by RCC_SYSCLKConfig():
\r
858 * @note If SYSCLK source is MSI, function returns values based on MSI
\r
859 * Value as defined by the MSI range, refer to RCC_MSIRangeConfig()
\r
861 * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
\r
863 * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
\r
865 * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(**)
\r
866 * or HSI_VALUE(*) multiplied/divided by the PLL factors.
\r
868 * (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value
\r
869 * 16 MHz) but the real value may vary depending on the variations
\r
870 * in voltage and temperature, refer to RCC_AdjustHSICalibrationValue().
\r
872 * (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value
\r
873 * 8 MHz), user has to ensure that HSE_VALUE is same as the real
\r
874 * frequency of the crystal used. Otherwise, this function may
\r
875 * return wrong result.
\r
877 * - The result of this function could be not correct when using fractional
\r
878 * value for HSE crystal.
\r
880 * @param RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold
\r
881 * the clocks frequencies.
\r
883 * @note This function can be used by the user application to compute the
\r
884 * baudrate for the communication peripherals or configure other parameters.
\r
885 * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function
\r
886 * must be called to update the structure's field. Otherwise, any
\r
887 * configuration based on this function will be incorrect.
\r
891 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)
\r
893 uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, presc = 0, msirange = 0;
\r
895 /* Get SYSCLK source -------------------------------------------------------*/
\r
896 tmp = RCC->CFGR & RCC_CFGR_SWS;
\r
900 case 0x00: /* MSI used as system clock */
\r
901 msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13;
\r
902 RCC_Clocks->SYSCLK_Frequency = (32768 * (1 << (msirange + 1)));
\r
904 case 0x04: /* HSI used as system clock */
\r
905 RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
\r
907 case 0x08: /* HSE used as system clock */
\r
908 RCC_Clocks->SYSCLK_Frequency = HSE_VALUE;
\r
910 case 0x0C: /* PLL used as system clock */
\r
911 /* Get PLL clock source and multiplication factor ----------------------*/
\r
912 pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;
\r
913 plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;
\r
914 pllmul = PLLMulTable[(pllmul >> 18)];
\r
915 plldiv = (plldiv >> 22) + 1;
\r
917 pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
\r
919 if (pllsource == 0x00)
\r
921 /* HSI oscillator clock selected as PLL clock source */
\r
922 RCC_Clocks->SYSCLK_Frequency = (((HSI_VALUE) * pllmul) / plldiv);
\r
926 /* HSE selected as PLL clock source */
\r
927 RCC_Clocks->SYSCLK_Frequency = (((HSE_VALUE) * pllmul) / plldiv);
\r
930 default: /* MSI used as system clock */
\r
931 msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13;
\r
932 RCC_Clocks->SYSCLK_Frequency = (32768 * (1 << (msirange + 1)));
\r
935 /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/
\r
936 /* Get HCLK prescaler */
\r
937 tmp = RCC->CFGR & RCC_CFGR_HPRE;
\r
939 presc = APBAHBPrescTable[tmp];
\r
940 /* HCLK clock frequency */
\r
941 RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;
\r
943 /* Get PCLK1 prescaler */
\r
944 tmp = RCC->CFGR & RCC_CFGR_PPRE1;
\r
946 presc = APBAHBPrescTable[tmp];
\r
947 /* PCLK1 clock frequency */
\r
948 RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
\r
950 /* Get PCLK2 prescaler */
\r
951 tmp = RCC->CFGR & RCC_CFGR_PPRE2;
\r
953 presc = APBAHBPrescTable[tmp];
\r
954 /* PCLK2 clock frequency */
\r
955 RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
\r
962 /** @defgroup RCC_Group3 Peripheral clocks configuration functions
\r
963 * @brief Peripheral clocks configuration functions
\r
966 ===============================================================================
\r
967 ##### Peripheral clocks configuration functions #####
\r
968 ===============================================================================
\r
969 [..] This section provide functions allowing to configure the Peripheral clocks.
\r
970 (#) The RTC/LCD clock which is derived from the LSE, LSI or 1 MHz HSE_RTC
\r
971 (HSE divided by a programmable prescaler).
\r
972 (#) After restart from Reset or wakeup from STANDBY, all peripherals are
\r
973 off except internal SRAM, Flash and JTAG. Before to start using a
\r
974 peripheral you have to enable its interface clock. You can do this
\r
975 using RCC_AHBPeriphClockCmd(), RCC_APB2PeriphClockCmd() and
\r
976 RCC_APB1PeriphClockCmd() functions.
\r
978 (#) To reset the peripherals configuration (to the default state after
\r
979 device reset) you can use RCC_AHBPeriphResetCmd(),
\r
980 RCC_APB2PeriphResetCmd() and RCC_APB1PeriphResetCmd() functions.
\r
981 (#) To further reduce power consumption in SLEEP mode the peripheral
\r
982 clocks can be disabled prior to executing the WFI or WFE instructions.
\r
983 You can do this using RCC_AHBPeriphClockLPModeCmd(),
\r
984 RCC_APB2PeriphClockLPModeCmd() and RCC_APB1PeriphClockLPModeCmd()
\r
992 * @brief Configures the RTC and LCD clock (RTCCLK / LCDCLK).
\r
993 * @note As the RTC clock configuration bits are in the RTC domain and write
\r
994 * access is denied to this domain after reset, you have to enable write
\r
995 * access using PWR_RTCAccessCmd(ENABLE) function before to configure
\r
996 * the RTC clock source (to be done once after reset).
\r
997 * @note Once the RTC clock is configured it can't be changed unless the RTC
\r
998 * is reset using RCC_RTCResetCmd function, or by a Power On Reset (POR)
\r
999 * @note The RTC clock (RTCCLK) is used also to clock the LCD (LCDCLK).
\r
1001 * @param RCC_RTCCLKSource: specifies the RTC clock source.
\r
1002 * This parameter can be one of the following values:
\r
1003 * @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock
\r
1004 * @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock
\r
1005 * @arg RCC_RTCCLKSource_HSE_Div2: HSE divided by 2 selected as RTC clock
\r
1006 * @arg RCC_RTCCLKSource_HSE_Div4: HSE divided by 4 selected as RTC clock
\r
1007 * @arg RCC_RTCCLKSource_HSE_Div8: HSE divided by 8 selected as RTC clock
\r
1008 * @arg RCC_RTCCLKSource_HSE_Div16: HSE divided by 16 selected as RTC clock
\r
1010 * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
\r
1011 * work in STOP and STANDBY modes, and can be used as wakeup source.
\r
1012 * However, when the HSE clock is used as RTC clock source, the RTC
\r
1013 * cannot be used in STOP and STANDBY modes.
\r
1015 * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
\r
1016 * RTC clock source).
\r
1020 void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)
\r
1022 uint32_t tmpreg = 0;
\r
1024 /* Check the parameters */
\r
1025 assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));
\r
1027 if ((RCC_RTCCLKSource & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE)
\r
1029 /* If HSE is selected as RTC clock source, configure HSE division factor for RTC clock */
\r
1032 /* Clear RTCPRE[1:0] bits */
\r
1033 tmpreg &= ~RCC_CR_RTCPRE;
\r
1035 /* Configure HSE division factor for RTC clock */
\r
1036 tmpreg |= (RCC_RTCCLKSource & RCC_CR_RTCPRE);
\r
1038 /* Store the new value */
\r
1042 RCC->CSR &= ~RCC_CSR_RTCSEL;
\r
1044 /* Select the RTC clock source */
\r
1045 RCC->CSR |= (RCC_RTCCLKSource & RCC_CSR_RTCSEL);
\r
1049 * @brief Enables or disables the RTC clock.
\r
1050 * @note This function must be used only after the RTC clock source was selected
\r
1051 * using the RCC_RTCCLKConfig function.
\r
1052 * @param NewState: new state of the RTC clock.
\r
1053 * This parameter can be: ENABLE or DISABLE.
\r
1056 void RCC_RTCCLKCmd(FunctionalState NewState)
\r
1058 /* Check the parameters */
\r
1059 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1061 *(__IO uint32_t *) CSR_RTCEN_BB = (uint32_t)NewState;
\r
1065 * @brief Forces or releases the RTC peripheral and associated resources reset.
\r
1066 * @note This function resets the RTC peripheral, RTC clock source selection
\r
1067 * (in RCC_CSR) and the backup registers.
\r
1068 * @param NewState: new state of the RTC reset.
\r
1069 * This parameter can be: ENABLE or DISABLE.
\r
1072 void RCC_RTCResetCmd(FunctionalState NewState)
\r
1074 /* Check the parameters */
\r
1075 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1077 *(__IO uint32_t *) CSR_RTCRST_BB = (uint32_t)NewState;
\r
1081 * @brief Enables or disables the AHB peripheral clock.
\r
1082 * @note After reset, the peripheral clock (used for registers read/write access)
\r
1083 * is disabled and the application software has to enable this clock before
\r
1085 * @param RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.
\r
1086 * This parameter can be any combination of the following values:
\r
1087 * @arg RCC_AHBPeriph_GPIOA: GPIOA clock
\r
1088 * @arg RCC_AHBPeriph_GPIOB: GPIOB clock
\r
1089 * @arg RCC_AHBPeriph_GPIOC: GPIOC clock
\r
1090 * @arg RCC_AHBPeriph_GPIOD: GPIOD clock
\r
1091 * @arg RCC_AHBPeriph_GPIOE: GPIOE clock
\r
1092 * @arg RCC_AHBPeriph_GPIOH: GPIOH clock
\r
1093 * @arg RCC_AHBPeriph_GPIOF: GPIOF clock
\r
1094 * @arg RCC_AHBPeriph_GPIOG: GPIOG clock
\r
1095 * @arg RCC_AHBPeriph_CRC: CRC clock
\r
1096 * @arg RCC_AHBPeriph_FLITF: (has effect only when the Flash memory is in power down mode)
\r
1097 * @arg RCC_AHBPeriph_DMA1: DMA1 clock
\r
1098 * @arg RCC_AHBPeriph_DMA2: DMA2 clock
\r
1099 * @arg RCC_AHBPeriph_AES: AES clock
\r
1100 * @arg RCC_AHBPeriph_FSMC: FSMC clock
\r
1101 * @param NewState: new state of the specified peripheral clock.
\r
1102 * This parameter can be: ENABLE or DISABLE.
\r
1105 void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
\r
1107 /* Check the parameters */
\r
1108 assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));
\r
1109 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1111 if (NewState != DISABLE)
\r
1113 RCC->AHBENR |= RCC_AHBPeriph;
\r
1117 RCC->AHBENR &= ~RCC_AHBPeriph;
\r
1122 * @brief Enables or disables the High Speed APB (APB2) peripheral clock.
\r
1123 * @note After reset, the peripheral clock (used for registers read/write access)
\r
1124 * is disabled and the application software has to enable this clock before
\r
1126 * @param RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
\r
1127 * This parameter can be any combination of the following values:
\r
1128 * @arg RCC_APB2Periph_SYSCFG: SYSCFG APB2 Clock.
\r
1129 * @arg RCC_APB2Periph_TIM9: TIM9 APB2 Clock.
\r
1130 * @arg RCC_APB2Periph_TIM10: TIM10 APB2 Clock.
\r
1131 * @arg RCC_APB2Periph_TIM11: TIM11 APB2 Clock.
\r
1132 * @arg RCC_APB2Periph_ADC1: ADC1 APB2 Clock.
\r
1133 * @arg RCC_APB2Periph_SDIO: SDIO APB2 Clock.
\r
1134 * @arg RCC_APB2Periph_SPI1: SPI1 APB2 Clock.
\r
1135 * @arg RCC_APB2Periph_USART1: USART1 APB2 Clock.
\r
1136 * @param NewState: new state of the specified peripheral clock.
\r
1137 * This parameter can be: ENABLE or DISABLE.
\r
1140 void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
\r
1142 /* Check the parameters */
\r
1143 assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
\r
1144 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1146 if (NewState != DISABLE)
\r
1148 RCC->APB2ENR |= RCC_APB2Periph;
\r
1152 RCC->APB2ENR &= ~RCC_APB2Periph;
\r
1157 * @brief Enables or disables the Low Speed APB (APB1) peripheral clock.
\r
1158 * @note After reset, the peripheral clock (used for registers read/write access)
\r
1159 * is disabled and the application software has to enable this clock before
\r
1161 * @param RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
\r
1162 * This parameter can be any combination of the following values:
\r
1163 * @arg RCC_APB1Periph_TIM2: TIM2 clock
\r
1164 * @arg RCC_APB1Periph_TIM3: TIM3 clock
\r
1165 * @arg RCC_APB1Periph_TIM4: TIM4 clock
\r
1166 * @arg RCC_APB1Periph_TIM5: TIM5 clock
\r
1167 * @arg RCC_APB1Periph_TIM6: TIM6 clock
\r
1168 * @arg RCC_APB1Periph_TIM7: TIM7 clock
\r
1169 * @arg RCC_APB1Periph_LCD: LCD clock
\r
1170 * @arg RCC_APB1Periph_WWDG: WWDG clock
\r
1171 * @arg RCC_APB1Periph_SPI2: SPI2 clock
\r
1172 * @arg RCC_APB1Periph_SPI3: SPI3 clock
\r
1173 * @arg RCC_APB1Periph_USART2: USART2 clock
\r
1174 * @arg RCC_APB1Periph_USART3: USART3 clock
\r
1175 * @arg RCC_APB1Periph_UART4: UART4 clock
\r
1176 * @arg RCC_APB1Periph_UART5: UART5 clock
\r
1177 * @arg RCC_APB1Periph_I2C1: I2C1 clock
\r
1178 * @arg RCC_APB1Periph_I2C2: I2C2 clock
\r
1179 * @arg RCC_APB1Periph_USB: USB clock
\r
1180 * @arg RCC_APB1Periph_PWR: PWR clock
\r
1181 * @arg RCC_APB1Periph_DAC: DAC clock
\r
1182 * @arg RCC_APB1Periph_COMP COMP clock
\r
1183 * @param NewState: new state of the specified peripheral clock.
\r
1184 * This parameter can be: ENABLE or DISABLE.
\r
1187 void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
\r
1189 /* Check the parameters */
\r
1190 assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
\r
1191 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1193 if (NewState != DISABLE)
\r
1195 RCC->APB1ENR |= RCC_APB1Periph;
\r
1199 RCC->APB1ENR &= ~RCC_APB1Periph;
\r
1204 * @brief Forces or releases AHB peripheral reset.
\r
1205 * @param RCC_AHBPeriph: specifies the AHB peripheral to reset.
\r
1206 * This parameter can be any combination of the following values:
\r
1207 * @arg RCC_AHBPeriph_GPIOA: GPIOA clock
\r
1208 * @arg RCC_AHBPeriph_GPIOB: GPIOB clock
\r
1209 * @arg RCC_AHBPeriph_GPIOC: GPIOC clock
\r
1210 * @arg RCC_AHBPeriph_GPIOD: GPIOD clock
\r
1211 * @arg RCC_AHBPeriph_GPIOE: GPIOE clock
\r
1212 * @arg RCC_AHBPeriph_GPIOH: GPIOH clock
\r
1213 * @arg RCC_AHBPeriph_GPIOF: GPIOF clock
\r
1214 * @arg RCC_AHBPeriph_GPIOG: GPIOG clock
\r
1215 * @arg RCC_AHBPeriph_CRC: CRC clock
\r
1216 * @arg RCC_AHBPeriph_FLITF: (has effect only when the Flash memory is in power down mode)
\r
1217 * @arg RCC_AHBPeriph_DMA1: DMA1 clock
\r
1218 * @arg RCC_AHBPeriph_DMA2: DMA2 clock
\r
1219 * @arg RCC_AHBPeriph_AES: AES clock
\r
1220 * @arg RCC_AHBPeriph_FSMC: FSMC clock
\r
1221 * @param NewState: new state of the specified peripheral reset.
\r
1222 * This parameter can be: ENABLE or DISABLE.
\r
1225 void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
\r
1227 /* Check the parameters */
\r
1228 assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));
\r
1229 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1231 if (NewState != DISABLE)
\r
1233 RCC->AHBRSTR |= RCC_AHBPeriph;
\r
1237 RCC->AHBRSTR &= ~RCC_AHBPeriph;
\r
1242 * @brief Forces or releases High Speed APB (APB2) peripheral reset.
\r
1243 * @param RCC_APB2Periph: specifies the APB2 peripheral to reset.
\r
1244 * This parameter can be any combination of the following values:
\r
1245 * @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
\r
1246 * @arg RCC_APB2Periph_TIM9: TIM9 clock
\r
1247 * @arg RCC_APB2Periph_TIM10: TIM10 clock
\r
1248 * @arg RCC_APB2Periph_TIM11: TIM11 clock
\r
1249 * @arg RCC_APB2Periph_ADC1: ADC1 clock
\r
1250 * @arg RCC_APB2Periph_SDIO: SDIO clock
\r
1251 * @arg RCC_APB2Periph_SPI1: SPI1 clock
\r
1252 * @arg RCC_APB2Periph_USART1: USART1 clock
\r
1253 * @param NewState: new state of the specified peripheral reset.
\r
1254 * This parameter can be: ENABLE or DISABLE.
\r
1257 void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
\r
1259 /* Check the parameters */
\r
1260 assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
\r
1261 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1263 if (NewState != DISABLE)
\r
1265 RCC->APB2RSTR |= RCC_APB2Periph;
\r
1269 RCC->APB2RSTR &= ~RCC_APB2Periph;
\r
1274 * @brief Forces or releases Low Speed APB (APB1) peripheral reset.
\r
1275 * @param RCC_APB1Periph: specifies the APB1 peripheral to reset.
\r
1276 * This parameter can be any combination of the following values:
\r
1277 * @arg RCC_APB1Periph_TIM2: TIM2 clock
\r
1278 * @arg RCC_APB1Periph_TIM3: TIM3 clock
\r
1279 * @arg RCC_APB1Periph_TIM4: TIM4 clock
\r
1280 * @arg RCC_APB1Periph_TIM5: TIM5 clock
\r
1281 * @arg RCC_APB1Periph_TIM6: TIM6 clock
\r
1282 * @arg RCC_APB1Periph_TIM7: TIM7 clock
\r
1283 * @arg RCC_APB1Periph_LCD: LCD clock
\r
1284 * @arg RCC_APB1Periph_WWDG: WWDG clock
\r
1285 * @arg RCC_APB1Periph_SPI2: SPI2 clock
\r
1286 * @arg RCC_APB1Periph_SPI3: SPI3 clock
\r
1287 * @arg RCC_APB1Periph_USART2: USART2 clock
\r
1288 * @arg RCC_APB1Periph_USART3: USART3 clock
\r
1289 * @arg RCC_APB1Periph_UART4: UART4 clock
\r
1290 * @arg RCC_APB1Periph_UART5: UART5 clock
\r
1291 * @arg RCC_APB1Periph_I2C1: I2C1 clock
\r
1292 * @arg RCC_APB1Periph_I2C2: I2C2 clock
\r
1293 * @arg RCC_APB1Periph_USB: USB clock
\r
1294 * @arg RCC_APB1Periph_PWR: PWR clock
\r
1295 * @arg RCC_APB1Periph_DAC: DAC clock
\r
1296 * @arg RCC_APB1Periph_COMP
\r
1297 * @param NewState: new state of the specified peripheral clock.
\r
1298 * This parameter can be: ENABLE or DISABLE.
\r
1301 void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
\r
1303 /* Check the parameters */
\r
1304 assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
\r
1305 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1307 if (NewState != DISABLE)
\r
1309 RCC->APB1RSTR |= RCC_APB1Periph;
\r
1313 RCC->APB1RSTR &= ~RCC_APB1Periph;
\r
1318 * @brief Enables or disables the AHB peripheral clock during SLEEP mode.
\r
1319 * @note Peripheral clock gating in SLEEP mode can be used to further reduce
\r
1320 * power consumption.
\r
1321 * - After wakeup from SLEEP mode, the peripheral clock is enabled again.
\r
1322 * - By default, all peripheral clocks are enabled during SLEEP mode.
\r
1323 * @param RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.
\r
1324 * This parameter can be any combination of the following values:
\r
1325 * @arg RCC_AHBPeriph_GPIOA: GPIOA clock
\r
1326 * @arg RCC_AHBPeriph_GPIOB: GPIOB clock
\r
1327 * @arg RCC_AHBPeriph_GPIOC: GPIOC clock
\r
1328 * @arg RCC_AHBPeriph_GPIOD: GPIOD clock
\r
1329 * @arg RCC_AHBPeriph_GPIOE: GPIOE clock
\r
1330 * @arg RCC_AHBPeriph_GPIOH: GPIOH clock
\r
1331 * @arg RCC_AHBPeriph_GPIOF: GPIOF clock
\r
1332 * @arg RCC_AHBPeriph_GPIOG: GPIOG clock
\r
1333 * @arg RCC_AHBPeriph_CRC: CRC clock
\r
1334 * @arg RCC_AHBPeriph_FLITF: (has effect only when the Flash memory is in power down mode)
\r
1335 * @arg RCC_AHBPeriph_SRAM: SRAM clock
\r
1336 * @arg RCC_AHBPeriph_DMA1: DMA1 clock
\r
1337 * @arg RCC_AHBPeriph_DMA2: DMA2 clock
\r
1338 * @arg RCC_AHBPeriph_AES: AES clock
\r
1339 * @arg RCC_AHBPeriph_FSMC: FSMC clock
\r
1340 * @param NewState: new state of the specified peripheral clock.
\r
1341 * This parameter can be: ENABLE or DISABLE.
\r
1344 void RCC_AHBPeriphClockLPModeCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
\r
1346 /* Check the parameters */
\r
1347 assert_param(IS_RCC_AHB_LPMODE_PERIPH(RCC_AHBPeriph));
\r
1348 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1350 if (NewState != DISABLE)
\r
1352 RCC->AHBLPENR |= RCC_AHBPeriph;
\r
1356 RCC->AHBLPENR &= ~RCC_AHBPeriph;
\r
1361 * @brief Enables or disables the APB2 peripheral clock during SLEEP mode.
\r
1362 * @note Peripheral clock gating in SLEEP mode can be used to further reduce
\r
1363 * power consumption.
\r
1364 * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
\r
1365 * @note By default, all peripheral clocks are enabled during SLEEP mode.
\r
1366 * @param RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
\r
1367 * This parameter can be any combination of the following values:
\r
1368 * @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
\r
1369 * @arg RCC_APB2Periph_TIM9: TIM9 clock
\r
1370 * @arg RCC_APB2Periph_TIM10: TIM10 clock
\r
1371 * @arg RCC_APB2Periph_TIM11: TIM11 clock
\r
1372 * @arg RCC_APB2Periph_ADC1: ADC1 clock
\r
1373 * @arg RCC_APB2Periph_SDIO: SDIO clock
\r
1374 * @arg RCC_APB2Periph_SPI1: SPI1 clock
\r
1375 * @arg RCC_APB2Periph_USART1: USART1 clock
\r
1376 * @param NewState: new state of the specified peripheral clock.
\r
1377 * This parameter can be: ENABLE or DISABLE.
\r
1380 void RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
\r
1382 /* Check the parameters */
\r
1383 assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
\r
1384 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1386 if (NewState != DISABLE)
\r
1388 RCC->APB2LPENR |= RCC_APB2Periph;
\r
1392 RCC->APB2LPENR &= ~RCC_APB2Periph;
\r
1397 * @brief Enables or disables the APB1 peripheral clock during SLEEP mode.
\r
1398 * @note Peripheral clock gating in SLEEP mode can be used to further reduce
\r
1399 * power consumption.
\r
1400 * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
\r
1401 * @note By default, all peripheral clocks are enabled during SLEEP mode.
\r
1402 * @param RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
\r
1403 * This parameter can be any combination of the following values:
\r
1404 * @arg RCC_APB1Periph_TIM2: TIM2 clock
\r
1405 * @arg RCC_APB1Periph_TIM3: TIM3 clock
\r
1406 * @arg RCC_APB1Periph_TIM4: TIM4 clock
\r
1407 * @arg RCC_APB1Periph_TIM5: TIM5 clock
\r
1408 * @arg RCC_APB1Periph_TIM6: TIM6 clock
\r
1409 * @arg RCC_APB1Periph_TIM7: TIM7 clock
\r
1410 * @arg RCC_APB1Periph_LCD: LCD clock
\r
1411 * @arg RCC_APB1Periph_WWDG: WWDG clock
\r
1412 * @arg RCC_APB1Periph_SPI2: SPI2 clock
\r
1413 * @arg RCC_APB1Periph_SPI3: SPI3 clock
\r
1414 * @arg RCC_APB1Periph_USART2: USART2 clock
\r
1415 * @arg RCC_APB1Periph_USART3: USART3 clock
\r
1416 * @arg RCC_APB1Periph_UART4: UART4 clock
\r
1417 * @arg RCC_APB1Periph_UART5: UART5 clock
\r
1418 * @arg RCC_APB1Periph_I2C1: I2C1 clock
\r
1419 * @arg RCC_APB1Periph_I2C2: I2C2 clock
\r
1420 * @arg RCC_APB1Periph_USB: USB clock
\r
1421 * @arg RCC_APB1Periph_PWR: PWR clock
\r
1422 * @arg RCC_APB1Periph_DAC: DAC clock
\r
1423 * @arg RCC_APB1Periph_COMP: COMP clock
\r
1424 * @param NewState: new state
\r
1425 * @param NewState: new state of the specified peripheral clock.
\r
1426 * This parameter can be: ENABLE or DISABLE.
\r
1429 void RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
\r
1431 /* Check the parameters */
\r
1432 assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
\r
1433 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1435 if (NewState != DISABLE)
\r
1437 RCC->APB1LPENR |= RCC_APB1Periph;
\r
1441 RCC->APB1LPENR &= ~RCC_APB1Periph;
\r
1449 /** @defgroup RCC_Group4 Interrupts and flags management functions
\r
1450 * @brief Interrupts and flags management functions
\r
1453 ===============================================================================
\r
1454 ##### Interrupts and flags management functions #####
\r
1455 ===============================================================================
\r
1462 * @brief Enables or disables the specified RCC interrupts.
\r
1463 * @note The CSS interrupt doesn't have an enable bit; once the CSS is enabled
\r
1464 * and if the HSE clock fails, the CSS interrupt occurs and an NMI is
\r
1465 * automatically generated. The NMI will be executed indefinitely, and
\r
1466 * since NMI has higher priority than any other IRQ (and main program)
\r
1467 * the application will be stacked in the NMI ISR unless the CSS interrupt
\r
1468 * pending bit is cleared.
\r
1469 * @param RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.
\r
1470 * This parameter can be any combination of the following values:
\r
1471 * @arg RCC_IT_LSIRDY: LSI ready interrupt
\r
1472 * @arg RCC_IT_LSERDY: LSE ready interrupt
\r
1473 * @arg RCC_IT_HSIRDY: HSI ready interrupt
\r
1474 * @arg RCC_IT_HSERDY: HSE ready interrupt
\r
1475 * @arg RCC_IT_PLLRDY: PLL ready interrupt
\r
1476 * @arg RCC_IT_MSIRDY: MSI ready interrupt
\r
1477 * @arg RCC_IT_LSECSS: LSE CSS interrupt
\r
1478 * @param NewState: new state of the specified RCC interrupts.
\r
1479 * This parameter can be: ENABLE or DISABLE.
\r
1482 void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)
\r
1484 /* Check the parameters */
\r
1485 assert_param(IS_RCC_IT(RCC_IT));
\r
1486 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1488 if (NewState != DISABLE)
\r
1490 /* Perform Byte access to RCC_CIR[12:8] bits to enable the selected interrupts */
\r
1491 *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;
\r
1495 /* Perform Byte access to RCC_CIR[12:8] bits to disable the selected interrupts */
\r
1496 *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;
\r
1501 * @brief Checks whether the specified RCC flag is set or not.
\r
1502 * @param RCC_FLAG: specifies the flag to check.
\r
1503 * This parameter can be one of the following values:
\r
1504 * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
\r
1505 * @arg RCC_FLAG_MSIRDY: MSI oscillator clock ready
\r
1506 * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
\r
1507 * @arg RCC_FLAG_PLLRDY: PLL clock ready
\r
1508 * @arg RCC_FLAG_LSECSS: LSE oscillator clock CSS detected
\r
1509 * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
\r
1510 * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
\r
1511 * @arg RCC_FLAG_OBLRST: Option Byte Loader (OBL) reset
\r
1512 * @arg RCC_FLAG_PINRST: Pin reset
\r
1513 * @arg RCC_FLAG_PORRST: POR/PDR reset
\r
1514 * @arg RCC_FLAG_SFTRST: Software reset
\r
1515 * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
\r
1516 * @arg RCC_FLAG_WWDGRST: Window Watchdog reset
\r
1517 * @arg RCC_FLAG_LPWRRST: Low Power reset
\r
1518 * @retval The new state of RCC_FLAG (SET or RESET).
\r
1520 FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
\r
1523 uint32_t statusreg = 0;
\r
1524 FlagStatus bitstatus = RESET;
\r
1526 /* Check the parameters */
\r
1527 assert_param(IS_RCC_FLAG(RCC_FLAG));
\r
1529 /* Get the RCC register index */
\r
1530 tmp = RCC_FLAG >> 5;
\r
1532 if (tmp == 1) /* The flag to check is in CR register */
\r
1534 statusreg = RCC->CR;
\r
1536 else /* The flag to check is in CSR register (tmp == 2) */
\r
1538 statusreg = RCC->CSR;
\r
1541 /* Get the flag position */
\r
1542 tmp = RCC_FLAG & FLAG_MASK;
\r
1544 if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
\r
1550 bitstatus = RESET;
\r
1552 /* Return the flag status */
\r
1557 * @brief Clears the RCC reset flags.
\r
1558 * The reset flags are: RCC_FLAG_OBLRST, RCC_FLAG_PINRST, RCC_FLAG_PORRST,
\r
1559 * RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST.
\r
1563 void RCC_ClearFlag(void)
\r
1565 /* Set RMVF bit to clear the reset flags */
\r
1566 RCC->CSR |= RCC_CSR_RMVF;
\r
1570 * @brief Checks whether the specified RCC interrupt has occurred or not.
\r
1571 * @param RCC_IT: specifies the RCC interrupt source to check.
\r
1572 * This parameter can be one of the following values:
\r
1573 * @arg RCC_IT_LSIRDY: LSI ready interrupt
\r
1574 * @arg RCC_IT_LSERDY: LSE ready interrupt
\r
1575 * @arg RCC_IT_HSIRDY: HSI ready interrupt
\r
1576 * @arg RCC_IT_HSERDY: HSE ready interrupt
\r
1577 * @arg RCC_IT_PLLRDY: PLL ready interrupt
\r
1578 * @arg RCC_IT_MSIRDY: MSI ready interrupt
\r
1579 * @arg RCC_IT_LSECSS: LSE CSS interrupt
\r
1580 * @arg RCC_IT_CSS: Clock Security System interrupt
\r
1581 * @retval The new state of RCC_IT (SET or RESET).
\r
1583 ITStatus RCC_GetITStatus(uint8_t RCC_IT)
\r
1585 ITStatus bitstatus = RESET;
\r
1586 /* Check the parameters */
\r
1587 assert_param(IS_RCC_GET_IT(RCC_IT));
\r
1589 /* Check the status of the specified RCC interrupt */
\r
1590 if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)
\r
1596 bitstatus = RESET;
\r
1598 /* Return the RCC_IT status */
\r
1603 * @brief Clears the RCC's interrupt pending bits.
\r
1604 * @param RCC_IT: specifies the interrupt pending bit to clear.
\r
1605 * This parameter can be any combination of the following values:
\r
1606 * @arg RCC_IT_LSIRDY: LSI ready interrupt
\r
1607 * @arg RCC_IT_LSERDY: LSE ready interrupt
\r
1608 * @arg RCC_IT_HSIRDY: HSI ready interrupt
\r
1609 * @arg RCC_IT_HSERDY: HSE ready interrupt
\r
1610 * @arg RCC_IT_PLLRDY: PLL ready interrupt
\r
1611 * @arg RCC_IT_MSIRDY: MSI ready interrupt
\r
1612 * @arg RCC_IT_LSECSS: LSE CSS interrupt
\r
1613 * @arg RCC_IT_CSS: Clock Security System interrupt
\r
1616 void RCC_ClearITPendingBit(uint8_t RCC_IT)
\r
1618 /* Check the parameters */
\r
1619 assert_param(IS_RCC_CLEAR_IT(RCC_IT));
\r
1621 /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt
\r
1623 *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;
\r
1642 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r