]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_rcc.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_rcc.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_rcc.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of RCC HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_RCC_H
40 #define __STM32F4xx_HAL_RCC_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup RCC
54   * @{
55   */
56
57 /* Exported types ------------------------------------------------------------*/ 
58
59 /**
60   * @brief  RCC PLL configuration structure definition
61   */
62 typedef struct
63 {
64   uint32_t PLLState;   /*!< The new state of the PLL.
65                             This parameter can be a value of @ref RCC_PLL_Config                      */
66
67   uint32_t PLLSource;  /*!< RCC_PLLSource: PLL entry clock source.
68                             This parameter must be a value of @ref RCC_PLL_Clock_Source               */           
69
70   uint32_t PLLM;       /*!< PLLM: Division factor for PLL VCO input clock.
71                             This parameter must be a number between Min_Data = 0 and Max_Data = 63    */        
72
73   uint32_t PLLN;       /*!< PLLN: Multiplication factor for PLL VCO output clock.
74                             This parameter must be a number between Min_Data = 192 and Max_Data = 432 */
75
76   uint32_t PLLP;       /*!< PLLP: Division factor for main system clock (SYSCLK).
77                             This parameter must be a value of @ref RCC_PLLP_Clock_Divider             */
78
79   uint32_t PLLQ;       /*!< PLLQ: Division factor for OTG FS, SDIO and RNG clocks.
80                             This parameter must be a number between Min_Data = 0 and Max_Data = 63    */
81
82 }RCC_PLLInitTypeDef;
83
84 /**
85   * @brief  RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition  
86   */
87 typedef struct
88 {
89   uint32_t OscillatorType;       /*!< The oscillators to be configured.
90                                       This parameter can be a value of @ref RCC_Oscillator_Type                   */
91
92   uint32_t HSEState;             /*!< The new state of the HSE.
93                                       This parameter can be a value of @ref RCC_HSE_Config                        */
94
95   uint32_t LSEState;             /*!< The new state of the LSE.
96                                       This parameter can be a value of @ref RCC_LSE_Config                        */
97                                           
98   uint32_t HSIState;             /*!< The new state of the HSI.
99                                       This parameter can be a value of @ref RCC_HSI_Config                        */
100
101   uint32_t HSICalibrationValue;  /*!< The calibration trimming value.
102                                       This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1F */
103                                
104   uint32_t LSIState;             /*!< The new state of the LSI.
105                                       This parameter can be a value of @ref RCC_LSI_Config                        */
106
107   RCC_PLLInitTypeDef PLL;        /*!< PLL structure parameters                                                    */      
108
109 }RCC_OscInitTypeDef;
110
111 /**
112   * @brief  RCC System, AHB and APB busses clock configuration structure definition  
113   */
114 typedef struct
115 {
116   uint32_t ClockType;             /*!< The clock to be configured.
117                                        This parameter can be a value of @ref RCC_System_Clock_Type      */
118
119   uint32_t SYSCLKSource;          /*!< The clock source (SYSCLKS) used as system clock.
120                                        This parameter can be a value of @ref RCC_System_Clock_Source    */
121
122   uint32_t AHBCLKDivider;         /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
123                                        This parameter can be a value of @ref RCC_AHB_Clock_Source       */
124
125   uint32_t APB1CLKDivider;        /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
126                                        This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
127
128   uint32_t APB2CLKDivider;        /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
129                                        This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
130
131 }RCC_ClkInitTypeDef;
132
133 /* Exported constants --------------------------------------------------------*/
134 /** @defgroup RCC_Exported_Constants
135   * @{
136   */
137
138 /** @defgroup RCC_BitAddress_AliasRegion
139   * @brief RCC registers bit address in the alias region
140   * @{
141   */
142 #define RCC_OFFSET                (RCC_BASE - PERIPH_BASE)
143 /* --- CR Register ---*/
144 /* Alias word address of HSION bit */
145 #define RCC_CR_OFFSET             (RCC_OFFSET + 0x00)
146 #define HSION_BitNumber           0x00
147 #define CR_HSION_BB               (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (HSION_BitNumber * 4))
148 /* Alias word address of CSSON bit */
149 #define CSSON_BitNumber           0x13
150 #define CR_CSSON_BB               (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (CSSON_BitNumber * 4))
151 /* Alias word address of PLLON bit */
152 #define PLLON_BitNumber           0x18
153 #define CR_PLLON_BB               (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (PLLON_BitNumber * 4))
154 /* Alias word address of PLLI2SON bit */
155 #define PLLI2SON_BitNumber        0x1A
156 #define CR_PLLI2SON_BB            (PERIPH_BB_BASE + (RCC_CR_OFFSET * 32) + (PLLI2SON_BitNumber * 4))
157
158 /* --- CFGR Register ---*/
159 /* Alias word address of I2SSRC bit */
160 #define RCC_CFGR_OFFSET           (RCC_OFFSET + 0x08)
161 #define I2SSRC_BitNumber          0x17
162 #define CFGR_I2SSRC_BB            (PERIPH_BB_BASE + (RCC_CFGR_OFFSET * 32) + (I2SSRC_BitNumber * 4))
163
164 /* --- BDCR Register ---*/
165 /* Alias word address of RTCEN bit */
166 #define RCC_BDCR_OFFSET           (RCC_OFFSET + 0x70)
167 #define RTCEN_BitNumber           0x0F
168 #define BDCR_RTCEN_BB             (PERIPH_BB_BASE + (RCC_BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))
169 /* Alias word address of BDRST bit */
170 #define BDRST_BitNumber           0x10
171 #define BDCR_BDRST_BB             (PERIPH_BB_BASE + (RCC_BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))
172
173 /* --- CSR Register ---*/
174 /* Alias word address of LSION bit */
175 #define RCC_CSR_OFFSET            (RCC_OFFSET + 0x74)
176 #define LSION_BitNumber           0x00
177 #define CSR_LSION_BB              (PERIPH_BB_BASE + (RCC_CSR_OFFSET * 32) + (LSION_BitNumber * 4))
178
179 /* CR register byte 3 (Bits[23:16]) base address */
180 #define CR_BYTE2_ADDRESS          ((uint32_t)0x40023802)
181
182 /* CIR register byte 2 (Bits[15:8]) base address */
183 #define CIR_BYTE1_ADDRESS         ((uint32_t)(RCC_BASE + 0x0C + 0x01))
184
185 /* CIR register byte 3 (Bits[23:16]) base address */
186 #define CIR_BYTE2_ADDRESS         ((uint32_t)(RCC_BASE + 0x0C + 0x02))
187
188 /* BDCR register base address */
189 #define BDCR_BYTE0_ADDRESS        (PERIPH_BASE + RCC_BDCR_OFFSET)
190
191
192 #define DBP_TIMEOUT_VALUE          ((uint32_t)100)
193 #define LSE_TIMEOUT_VALUE          ((uint32_t)5000)
194 /**
195   * @}
196   */
197
198 /** @defgroup RCC_Oscillator_Type
199   * @{
200   */
201 #define RCC_OSCILLATORTYPE_NONE            ((uint32_t)0x00000000)
202 #define RCC_OSCILLATORTYPE_HSE             ((uint32_t)0x00000001)
203 #define RCC_OSCILLATORTYPE_HSI             ((uint32_t)0x00000002)
204 #define RCC_OSCILLATORTYPE_LSE             ((uint32_t)0x00000004)
205 #define RCC_OSCILLATORTYPE_LSI             ((uint32_t)0x00000008)
206
207 #define IS_RCC_OSCILLATORTYPE(OSCILLATOR) ((OSCILLATOR) <= 15)
208 /**
209   * @}
210   */
211
212 /** @defgroup RCC_HSE_Config
213   * @{
214   */
215 #define RCC_HSE_OFF                      ((uint8_t)0x00)
216 #define RCC_HSE_ON                       ((uint8_t)0x01)
217 #define RCC_HSE_BYPASS                   ((uint8_t)0x05)
218
219 #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
220                          ((HSE) == RCC_HSE_BYPASS))
221 /**
222   * @}
223   */
224
225 /** @defgroup RCC_LSE_Config
226   * @{
227   */
228 #define RCC_LSE_OFF                      ((uint8_t)0x00)
229 #define RCC_LSE_ON                       ((uint8_t)0x01)
230 #define RCC_LSE_BYPASS                   ((uint8_t)0x05)
231
232 #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
233                          ((LSE) == RCC_LSE_BYPASS))
234 /**
235   * @}
236   */
237
238 /** @defgroup RCC_HSI_Config
239   * @{
240   */
241 #define RCC_HSI_OFF                      ((uint8_t)0x00)
242 #define RCC_HSI_ON                       ((uint8_t)0x01)
243
244 #define IS_RCC_HSI(HSI) (((HSI) == RCC_HSI_OFF) || ((HSI) == RCC_HSI_ON))
245 /**
246   * @}
247   */
248
249 /** @defgroup RCC_LSI_Config 
250   * @{
251   */
252 #define RCC_LSI_OFF                      ((uint8_t)0x00)
253 #define RCC_LSI_ON                       ((uint8_t)0x01)
254
255 #define IS_RCC_LSI(LSI) (((LSI) == RCC_LSI_OFF) || ((LSI) == RCC_LSI_ON))
256 /**
257   * @}
258   */
259
260 /** @defgroup RCC_PLL_Config 
261   * @{
262   */
263 #define RCC_PLL_NONE                      ((uint8_t)0x00)
264 #define RCC_PLL_OFF                       ((uint8_t)0x01)
265 #define RCC_PLL_ON                        ((uint8_t)0x02)
266
267 #define IS_RCC_PLL(PLL) (((PLL) == RCC_PLL_NONE) ||((PLL) == RCC_PLL_OFF) || ((PLL) == RCC_PLL_ON))
268 /**
269   * @}
270   */
271
272 /** @defgroup RCC_PLLP_Clock_Divider
273   * @{
274   */
275 #define RCC_PLLP_DIV2                  ((uint32_t)0x00000002)
276 #define RCC_PLLP_DIV4                  ((uint32_t)0x00000004)
277 #define RCC_PLLP_DIV6                  ((uint32_t)0x00000006)
278 #define RCC_PLLP_DIV8                  ((uint32_t)0x00000008)
279 /**
280   * @}
281   */
282
283 /** @defgroup RCC_PLL_Clock_Source 
284   * @{
285   */
286 #define RCC_PLLSOURCE_HSI                RCC_PLLCFGR_PLLSRC_HSI
287 #define RCC_PLLSOURCE_HSE                RCC_PLLCFGR_PLLSRC_HSE
288
289 #define IS_RCC_PLLSOURCE(SOURCE) (((SOURCE) == RCC_PLLSOURCE_HSI) || \
290                                   ((SOURCE) == RCC_PLLSOURCE_HSE))
291 #define IS_RCC_PLLM_VALUE(VALUE) ((VALUE) <= 63)
292 #define IS_RCC_PLLN_VALUE(VALUE) ((192 <= (VALUE)) && ((VALUE) <= 432))
293 #define IS_RCC_PLLP_VALUE(VALUE) (((VALUE) == 2) || ((VALUE) == 4) || ((VALUE) == 6) || ((VALUE) == 8))
294 #define IS_RCC_PLLQ_VALUE(VALUE) ((4 <= (VALUE)) && ((VALUE) <= 15))
295
296 #define IS_RCC_PLLI2SN_VALUE(VALUE) ((192 <= (VALUE)) && ((VALUE) <= 432))
297 #define IS_RCC_PLLI2SR_VALUE(VALUE) ((2 <= (VALUE)) && ((VALUE) <= 7))  
298
299 /**
300   * @}
301   */
302
303 /** @defgroup RCC_System_Clock_Type
304   * @{
305   */
306 #define RCC_CLOCKTYPE_SYSCLK             ((uint32_t)0x00000001)
307 #define RCC_CLOCKTYPE_HCLK               ((uint32_t)0x00000002)
308 #define RCC_CLOCKTYPE_PCLK1              ((uint32_t)0x00000004)
309 #define RCC_CLOCKTYPE_PCLK2              ((uint32_t)0x00000008)
310
311 #define IS_RCC_CLOCKTYPE(CLK) ((1 <= (CLK)) && ((CLK) <= 15))
312 /**
313   * @}
314   */
315   
316 /** @defgroup RCC_System_Clock_Source 
317   * @{
318   */
319 #define RCC_SYSCLKSOURCE_HSI             RCC_CFGR_SW_HSI
320 #define RCC_SYSCLKSOURCE_HSE             RCC_CFGR_SW_HSE
321 #define RCC_SYSCLKSOURCE_PLLCLK          RCC_CFGR_SW_PLL
322
323 #define IS_RCC_SYSCLKSOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSOURCE_HSI) || \
324                                      ((SOURCE) == RCC_SYSCLKSOURCE_HSE) || \
325                                      ((SOURCE) == RCC_SYSCLKSOURCE_PLLCLK))
326 /**
327   * @}
328   */ 
329
330 /** @defgroup RCC_AHB_Clock_Source
331   * @{
332   */
333 #define RCC_SYSCLK_DIV1                  RCC_CFGR_HPRE_DIV1
334 #define RCC_SYSCLK_DIV2                  RCC_CFGR_HPRE_DIV2
335 #define RCC_SYSCLK_DIV4                  RCC_CFGR_HPRE_DIV4
336 #define RCC_SYSCLK_DIV8                  RCC_CFGR_HPRE_DIV8
337 #define RCC_SYSCLK_DIV16                 RCC_CFGR_HPRE_DIV16
338 #define RCC_SYSCLK_DIV64                 RCC_CFGR_HPRE_DIV64
339 #define RCC_SYSCLK_DIV128                RCC_CFGR_HPRE_DIV128
340 #define RCC_SYSCLK_DIV256                RCC_CFGR_HPRE_DIV256
341 #define RCC_SYSCLK_DIV512                RCC_CFGR_HPRE_DIV512
342
343 #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_DIV1)   || ((HCLK) == RCC_SYSCLK_DIV2)   || \
344                            ((HCLK) == RCC_SYSCLK_DIV4)   || ((HCLK) == RCC_SYSCLK_DIV8)   || \
345                            ((HCLK) == RCC_SYSCLK_DIV16)  || ((HCLK) == RCC_SYSCLK_DIV64)  || \
346                            ((HCLK) == RCC_SYSCLK_DIV128) || ((HCLK) == RCC_SYSCLK_DIV256) || \
347                            ((HCLK) == RCC_SYSCLK_DIV512))
348 /**
349   * @}
350   */ 
351   
352 /** @defgroup RCC_APB1_APB2_Clock_Source
353   * @{
354   */
355 #define RCC_HCLK_DIV1                    RCC_CFGR_PPRE1_DIV1
356 #define RCC_HCLK_DIV2                    RCC_CFGR_PPRE1_DIV2
357 #define RCC_HCLK_DIV4                    RCC_CFGR_PPRE1_DIV4
358 #define RCC_HCLK_DIV8                    RCC_CFGR_PPRE1_DIV8
359 #define RCC_HCLK_DIV16                   RCC_CFGR_PPRE1_DIV16
360
361 #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_DIV1) || ((PCLK) == RCC_HCLK_DIV2) || \
362                            ((PCLK) == RCC_HCLK_DIV4) || ((PCLK) == RCC_HCLK_DIV8) || \
363                            ((PCLK) == RCC_HCLK_DIV16))
364 /**
365   * @}
366   */ 
367
368 /** @defgroup RCC_RTC_Clock_Source
369   * @{
370   */
371 #define RCC_RTCCLKSOURCE_LSE             ((uint32_t)0x00000100)
372 #define RCC_RTCCLKSOURCE_LSI             ((uint32_t)0x00000200)
373 #define RCC_RTCCLKSOURCE_HSE_DIV2        ((uint32_t)0x00020300)
374 #define RCC_RTCCLKSOURCE_HSE_DIV3        ((uint32_t)0x00030300)
375 #define RCC_RTCCLKSOURCE_HSE_DIV4        ((uint32_t)0x00040300)
376 #define RCC_RTCCLKSOURCE_HSE_DIV5        ((uint32_t)0x00050300)
377 #define RCC_RTCCLKSOURCE_HSE_DIV6        ((uint32_t)0x00060300)
378 #define RCC_RTCCLKSOURCE_HSE_DIV7        ((uint32_t)0x00070300)
379 #define RCC_RTCCLKSOURCE_HSE_DIV8        ((uint32_t)0x00080300)
380 #define RCC_RTCCLKSOURCE_HSE_DIV9        ((uint32_t)0x00090300)
381 #define RCC_RTCCLKSOURCE_HSE_DIV10       ((uint32_t)0x000A0300)
382 #define RCC_RTCCLKSOURCE_HSE_DIV11       ((uint32_t)0x000B0300)
383 #define RCC_RTCCLKSOURCE_HSE_DIV12       ((uint32_t)0x000C0300)
384 #define RCC_RTCCLKSOURCE_HSE_DIV13       ((uint32_t)0x000D0300)
385 #define RCC_RTCCLKSOURCE_HSE_DIV14       ((uint32_t)0x000E0300)
386 #define RCC_RTCCLKSOURCE_HSE_DIV15       ((uint32_t)0x000F0300)
387 #define RCC_RTCCLKSOURCE_HSE_DIV16       ((uint32_t)0x00100300)
388 #define RCC_RTCCLKSOURCE_HSE_DIV17       ((uint32_t)0x00110300)
389 #define RCC_RTCCLKSOURCE_HSE_DIV18       ((uint32_t)0x00120300)
390 #define RCC_RTCCLKSOURCE_HSE_DIV19       ((uint32_t)0x00130300)
391 #define RCC_RTCCLKSOURCE_HSE_DIV20       ((uint32_t)0x00140300)
392 #define RCC_RTCCLKSOURCE_HSE_DIV21       ((uint32_t)0x00150300)
393 #define RCC_RTCCLKSOURCE_HSE_DIV22       ((uint32_t)0x00160300)
394 #define RCC_RTCCLKSOURCE_HSE_DIV23       ((uint32_t)0x00170300)
395 #define RCC_RTCCLKSOURCE_HSE_DIV24       ((uint32_t)0x00180300)
396 #define RCC_RTCCLKSOURCE_HSE_DIV25       ((uint32_t)0x00190300)
397 #define RCC_RTCCLKSOURCE_HSE_DIV26       ((uint32_t)0x001A0300)
398 #define RCC_RTCCLKSOURCE_HSE_DIV27       ((uint32_t)0x001B0300)
399 #define RCC_RTCCLKSOURCE_HSE_DIV28       ((uint32_t)0x001C0300)
400 #define RCC_RTCCLKSOURCE_HSE_DIV29       ((uint32_t)0x001D0300)
401 #define RCC_RTCCLKSOURCE_HSE_DIV30       ((uint32_t)0x001E0300)
402 #define RCC_RTCCLKSOURCE_HSE_DIV31       ((uint32_t)0x001F0300)
403 /**
404   * @}
405   */
406
407 /** @defgroup RCC_I2S_Clock_Source
408   * @{
409   */
410 #define RCC_I2SCLKSOURCE_PLLI2S         ((uint32_t)0x00000000)
411 #define RCC_I2SCLKSOURCE_EXT            ((uint32_t)0x00000001)
412 /**
413   * @}
414   */
415
416 /** @defgroup RCC_MCO_Index
417   * @{
418   */
419 #define RCC_MCO1                         ((uint32_t)0x00000000)
420 #define RCC_MCO2                         ((uint32_t)0x00000001)
421
422 #define IS_RCC_MCO(MCOx) (((MCOx) == RCC_MCO1) || ((MCOx) == RCC_MCO2))
423 /**
424   * @}
425   */
426
427 /** @defgroup RCC_MCO1_Clock_Source
428   * @{
429   */
430 #define RCC_MCO1SOURCE_HSI               ((uint32_t)0x00000000)
431 #define RCC_MCO1SOURCE_LSE               RCC_CFGR_MCO1_0
432 #define RCC_MCO1SOURCE_HSE               RCC_CFGR_MCO1_1
433 #define RCC_MCO1SOURCE_PLLCLK            RCC_CFGR_MCO1
434
435 #define IS_RCC_MCO1SOURCE(SOURCE) (((SOURCE) == RCC_MCO1SOURCE_HSI) || ((SOURCE) == RCC_MCO1SOURCE_LSE) || \
436                                    ((SOURCE) == RCC_MCO1SOURCE_HSE) || ((SOURCE) == RCC_MCO1SOURCE_PLLCLK))
437 /**
438   * @}
439   */
440
441 /** @defgroup RCC_MCO2_Clock_Source
442   * @{
443   */
444 #define RCC_MCO2SOURCE_SYSCLK            ((uint32_t)0x00000000)
445 #define RCC_MCO2SOURCE_PLLI2SCLK         RCC_CFGR_MCO2_0
446 #define RCC_MCO2SOURCE_HSE               RCC_CFGR_MCO2_1
447 #define RCC_MCO2SOURCE_PLLCLK            RCC_CFGR_MCO2
448
449 #define IS_RCC_MCO2SOURCE(SOURCE) (((SOURCE) == RCC_MCO2SOURCE_SYSCLK) || ((SOURCE) == RCC_MCO2SOURCE_PLLI2SCLK)|| \
450                                    ((SOURCE) == RCC_MCO2SOURCE_HSE)    || ((SOURCE) == RCC_MCO2SOURCE_PLLCLK))
451 /**
452   * @}
453   */
454
455 /** @defgroup RCC_MCOx_Clock_Prescaler
456   * @{
457   */
458 #define RCC_MCODIV_1                    ((uint32_t)0x00000000)
459 #define RCC_MCODIV_2                    RCC_CFGR_MCO1PRE_2
460 #define RCC_MCODIV_3                    ((uint32_t)RCC_CFGR_MCO1PRE_0 | RCC_CFGR_MCO1PRE_2)
461 #define RCC_MCODIV_4                    ((uint32_t)RCC_CFGR_MCO1PRE_1 | RCC_CFGR_MCO1PRE_2)
462 #define RCC_MCODIV_5                    RCC_CFGR_MCO1PRE
463
464 #define IS_RCC_MCODIV(DIV) (((DIV) == RCC_MCODIV_1)  || ((DIV) == RCC_MCODIV_2) || \
465                              ((DIV) == RCC_MCODIV_3) || ((DIV) == RCC_MCODIV_4) || \
466                              ((DIV) == RCC_MCODIV_5)) 
467 /**
468   * @}
469   */
470
471 /** @defgroup RCC_Interrupt 
472   * @{
473   */
474 #define RCC_IT_LSIRDY                    ((uint8_t)0x01)
475 #define RCC_IT_LSERDY                    ((uint8_t)0x02)
476 #define RCC_IT_HSIRDY                    ((uint8_t)0x04)
477 #define RCC_IT_HSERDY                    ((uint8_t)0x08)
478 #define RCC_IT_PLLRDY                    ((uint8_t)0x10)
479 #define RCC_IT_PLLI2SRDY                 ((uint8_t)0x20)
480 #define RCC_IT_CSS                       ((uint8_t)0x80)
481 /**
482   * @}
483   */
484   
485 /** @defgroup RCC_Flag
486   *        Elements values convention: 0XXYYYYYb
487   *           - YYYYY  : Flag position in the register
488   *           - 0XX  : Register index
489   *                 - 01: CR register
490   *                 - 10: BDCR register
491   *                 - 11: CSR register
492   * @{
493   */
494 /* Flags in the CR register */
495 #define RCC_FLAG_HSIRDY                  ((uint8_t)0x21)
496 #define RCC_FLAG_HSERDY                  ((uint8_t)0x31)
497 #define RCC_FLAG_PLLRDY                  ((uint8_t)0x39)
498 #define RCC_FLAG_PLLI2SRDY               ((uint8_t)0x3B)
499
500 /* Flags in the BDCR register */
501 #define RCC_FLAG_LSERDY                  ((uint8_t)0x41)
502
503 /* Flags in the CSR register */
504 #define RCC_FLAG_LSIRDY                  ((uint8_t)0x61)
505 #define RCC_FLAG_BORRST                  ((uint8_t)0x79)
506 #define RCC_FLAG_PINRST                  ((uint8_t)0x7A)
507 #define RCC_FLAG_PORRST                  ((uint8_t)0x7B)
508 #define RCC_FLAG_SFTRST                  ((uint8_t)0x7C)
509 #define RCC_FLAG_IWDGRST                 ((uint8_t)0x7D)
510 #define RCC_FLAG_WWDGRST                 ((uint8_t)0x7E)
511 #define RCC_FLAG_LPWRRST                 ((uint8_t)0x7F)
512
513 #define IS_RCC_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
514 /**
515   * @}
516   */ 
517
518 /**
519   * @}
520   */   
521 /* Exported macro ------------------------------------------------------------*/
522
523 /** @brief  Enable or disable the AHB1 peripheral clock.
524   * @note   After reset, the peripheral clock (used for registers read/write access)
525   *         is disabled and the application software has to enable this clock before 
526   *         using it.   
527   */
528 #define __GPIOA_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN))
529 #define __GPIOB_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOBEN))
530 #define __GPIOC_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOCEN))
531 #define __GPIOD_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIODEN))
532 #define __GPIOE_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOEEN))
533 #define __GPIOF_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOFEN))
534 #define __GPIOG_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOGEN))
535 #define __GPIOH_CLK_ENABLE()         (RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOHEN))
536 #define __CRC_CLK_ENABLE()           (RCC->AHB1ENR |= (RCC_AHB1ENR_CRCEN))
537 #define __BKPSRAM_CLK_ENABLE()       (RCC->AHB1ENR |= (RCC_AHB1ENR_BKPSRAMEN))
538 #define __CCMDATARAMEN_CLK_ENABLE()  (RCC->AHB1ENR |= (RCC_AHB1ENR_CCMDATARAMEN))
539 #define __DMA1_CLK_ENABLE()          (RCC->AHB1ENR |= (RCC_AHB1ENR_DMA1EN))
540 #define __DMA2_CLK_ENABLE()          (RCC->AHB1ENR |= (RCC_AHB1ENR_DMA2EN))
541
542 #define __GPIOA_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOAEN))
543 #define __GPIOB_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOBEN))
544 #define __GPIOC_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOCEN))
545 #define __GPIOD_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIODEN))
546 #define __GPIOE_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOEEN))
547 #define __GPIOF_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOFEN))
548 #define __GPIOG_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOGEN))
549 #define __GPIOH_CLK_DISABLE()        (RCC->AHB1ENR &= ~(RCC_AHB1ENR_GPIOHEN))
550 #define __CRC_CLK_DISABLE()          (RCC->AHB1ENR &= ~(RCC_AHB1ENR_CRCEN))
551 #define __BKPSRAM_CLK_DISABLE()      (RCC->AHB1ENR &= ~(RCC_AHB1ENR_BKPSRAMEN))
552 #define __CCMDATARAMEN_CLK_DISABLE() (RCC->AHB1ENR &= ~(RCC_AHB1ENR_CCMDATARAMEN))
553 #define __DMA1_CLK_DISABLE()         (RCC->AHB1ENR &= ~(RCC_AHB1ENR_DMA1EN))
554 #define __DMA2_CLK_DISABLE()         (RCC->AHB1ENR &= ~(RCC_AHB1ENR_DMA2EN))
555
556 /** @brief  Enable or disable the AHB2 peripheral clock.
557   * @note   After reset, the peripheral clock (used for registers read/write access)
558   *         is disabled and the application software has to enable this clock before 
559   *         using it.
560   */
561 #define __USB_OTG_FS_CLK_ENABLE()  do {(RCC->AHB2ENR |= (RCC_AHB2ENR_OTGFSEN));\
562                                        __SYSCFG_CLK_ENABLE();\
563                                     }while(0)
564                                         
565
566 #define __USB_OTG_FS_CLK_DISABLE() do { (RCC->AHB2ENR &= ~(RCC_AHB2ENR_OTGFSEN));\
567                                          __SYSCFG_CLK_DISABLE();\
568                                     }while(0)
569
570 #define __RNG_CLK_ENABLE()    (RCC->AHB2ENR |= (RCC_AHB2ENR_RNGEN))
571 #define __RNG_CLK_DISABLE()   (RCC->AHB2ENR &= ~(RCC_AHB2ENR_RNGEN))
572 /** @brief  Enable or disable the Low Speed APB (APB1) peripheral clock.
573   * @note   After reset, the peripheral clock (used for registers read/write access)
574   *         is disabled and the application software has to enable this clock before
575   *         using it.
576   */
577 #define __TIM2_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_TIM2EN))
578 #define __TIM3_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_TIM3EN))
579 #define __TIM4_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_TIM4EN))
580 #define __TIM5_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_TIM5EN))
581 #define __WWDG_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_WWDGEN))
582 #define __SPI2_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_SPI2EN))
583 #define __SPI3_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_SPI3EN))
584 #define __USART2_CLK_ENABLE()  (RCC->APB1ENR |= (RCC_APB1ENR_USART2EN))
585 #define __I2C1_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_I2C1EN))
586 #define __I2C2_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_I2C2EN))
587 #define __I2C3_CLK_ENABLE()    (RCC->APB1ENR |= (RCC_APB1ENR_I2C3EN))
588 #define __PWR_CLK_ENABLE()     (RCC->APB1ENR |= (RCC_APB1ENR_PWREN))
589
590 #define __TIM2_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
591 #define __TIM3_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
592 #define __TIM4_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM4EN))
593 #define __TIM5_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM5EN))
594 #define __WWDG_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
595 #define __SPI2_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI2EN))
596 #define __SPI3_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI3EN))
597 #define __USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
598 #define __I2C1_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
599 #define __I2C2_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C2EN))
600 #define __I2C3_CLK_DISABLE()   (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C3EN))
601 #define __PWR_CLK_DISABLE()    (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN)) 
602
603 /** @brief  Enable or disable the High Speed APB (APB2) peripheral clock.
604   * @note   After reset, the peripheral clock (used for registers read/write access)
605   *         is disabled and the application software has to enable this clock before 
606   *         using it.
607   */
608 #define __TIM1_CLK_ENABLE()    (RCC->APB2ENR |= (RCC_APB2ENR_TIM1EN))
609 #define __USART1_CLK_ENABLE()  (RCC->APB2ENR |= (RCC_APB2ENR_USART1EN))
610 #define __USART6_CLK_ENABLE()  (RCC->APB2ENR |= (RCC_APB2ENR_USART6EN))
611 #define __ADC1_CLK_ENABLE()    (RCC->APB2ENR |= (RCC_APB2ENR_ADC1EN))
612 #define __SDIO_CLK_ENABLE()    (RCC->APB2ENR |= (RCC_APB2ENR_SDIOEN))
613 #define __SPI1_CLK_ENABLE()    (RCC->APB2ENR |= (RCC_APB2ENR_SPI1EN))
614 #define __SPI4_CLK_ENABLE()    (RCC->APB2ENR |= (RCC_APB2ENR_SPI4EN))
615 #define __SYSCFG_CLK_ENABLE()  (RCC->APB2ENR |= (RCC_APB2ENR_SYSCFGEN))
616 #define __TIM9_CLK_ENABLE()    (RCC->APB2ENR |= (RCC_APB2ENR_TIM9EN))
617 #define __TIM10_CLK_ENABLE()   (RCC->APB2ENR |= (RCC_APB2ENR_TIM10EN))
618 #define __TIM11_CLK_ENABLE()   (RCC->APB2ENR |= (RCC_APB2ENR_TIM11EN))
619
620 #define __TIM1_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
621 #define __USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
622 #define __USART6_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART6EN))
623 #define __ADC1_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
624 #define __SDIO_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_SDIOEN))
625 #define __SPI1_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
626 #define __SPI4_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI4EN))
627 #define __SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
628 #define __TIM9_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM9EN))
629 #define __TIM10_CLK_DISABLE()  (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM10EN))
630 #define __TIM11_CLK_DISABLE()  (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM11EN))
631
632 /** @brief  Force or release AHB1 peripheral reset.
633   */  
634 #define __AHB1_FORCE_RESET()    (RCC->AHB1RSTR = 0xFFFFFFFF)
635 #define __GPIOA_FORCE_RESET()   (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOARST))
636 #define __GPIOB_FORCE_RESET()   (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOBRST))
637 #define __GPIOC_FORCE_RESET()   (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOCRST))
638 #define __GPIOD_FORCE_RESET()   (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIODRST))
639 #define __GPIOE_FORCE_RESET()   (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOERST))
640 #define __GPIOH_FORCE_RESET()   (RCC->AHB1RSTR |= (RCC_AHB1RSTR_GPIOHRST))
641 #define __CRC_FORCE_RESET()     (RCC->AHB1RSTR |= (RCC_AHB1RSTR_CRCRST))
642 #define __DMA1_FORCE_RESET()    (RCC->AHB1RSTR |= (RCC_AHB1RSTR_DMA1RST))
643 #define __DMA2_FORCE_RESET()    (RCC->AHB1RSTR |= (RCC_AHB1RSTR_DMA2RST))
644
645 #define __AHB1_RELEASE_RESET()  (RCC->AHB1RSTR = 0x00)
646 #define __GPIOA_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOARST))
647 #define __GPIOB_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOBRST))
648 #define __GPIOC_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOCRST))
649 #define __GPIOD_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIODRST))
650 #define __GPIOE_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOERST))
651 #define __GPIOF_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOFRST))
652 #define __GPIOG_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOGRST))
653 #define __GPIOH_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOHRST))
654 #define __GPIOI_RELEASE_RESET() (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOIRST))
655 #define __CRC_RELEASE_RESET()   (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_CRCRST))
656 #define __DMA1_RELEASE_RESET()  (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_DMA1RST))
657 #define __DMA2_RELEASE_RESET()  (RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_DMA2RST))
658
659 /** @brief  Force or release AHB2 peripheral reset.
660   */
661 #define __AHB2_FORCE_RESET()    (RCC->AHB2RSTR = 0xFFFFFFFF) 
662 #define __USB_OTG_FS_FORCE_RESET()   (RCC->AHB2RSTR |= (RCC_AHB2RSTR_OTGFSRST))
663
664 #define __AHB2_RELEASE_RESET()  (RCC->AHB2RSTR = 0x00)
665 #define __USB_OTG_FS_RELEASE_RESET() (RCC->AHB2RSTR &= ~(RCC_AHB2RSTR_OTGFSRST))
666
667 /* alias define maintained for legacy */
668 #define __OTGFS_FORCE_RESET    __USB_OTG_FS_FORCE_RESET
669 #define __OTGFS_RELEASE_RESET  __USB_OTG_FS_RELEASE_RESET                                      
670                                       
671 #define __RNG_FORCE_RESET()    (RCC->AHB2RSTR |= (RCC_AHB2RSTR_RNGRST))
672 #define __RNG_RELEASE_RESET()  (RCC->AHB2RSTR &= ~(RCC_AHB2RSTR_RNGRST))
673
674 /** @brief  Force or release APB1 peripheral reset.
675   */
676 #define __APB1_FORCE_RESET()     (RCC->APB1RSTR = 0xFFFFFFFF)  
677 #define __TIM2_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
678 #define __TIM3_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
679 #define __TIM4_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM4RST))
680 #define __TIM5_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM5RST))
681 #define __WWDG_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
682 #define __SPI2_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI2RST))
683 #define __SPI3_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI3RST))
684 #define __USART2_FORCE_RESET()   (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
685 #define __I2C1_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
686 #define __I2C2_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C2RST))
687 #define __I2C3_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C3RST))
688 #define __PWR_FORCE_RESET()      (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
689
690 #define __APB1_RELEASE_RESET()   (RCC->APB1RSTR = 0x00) 
691 #define __TIM2_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
692 #define __TIM3_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
693 #define __TIM4_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM4RST))
694 #define __TIM5_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM5RST))
695 #define __WWDG_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
696 #define __SPI2_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI2RST))
697 #define __SPI3_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI3RST))
698 #define __USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
699 #define __I2C1_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
700 #define __I2C2_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C2RST))
701 #define __I2C3_RELEASE_RESET()   (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C3RST))
702 #define __PWR_RELEASE_RESET()    (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
703
704 /** @brief  Force or release APB2 peripheral reset.
705   */
706 #define __APB2_FORCE_RESET()     (RCC->APB2RSTR = 0xFFFFFFFF)  
707 #define __TIM1_FORCE_RESET()     (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM1RST))
708 #define __USART1_FORCE_RESET()   (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
709 #define __USART6_FORCE_RESET()   (RCC->APB2RSTR |= (RCC_APB2RSTR_USART6RST))
710 #define __ADC_FORCE_RESET()      (RCC->APB2RSTR |= (RCC_APB2RSTR_ADCRST))
711 #define __SDIO_FORCE_RESET()     (RCC->APB2RSTR |= (RCC_APB2RSTR_SDIORST))
712 #define __SPI1_FORCE_RESET()     (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
713 #define __SPI4_FORCE_RESET()     (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI4RST))
714 #define __SYSCFG_FORCE_RESET()   (RCC->APB2RSTR |= (RCC_APB2RSTR_SYSCFGRST))
715 #define __TIM9_FORCE_RESET()     (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM9RST))
716 #define __TIM10_FORCE_RESET()    (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM10RST))
717 #define __TIM11_FORCE_RESET()    (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM11RST))
718
719 #define __APB2_RELEASE_RESET()   (RCC->APB2RSTR = 0x00)
720 #define __TIM1_RELEASE_RESET()   (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM1RST))
721 #define __USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
722 #define __USART6_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART6RST))
723 #define __ADC_RELEASE_RESET()    (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADCRST))
724 #define __SDIO_RELEASE_RESET()   (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SDIORST))
725 #define __SPI1_RELEASE_RESET()   (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
726 #define __SPI4_RELEASE_RESET()   (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI4RST))
727 #define __SYSCFG_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SYSCFGRST))
728 #define __TIM9_RELEASE_RESET()   (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM9RST))
729 #define __TIM10_RELEASE_RESET()  (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM10RST))
730 #define __TIM11_RELEASE_RESET()  (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM11RST))
731
732 /** @brief  Force or release AHB3 peripheral reset.
733   */  
734 #define __AHB3_FORCE_RESET() (RCC->AHB3RSTR = 0xFFFFFFFF)
735 #define __AHB3_RELEASE_RESET() (RCC->AHB3RSTR = 0x00) 
736
737 /** @brief  Enable or disable the AHB1 peripheral clock during Low Power (Sleep) mode.
738   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
739   *         power consumption.
740   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
741   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
742   */
743 #define __GPIOA_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOALPEN))
744 #define __GPIOB_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOBLPEN))
745 #define __GPIOC_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOCLPEN))
746 #define __GPIOD_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIODLPEN))
747 #define __GPIOE_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOELPEN))
748 #define __GPIOH_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_GPIOHLPEN))
749 #define __CRC_CLK_SLEEP_ENABLE()      (RCC->AHB1LPENR |= (RCC_AHB1LPENR_CRCLPEN))
750 #define __FLITF_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_FLITFLPEN))
751 #define __SRAM1_CLK_SLEEP_ENABLE()    (RCC->AHB1LPENR |= (RCC_AHB1LPENR_SRAM1LPEN))
752 #define __BKPSRAM_CLK_SLEEP_ENABLE()  (RCC->AHB1LPENR |= (RCC_AHB1LPENR_BKPSRAMLPEN))
753 #define __DMA1_CLK_SLEEP_ENABLE()     (RCC->AHB1LPENR |= (RCC_AHB1LPENR_DMA1LPEN))
754 #define __DMA2_CLK_SLEEP_ENABLE()     (RCC->AHB1LPENR |= (RCC_AHB1LPENR_DMA2LPEN))
755
756 #define __GPIOA_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOALPEN))
757 #define __GPIOB_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOBLPEN))
758 #define __GPIOC_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOCLPEN))
759 #define __GPIOD_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIODLPEN))
760 #define __GPIOE_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOELPEN))
761 #define __GPIOH_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_GPIOHLPEN))
762 #define __CRC_CLK_SLEEP_DISABLE()     (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_CRCLPEN))
763 #define __FLITF_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_FLITFLPEN))
764 #define __SRAM1_CLK_SLEEP_DISABLE()   (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_SRAM1LPEN))
765 #define __BKPSRAM_CLK_SLEEP_DISABLE() (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_BKPSRAMLPEN))
766 #define __DMA1_CLK_SLEEP_DISABLE()    (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_DMA1LPEN))
767 #define __DMA2_CLK_SLEEP_DISABLE()    (RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_DMA2LPEN))
768
769 /** @brief  Enable or disable the AHB2 peripheral clock during Low Power (Sleep) mode.
770   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
771   *         power consumption.
772   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
773   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
774   */
775 #define __USB_OTG_FS_CLK_SLEEP_ENABLE()  (RCC->AHB2LPENR |= (RCC_AHB2LPENR_OTGFSLPEN))
776
777 #define __USB_OTG_FS_CLK_SLEEP_DISABLE()   (RCC->AHB2LPENR &= ~(RCC_AHB2LPENR_OTGFSLPEN))
778
779 /* alias define maintained for legacy */
780 #define __OTGFS_CLK_SLEEP_ENABLE    __USB_OTG_FS_CLK_SLEEP_ENABLE
781 #define __OTGFS_CLK_SLEEP_DISABLE   __USB_OTG_FS_CLK_SLEEP_DISABLE
782
783 #define __RNG_CLK_SLEEP_ENABLE()   (RCC->AHB2LPENR |= (RCC_AHB2LPENR_RNGLPEN))
784 #define __RNG_CLK_SLEEP_DISABLE()  (RCC->AHB2LPENR &= ~(RCC_AHB2LPENR_RNGLPEN))
785
786 /** @brief  Enable or disable the APB1 peripheral clock during Low Power (Sleep) mode.
787   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
788   *         power consumption.
789   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
790   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
791   */
792 #define __TIM2_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM2LPEN))
793 #define __TIM3_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM3LPEN))
794 #define __TIM4_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM4LPEN))
795 #define __TIM5_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_TIM5LPEN))
796 #define __WWDG_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_WWDGLPEN))
797 #define __SPI2_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI2LPEN))
798 #define __SPI3_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI3LPEN))
799 #define __USART2_CLK_SLEEP_ENABLE()  (RCC->APB1LPENR |= (RCC_APB1LPENR_USART2LPEN))
800 #define __I2C1_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C1LPEN))
801 #define __I2C2_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C2LPEN))
802 #define __I2C3_CLK_SLEEP_ENABLE()    (RCC->APB1LPENR |= (RCC_APB1LPENR_I2C3LPEN))
803 #define __PWR_CLK_SLEEP_ENABLE()     (RCC->APB1LPENR |= (RCC_APB1LPENR_PWRLPEN))
804
805 #define __TIM2_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM2LPEN))
806 #define __TIM3_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM3LPEN))
807 #define __TIM4_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM4LPEN))
808 #define __TIM5_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_TIM5LPEN))
809 #define __WWDG_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_WWDGLPEN))
810 #define __SPI2_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI2LPEN))
811 #define __SPI3_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI3LPEN))
812 #define __USART2_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART2LPEN))
813 #define __I2C1_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C1LPEN))
814 #define __I2C2_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C2LPEN))
815 #define __I2C3_CLK_SLEEP_DISABLE()   (RCC->APB1LPENR &= ~(RCC_APB1LPENR_I2C3LPEN))
816 #define __PWR_CLK_SLEEP_DISABLE()    (RCC->APB1LPENR &= ~(RCC_APB1LPENR_PWRLPEN))
817
818 /** @brief  Enable or disable the APB2 peripheral clock during Low Power (Sleep) mode.
819   * @note   Peripheral clock gating in SLEEP mode can be used to further reduce
820   *         power consumption.
821   * @note   After wakeup from SLEEP mode, the peripheral clock is enabled again.
822   * @note   By default, all peripheral clocks are enabled during SLEEP mode.
823   */
824 #define __TIM1_CLK_SLEEP_ENABLE()    (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM1LPEN))
825 #define __USART1_CLK_SLEEP_ENABLE()  (RCC->APB2LPENR |= (RCC_APB2LPENR_USART1LPEN))
826 #define __USART6_CLK_SLEEP_ENABLE()  (RCC->APB2LPENR |= (RCC_APB2LPENR_USART6LPEN))
827 #define __ADC1_CLK_SLEEP_ENABLE()    (RCC->APB2LPENR |= (RCC_APB2LPENR_ADC1LPEN))
828 #define __SDIO_CLK_SLEEP_ENABLE()    (RCC->APB2LPENR |= (RCC_APB2LPENR_SDIOLPEN))
829 #define __SPI1_CLK_SLEEP_ENABLE()    (RCC->APB2LPENR |= (RCC_APB2LPENR_SPI1LPEN))
830 #define __SPI4_CLK_SLEEP_ENABLE()    (RCC->APB2LPENR |= (RCC_APB2LPENR_SPI4LPEN))
831 #define __SYSCFG_CLK_SLEEP_ENABLE()  (RCC->APB2LPENR |= (RCC_APB2LPENR_SYSCFGLPEN))
832 #define __TIM9_CLK_SLEEP_ENABLE()    (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM9LPEN))
833 #define __TIM10_CLK_SLEEP_ENABLE()   (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM10LPEN))
834 #define __TIM11_CLK_SLEEP_ENABLE()   (RCC->APB2LPENR |= (RCC_APB2LPENR_TIM11LPEN))
835
836 #define __TIM1_CLK_SLEEP_DISABLE()   (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM1LPEN))
837 #define __USART1_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_USART1LPEN))
838 #define __USART6_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_USART6LPEN))
839 #define __ADC1_CLK_SLEEP_DISABLE()   (RCC->APB2LPENR &= ~(RCC_APB2LPENR_ADC1LPEN))
840 #define __SDIO_CLK_SLEEP_DISABLE()   (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SDIOLPEN))
841 #define __SPI1_CLK_SLEEP_DISABLE()   (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SPI1LPEN))
842 #define __SPI4_CLK_SLEEP_DISABLE()   (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SPI4LPEN))
843 #define __SYSCFG_CLK_SLEEP_DISABLE() (RCC->APB2LPENR &= ~(RCC_APB2LPENR_SYSCFGLPEN))
844 #define __TIM9_CLK_SLEEP_DISABLE()   (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM9LPEN))
845 #define __TIM10_CLK_SLEEP_DISABLE()  (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM10LPEN))
846 #define __TIM11_CLK_SLEEP_DISABLE()  (RCC->APB2LPENR &= ~(RCC_APB2LPENR_TIM11LPEN))
847
848 /** @brief  Macros to enable or disable the Internal High Speed oscillator (HSI).
849   * @note   The HSI is stopped by hardware when entering STOP and STANDBY modes.
850   *         It is used (enabled by hardware) as system clock source after startup
851   *         from Reset, wakeup from STOP and STANDBY mode, or in case of failure
852   *         of the HSE used directly or indirectly as system clock (if the Clock
853   *         Security System CSS is enabled).             
854   * @note   HSI can not be stopped if it is used as system clock source. In this case,
855   *         you have to select another source of the system clock then stop the HSI.  
856   * @note   After enabling the HSI, the application software should wait on HSIRDY
857   *         flag to be set indicating that HSI clock is stable and can be used as
858   *         system clock source.  
859   *         This parameter can be: ENABLE or DISABLE.
860   * @note   When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
861   *         clock cycles.  
862   */
863 #define __HAL_RCC_HSI_ENABLE() (*(__IO uint32_t *) CR_HSION_BB = ENABLE)
864 #define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) CR_HSION_BB = DISABLE)
865
866 /** @brief  Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
867   * @note   The calibration is used to compensate for the variations in voltage
868   *         and temperature that influence the frequency of the internal HSI RC.
869   * @param  __HSICalibrationValue__: specifies the calibration trimming value.
870   *         This parameter must be a number between 0 and 0x1F.
871   */
872 #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(__HSICalibrationValue__) (MODIFY_REG(RCC->CR,\
873         RCC_CR_HSITRIM, (uint32_t)(__HSICalibrationValue__) << POSITION_VAL(RCC_CR_HSITRIM)))
874
875 /** @brief  Macros to enable or disable the Internal Low Speed oscillator (LSI).
876   * @note   After enabling the LSI, the application software should wait on 
877   *         LSIRDY flag to be set indicating that LSI clock is stable and can
878   *         be used to clock the IWDG and/or the RTC.
879   * @note   LSI can not be disabled if the IWDG is running.
880   * @note   When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
881   *         clock cycles. 
882   */
883 #define __HAL_RCC_LSI_ENABLE() (*(__IO uint32_t *) CSR_LSION_BB = ENABLE)
884 #define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) CSR_LSION_BB = DISABLE)
885
886 /**
887   * @brief  Macro to configure the External High Speed oscillator (HSE).
888   * @note   After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
889   *         software should wait on HSERDY flag to be set indicating that HSE clock
890   *         is stable and can be used to clock the PLL and/or system clock.
891   * @note   HSE state can not be changed if it is used directly or through the
892   *         PLL as system clock. In this case, you have to select another source
893   *         of the system clock then change the HSE state (ex. disable it).
894   * @note   The HSE is stopped by hardware when entering STOP and STANDBY modes.  
895   * @note   This function reset the CSSON bit, so if the clock security system(CSS)
896   *         was previously enabled you have to enable it again after calling this
897   *         function.    
898   * @param  __STATE__: specifies the new state of the HSE.
899   *         This parameter can be one of the following values:
900   *            @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
901   *                              6 HSE oscillator clock cycles.
902   *            @arg RCC_HSE_ON: turn ON the HSE oscillator.
903   *            @arg RCC_HSE_BYPASS: HSE oscillator bypassed with external clock.
904   */
905 #define __HAL_RCC_HSE_CONFIG(__STATE__) (*(__IO uint8_t *) CR_BYTE2_ADDRESS = (__STATE__))
906
907 /**
908   * @brief  Macro to configure the External Low Speed oscillator (LSE).
909   * @note   As the LSE is in the Backup domain and write access is denied to
910   *         this domain after reset, you have to enable write access using 
911   *         HAL_PWR_EnableBkUpAccess() function before to configure the LSE
912   *         (to be done once after reset).  
913   * @note   After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
914   *         software should wait on LSERDY flag to be set indicating that LSE clock
915   *         is stable and can be used to clock the RTC.
916   * @param  __STATE__: specifies the new state of the LSE.
917   *         This parameter can be one of the following values:
918   *            @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
919   *                              6 LSE oscillator clock cycles.
920   *            @arg RCC_LSE_ON: turn ON the LSE oscillator.
921   *            @arg RCC_LSE_BYPASS: LSE oscillator bypassed with external clock.
922   */
923 #define __HAL_RCC_LSE_CONFIG(__STATE__)  (*(__IO uint8_t *) BDCR_BYTE0_ADDRESS = (__STATE__))
924
925 /** @brief  Macros to enable or disable the the RTC clock.
926   * @note   These macros must be used only after the RTC clock source was selected.
927   */
928 #define __HAL_RCC_RTC_ENABLE() (*(__IO uint32_t *) BDCR_RTCEN_BB = ENABLE)
929 #define __HAL_RCC_RTC_DISABLE() (*(__IO uint32_t *) BDCR_RTCEN_BB = DISABLE)
930
931 /** @brief  Macros to configure the RTC clock (RTCCLK).
932   * @note   As the RTC clock configuration bits are in the Backup domain and write
933   *         access is denied to this domain after reset, you have to enable write
934   *         access using the Power Backup Access macro before to configure
935   *         the RTC clock source (to be done once after reset).    
936   * @note   Once the RTC clock is configured it can't be changed unless the  
937   *         Backup domain is reset using __HAL_RCC_BackupReset_RELEASE() macro, or by
938   *         a Power On Reset (POR).
939   * @param  __RTCCLKSource__: specifies the RTC clock source.
940   *         This parameter can be one of the following values:
941   *            @arg RCC_RTCCLKSOURCE_LSE: LSE selected as RTC clock.
942   *            @arg RCC_RTCCLKSOURCE_LSI: LSI selected as RTC clock.
943   *            @arg RCC_RTCCLKSOURCE_HSE_DIVx: HSE clock divided by x selected
944   *                                            as RTC clock, where x:[2,31]
945   * @note   If the LSE or LSI is used as RTC clock source, the RTC continues to
946   *         work in STOP and STANDBY modes, and can be used as wakeup source.
947   *         However, when the HSE clock is used as RTC clock source, the RTC
948   *         cannot be used in STOP and STANDBY modes.    
949   * @note   The maximum input clock frequency for RTC is 1MHz (when using HSE as
950   *         RTC clock source).
951   */
952 #define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__) (((__RTCCLKSource__) & RCC_BDCR_RTCSEL) == RCC_BDCR_RTCSEL) ?    \
953                                                  MODIFY_REG(RCC->CFGR, RCC_CFGR_RTCPRE, ((__RTCCLKSource__) & 0xFFFFCFF)) : CLEAR_BIT(RCC->CFGR, RCC_CFGR_RTCPRE)
954                                                    
955 #define __HAL_RCC_RTC_CONFIG(__RTCCLKSource__) do { __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__);    \
956                                                     RCC->BDCR |= ((__RTCCLKSource__) & 0x00000FFF);  \
957                                                    } while (0)
958
959 /** @brief  Macros to force or release the Backup domain reset.
960   * @note   This function resets the RTC peripheral (including the backup registers)
961   *         and the RTC clock source selection in RCC_CSR register.
962   * @note   The BKPSRAM is not affected by this reset.   
963   */
964 #define __HAL_RCC_BACKUPRESET_FORCE() (*(__IO uint32_t *) BDCR_BDRST_BB = ENABLE)
965 #define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) BDCR_BDRST_BB = DISABLE)
966
967 /** @brief  Macros to enable or disable the main PLL.
968   * @note   After enabling the main PLL, the application software should wait on 
969   *         PLLRDY flag to be set indicating that PLL clock is stable and can
970   *         be used as system clock source.
971   * @note   The main PLL can not be disabled if it is used as system clock source
972   * @note   The main PLL is disabled by hardware when entering STOP and STANDBY modes.
973   */
974 #define __HAL_RCC_PLL_ENABLE() (*(__IO uint32_t *) CR_PLLON_BB = ENABLE)
975 #define __HAL_RCC_PLL_DISABLE() (*(__IO uint32_t *) CR_PLLON_BB = DISABLE)
976
977 /** @brief  Macro to configure the main PLL clock source, multiplication and division factors.
978   * @note   This function must be used only when the main PLL is disabled.
979   * @param  __RCC_PLLSource__: specifies the PLL entry clock source.
980   *         This parameter can be one of the following values:
981   *            @arg RCC_PLLSOURCE_HSI: HSI oscillator clock selected as PLL clock entry
982   *            @arg RCC_PLLSOURCE_HSE: HSE oscillator clock selected as PLL clock entry
983   * @note   This clock source (RCC_PLLSource) is common for the main PLL and PLLI2S.  
984   * @param  __PLLM__: specifies the division factor for PLL VCO input clock
985   *         This parameter must be a number between Min_Data = 2 and Max_Data = 63.
986   * @note   You have to set the PLLM parameter correctly to ensure that the VCO input
987   *         frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
988   *         of 2 MHz to limit PLL jitter.
989   * @param  __PLLN__: specifies the multiplication factor for PLL VCO output clock
990   *         This parameter must be a number between Min_Data = 192 and Max_Data = 432.
991   * @note   You have to set the PLLN parameter correctly to ensure that the VCO
992   *         output frequency is between 192 and 432 MHz.
993   * @param  __PLLP__: specifies the division factor for main system clock (SYSCLK)
994   *         This parameter must be a number in the range {2, 4, 6, or 8}.
995   * @note   You have to set the PLLP parameter correctly to not exceed 168 MHz on
996   *         the System clock frequency.
997   * @param  __PLLQ__: specifies the division factor for OTG FS, SDIO and RNG clocks
998   *         This parameter must be a number between Min_Data = 2 and Max_Data = 15.
999   * @note   If the USB OTG FS is used in your application, you have to set the
1000   *         PLLQ parameter correctly to have 48 MHz clock for the USB. However,
1001   *         the SDIO and RNG need a frequency lower than or equal to 48 MHz to work
1002   *         correctly.
1003   */
1004 #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSource__, __PLLM__, __PLLN__, __PLLP__, __PLLQ__)\
1005                             (RCC->PLLCFGR = (0x20000000 | (__PLLM__) | ((__PLLN__) << POSITION_VAL(RCC_PLLCFGR_PLLN)) | \
1006                             ((((__PLLP__) >> 1) -1) << POSITION_VAL(RCC_PLLCFGR_PLLP)) | (__RCC_PLLSource__) | \
1007                             ((__PLLQ__) << POSITION_VAL(RCC_PLLCFGR_PLLQ))))
1008
1009 /** @brief  Macro to configure the I2S clock source (I2SCLK).
1010   * @note   This function must be called before enabling the I2S APB clock.
1011   * @param  __SOURCE__: specifies the I2S clock source.
1012   *         This parameter can be one of the following values:
1013   *            @arg RCC_I2SCLKSOURCE_PLLI2S: PLLI2S clock used as I2S clock source.
1014   *            @arg RCC_I2SCLKSOURCE_EXT: External clock mapped on the I2S_CKIN pin
1015   *                                       used as I2S clock source.
1016   */
1017 #define __HAL_RCC_I2SCLK(__SOURCE__) (*(__IO uint32_t *) CFGR_I2SSRC_BB = (__SOURCE__))
1018
1019 /** @brief Macros to enable or disable the PLLI2S. 
1020   * @note  The PLLI2S is disabled by hardware when entering STOP and STANDBY modes.
1021   */
1022 #define __HAL_RCC_PLLI2S_ENABLE() (*(__IO uint32_t *) CR_PLLI2SON_BB = ENABLE)
1023 #define __HAL_RCC_PLLI2S_DISABLE() (*(__IO uint32_t *) CR_PLLI2SON_BB = DISABLE)
1024
1025 /** @brief  Macro to configure the PLLI2S clock multiplication and division factors .
1026   * @note   This macro must be used only when the PLLI2S is disabled.
1027   * @note   PLLI2S clock source is common with the main PLL (configured in 
1028   *         HAL_RCC_ClockConfig() API).  
1029   * @param  __PLLI2SN__: specifies the multiplication factor for PLLI2S VCO output clock
1030   *         This parameter must be a number between Min_Data = 192 and Max_Data = 432.
1031   * @note   You have to set the PLLI2SN parameter correctly to ensure that the VCO 
1032   *         output frequency is between Min_Data = 192 and Max_Data = 432 MHz.
1033   * @param  __PLLI2SR__: specifies the division factor for I2S clock
1034   *         This parameter must be a number between Min_Data = 2 and Max_Data = 7.
1035   * @note   You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
1036   *         on the I2S clock frequency.
1037   */
1038 #define __HAL_RCC_PLLI2S_CONFIG(__PLLI2SN__, __PLLI2SR__) (RCC->PLLI2SCFGR = ((__PLLI2SN__) << POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SN)) | ((__PLLI2SR__) << POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR)))
1039
1040 /** @brief  Macro to get the clock source used as system clock.
1041   * @retval The clock source used as system clock. The returned value can be one
1042   *         of the following:
1043   *              - RCC_CFGR_SWS_HSI: HSI used as system clock.
1044   *              - RCC_CFGR_SWS_HSE: HSE used as system clock.
1045   *              - RCC_CFGR_SWS_PLL: PLL used as system clock.
1046   */     
1047 #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(RCC->CFGR & RCC_CFGR_SWS))
1048
1049 /** @brief  Macro to get the oscillator used as PLL clock source.
1050   * @retval The oscillator used as PLL clock source. The returned value can be one
1051   *         of the following:
1052   *              - RCC_PLLSOURCE_HSI: HSI oscillator is used as PLL clock source.
1053   *              - RCC_PLLSOURCE_HSE: HSE oscillator is used as PLL clock source.
1054   */
1055 #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC))
1056
1057 /** @brief  Enable RCC interrupt (Perform Byte access to RCC_CIR[14:8] bits to enable
1058   *         the selected interrupts).
1059   * @param  __INTERRUPT__: specifies the RCC interrupt sources to be enabled.
1060   *         This parameter can be any combination of the following values:
1061   *            @arg RCC_IT_LSIRDY: LSI ready interrupt.
1062   *            @arg RCC_IT_LSERDY: LSE ready interrupt.
1063   *            @arg RCC_IT_HSIRDY: HSI ready interrupt.
1064   *            @arg RCC_IT_HSERDY: HSE ready interrupt.
1065   *            @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
1066   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
1067   */
1068 #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
1069
1070 /** @brief Disable RCC interrupt (Perform Byte access to RCC_CIR[14:8] bits to disable 
1071   *        the selected interrupts).
1072   * @param  __INTERRUPT__: specifies the RCC interrupt sources to be disabled.
1073   *         This parameter can be any combination of the following values:
1074   *            @arg RCC_IT_LSIRDY: LSI ready interrupt.
1075   *            @arg RCC_IT_LSERDY: LSE ready interrupt.
1076   *            @arg RCC_IT_HSIRDY: HSI ready interrupt.
1077   *            @arg RCC_IT_HSERDY: HSE ready interrupt.
1078   *            @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
1079   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
1080   */
1081 #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) CIR_BYTE1_ADDRESS &= ~(__INTERRUPT__))
1082
1083 /** @brief  Clear the RCC's interrupt pending bits (Perform Byte access to RCC_CIR[23:16]
1084   *         bits to clear the selected interrupt pending bits.
1085   * @param  __INTERRUPT__: specifies the interrupt pending bit to clear.
1086   *         This parameter can be any combination of the following values:
1087   *            @arg RCC_IT_LSIRDY: LSI ready interrupt.
1088   *            @arg RCC_IT_LSERDY: LSE ready interrupt.
1089   *            @arg RCC_IT_HSIRDY: HSI ready interrupt.
1090   *            @arg RCC_IT_HSERDY: HSE ready interrupt.
1091   *            @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
1092   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.  
1093   *            @arg RCC_IT_CSS: Clock Security System interrupt
1094   */
1095 #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) CIR_BYTE2_ADDRESS = (__INTERRUPT__))
1096
1097 /** @brief  Check the RCC's interrupt has occurred or not.
1098   * @param  __INTERRUPT__: specifies the RCC interrupt source to check.
1099   *         This parameter can be one of the following values:
1100   *            @arg RCC_IT_LSIRDY: LSI ready interrupt.
1101   *            @arg RCC_IT_LSERDY: LSE ready interrupt.
1102   *            @arg RCC_IT_HSIRDY: HSI ready interrupt.
1103   *            @arg RCC_IT_HSERDY: HSE ready interrupt.
1104   *            @arg RCC_IT_PLLRDY: Main PLL ready interrupt.
1105   *            @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt.
1106   *            @arg RCC_IT_CSS: Clock Security System interrupt
1107   * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
1108   */
1109 #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
1110
1111 /** @brief Set RMVF bit to clear the reset flags: RCC_FLAG_PINRST, RCC_FLAG_PORRST, 
1112   *        RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST and RCC_FLAG_LPWRRST.
1113   */
1114 #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
1115
1116 /** @brief  Check RCC flag is set or not.
1117   * @param  __FLAG__: specifies the flag to check.
1118   *         This parameter can be one of the following values:
1119   *            @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready.
1120   *            @arg RCC_FLAG_HSERDY: HSE oscillator clock ready.
1121   *            @arg RCC_FLAG_PLLRDY: Main PLL clock ready.
1122   *            @arg RCC_FLAG_PLLI2SRDY: PLLI2S clock ready.
1123   *            @arg RCC_FLAG_LSERDY: LSE oscillator clock ready.
1124   *            @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready.
1125   *            @arg RCC_FLAG_BORRST: POR/PDR or BOR reset.
1126   *            @arg RCC_FLAG_PINRST: Pin reset.
1127   *            @arg RCC_FLAG_PORRST: POR/PDR reset.
1128   *            @arg RCC_FLAG_SFTRST: Software reset.
1129   *            @arg RCC_FLAG_IWDGRST: Independent Watchdog reset.
1130   *            @arg RCC_FLAG_WWDGRST: Window Watchdog reset.
1131   *            @arg RCC_FLAG_LPWRRST: Low Power reset.
1132   * @retval The new state of __FLAG__ (TRUE or FALSE).
1133   */
1134 #define RCC_FLAG_MASK  ((uint8_t)0x1F)
1135 #define __HAL_RCC_GET_FLAG(__FLAG__) (((((((__FLAG__) >> 5) == 1)? RCC->CR :((((__FLAG__) >> 5) == 2) ? RCC->BDCR :((((__FLAG__) >> 5) == 3)? RCC->CSR :RCC->CIR))) & ((uint32_t)1 << ((__FLAG__) & RCC_FLAG_MASK)))!= 0)? 1 : 0)
1136
1137 #define __RCC_PLLSRC() ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> POSITION_VAL(RCC_PLLCFGR_PLLSRC))
1138
1139
1140 /* Include RCC HAL Extension module */
1141 #include "stm32f4xx_hal_rcc_ex.h"
1142
1143 /* Exported functions --------------------------------------------------------*/
1144                               
1145 /* Initialization and de-initialization functions  ******************************/
1146 void HAL_RCC_DeInit(void);
1147 HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
1148 HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
1149
1150 /* Peripheral Control functions  ************************************************/
1151 void     HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
1152 void     HAL_RCC_EnableCSS(void);
1153 void     HAL_RCC_DisableCSS(void);
1154 uint32_t HAL_RCC_GetSysClockFreq(void);
1155 uint32_t HAL_RCC_GetHCLKFreq(void);
1156 uint32_t HAL_RCC_GetPCLK1Freq(void);
1157 uint32_t HAL_RCC_GetPCLK2Freq(void);
1158 void     HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
1159 void     HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
1160
1161 /* CSS NMI IRQ handler */
1162 void HAL_RCC_NMI_IRQHandler(void);
1163
1164 /* User Callbacks in non blocking mode (IT mode) */ 
1165 void HAL_RCC_CCSCallback(void);
1166
1167 /**
1168   * @}
1169   */ 
1170
1171 /**
1172   * @}
1173   */
1174
1175 #ifdef __cplusplus
1176 }
1177 #endif
1178
1179 #endif /* __STM32F4xx_HAL_RCC_H */
1180
1181 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/