Go to the documentation of this file.00001
00029
00030 #ifndef __STM32L1xx_RCC_H
00031 #define __STM32L1xx_RCC_H
00032
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036
00037
00038 #include "stm32l1xx.h"
00039
00048
00049
00050 typedef struct
00051 {
00052 uint32_t SYSCLK_Frequency;
00053 uint32_t HCLK_Frequency;
00054 uint32_t PCLK1_Frequency;
00055 uint32_t PCLK2_Frequency;
00056 }RCC_ClocksTypeDef;
00057
00058
00059
00068 #define RCC_HSE_OFF ((uint8_t)0x00)
00069 #define RCC_HSE_ON ((uint8_t)0x01)
00070 #define RCC_HSE_Bypass ((uint8_t)0x05)
00071 #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
00072 ((HSE) == RCC_HSE_Bypass))
00073
00082 #define RCC_MSIRange_0 RCC_ICSCR_MSIRANGE_0
00083 #define RCC_MSIRange_1 RCC_ICSCR_MSIRANGE_1
00084 #define RCC_MSIRange_2 RCC_ICSCR_MSIRANGE_2
00085 #define RCC_MSIRange_3 RCC_ICSCR_MSIRANGE_3
00086 #define RCC_MSIRange_4 RCC_ICSCR_MSIRANGE_4
00087 #define RCC_MSIRange_5 RCC_ICSCR_MSIRANGE_5
00088 #define RCC_MSIRange_6 RCC_ICSCR_MSIRANGE_6
00090 #define IS_RCC_MSI_CLOCK_RANGE(RANGE) (((RANGE) == RCC_MSIRange_0) || \
00091 ((RANGE) == RCC_MSIRange_1) || \
00092 ((RANGE) == RCC_MSIRange_2) || \
00093 ((RANGE) == RCC_MSIRange_3) || \
00094 ((RANGE) == RCC_MSIRange_4) || \
00095 ((RANGE) == RCC_MSIRange_5) || \
00096 ((RANGE) == RCC_MSIRange_6))
00097
00106 #define RCC_PLLSource_HSI ((uint8_t)0x00)
00107 #define RCC_PLLSource_HSE ((uint8_t)0x01)
00108
00109 #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI) || \
00110 ((SOURCE) == RCC_PLLSource_HSE))
00111
00119 #define RCC_PLLMul_3 ((uint8_t)0x00)
00120 #define RCC_PLLMul_4 ((uint8_t)0x04)
00121 #define RCC_PLLMul_6 ((uint8_t)0x08)
00122 #define RCC_PLLMul_8 ((uint8_t)0x0C)
00123 #define RCC_PLLMul_12 ((uint8_t)0x10)
00124 #define RCC_PLLMul_16 ((uint8_t)0x14)
00125 #define RCC_PLLMul_24 ((uint8_t)0x18)
00126 #define RCC_PLLMul_32 ((uint8_t)0x1C)
00127 #define RCC_PLLMul_48 ((uint8_t)0x20)
00128
00129
00130 #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_3) || ((MUL) == RCC_PLLMul_4) || \
00131 ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_8) || \
00132 ((MUL) == RCC_PLLMul_12) || ((MUL) == RCC_PLLMul_16) || \
00133 ((MUL) == RCC_PLLMul_24) || ((MUL) == RCC_PLLMul_32) || \
00134 ((MUL) == RCC_PLLMul_48))
00135
00143 #define RCC_PLLDiv_2 ((uint8_t)0x40)
00144 #define RCC_PLLDiv_3 ((uint8_t)0x80)
00145 #define RCC_PLLDiv_4 ((uint8_t)0xC0)
00146
00147
00148 #define IS_RCC_PLL_DIV(DIV) (((DIV) == RCC_PLLDiv_2) || ((DIV) == RCC_PLLDiv_3) || \
00149 ((DIV) == RCC_PLLDiv_4))
00150
00158 #define RCC_SYSCLKSource_MSI RCC_CFGR_SW_MSI
00159 #define RCC_SYSCLKSource_HSI RCC_CFGR_SW_HSI
00160 #define RCC_SYSCLKSource_HSE RCC_CFGR_SW_HSE
00161 #define RCC_SYSCLKSource_PLLCLK RCC_CFGR_SW_PLL
00162 #define IS_RCC_SYSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSource_MSI) || \
00163 ((SOURCE) == RCC_SYSCLKSource_HSI) || \
00164 ((SOURCE) == RCC_SYSCLKSource_HSE) || \
00165 ((SOURCE) == RCC_SYSCLKSource_PLLCLK))
00166
00174 #define RCC_SYSCLK_Div1 RCC_CFGR_HPRE_DIV1
00175 #define RCC_SYSCLK_Div2 RCC_CFGR_HPRE_DIV2
00176 #define RCC_SYSCLK_Div4 RCC_CFGR_HPRE_DIV4
00177 #define RCC_SYSCLK_Div8 RCC_CFGR_HPRE_DIV8
00178 #define RCC_SYSCLK_Div16 RCC_CFGR_HPRE_DIV16
00179 #define RCC_SYSCLK_Div64 RCC_CFGR_HPRE_DIV64
00180 #define RCC_SYSCLK_Div128 RCC_CFGR_HPRE_DIV128
00181 #define RCC_SYSCLK_Div256 RCC_CFGR_HPRE_DIV256
00182 #define RCC_SYSCLK_Div512 RCC_CFGR_HPRE_DIV512
00183 #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_Div1) || ((HCLK) == RCC_SYSCLK_Div2) || \
00184 ((HCLK) == RCC_SYSCLK_Div4) || ((HCLK) == RCC_SYSCLK_Div8) || \
00185 ((HCLK) == RCC_SYSCLK_Div16) || ((HCLK) == RCC_SYSCLK_Div64) || \
00186 ((HCLK) == RCC_SYSCLK_Div128) || ((HCLK) == RCC_SYSCLK_Div256) || \
00187 ((HCLK) == RCC_SYSCLK_Div512))
00188
00196 #define RCC_HCLK_Div1 RCC_CFGR_PPRE1_DIV1
00197 #define RCC_HCLK_Div2 RCC_CFGR_PPRE1_DIV2
00198 #define RCC_HCLK_Div4 RCC_CFGR_PPRE1_DIV4
00199 #define RCC_HCLK_Div8 RCC_CFGR_PPRE1_DIV8
00200 #define RCC_HCLK_Div16 RCC_CFGR_PPRE1_DIV16
00201 #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_Div1) || ((PCLK) == RCC_HCLK_Div2) || \
00202 ((PCLK) == RCC_HCLK_Div4) || ((PCLK) == RCC_HCLK_Div8) || \
00203 ((PCLK) == RCC_HCLK_Div16))
00204
00213 #define RCC_IT_LSIRDY ((uint8_t)0x01)
00214 #define RCC_IT_LSERDY ((uint8_t)0x02)
00215 #define RCC_IT_HSIRDY ((uint8_t)0x04)
00216 #define RCC_IT_HSERDY ((uint8_t)0x08)
00217 #define RCC_IT_PLLRDY ((uint8_t)0x10)
00218 #define RCC_IT_MSIRDY ((uint8_t)0x20)
00219 #define RCC_IT_LSECSS ((uint8_t)0x40)
00220 #define RCC_IT_CSS ((uint8_t)0x80)
00221
00222 #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0x80) == 0x00) && ((IT) != 0x00))
00223
00224 #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
00225 ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
00226 ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_MSIRDY) || \
00227 ((IT) == RCC_IT_CSS) || ((IT) == RCC_IT_LSECSS))
00228
00229 #define IS_RCC_CLEAR_IT(IT) ((((IT) & (uint8_t)0x00) == 0x00) && ((IT) != 0x00))
00230
00239 #define RCC_LSE_OFF ((uint8_t)0x00)
00240 #define RCC_LSE_ON ((uint8_t)0x01)
00241 #define RCC_LSE_Bypass ((uint8_t)0x05)
00242 #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
00243 ((LSE) == RCC_LSE_Bypass))
00244
00252 #define RCC_RTCCLKSource_LSE RCC_CSR_RTCSEL_LSE
00253 #define RCC_RTCCLKSource_LSI RCC_CSR_RTCSEL_LSI
00254 #define RCC_RTCCLKSource_HSE_Div2 RCC_CSR_RTCSEL_HSE
00255 #define RCC_RTCCLKSource_HSE_Div4 ((uint32_t)RCC_CSR_RTCSEL_HSE | RCC_CR_RTCPRE_0)
00256 #define RCC_RTCCLKSource_HSE_Div8 ((uint32_t)RCC_CSR_RTCSEL_HSE | RCC_CR_RTCPRE_1)
00257 #define RCC_RTCCLKSource_HSE_Div16 ((uint32_t)RCC_CSR_RTCSEL_HSE | RCC_CR_RTCPRE)
00258 #define IS_RCC_RTCCLK_SOURCE(SOURCE) (((SOURCE) == RCC_RTCCLKSource_LSE) || \
00259 ((SOURCE) == RCC_RTCCLKSource_LSI) || \
00260 ((SOURCE) == RCC_RTCCLKSource_HSE_Div2) || \
00261 ((SOURCE) == RCC_RTCCLKSource_HSE_Div4) || \
00262 ((SOURCE) == RCC_RTCCLKSource_HSE_Div8) || \
00263 ((SOURCE) == RCC_RTCCLKSource_HSE_Div16))
00264
00272 #define RCC_AHBPeriph_GPIOA RCC_AHBENR_GPIOAEN
00273 #define RCC_AHBPeriph_GPIOB RCC_AHBENR_GPIOBEN
00274 #define RCC_AHBPeriph_GPIOC RCC_AHBENR_GPIOCEN
00275 #define RCC_AHBPeriph_GPIOD RCC_AHBENR_GPIODEN
00276 #define RCC_AHBPeriph_GPIOE RCC_AHBENR_GPIOEEN
00277 #define RCC_AHBPeriph_GPIOH RCC_AHBENR_GPIOHEN
00278 #define RCC_AHBPeriph_GPIOF RCC_AHBENR_GPIOFEN
00279 #define RCC_AHBPeriph_GPIOG RCC_AHBENR_GPIOGEN
00280 #define RCC_AHBPeriph_CRC RCC_AHBENR_CRCEN
00281 #define RCC_AHBPeriph_FLITF RCC_AHBENR_FLITFEN
00282 #define RCC_AHBPeriph_SRAM RCC_AHBLPENR_SRAMLPEN
00283 #define RCC_AHBPeriph_DMA1 RCC_AHBENR_DMA1EN
00284 #define RCC_AHBPeriph_DMA2 RCC_AHBENR_DMA2EN
00285 #define RCC_AHBPeriph_AES RCC_AHBENR_AESEN
00286 #define RCC_AHBPeriph_FSMC RCC_AHBENR_FSMCEN
00287
00288 #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xB4FF6F00) == 0x00) && ((PERIPH) != 0x00))
00289 #define IS_RCC_AHB_LPMODE_PERIPH(PERIPH) ((((PERIPH) & 0xB4FF6F00) == 0x00) && ((PERIPH) != 0x00))
00290
00299 #define RCC_APB2Periph_SYSCFG RCC_APB2ENR_SYSCFGEN
00300 #define RCC_APB2Periph_TIM9 RCC_APB2ENR_TIM9EN
00301 #define RCC_APB2Periph_TIM10 RCC_APB2ENR_TIM10EN
00302 #define RCC_APB2Periph_TIM11 RCC_APB2ENR_TIM11EN
00303 #define RCC_APB2Periph_ADC1 RCC_APB2ENR_ADC1EN
00304 #define RCC_APB2Periph_SDIO RCC_APB2ENR_SDIOEN
00305 #define RCC_APB2Periph_SPI1 RCC_APB2ENR_SPI1EN
00306 #define RCC_APB2Periph_USART1 RCC_APB2ENR_USART1EN
00307
00308 #define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFA5E2) == 0x00) && ((PERIPH) != 0x00))
00309
00317 #define RCC_APB1Periph_TIM2 RCC_APB1ENR_TIM2EN
00318 #define RCC_APB1Periph_TIM3 RCC_APB1ENR_TIM3EN
00319 #define RCC_APB1Periph_TIM4 RCC_APB1ENR_TIM4EN
00320 #define RCC_APB1Periph_TIM5 RCC_APB1ENR_TIM5EN
00321 #define RCC_APB1Periph_TIM6 RCC_APB1ENR_TIM6EN
00322 #define RCC_APB1Periph_TIM7 RCC_APB1ENR_TIM7EN
00323 #define RCC_APB1Periph_LCD RCC_APB1ENR_LCDEN
00324 #define RCC_APB1Periph_WWDG RCC_APB1ENR_WWDGEN
00325 #define RCC_APB1Periph_SPI2 RCC_APB1ENR_SPI2EN
00326 #define RCC_APB1Periph_SPI3 RCC_APB1ENR_SPI3EN
00327 #define RCC_APB1Periph_USART2 RCC_APB1ENR_USART2EN
00328 #define RCC_APB1Periph_USART3 RCC_APB1ENR_USART3EN
00329 #define RCC_APB1Periph_UART4 RCC_APB1ENR_UART4EN
00330 #define RCC_APB1Periph_UART5 RCC_APB1ENR_UART5EN
00331 #define RCC_APB1Periph_I2C1 RCC_APB1ENR_I2C1EN
00332 #define RCC_APB1Periph_I2C2 RCC_APB1ENR_I2C2EN
00333 #define RCC_APB1Periph_USB RCC_APB1ENR_USBEN
00334 #define RCC_APB1Periph_PWR RCC_APB1ENR_PWREN
00335 #define RCC_APB1Periph_DAC RCC_APB1ENR_DACEN
00336 #define RCC_APB1Periph_COMP RCC_APB1ENR_COMPEN
00337
00338
00339 #define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x4F0135C0) == 0x00) && ((PERIPH) != 0x00))
00340
00348 #define RCC_MCOSource_NoClock ((uint8_t)0x00)
00349 #define RCC_MCOSource_SYSCLK ((uint8_t)0x01)
00350 #define RCC_MCOSource_HSI ((uint8_t)0x02)
00351 #define RCC_MCOSource_MSI ((uint8_t)0x03)
00352 #define RCC_MCOSource_HSE ((uint8_t)0x04)
00353 #define RCC_MCOSource_PLLCLK ((uint8_t)0x05)
00354 #define RCC_MCOSource_LSI ((uint8_t)0x06)
00355 #define RCC_MCOSource_LSE ((uint8_t)0x07)
00356
00357 #define IS_RCC_MCO_SOURCE(SOURCE) (((SOURCE) == RCC_MCOSource_NoClock) || ((SOURCE) == RCC_MCOSource_SYSCLK) || \
00358 ((SOURCE) == RCC_MCOSource_HSI) || ((SOURCE) == RCC_MCOSource_MSI) || \
00359 ((SOURCE) == RCC_MCOSource_HSE) || ((SOURCE) == RCC_MCOSource_PLLCLK) || \
00360 ((SOURCE) == RCC_MCOSource_LSI) || ((SOURCE) == RCC_MCOSource_LSE))
00361
00369 #define RCC_MCODiv_1 ((uint8_t)0x00)
00370 #define RCC_MCODiv_2 ((uint8_t)0x10)
00371 #define RCC_MCODiv_4 ((uint8_t)0x20)
00372 #define RCC_MCODiv_8 ((uint8_t)0x30)
00373 #define RCC_MCODiv_16 ((uint8_t)0x40)
00374
00375 #define IS_RCC_MCO_DIV(DIV) (((DIV) == RCC_MCODiv_1) || ((DIV) == RCC_MCODiv_2) || \
00376 ((DIV) == RCC_MCODiv_4) || ((DIV) == RCC_MCODiv_8) || \
00377 ((DIV) == RCC_MCODiv_16))
00378
00386 #define RCC_FLAG_HSIRDY ((uint8_t)0x21)
00387 #define RCC_FLAG_MSIRDY ((uint8_t)0x29)
00388 #define RCC_FLAG_HSERDY ((uint8_t)0x31)
00389 #define RCC_FLAG_PLLRDY ((uint8_t)0x39)
00390 #define RCC_FLAG_LSERDY ((uint8_t)0x49)
00391 #define RCC_FLAG_LSECSS ((uint8_t)0x4A)
00392 #define RCC_FLAG_LSIRDY ((uint8_t)0x41)
00393 #define RCC_FLAG_OBLRST ((uint8_t)0x59)
00394 #define RCC_FLAG_PINRST ((uint8_t)0x5A)
00395 #define RCC_FLAG_PORRST ((uint8_t)0x5B)
00396 #define RCC_FLAG_SFTRST ((uint8_t)0x5C)
00397 #define RCC_FLAG_IWDGRST ((uint8_t)0x5D)
00398 #define RCC_FLAG_WWDGRST ((uint8_t)0x5E)
00399 #define RCC_FLAG_LPWRRST ((uint8_t)0x5F)
00400
00401 #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
00402 ((FLAG) == RCC_FLAG_MSIRDY) || ((FLAG) == RCC_FLAG_PLLRDY) || \
00403 ((FLAG) == RCC_FLAG_LSERDY) || ((FLAG) == RCC_FLAG_LSIRDY) || \
00404 ((FLAG) == RCC_FLAG_PINRST) || ((FLAG) == RCC_FLAG_PORRST) || \
00405 ((FLAG) == RCC_FLAG_SFTRST) || ((FLAG) == RCC_FLAG_IWDGRST)|| \
00406 ((FLAG) == RCC_FLAG_WWDGRST)|| ((FLAG) == RCC_FLAG_LPWRRST)|| \
00407 ((FLAG) == RCC_FLAG_WWDGRST)|| ((FLAG) == RCC_FLAG_LSECSS))
00408
00409 #define IS_RCC_HSI_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
00410 #define IS_RCC_MSI_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x3F)
00411
00420
00421
00422
00423
00424 void RCC_DeInit(void);
00425
00426
00427 void RCC_HSEConfig(uint8_t RCC_HSE);
00428 ErrorStatus RCC_WaitForHSEStartUp(void);
00429 void RCC_MSIRangeConfig(uint32_t RCC_MSIRange);
00430 void RCC_AdjustMSICalibrationValue(uint8_t MSICalibrationValue);
00431 void RCC_MSICmd(FunctionalState NewState);
00432 void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue);
00433 void RCC_HSICmd(FunctionalState NewState);
00434 void RCC_LSEConfig(uint8_t RCC_LSE);
00435 void RCC_LSICmd(FunctionalState NewState);
00436 void RCC_PLLConfig(uint8_t RCC_PLLSource, uint8_t RCC_PLLMul, uint8_t RCC_PLLDiv);
00437 void RCC_PLLCmd(FunctionalState NewState);
00438 void RCC_ClockSecuritySystemCmd(FunctionalState NewState);
00439 void RCC_LSEClockSecuritySystemCmd(FunctionalState NewState);
00440 void RCC_MCOConfig(uint8_t RCC_MCOSource, uint8_t RCC_MCODiv);
00441
00442
00443 void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);
00444 uint8_t RCC_GetSYSCLKSource(void);
00445 void RCC_HCLKConfig(uint32_t RCC_SYSCLK);
00446 void RCC_PCLK1Config(uint32_t RCC_HCLK);
00447 void RCC_PCLK2Config(uint32_t RCC_HCLK);
00448 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks);
00449
00450
00451 void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource);
00452 void RCC_RTCCLKCmd(FunctionalState NewState);
00453 void RCC_RTCResetCmd(FunctionalState NewState);
00454
00455 void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
00456 void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
00457 void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
00458
00459 void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
00460 void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
00461 void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
00462
00463 void RCC_AHBPeriphClockLPModeCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
00464 void RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
00465 void RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
00466
00467
00468 void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState);
00469 FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG);
00470 void RCC_ClearFlag(void);
00471 ITStatus RCC_GetITStatus(uint8_t RCC_IT);
00472 void RCC_ClearITPendingBit(uint8_t RCC_IT);
00473
00474 #ifdef __cplusplus
00475 }
00476 #endif
00477
00478 #endif
00479
00488