Subversion Repositories LedShow

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_rcc.h
4
  * @author  MCD Application Team
5
  * @brief   Header file of RCC HAL module.
6
  ******************************************************************************
7
  * @attention
8
  *
9
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
  *
11
  * Redistribution and use in source and binary forms, with or without modification,
12
  * are permitted provided that the following conditions are met:
13
  *   1. Redistributions of source code must retain the above copyright notice,
14
  *      this list of conditions and the following disclaimer.
15
  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
  *      this list of conditions and the following disclaimer in the documentation
17
  *      and/or other materials provided with the distribution.
18
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
  *      may be used to endorse or promote products derived from this software
20
  *      without specific prior written permission.
21
  *
22
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
  *
33
  ******************************************************************************
34
  */
35
 
36
/* Define to prevent recursive inclusion -------------------------------------*/
37
#ifndef __STM32F1xx_HAL_RCC_H
38
#define __STM32F1xx_HAL_RCC_H
39
 
40
#ifdef __cplusplus
41
 extern "C" {
42
#endif
43
 
44
/* Includes ------------------------------------------------------------------*/
45
#include "stm32f1xx_hal_def.h"
46
 
47
/** @addtogroup STM32F1xx_HAL_Driver
48
  * @{
49
  */
50
 
51
/** @addtogroup RCC
52
  * @{
53
  */
54
 
55
/* Exported types ------------------------------------------------------------*/
56
 
57
/** @defgroup RCC_Exported_Types RCC Exported Types
58
  * @{
59
  */
60
 
61
/**
62
  * @brief  RCC PLL configuration structure definition  
63
  */
64
typedef struct
65
{
66
  uint32_t PLLState;      /*!< PLLState: The new state of the PLL.
67
                              This parameter can be a value of @ref RCC_PLL_Config */
68
 
69
  uint32_t PLLSource;     /*!< PLLSource: PLL entry clock source.
70
                              This parameter must be a value of @ref RCC_PLL_Clock_Source */          
71
 
72
  uint32_t PLLMUL;        /*!< PLLMUL: Multiplication factor for PLL VCO input clock
73
                              This parameter must be a value of @ref RCCEx_PLL_Multiplication_Factor */
74
} RCC_PLLInitTypeDef;
75
 
76
/**
77
  * @brief  RCC System, AHB and APB busses clock configuration structure definition  
78
  */
79
typedef struct
80
{
81
  uint32_t ClockType;             /*!< The clock to be configured.
82
                                       This parameter can be a value of @ref RCC_System_Clock_Type */
83
 
84
  uint32_t SYSCLKSource;          /*!< The clock source (SYSCLKS) used as system clock.
85
                                       This parameter can be a value of @ref RCC_System_Clock_Source */
86
 
87
  uint32_t AHBCLKDivider;         /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
88
                                       This parameter can be a value of @ref RCC_AHB_Clock_Source */
89
 
90
  uint32_t APB1CLKDivider;        /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
91
                                       This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
92
 
93
  uint32_t APB2CLKDivider;        /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
94
                                       This parameter can be a value of @ref RCC_APB1_APB2_Clock_Source */
95
} RCC_ClkInitTypeDef;
96
 
97
/**
98
  * @}
99
  */
100
 
101
/* Exported constants --------------------------------------------------------*/
102
/** @defgroup RCC_Exported_Constants RCC Exported Constants
103
  * @{
104
  */
105
 
106
/** @defgroup RCC_PLL_Clock_Source PLL Clock Source
107
  * @{
108
  */
109
 
110
#define RCC_PLLSOURCE_HSI_DIV2      0x00000000U     /*!< HSI clock divided by 2 selected as PLL entry clock source */
111
#define RCC_PLLSOURCE_HSE           RCC_CFGR_PLLSRC            /*!< HSE clock selected as PLL entry clock source */
112
 
113
/**
114
  * @}
115
  */
116
 
117
/** @defgroup RCC_Oscillator_Type Oscillator Type
118
  * @{
119
  */
120
#define RCC_OSCILLATORTYPE_NONE            0x00000000U
121
#define RCC_OSCILLATORTYPE_HSE             0x00000001U
122
#define RCC_OSCILLATORTYPE_HSI             0x00000002U
123
#define RCC_OSCILLATORTYPE_LSE             0x00000004U
124
#define RCC_OSCILLATORTYPE_LSI             0x00000008U
125
/**
126
  * @}
127
  */
128
 
129
/** @defgroup RCC_HSE_Config HSE Config
130
  * @{
131
  */
132
#define RCC_HSE_OFF                      0x00000000U                                /*!< HSE clock deactivation */
133
#define RCC_HSE_ON                       RCC_CR_HSEON                               /*!< HSE clock activation */
134
#define RCC_HSE_BYPASS                   ((uint32_t)(RCC_CR_HSEBYP | RCC_CR_HSEON)) /*!< External clock source for HSE clock */
135
/**
136
  * @}
137
  */
138
 
139
/** @defgroup RCC_LSE_Config LSE Config
140
  * @{
141
  */
142
#define RCC_LSE_OFF                      0x00000000U                                    /*!< LSE clock deactivation */
143
#define RCC_LSE_ON                       RCC_BDCR_LSEON                                 /*!< LSE clock activation */
144
#define RCC_LSE_BYPASS                   ((uint32_t)(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON)) /*!< External clock source for LSE clock */
145
 
146
/**
147
  * @}
148
  */
149
 
150
/** @defgroup RCC_HSI_Config HSI Config
151
  * @{
152
  */
153
#define RCC_HSI_OFF                      0x00000000U                      /*!< HSI clock deactivation */
154
#define RCC_HSI_ON                       RCC_CR_HSION                     /*!< HSI clock activation */
155
 
156
#define RCC_HSICALIBRATION_DEFAULT       0x10U         /* Default HSI calibration trimming value */
157
 
158
/**
159
  * @}
160
  */
161
 
162
/** @defgroup RCC_LSI_Config LSI Config
163
  * @{
164
  */
165
#define RCC_LSI_OFF                      0x00000000U              /*!< LSI clock deactivation */
166
#define RCC_LSI_ON                       RCC_CSR_LSION            /*!< LSI clock activation */
167
 
168
/**
169
  * @}
170
  */
171
 
172
/** @defgroup RCC_PLL_Config PLL Config
173
  * @{
174
  */
175
#define RCC_PLL_NONE                      0x00000000U  /*!< PLL is not configured */
176
#define RCC_PLL_OFF                       0x00000001U  /*!< PLL deactivation */
177
#define RCC_PLL_ON                        0x00000002U  /*!< PLL activation */
178
 
179
/**
180
  * @}
181
  */
182
 
183
/** @defgroup RCC_System_Clock_Type System Clock Type
184
  * @{
185
  */
186
#define RCC_CLOCKTYPE_SYSCLK             0x00000001U /*!< SYSCLK to configure */
187
#define RCC_CLOCKTYPE_HCLK               0x00000002U /*!< HCLK to configure */
188
#define RCC_CLOCKTYPE_PCLK1              0x00000004U /*!< PCLK1 to configure */
189
#define RCC_CLOCKTYPE_PCLK2              0x00000008U /*!< PCLK2 to configure */
190
 
191
/**
192
  * @}
193
  */
194
 
195
/** @defgroup RCC_System_Clock_Source System Clock Source
196
  * @{
197
  */
198
#define RCC_SYSCLKSOURCE_HSI             RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
199
#define RCC_SYSCLKSOURCE_HSE             RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
200
#define RCC_SYSCLKSOURCE_PLLCLK          RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
201
 
202
/**
203
  * @}
204
  */
205
 
206
/** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
207
  * @{
208
  */
209
#define RCC_SYSCLKSOURCE_STATUS_HSI      RCC_CFGR_SWS_HSI            /*!< HSI used as system clock */
210
#define RCC_SYSCLKSOURCE_STATUS_HSE      RCC_CFGR_SWS_HSE            /*!< HSE used as system clock */
211
#define RCC_SYSCLKSOURCE_STATUS_PLLCLK   RCC_CFGR_SWS_PLL            /*!< PLL used as system clock */
212
 
213
/**
214
  * @}
215
  */
216
 
217
/** @defgroup RCC_AHB_Clock_Source AHB Clock Source
218
  * @{
219
  */
220
#define RCC_SYSCLK_DIV1                  RCC_CFGR_HPRE_DIV1   /*!< SYSCLK not divided */
221
#define RCC_SYSCLK_DIV2                  RCC_CFGR_HPRE_DIV2   /*!< SYSCLK divided by 2 */
222
#define RCC_SYSCLK_DIV4                  RCC_CFGR_HPRE_DIV4   /*!< SYSCLK divided by 4 */
223
#define RCC_SYSCLK_DIV8                  RCC_CFGR_HPRE_DIV8   /*!< SYSCLK divided by 8 */
224
#define RCC_SYSCLK_DIV16                 RCC_CFGR_HPRE_DIV16  /*!< SYSCLK divided by 16 */
225
#define RCC_SYSCLK_DIV64                 RCC_CFGR_HPRE_DIV64  /*!< SYSCLK divided by 64 */
226
#define RCC_SYSCLK_DIV128                RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
227
#define RCC_SYSCLK_DIV256                RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
228
#define RCC_SYSCLK_DIV512                RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
229
 
230
/**
231
  * @}
232
  */
233
 
234
/** @defgroup RCC_APB1_APB2_Clock_Source APB1 APB2 Clock Source
235
  * @{
236
  */
237
#define RCC_HCLK_DIV1                    RCC_CFGR_PPRE1_DIV1  /*!< HCLK not divided */
238
#define RCC_HCLK_DIV2                    RCC_CFGR_PPRE1_DIV2  /*!< HCLK divided by 2 */
239
#define RCC_HCLK_DIV4                    RCC_CFGR_PPRE1_DIV4  /*!< HCLK divided by 4 */
240
#define RCC_HCLK_DIV8                    RCC_CFGR_PPRE1_DIV8  /*!< HCLK divided by 8 */
241
#define RCC_HCLK_DIV16                   RCC_CFGR_PPRE1_DIV16 /*!< HCLK divided by 16 */
242
 
243
/**
244
  * @}
245
  */
246
 
247
/** @defgroup RCC_RTC_Clock_Source RTC Clock Source
248
  * @{
249
  */
250
#define RCC_RTCCLKSOURCE_NO_CLK          0x00000000U                 /*!< No clock */
251
#define RCC_RTCCLKSOURCE_LSE             RCC_BDCR_RTCSEL_LSE                  /*!< LSE oscillator clock used as RTC clock */
252
#define RCC_RTCCLKSOURCE_LSI             RCC_BDCR_RTCSEL_LSI                  /*!< LSI oscillator clock used as RTC clock */
253
#define RCC_RTCCLKSOURCE_HSE_DIV128      RCC_BDCR_RTCSEL_HSE                    /*!< HSE oscillator clock divided by 128 used as RTC clock */
254
/**
255
  * @}
256
  */
257
 
258
 
259
/** @defgroup RCC_MCO_Index MCO Index
260
  * @{
261
  */
262
#define RCC_MCO1                         0x00000000U
263
#define RCC_MCO                          RCC_MCO1               /*!< MCO1 to be compliant with other families with 2 MCOs*/
264
 
265
/**
266
  * @}
267
  */
268
 
269
/** @defgroup RCC_MCOx_Clock_Prescaler MCO Clock Prescaler
270
  * @{
271
  */
272
#define RCC_MCODIV_1                    0x00000000U
273
 
274
/**
275
  * @}
276
  */
277
 
278
/** @defgroup RCC_Interrupt Interrupts
279
  * @{
280
  */
281
#define RCC_IT_LSIRDY                    ((uint8_t)RCC_CIR_LSIRDYF)   /*!< LSI Ready Interrupt flag */
282
#define RCC_IT_LSERDY                    ((uint8_t)RCC_CIR_LSERDYF)   /*!< LSE Ready Interrupt flag */
283
#define RCC_IT_HSIRDY                    ((uint8_t)RCC_CIR_HSIRDYF)   /*!< HSI Ready Interrupt flag */
284
#define RCC_IT_HSERDY                    ((uint8_t)RCC_CIR_HSERDYF)   /*!< HSE Ready Interrupt flag */
285
#define RCC_IT_PLLRDY                    ((uint8_t)RCC_CIR_PLLRDYF)   /*!< PLL Ready Interrupt flag */
286
#define RCC_IT_CSS                       ((uint8_t)RCC_CIR_CSSF)      /*!< Clock Security System Interrupt flag */
287
/**
288
  * @}
289
  */
290
 
291
/** @defgroup RCC_Flag Flags
292
  *        Elements values convention: XXXYYYYYb
293
  *           - YYYYY  : Flag position in the register
294
  *           - XXX  : Register index
295
  *                 - 001: CR register
296
  *                 - 010: BDCR register
297
  *                 - 011: CSR register
298
  * @{
299
  */
300
/* Flags in the CR register */
301
#define RCC_FLAG_HSIRDY                  ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSIRDY_Pos)) /*!< Internal High Speed clock ready flag */
302
#define RCC_FLAG_HSERDY                  ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSERDY_Pos)) /*!< External High Speed clock ready flag */
303
#define RCC_FLAG_PLLRDY                  ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_PLLRDY_Pos)) /*!< PLL clock ready flag */
304
 
305
/* Flags in the CSR register */
306
#define RCC_FLAG_LSIRDY                  ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LSIRDY_Pos))   /*!< Internal Low Speed oscillator Ready */
307
#define RCC_FLAG_PINRST                  ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PINRSTF_Pos))  /*!< PIN reset flag */
308
#define RCC_FLAG_PORRST                  ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PORRSTF_Pos))  /*!< POR/PDR reset flag */
309
#define RCC_FLAG_SFTRST                  ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_SFTRSTF_Pos))  /*!< Software Reset flag */
310
#define RCC_FLAG_IWDGRST                 ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_IWDGRSTF_Pos)) /*!< Independent Watchdog reset flag */
311
#define RCC_FLAG_WWDGRST                 ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_WWDGRSTF_Pos)) /*!< Window watchdog reset flag */
312
#define RCC_FLAG_LPWRRST                 ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LPWRRSTF_Pos)) /*!< Low-Power reset flag */
313
 
314
/* Flags in the BDCR register */
315
#define RCC_FLAG_LSERDY                  ((uint8_t)((BDCR_REG_INDEX << 5U) | RCC_BDCR_LSERDY_Pos)) /*!< External Low Speed oscillator Ready */
316
 
317
/**
318
  * @}
319
  */
320
 
321
/**
322
  * @}
323
  */
324
 
325
/* Exported macro ------------------------------------------------------------*/
326
 
327
/** @defgroup RCC_Exported_Macros RCC Exported Macros
328
  * @{
329
  */
330
 
331
/** @defgroup RCC_Peripheral_Clock_Enable_Disable Peripheral Clock Enable Disable
332
  * @brief  Enable or disable the AHB1 peripheral clock.
333
  * @note   After reset, the peripheral clock (used for registers read/write access)
334
  *         is disabled and the application software has to enable this clock before
335
  *         using it.  
336
  * @{
337
  */
338
#define __HAL_RCC_DMA1_CLK_ENABLE()   do { \
339
                                        __IO uint32_t tmpreg; \
340
                                        SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
341
                                        /* Delay after an RCC peripheral clock enabling */\
342
                                        tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
343
                                        UNUSED(tmpreg); \
344
                                      } while(0U)
345
 
346
#define __HAL_RCC_SRAM_CLK_ENABLE()   do { \
347
                                        __IO uint32_t tmpreg; \
348
                                        SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
349
                                        /* Delay after an RCC peripheral clock enabling */\
350
                                        tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
351
                                        UNUSED(tmpreg); \
352
                                      } while(0U)
353
 
354
#define __HAL_RCC_FLITF_CLK_ENABLE()   do { \
355
                                        __IO uint32_t tmpreg; \
356
                                        SET_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
357
                                        /* Delay after an RCC peripheral clock enabling */\
358
                                        tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
359
                                        UNUSED(tmpreg); \
360
                                      } while(0U)
361
 
362
#define __HAL_RCC_CRC_CLK_ENABLE()   do { \
363
                                        __IO uint32_t tmpreg; \
364
                                        SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
365
                                        /* Delay after an RCC peripheral clock enabling */\
366
                                        tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
367
                                        UNUSED(tmpreg); \
368
                                      } while(0U)
369
 
370
#define __HAL_RCC_DMA1_CLK_DISABLE()      (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
371
#define __HAL_RCC_SRAM_CLK_DISABLE()      (RCC->AHBENR &= ~(RCC_AHBENR_SRAMEN))
372
#define __HAL_RCC_FLITF_CLK_DISABLE()     (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
373
#define __HAL_RCC_CRC_CLK_DISABLE()       (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
374
 
375
/**
376
  * @}
377
  */
378
 
379
/** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enable Disable Status
380
  * @brief  Get the enable or disable status of the AHB peripheral clock.
381
  * @note   After reset, the peripheral clock (used for registers read/write access)
382
  *         is disabled and the application software has to enable this clock before
383
  *         using it.
384
  * @{
385
  */
386
 
387
#define __HAL_RCC_DMA1_IS_CLK_ENABLED()       ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) != RESET)
388
#define __HAL_RCC_DMA1_IS_CLK_DISABLED()      ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) == RESET)
389
#define __HAL_RCC_SRAM_IS_CLK_ENABLED()       ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) != RESET)
390
#define __HAL_RCC_SRAM_IS_CLK_DISABLED()      ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) == RESET)
391
#define __HAL_RCC_FLITF_IS_CLK_ENABLED()       ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) != RESET)
392
#define __HAL_RCC_FLITF_IS_CLK_DISABLED()      ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) == RESET)
393
#define __HAL_RCC_CRC_IS_CLK_ENABLED()       ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) != RESET)
394
#define __HAL_RCC_CRC_IS_CLK_DISABLED()      ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) == RESET)
395
 
396
/**
397
  * @}
398
  */
399
 
400
/** @defgroup RCC_APB1_Clock_Enable_Disable APB1 Clock Enable Disable
401
  * @brief  Enable or disable the Low Speed APB (APB1) peripheral clock.
402
  * @note   After reset, the peripheral clock (used for registers read/write access)
403
  *         is disabled and the application software has to enable this clock before
404
  *         using it.
405
  * @{  
406
  */
407
#define __HAL_RCC_TIM2_CLK_ENABLE()   do { \
408
                                        __IO uint32_t tmpreg; \
409
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
410
                                        /* Delay after an RCC peripheral clock enabling */\
411
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
412
                                        UNUSED(tmpreg); \
413
                                      } while(0U)
414
 
415
#define __HAL_RCC_TIM3_CLK_ENABLE()   do { \
416
                                        __IO uint32_t tmpreg; \
417
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
418
                                        /* Delay after an RCC peripheral clock enabling */\
419
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
420
                                        UNUSED(tmpreg); \
421
                                      } while(0U)
422
 
423
#define __HAL_RCC_WWDG_CLK_ENABLE()   do { \
424
                                        __IO uint32_t tmpreg; \
425
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
426
                                        /* Delay after an RCC peripheral clock enabling */\
427
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
428
                                        UNUSED(tmpreg); \
429
                                      } while(0U)
430
 
431
#define __HAL_RCC_USART2_CLK_ENABLE()   do { \
432
                                        __IO uint32_t tmpreg; \
433
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
434
                                        /* Delay after an RCC peripheral clock enabling */\
435
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
436
                                        UNUSED(tmpreg); \
437
                                      } while(0U)
438
 
439
#define __HAL_RCC_I2C1_CLK_ENABLE()   do { \
440
                                        __IO uint32_t tmpreg; \
441
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
442
                                        /* Delay after an RCC peripheral clock enabling */\
443
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
444
                                        UNUSED(tmpreg); \
445
                                      } while(0U)
446
 
447
#define __HAL_RCC_BKP_CLK_ENABLE()   do { \
448
                                        __IO uint32_t tmpreg; \
449
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_BKPEN);\
450
                                        /* Delay after an RCC peripheral clock enabling */\
451
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_BKPEN);\
452
                                        UNUSED(tmpreg); \
453
                                      } while(0U)
454
 
455
#define __HAL_RCC_PWR_CLK_ENABLE()   do { \
456
                                        __IO uint32_t tmpreg; \
457
                                        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
458
                                        /* Delay after an RCC peripheral clock enabling */\
459
                                        tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
460
                                        UNUSED(tmpreg); \
461
                                      } while(0U)
462
 
463
#define __HAL_RCC_TIM2_CLK_DISABLE()      (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
464
#define __HAL_RCC_TIM3_CLK_DISABLE()      (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
465
#define __HAL_RCC_WWDG_CLK_DISABLE()      (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
466
#define __HAL_RCC_USART2_CLK_DISABLE()    (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
467
#define __HAL_RCC_I2C1_CLK_DISABLE()      (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
468
 
469
#define __HAL_RCC_BKP_CLK_DISABLE()       (RCC->APB1ENR &= ~(RCC_APB1ENR_BKPEN))
470
#define __HAL_RCC_PWR_CLK_DISABLE()       (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
471
 
472
/**
473
  * @}
474
  */
475
 
476
/** @defgroup RCC_APB1_Peripheral_Clock_Enable_Disable_Status APB1 Peripheral Clock Enable Disable Status
477
  * @brief  Get the enable or disable status of the APB1 peripheral clock.
478
  * @note   After reset, the peripheral clock (used for registers read/write access)
479
  *         is disabled and the application software has to enable this clock before
480
  *         using it.
481
  * @{
482
  */
483
 
484
#define __HAL_RCC_TIM2_IS_CLK_ENABLED()       ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) != RESET)
485
#define __HAL_RCC_TIM2_IS_CLK_DISABLED()      ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) == RESET)
486
#define __HAL_RCC_TIM3_IS_CLK_ENABLED()       ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) != RESET)
487
#define __HAL_RCC_TIM3_IS_CLK_DISABLED()      ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) == RESET)
488
#define __HAL_RCC_WWDG_IS_CLK_ENABLED()       ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) != RESET)
489
#define __HAL_RCC_WWDG_IS_CLK_DISABLED()      ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) == RESET)
490
#define __HAL_RCC_USART2_IS_CLK_ENABLED()     ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != RESET)
491
#define __HAL_RCC_USART2_IS_CLK_DISABLED()    ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == RESET)
492
#define __HAL_RCC_I2C1_IS_CLK_ENABLED()       ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) != RESET)
493
#define __HAL_RCC_I2C1_IS_CLK_DISABLED()      ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) == RESET)
494
#define __HAL_RCC_BKP_IS_CLK_ENABLED()        ((RCC->APB1ENR & (RCC_APB1ENR_BKPEN)) != RESET)
495
#define __HAL_RCC_BKP_IS_CLK_DISABLED()       ((RCC->APB1ENR & (RCC_APB1ENR_BKPEN)) == RESET)
496
#define __HAL_RCC_PWR_IS_CLK_ENABLED()        ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) != RESET)
497
#define __HAL_RCC_PWR_IS_CLK_DISABLED()       ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) == RESET)
498
 
499
/**
500
  * @}
501
  */
502
 
503
/** @defgroup RCC_APB2_Clock_Enable_Disable APB2 Clock Enable Disable
504
  * @brief  Enable or disable the High Speed APB (APB2) peripheral clock.
505
  * @note   After reset, the peripheral clock (used for registers read/write access)
506
  *         is disabled and the application software has to enable this clock before
507
  *         using it.
508
  * @{  
509
  */
510
#define __HAL_RCC_AFIO_CLK_ENABLE()   do { \
511
                                        __IO uint32_t tmpreg; \
512
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_AFIOEN);\
513
                                        /* Delay after an RCC peripheral clock enabling */\
514
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_AFIOEN);\
515
                                        UNUSED(tmpreg); \
516
                                      } while(0U)
517
 
518
#define __HAL_RCC_GPIOA_CLK_ENABLE()   do { \
519
                                        __IO uint32_t tmpreg; \
520
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);\
521
                                        /* Delay after an RCC peripheral clock enabling */\
522
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);\
523
                                        UNUSED(tmpreg); \
524
                                      } while(0U)
525
 
526
#define __HAL_RCC_GPIOB_CLK_ENABLE()   do { \
527
                                        __IO uint32_t tmpreg; \
528
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);\
529
                                        /* Delay after an RCC peripheral clock enabling */\
530
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);\
531
                                        UNUSED(tmpreg); \
532
                                      } while(0U)
533
 
534
#define __HAL_RCC_GPIOC_CLK_ENABLE()   do { \
535
                                        __IO uint32_t tmpreg; \
536
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPCEN);\
537
                                        /* Delay after an RCC peripheral clock enabling */\
538
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPCEN);\
539
                                        UNUSED(tmpreg); \
540
                                      } while(0U)
541
 
542
#define __HAL_RCC_GPIOD_CLK_ENABLE()   do { \
543
                                        __IO uint32_t tmpreg; \
544
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);\
545
                                        /* Delay after an RCC peripheral clock enabling */\
546
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);\
547
                                        UNUSED(tmpreg); \
548
                                      } while(0U)
549
 
550
#define __HAL_RCC_ADC1_CLK_ENABLE()   do { \
551
                                        __IO uint32_t tmpreg; \
552
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
553
                                        /* Delay after an RCC peripheral clock enabling */\
554
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
555
                                        UNUSED(tmpreg); \
556
                                      } while(0U)
557
 
558
#define __HAL_RCC_TIM1_CLK_ENABLE()   do { \
559
                                        __IO uint32_t tmpreg; \
560
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
561
                                        /* Delay after an RCC peripheral clock enabling */\
562
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
563
                                        UNUSED(tmpreg); \
564
                                      } while(0U)
565
 
566
#define __HAL_RCC_SPI1_CLK_ENABLE()   do { \
567
                                        __IO uint32_t tmpreg; \
568
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
569
                                        /* Delay after an RCC peripheral clock enabling */\
570
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
571
                                        UNUSED(tmpreg); \
572
                                      } while(0U)
573
 
574
#define __HAL_RCC_USART1_CLK_ENABLE()   do { \
575
                                        __IO uint32_t tmpreg; \
576
                                        SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
577
                                        /* Delay after an RCC peripheral clock enabling */\
578
                                        tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
579
                                        UNUSED(tmpreg); \
580
                                      } while(0U)
581
 
582
#define __HAL_RCC_AFIO_CLK_DISABLE()      (RCC->APB2ENR &= ~(RCC_APB2ENR_AFIOEN))
583
#define __HAL_RCC_GPIOA_CLK_DISABLE()     (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPAEN))
584
#define __HAL_RCC_GPIOB_CLK_DISABLE()     (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPBEN))
585
#define __HAL_RCC_GPIOC_CLK_DISABLE()     (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPCEN))
586
#define __HAL_RCC_GPIOD_CLK_DISABLE()     (RCC->APB2ENR &= ~(RCC_APB2ENR_IOPDEN))
587
#define __HAL_RCC_ADC1_CLK_DISABLE()      (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
588
 
589
#define __HAL_RCC_TIM1_CLK_DISABLE()      (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
590
#define __HAL_RCC_SPI1_CLK_DISABLE()      (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
591
#define __HAL_RCC_USART1_CLK_DISABLE()    (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
592
 
593
/**
594
  * @}
595
  */
596
 
597
/** @defgroup RCC_APB2_Peripheral_Clock_Enable_Disable_Status APB2 Peripheral Clock Enable Disable Status
598
  * @brief  Get the enable or disable status of the APB2 peripheral clock.
599
  * @note   After reset, the peripheral clock (used for registers read/write access)
600
  *         is disabled and the application software has to enable this clock before
601
  *         using it.
602
  * @{
603
  */
604
 
605
#define __HAL_RCC_AFIO_IS_CLK_ENABLED()       ((RCC->APB2ENR & (RCC_APB2ENR_AFIOEN)) != RESET)
606
#define __HAL_RCC_AFIO_IS_CLK_DISABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_AFIOEN)) == RESET)
607
#define __HAL_RCC_GPIOA_IS_CLK_ENABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_IOPAEN)) != RESET)
608
#define __HAL_RCC_GPIOA_IS_CLK_DISABLED()     ((RCC->APB2ENR & (RCC_APB2ENR_IOPAEN)) == RESET)
609
#define __HAL_RCC_GPIOB_IS_CLK_ENABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_IOPBEN)) != RESET)
610
#define __HAL_RCC_GPIOB_IS_CLK_DISABLED()     ((RCC->APB2ENR & (RCC_APB2ENR_IOPBEN)) == RESET)
611
#define __HAL_RCC_GPIOC_IS_CLK_ENABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_IOPCEN)) != RESET)
612
#define __HAL_RCC_GPIOC_IS_CLK_DISABLED()     ((RCC->APB2ENR & (RCC_APB2ENR_IOPCEN)) == RESET)
613
#define __HAL_RCC_GPIOD_IS_CLK_ENABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_IOPDEN)) != RESET)
614
#define __HAL_RCC_GPIOD_IS_CLK_DISABLED()     ((RCC->APB2ENR & (RCC_APB2ENR_IOPDEN)) == RESET)
615
#define __HAL_RCC_ADC1_IS_CLK_ENABLED()       ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) != RESET)
616
#define __HAL_RCC_ADC1_IS_CLK_DISABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) == RESET)
617
#define __HAL_RCC_TIM1_IS_CLK_ENABLED()       ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) != RESET)
618
#define __HAL_RCC_TIM1_IS_CLK_DISABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) == RESET)
619
#define __HAL_RCC_SPI1_IS_CLK_ENABLED()       ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) != RESET)
620
#define __HAL_RCC_SPI1_IS_CLK_DISABLED()      ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) == RESET)
621
#define __HAL_RCC_USART1_IS_CLK_ENABLED()     ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) != RESET)
622
#define __HAL_RCC_USART1_IS_CLK_DISABLED()    ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) == RESET)
623
 
624
/**
625
  * @}
626
  */
627
 
628
/** @defgroup RCC_APB1_Force_Release_Reset APB1 Force Release Reset
629
  * @brief  Force or release APB1 peripheral reset.
630
  * @{  
631
  */
632
#define __HAL_RCC_APB1_FORCE_RESET()       (RCC->APB2RSTR = 0xFFFFFFFFU)  
633
#define __HAL_RCC_TIM2_FORCE_RESET()       (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
634
#define __HAL_RCC_TIM3_FORCE_RESET()       (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
635
#define __HAL_RCC_WWDG_FORCE_RESET()       (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
636
#define __HAL_RCC_USART2_FORCE_RESET()     (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
637
#define __HAL_RCC_I2C1_FORCE_RESET()       (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
638
 
639
#define __HAL_RCC_BKP_FORCE_RESET()        (RCC->APB1RSTR |= (RCC_APB1RSTR_BKPRST))
640
#define __HAL_RCC_PWR_FORCE_RESET()        (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
641
 
642
#define __HAL_RCC_APB1_RELEASE_RESET()      (RCC->APB1RSTR = 0x00)  
643
#define __HAL_RCC_TIM2_RELEASE_RESET()       (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
644
#define __HAL_RCC_TIM3_RELEASE_RESET()       (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
645
#define __HAL_RCC_WWDG_RELEASE_RESET()       (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
646
#define __HAL_RCC_USART2_RELEASE_RESET()     (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
647
#define __HAL_RCC_I2C1_RELEASE_RESET()       (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
648
 
649
#define __HAL_RCC_BKP_RELEASE_RESET()        (RCC->APB1RSTR &= ~(RCC_APB1RSTR_BKPRST))
650
#define __HAL_RCC_PWR_RELEASE_RESET()        (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
651
 
652
/**
653
  * @}
654
  */
655
 
656
/** @defgroup RCC_APB2_Force_Release_Reset APB2 Force Release Reset
657
  * @brief  Force or release APB2 peripheral reset.
658
  * @{  
659
  */
660
#define __HAL_RCC_APB2_FORCE_RESET()       (RCC->APB2RSTR = 0xFFFFFFFFU)  
661
#define __HAL_RCC_AFIO_FORCE_RESET()       (RCC->APB2RSTR |= (RCC_APB2RSTR_AFIORST))
662
#define __HAL_RCC_GPIOA_FORCE_RESET()      (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPARST))
663
#define __HAL_RCC_GPIOB_FORCE_RESET()      (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPBRST))
664
#define __HAL_RCC_GPIOC_FORCE_RESET()      (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPCRST))
665
#define __HAL_RCC_GPIOD_FORCE_RESET()      (RCC->APB2RSTR |= (RCC_APB2RSTR_IOPDRST))
666
#define __HAL_RCC_ADC1_FORCE_RESET()       (RCC->APB2RSTR |= (RCC_APB2RSTR_ADC1RST))
667
 
668
#define __HAL_RCC_TIM1_FORCE_RESET()       (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM1RST))
669
#define __HAL_RCC_SPI1_FORCE_RESET()       (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
670
#define __HAL_RCC_USART1_FORCE_RESET()     (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
671
 
672
#define __HAL_RCC_APB2_RELEASE_RESET()      (RCC->APB2RSTR = 0x00)  
673
#define __HAL_RCC_AFIO_RELEASE_RESET()       (RCC->APB2RSTR &= ~(RCC_APB2RSTR_AFIORST))
674
#define __HAL_RCC_GPIOA_RELEASE_RESET()      (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPARST))
675
#define __HAL_RCC_GPIOB_RELEASE_RESET()      (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPBRST))
676
#define __HAL_RCC_GPIOC_RELEASE_RESET()      (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPCRST))
677
#define __HAL_RCC_GPIOD_RELEASE_RESET()      (RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPDRST))
678
#define __HAL_RCC_ADC1_RELEASE_RESET()       (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADC1RST))
679
 
680
#define __HAL_RCC_TIM1_RELEASE_RESET()       (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM1RST))
681
#define __HAL_RCC_SPI1_RELEASE_RESET()       (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
682
#define __HAL_RCC_USART1_RELEASE_RESET()     (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
683
 
684
/**
685
  * @}
686
  */
687
 
688
/** @defgroup RCC_HSI_Configuration HSI Configuration
689
  * @{  
690
  */
691
 
692
/** @brief  Macros to enable or disable the Internal High Speed oscillator (HSI).
693
  * @note   The HSI is stopped by hardware when entering STOP and STANDBY modes.
694
  * @note   HSI can not be stopped if it is used as system clock source. In this case,
695
  *         you have to select another source of the system clock then stop the HSI.  
696
  * @note   After enabling the HSI, the application software should wait on HSIRDY
697
  *         flag to be set indicating that HSI clock is stable and can be used as
698
  *         system clock source.  
699
  * @note   When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
700
  *         clock cycles.  
701
  */
702
#define __HAL_RCC_HSI_ENABLE()  (*(__IO uint32_t *) RCC_CR_HSION_BB = ENABLE)
703
#define __HAL_RCC_HSI_DISABLE() (*(__IO uint32_t *) RCC_CR_HSION_BB = DISABLE)
704
 
705
/** @brief  Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
706
  * @note   The calibration is used to compensate for the variations in voltage
707
  *         and temperature that influence the frequency of the internal HSI RC.
708
  * @param  _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
709
  *         (default is RCC_HSICALIBRATION_DEFAULT).
710
  *         This parameter must be a number between 0 and 0x1F.
711
  */  
712
#define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
713
          (MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << RCC_CR_HSITRIM_Pos))
714
 
715
/**
716
  * @}
717
  */
718
 
719
/** @defgroup RCC_LSI_Configuration  LSI Configuration
720
  * @{  
721
  */
722
 
723
/** @brief Macro to enable the Internal Low Speed oscillator (LSI).
724
  * @note   After enabling the LSI, the application software should wait on
725
  *         LSIRDY flag to be set indicating that LSI clock is stable and can
726
  *         be used to clock the IWDG and/or the RTC.
727
  */
728
#define __HAL_RCC_LSI_ENABLE()  (*(__IO uint32_t *) RCC_CSR_LSION_BB = ENABLE)
729
 
730
/** @brief Macro to disable the Internal Low Speed oscillator (LSI).
731
  * @note   LSI can not be disabled if the IWDG is running.  
732
  * @note   When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
733
  *         clock cycles.
734
  */
735
#define __HAL_RCC_LSI_DISABLE() (*(__IO uint32_t *) RCC_CSR_LSION_BB = DISABLE)
736
 
737
/**
738
  * @}
739
  */
740
 
741
/** @defgroup RCC_HSE_Configuration HSE Configuration
742
  * @{  
743
  */
744
 
745
/**
746
  * @brief  Macro to configure the External High Speed oscillator (HSE).
747
  * @note   Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
748
  *         supported by this macro. User should request a transition to HSE Off
749
  *         first and then HSE On or HSE Bypass.
750
  * @note   After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
751
  *         software should wait on HSERDY flag to be set indicating that HSE clock
752
  *         is stable and can be used to clock the PLL and/or system clock.
753
  * @note   HSE state can not be changed if it is used directly or through the
754
  *         PLL as system clock. In this case, you have to select another source
755
  *         of the system clock then change the HSE state (ex. disable it).
756
  * @note   The HSE is stopped by hardware when entering STOP and STANDBY modes.
757
  * @note   This function reset the CSSON bit, so if the clock security system(CSS)
758
  *         was previously enabled you have to enable it again after calling this
759
  *         function.
760
  * @param  __STATE__ specifies the new state of the HSE.
761
  *          This parameter can be one of the following values:
762
  *            @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
763
  *                              6 HSE oscillator clock cycles.
764
  *            @arg @ref RCC_HSE_ON turn ON the HSE oscillator
765
  *            @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
766
  */
767
#define __HAL_RCC_HSE_CONFIG(__STATE__)                                     \
768
                    do{                                                     \
769
                      if ((__STATE__) == RCC_HSE_ON)                        \
770
                      {                                                     \
771
                        SET_BIT(RCC->CR, RCC_CR_HSEON);                     \
772
                      }                                                     \
773
                      else if ((__STATE__) == RCC_HSE_OFF)                  \
774
                      {                                                     \
775
                        CLEAR_BIT(RCC->CR, RCC_CR_HSEON);                   \
776
                        CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);                  \
777
                      }                                                     \
778
                      else if ((__STATE__) == RCC_HSE_BYPASS)               \
779
                      {                                                     \
780
                        SET_BIT(RCC->CR, RCC_CR_HSEBYP);                    \
781
                        SET_BIT(RCC->CR, RCC_CR_HSEON);                     \
782
                      }                                                     \
783
                      else                                                  \
784
                      {                                                     \
785
                        CLEAR_BIT(RCC->CR, RCC_CR_HSEON);                   \
786
                        CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);                  \
787
                      }                                                     \
788
                    }while(0U)
789
 
790
/**
791
  * @}
792
  */
793
 
794
/** @defgroup RCC_LSE_Configuration LSE Configuration
795
  * @{  
796
  */
797
 
798
/**
799
  * @brief  Macro to configure the External Low Speed oscillator (LSE).
800
  * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
801
  * @note   As the LSE is in the Backup domain and write access is denied to
802
  *         this domain after reset, you have to enable write access using
803
  *         @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
804
  *         (to be done once after reset).  
805
  * @note   After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
806
  *         software should wait on LSERDY flag to be set indicating that LSE clock
807
  *         is stable and can be used to clock the RTC.
808
  * @param  __STATE__ specifies the new state of the LSE.
809
  *         This parameter can be one of the following values:
810
  *            @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
811
  *                              6 LSE oscillator clock cycles.
812
  *            @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
813
  *            @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
814
  */
815
#define __HAL_RCC_LSE_CONFIG(__STATE__)                                     \
816
                    do{                                                     \
817
                      if ((__STATE__) == RCC_LSE_ON)                        \
818
                      {                                                     \
819
                        SET_BIT(RCC->BDCR, RCC_BDCR_LSEON);                   \
820
                      }                                                     \
821
                      else if ((__STATE__) == RCC_LSE_OFF)                  \
822
                      {                                                     \
823
                        CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON);                 \
824
                        CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP);                \
825
                      }                                                     \
826
                      else if ((__STATE__) == RCC_LSE_BYPASS)               \
827
                      {                                                     \
828
                        SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP);                  \
829
                        SET_BIT(RCC->BDCR, RCC_BDCR_LSEON);                   \
830
                      }                                                     \
831
                      else                                                  \
832
                      {                                                     \
833
                        CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON);                 \
834
                        CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP);                \
835
                      }                                                     \
836
                    }while(0U)
837
 
838
/**
839
  * @}
840
  */
841
 
842
/** @defgroup RCC_PLL_Configuration PLL Configuration
843
  * @{  
844
  */
845
 
846
/** @brief Macro to enable the main PLL.
847
  * @note   After enabling the main PLL, the application software should wait on
848
  *         PLLRDY flag to be set indicating that PLL clock is stable and can
849
  *         be used as system clock source.
850
  * @note   The main PLL is disabled by hardware when entering STOP and STANDBY modes.
851
  */
852
#define __HAL_RCC_PLL_ENABLE()          (*(__IO uint32_t *) RCC_CR_PLLON_BB = ENABLE)
853
 
854
/** @brief Macro to disable the main PLL.
855
  * @note   The main PLL can not be disabled if it is used as system clock source
856
  */
857
#define __HAL_RCC_PLL_DISABLE()         (*(__IO uint32_t *) RCC_CR_PLLON_BB = DISABLE)
858
 
859
/** @brief Macro to configure the main PLL clock source and multiplication factors.
860
  * @note   This function must be used only when the main PLL is disabled.
861
  *  
862
  * @param  __RCC_PLLSOURCE__ specifies the PLL entry clock source.
863
  *          This parameter can be one of the following values:
864
  *            @arg @ref RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL clock entry
865
  *            @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
866
  * @param  __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
867
  *          This parameter can be one of the following values:
868
  *             @arg @ref RCC_PLL_MUL4   PLLVCO = PLL clock entry x 4
869
  *             @arg @ref RCC_PLL_MUL6   PLLVCO = PLL clock entry x 6
870
  @if STM32F105xC
871
  *             @arg @ref RCC_PLL_MUL6_5 PLLVCO = PLL clock entry x 6.5
872
  @elseif STM32F107xC
873
  *             @arg @ref RCC_PLL_MUL6_5 PLLVCO = PLL clock entry x 6.5
874
  @else
875
  *             @arg @ref RCC_PLL_MUL2   PLLVCO = PLL clock entry x 2
876
  *             @arg @ref RCC_PLL_MUL3   PLLVCO = PLL clock entry x 3
877
  *             @arg @ref RCC_PLL_MUL10  PLLVCO = PLL clock entry x 10
878
  *             @arg @ref RCC_PLL_MUL11  PLLVCO = PLL clock entry x 11
879
  *             @arg @ref RCC_PLL_MUL12  PLLVCO = PLL clock entry x 12
880
  *             @arg @ref RCC_PLL_MUL13  PLLVCO = PLL clock entry x 13
881
  *             @arg @ref RCC_PLL_MUL14  PLLVCO = PLL clock entry x 14
882
  *             @arg @ref RCC_PLL_MUL15  PLLVCO = PLL clock entry x 15
883
  *             @arg @ref RCC_PLL_MUL16  PLLVCO = PLL clock entry x 16
884
  @endif
885
  *             @arg @ref RCC_PLL_MUL8   PLLVCO = PLL clock entry x 8
886
  *             @arg @ref RCC_PLL_MUL9   PLLVCO = PLL clock entry x 9
887
  *  
888
  */
889
#define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__, __PLLMUL__)\
890
          MODIFY_REG(RCC->CFGR, (RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL),((__RCC_PLLSOURCE__) | (__PLLMUL__) ))
891
 
892
/** @brief  Get oscillator clock selected as PLL input clock
893
  * @retval The clock source used for PLL entry. The returned value can be one
894
  *         of the following:
895
  *             @arg @ref RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL input clock
896
  *             @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
897
  */
898
#define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
899
 
900
/**
901
  * @}
902
  */
903
 
904
/** @defgroup RCC_Get_Clock_source Get Clock source
905
  * @{  
906
  */
907
 
908
/**
909
  * @brief  Macro to configure the system clock source.
910
  * @param  __SYSCLKSOURCE__ specifies the system clock source.
911
  *          This parameter can be one of the following values:
912
  *              @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
913
  *              @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
914
  *              @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
915
  */
916
#define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
917
                  MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
918
 
919
/** @brief  Macro to get the clock source used as system clock.
920
  * @retval The clock source used as system clock. The returned value can be one
921
  *         of the following:
922
  *             @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
923
  *             @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
924
  *             @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
925
  */
926
#define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
927
 
928
/**
929
  * @}
930
  */
931
 
932
/** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
933
  * @{  
934
  */
935
 
936
#if   defined(RCC_CFGR_MCO_3)
937
/** @brief  Macro to configure the MCO clock.
938
  * @param  __MCOCLKSOURCE__ specifies the MCO clock source.
939
  *         This parameter can be one of the following values:
940
  *            @arg @ref RCC_MCO1SOURCE_NOCLOCK      No clock selected as MCO clock
941
  *            @arg @ref RCC_MCO1SOURCE_SYSCLK       System clock (SYSCLK) selected as MCO clock
942
  *            @arg @ref RCC_MCO1SOURCE_HSI          HSI selected as MCO clock
943
  *            @arg @ref RCC_MCO1SOURCE_HSE          HSE selected as MCO clock
944
  *            @arg @ref RCC_MCO1SOURCE_PLLCLK       PLL clock divided by 2 selected as MCO clock
945
  *            @arg @ref RCC_MCO1SOURCE_PLL2CLK      PLL2 clock selected by 2 selected as MCO clock
946
  *            @arg @ref RCC_MCO1SOURCE_PLL3CLK_DIV2 PLL3 clock divided by 2 selected as MCO clock
947
  *            @arg @ref RCC_MCO1SOURCE_EXT_HSE XT1  external 3-25 MHz oscillator clock selected (for Ethernet) as MCO clock
948
  *            @arg @ref RCC_MCO1SOURCE_PLL3CLK      PLL3 clock selected (for Ethernet) as MCO clock
949
  * @param  __MCODIV__ specifies the MCO clock prescaler.
950
  *         This parameter can be one of the following values:
951
  *            @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
952
  */
953
#else
954
/** @brief  Macro to configure the MCO clock.
955
  * @param  __MCOCLKSOURCE__ specifies the MCO clock source.
956
  *         This parameter can be one of the following values:
957
  *            @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
958
  *            @arg @ref RCC_MCO1SOURCE_SYSCLK  System clock (SYSCLK) selected as MCO clock
959
  *            @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
960
  *            @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
961
  *            @arg @ref RCC_MCO1SOURCE_PLLCLK  PLL clock divided by 2 selected as MCO clock
962
  * @param  __MCODIV__ specifies the MCO clock prescaler.
963
  *         This parameter can be one of the following values:
964
  *            @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
965
  */
966
#endif
967
 
968
#define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
969
                 MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, (__MCOCLKSOURCE__))
970
 
971
 
972
/**
973
  * @}
974
  */
975
 
976
  /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
977
  * @{  
978
  */
979
 
980
/** @brief Macro to configure the RTC clock (RTCCLK).
981
  * @note   As the RTC clock configuration bits are in the Backup domain and write
982
  *         access is denied to this domain after reset, you have to enable write
983
  *         access using the Power Backup Access macro before to configure
984
  *         the RTC clock source (to be done once after reset).    
985
  * @note   Once the RTC clock is configured it can't be changed unless the  
986
  *         Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
987
  *         a Power On Reset (POR).
988
  *
989
  * @param  __RTC_CLKSOURCE__ specifies the RTC clock source.
990
  *          This parameter can be one of the following values:
991
  *             @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
992
  *             @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
993
  *             @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
994
  *             @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock
995
  * @note   If the LSE or LSI is used as RTC clock source, the RTC continues to
996
  *         work in STOP and STANDBY modes, and can be used as wakeup source.
997
  *         However, when the HSE clock is used as RTC clock source, the RTC
998
  *         cannot be used in STOP and STANDBY modes.    
999
  * @note   The maximum input clock frequency for RTC is 1MHz (when using HSE as
1000
  *         RTC clock source).
1001
  */
1002
#define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, (__RTC_CLKSOURCE__))
1003
 
1004
/** @brief Macro to get the RTC clock source.
1005
  * @retval The clock source can be one of the following values:
1006
  *            @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
1007
  *            @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
1008
  *            @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
1009
  *            @arg @ref RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock
1010
  */
1011
#define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL))
1012
 
1013
/** @brief Macro to enable the the RTC clock.
1014
  * @note   These macros must be used only after the RTC clock source was selected.
1015
  */
1016
#define __HAL_RCC_RTC_ENABLE()          (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = ENABLE)
1017
 
1018
/** @brief Macro to disable the the RTC clock.
1019
  * @note  These macros must be used only after the RTC clock source was selected.
1020
  */
1021
#define __HAL_RCC_RTC_DISABLE()         (*(__IO uint32_t *) RCC_BDCR_RTCEN_BB = DISABLE)
1022
 
1023
/** @brief  Macro to force the Backup domain reset.
1024
  * @note   This function resets the RTC peripheral (including the backup registers)
1025
  *         and the RTC clock source selection in RCC_BDCR register.
1026
  */
1027
#define __HAL_RCC_BACKUPRESET_FORCE()   (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = ENABLE)
1028
 
1029
/** @brief  Macros to release the Backup domain reset.
1030
  */
1031
#define __HAL_RCC_BACKUPRESET_RELEASE() (*(__IO uint32_t *) RCC_BDCR_BDRST_BB = DISABLE)
1032
 
1033
/**
1034
  * @}
1035
  */
1036
 
1037
/** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
1038
  * @brief macros to manage the specified RCC Flags and interrupts.
1039
  * @{
1040
  */
1041
 
1042
/** @brief Enable RCC interrupt.
1043
  * @param  __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
1044
  *          This parameter can be any combination of the following values:
1045
  *            @arg @ref RCC_IT_LSIRDY LSI ready interrupt
1046
  *            @arg @ref RCC_IT_LSERDY LSE ready interrupt
1047
  *            @arg @ref RCC_IT_HSIRDY HSI ready interrupt
1048
  *            @arg @ref RCC_IT_HSERDY HSE ready interrupt
1049
  *            @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
1050
  @if STM32F105xx
1051
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1052
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1053
  @elsif STM32F107xx
1054
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1055
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1056
  @endif
1057
  */
1058
#define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
1059
 
1060
/** @brief Disable RCC interrupt.
1061
  * @param  __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
1062
  *          This parameter can be any combination of the following values:
1063
  *            @arg @ref RCC_IT_LSIRDY LSI ready interrupt
1064
  *            @arg @ref RCC_IT_LSERDY LSE ready interrupt
1065
  *            @arg @ref RCC_IT_HSIRDY HSI ready interrupt
1066
  *            @arg @ref RCC_IT_HSERDY HSE ready interrupt
1067
  *            @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
1068
  @if STM32F105xx
1069
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1070
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1071
  @elsif STM32F107xx
1072
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1073
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1074
  @endif
1075
  */
1076
#define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= (uint8_t)(~(__INTERRUPT__)))
1077
 
1078
/** @brief Clear the RCC's interrupt pending bits.
1079
  * @param  __INTERRUPT__ specifies the interrupt pending bit to clear.
1080
  *          This parameter can be any combination of the following values:
1081
  *            @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
1082
  *            @arg @ref RCC_IT_LSERDY LSE ready interrupt.
1083
  *            @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
1084
  *            @arg @ref RCC_IT_HSERDY HSE ready interrupt.
1085
  *            @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
1086
  @if STM32F105xx
1087
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1088
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1089
  @elsif STM32F107xx
1090
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1091
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1092
  @endif
1093
  *            @arg @ref RCC_IT_CSS Clock Security System interrupt
1094
  */
1095
#define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_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 @ref RCC_IT_LSIRDY LSI ready interrupt.
1101
  *            @arg @ref RCC_IT_LSERDY LSE ready interrupt.
1102
  *            @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
1103
  *            @arg @ref RCC_IT_HSERDY HSE ready interrupt.
1104
  *            @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
1105
  @if STM32F105xx
1106
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1107
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1108
  @elsif STM32F107xx
1109
  *            @arg @ref RCC_IT_PLL2RDY Main PLL2 ready interrupt.
1110
  *            @arg @ref RCC_IT_PLLI2S2RDY Main PLLI2S ready interrupt.
1111
  @endif
1112
  *            @arg @ref RCC_IT_CSS Clock Security System interrupt
1113
  * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
1114
  */
1115
#define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
1116
 
1117
/** @brief Set RMVF bit to clear the reset flags.
1118
  *         The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
1119
  *         RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
1120
  */
1121
#define __HAL_RCC_CLEAR_RESET_FLAGS() (*(__IO uint32_t *)RCC_CSR_RMVF_BB = ENABLE)
1122
 
1123
/** @brief  Check RCC flag is set or not.
1124
  * @param  __FLAG__ specifies the flag to check.
1125
  *          This parameter can be one of the following values:
1126
  *            @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready.
1127
  *            @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready.
1128
  *            @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready.
1129
  @if STM32F105xx
1130
  *            @arg @ref RCC_FLAG_PLL2RDY Main PLL2 clock ready.
1131
  *            @arg @ref RCC_FLAG_PLLI2SRDY Main PLLI2S clock ready.
1132
  @elsif STM32F107xx
1133
  *            @arg @ref RCC_FLAG_PLL2RDY Main PLL2 clock ready.
1134
  *            @arg @ref RCC_FLAG_PLLI2SRDY Main PLLI2S clock ready.
1135
  @endif
1136
  *            @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready.
1137
  *            @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready.
1138
  *            @arg @ref RCC_FLAG_PINRST  Pin reset.
1139
  *            @arg @ref RCC_FLAG_PORRST  POR/PDR reset.
1140
  *            @arg @ref RCC_FLAG_SFTRST  Software reset.
1141
  *            @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset.
1142
  *            @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset.
1143
  *            @arg @ref RCC_FLAG_LPWRRST Low Power reset.
1144
  * @retval The new state of __FLAG__ (TRUE or FALSE).
1145
  */
1146
#define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5U) == CR_REG_INDEX)?   RCC->CR   : \
1147
                                      ((((__FLAG__) >> 5U) == BDCR_REG_INDEX)? RCC->BDCR : \
1148
                                                                              RCC->CSR)) & (1U << ((__FLAG__) & RCC_FLAG_MASK)))
1149
 
1150
/**
1151
  * @}
1152
  */
1153
 
1154
/**
1155
  * @}
1156
  */
1157
 
1158
/* Include RCC HAL Extension module */
1159
#include "stm32f1xx_hal_rcc_ex.h"
1160
 
1161
/* Exported functions --------------------------------------------------------*/
1162
/** @addtogroup RCC_Exported_Functions
1163
  * @{
1164
  */
1165
 
1166
/** @addtogroup RCC_Exported_Functions_Group1
1167
  * @{
1168
  */
1169
 
1170
/* Initialization and de-initialization functions  ******************************/
1171
HAL_StatusTypeDef HAL_RCC_DeInit(void);
1172
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef  *RCC_OscInitStruct);
1173
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef  *RCC_ClkInitStruct, uint32_t FLatency);
1174
 
1175
/**
1176
  * @}
1177
  */
1178
 
1179
/** @addtogroup RCC_Exported_Functions_Group2
1180
  * @{
1181
  */
1182
 
1183
/* Peripheral Control functions  ************************************************/
1184
void              HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
1185
void              HAL_RCC_EnableCSS(void);
1186
void              HAL_RCC_DisableCSS(void);
1187
uint32_t          HAL_RCC_GetSysClockFreq(void);
1188
uint32_t          HAL_RCC_GetHCLKFreq(void);
1189
uint32_t          HAL_RCC_GetPCLK1Freq(void);
1190
uint32_t          HAL_RCC_GetPCLK2Freq(void);
1191
void              HAL_RCC_GetOscConfig(RCC_OscInitTypeDef  *RCC_OscInitStruct);
1192
void              HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef  *RCC_ClkInitStruct, uint32_t *pFLatency);
1193
 
1194
/* CSS NMI IRQ handler */
1195
void              HAL_RCC_NMI_IRQHandler(void);
1196
 
1197
/* User Callbacks in non blocking mode (IT mode) */
1198
void              HAL_RCC_CSSCallback(void);
1199
 
1200
/**
1201
  * @}
1202
  */
1203
 
1204
/**
1205
  * @}
1206
  */
1207
 
1208
/** @addtogroup RCC_Private_Constants
1209
  * @{
1210
  */
1211
 
1212
/** @defgroup RCC_Timeout RCC Timeout
1213
  * @{
1214
  */
1215
 
1216
/* Disable Backup domain write protection state change timeout */
1217
#define RCC_DBP_TIMEOUT_VALUE          100U    /* 100 ms */
1218
/* LSE state change timeout */
1219
#define RCC_LSE_TIMEOUT_VALUE          LSE_STARTUP_TIMEOUT
1220
#define CLOCKSWITCH_TIMEOUT_VALUE      5000    /* 5 s    */
1221
#define HSE_TIMEOUT_VALUE              HSE_STARTUP_TIMEOUT
1222
#define HSI_TIMEOUT_VALUE              2U      /* 2 ms (minimum Tick + 1) */
1223
#define LSI_TIMEOUT_VALUE              2U      /* 2 ms (minimum Tick + 1) */
1224
#define PLL_TIMEOUT_VALUE              2U      /* 2 ms (minimum Tick + 1) */
1225
 
1226
/**
1227
  * @}
1228
  */
1229
 
1230
/** @defgroup RCC_Register_Offset Register offsets
1231
  * @{
1232
  */
1233
#define RCC_OFFSET                (RCC_BASE - PERIPH_BASE)
1234
#define RCC_CR_OFFSET             0x00U
1235
#define RCC_CFGR_OFFSET           0x04U
1236
#define RCC_CIR_OFFSET            0x08U
1237
#define RCC_BDCR_OFFSET           0x20U
1238
#define RCC_CSR_OFFSET            0x24U
1239
 
1240
/**
1241
  * @}
1242
  */
1243
 
1244
/** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
1245
  * @brief RCC registers bit address in the alias region
1246
  * @{
1247
  */
1248
#define RCC_CR_OFFSET_BB          (RCC_OFFSET + RCC_CR_OFFSET)
1249
#define RCC_CFGR_OFFSET_BB        (RCC_OFFSET + RCC_CFGR_OFFSET)
1250
#define RCC_CIR_OFFSET_BB         (RCC_OFFSET + RCC_CIR_OFFSET)
1251
#define RCC_BDCR_OFFSET_BB        (RCC_OFFSET + RCC_BDCR_OFFSET)
1252
#define RCC_CSR_OFFSET_BB         (RCC_OFFSET + RCC_CSR_OFFSET)
1253
 
1254
/* --- CR Register ---*/
1255
/* Alias word address of HSION bit */
1256
#define RCC_HSION_BIT_NUMBER      RCC_CR_HSION_Pos
1257
#define RCC_CR_HSION_BB           ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSION_BIT_NUMBER * 4U)))
1258
/* Alias word address of HSEON bit */
1259
#define RCC_HSEON_BIT_NUMBER      RCC_CR_HSEON_Pos
1260
#define RCC_CR_HSEON_BB           ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_HSEON_BIT_NUMBER * 4U)))
1261
/* Alias word address of CSSON bit */
1262
#define RCC_CSSON_BIT_NUMBER      RCC_CR_CSSON_Pos
1263
#define RCC_CR_CSSON_BB           ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_CSSON_BIT_NUMBER * 4U)))
1264
/* Alias word address of PLLON bit */
1265
#define RCC_PLLON_BIT_NUMBER      RCC_CR_PLLON_Pos
1266
#define RCC_CR_PLLON_BB           ((uint32_t)(PERIPH_BB_BASE + (RCC_CR_OFFSET_BB * 32U) + (RCC_PLLON_BIT_NUMBER * 4U)))
1267
 
1268
/* --- CSR Register ---*/
1269
/* Alias word address of LSION bit */
1270
#define RCC_LSION_BIT_NUMBER      RCC_CSR_LSION_Pos
1271
#define RCC_CSR_LSION_BB          ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_LSION_BIT_NUMBER * 4U)))
1272
 
1273
/* Alias word address of RMVF bit */
1274
#define RCC_RMVF_BIT_NUMBER       RCC_CSR_RMVF_Pos
1275
#define RCC_CSR_RMVF_BB           ((uint32_t)(PERIPH_BB_BASE + (RCC_CSR_OFFSET_BB * 32U) + (RCC_RMVF_BIT_NUMBER * 4U)))
1276
 
1277
/* --- BDCR Registers ---*/
1278
/* Alias word address of LSEON bit */
1279
#define RCC_LSEON_BIT_NUMBER      RCC_BDCR_LSEON_Pos
1280
#define RCC_BDCR_LSEON_BB          ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_LSEON_BIT_NUMBER * 4U)))
1281
 
1282
/* Alias word address of LSEON bit */
1283
#define RCC_LSEBYP_BIT_NUMBER     RCC_BDCR_LSEBYP_Pos
1284
#define RCC_BDCR_LSEBYP_BB         ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_LSEBYP_BIT_NUMBER * 4U)))
1285
 
1286
/* Alias word address of RTCEN bit */
1287
#define RCC_RTCEN_BIT_NUMBER      RCC_BDCR_RTCEN_Pos
1288
#define RCC_BDCR_RTCEN_BB          ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_RTCEN_BIT_NUMBER * 4U)))
1289
 
1290
/* Alias word address of BDRST bit */
1291
#define RCC_BDRST_BIT_NUMBER      RCC_BDCR_BDRST_Pos
1292
#define RCC_BDCR_BDRST_BB         ((uint32_t)(PERIPH_BB_BASE + (RCC_BDCR_OFFSET_BB * 32U) + (RCC_BDRST_BIT_NUMBER * 4U)))
1293
 
1294
/**
1295
  * @}
1296
  */
1297
 
1298
/* CR register byte 2 (Bits[23:16]) base address */
1299
#define RCC_CR_BYTE2_ADDRESS          ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02U))
1300
 
1301
/* CIR register byte 1 (Bits[15:8]) base address */
1302
#define RCC_CIR_BYTE1_ADDRESS     ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01U))
1303
 
1304
/* CIR register byte 2 (Bits[23:16]) base address */
1305
#define RCC_CIR_BYTE2_ADDRESS     ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02U))
1306
 
1307
/* Defines used for Flags */
1308
#define CR_REG_INDEX                     ((uint8_t)1)
1309
#define BDCR_REG_INDEX                   ((uint8_t)2)
1310
#define CSR_REG_INDEX                    ((uint8_t)3)
1311
 
1312
#define RCC_FLAG_MASK                    ((uint8_t)0x1F)
1313
 
1314
/**
1315
  * @}
1316
  */
1317
 
1318
/** @addtogroup RCC_Private_Macros
1319
  * @{
1320
  */
1321
/** @defgroup RCC_Alias_For_Legacy Alias define maintained for legacy
1322
  * @{
1323
  */
1324
#define __HAL_RCC_SYSCFG_CLK_DISABLE    __HAL_RCC_AFIO_CLK_DISABLE
1325
#define __HAL_RCC_SYSCFG_CLK_ENABLE     __HAL_RCC_AFIO_CLK_ENABLE
1326
#define __HAL_RCC_SYSCFG_FORCE_RESET    __HAL_RCC_AFIO_FORCE_RESET
1327
#define __HAL_RCC_SYSCFG_RELEASE_RESET  __HAL_RCC_AFIO_RELEASE_RESET
1328
/**
1329
  * @}
1330
  */
1331
 
1332
#define IS_RCC_PLLSOURCE(__SOURCE__) (((__SOURCE__) == RCC_PLLSOURCE_HSI_DIV2) || \
1333
                                      ((__SOURCE__) == RCC_PLLSOURCE_HSE))
1334
#define IS_RCC_OSCILLATORTYPE(__OSCILLATOR__) (((__OSCILLATOR__) == RCC_OSCILLATORTYPE_NONE)                           || \
1335
                                               (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
1336
                                               (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
1337
                                               (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
1338
                                               (((__OSCILLATOR__) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE))
1339
#define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
1340
                             ((__HSE__) == RCC_HSE_BYPASS))
1341
#define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
1342
                             ((__LSE__) == RCC_LSE_BYPASS))
1343
#define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
1344
#define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
1345
#define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
1346
#define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
1347
                             ((__PLL__) == RCC_PLL_ON))
1348
 
1349
#define IS_RCC_CLOCKTYPE(CLK) ((((CLK) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
1350
                               (((CLK) & RCC_CLOCKTYPE_HCLK)   == RCC_CLOCKTYPE_HCLK)   || \
1351
                               (((CLK) & RCC_CLOCKTYPE_PCLK1)  == RCC_CLOCKTYPE_PCLK1)  || \
1352
                               (((CLK) & RCC_CLOCKTYPE_PCLK2)  == RCC_CLOCKTYPE_PCLK2))
1353
#define IS_RCC_SYSCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_HSI) || \
1354
                                         ((__SOURCE__) == RCC_SYSCLKSOURCE_HSE) || \
1355
                                         ((__SOURCE__) == RCC_SYSCLKSOURCE_PLLCLK))
1356
#define IS_RCC_SYSCLKSOURCE_STATUS(__SOURCE__) (((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
1357
                                                ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
1358
                                                ((__SOURCE__) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
1359
#define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
1360
                               ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
1361
                               ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
1362
                               ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
1363
                               ((__HCLK__) == RCC_SYSCLK_DIV512))
1364
#define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
1365
                               ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
1366
                               ((__PCLK__) == RCC_HCLK_DIV16))
1367
#define IS_RCC_MCO(__MCO__)  ((__MCO__) == RCC_MCO)
1368
#define IS_RCC_MCODIV(__DIV__) (((__DIV__) == RCC_MCODIV_1)) 
1369
#define IS_RCC_RTCCLKSOURCE(__SOURCE__)  (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
1370
                                          ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
1371
                                          ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
1372
                                          ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV128))
1373
 
1374
/**
1375
  * @}
1376
  */
1377
 
1378
/**
1379
  * @}
1380
  */
1381
 
1382
/**
1383
  * @}
1384
  */
1385
 
1386
#ifdef __cplusplus
1387
}
1388
#endif
1389
 
1390
#endif /* __STM32F1xx_HAL_RCC_H */
1391
 
1392
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1393