47 #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
52 #define CR_OFFSET (RCC_OFFSET + 0x00)
53 #define HSION_BitNumber 0x00
54 #define CR_HSION_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))
57 #define PLLON_BitNumber 0x18
58 #define CR_PLLON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))
62 #define PLL2ON_BitNumber 0x1A
63 #define CR_PLL2ON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLL2ON_BitNumber * 4))
66 #define PLL3ON_BitNumber 0x1C
67 #define CR_PLL3ON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLL3ON_BitNumber * 4))
71 #define CSSON_BitNumber 0x13
72 #define CR_CSSON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))
77 #define CFGR_OFFSET (RCC_OFFSET + 0x04)
80 #define USBPRE_BitNumber 0x16
81 #define CFGR_USBPRE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (USBPRE_BitNumber * 4))
83 #define OTGFSPRE_BitNumber 0x16
84 #define CFGR_OTGFSPRE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (OTGFSPRE_BitNumber * 4))
90 #define BDCR_OFFSET (RCC_OFFSET + 0x20)
91 #define RTCEN_BitNumber 0x0F
92 #define BDCR_RTCEN_BB (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))
95 #define BDRST_BitNumber 0x10
96 #define BDCR_BDRST_BB (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))
101 #define CSR_OFFSET (RCC_OFFSET + 0x24)
102 #define LSION_BitNumber 0x00
103 #define CSR_LSION_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))
109 #define CFGR2_OFFSET (RCC_OFFSET + 0x2C)
110 #define I2S2SRC_BitNumber 0x11
111 #define CFGR2_I2S2SRC_BB (PERIPH_BB_BASE + (CFGR2_OFFSET * 32) + (I2S2SRC_BitNumber * 4))
114 #define I2S3SRC_BitNumber 0x12
115 #define CFGR2_I2S3SRC_BB (PERIPH_BB_BASE + (CFGR2_OFFSET * 32) + (I2S3SRC_BitNumber * 4))
121 #define CR_HSEBYP_Reset ((uint32_t)0xFFFBFFFF)
122 #define CR_HSEBYP_Set ((uint32_t)0x00040000)
123 #define CR_HSEON_Reset ((uint32_t)0xFFFEFFFF)
124 #define CR_HSEON_Set ((uint32_t)0x00010000)
125 #define CR_HSITRIM_Mask ((uint32_t)0xFFFFFF07)
128 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
129 #define CFGR_PLL_Mask ((uint32_t)0xFFC2FFFF)
131 #define CFGR_PLL_Mask ((uint32_t)0xFFC0FFFF)
134 #define CFGR_PLLMull_Mask ((uint32_t)0x003C0000)
135 #define CFGR_PLLSRC_Mask ((uint32_t)0x00010000)
136 #define CFGR_PLLXTPRE_Mask ((uint32_t)0x00020000)
137 #define CFGR_SWS_Mask ((uint32_t)0x0000000C)
138 #define CFGR_SW_Mask ((uint32_t)0xFFFFFFFC)
139 #define CFGR_HPRE_Reset_Mask ((uint32_t)0xFFFFFF0F)
140 #define CFGR_HPRE_Set_Mask ((uint32_t)0x000000F0)
141 #define CFGR_PPRE1_Reset_Mask ((uint32_t)0xFFFFF8FF)
142 #define CFGR_PPRE1_Set_Mask ((uint32_t)0x00000700)
143 #define CFGR_PPRE2_Reset_Mask ((uint32_t)0xFFFFC7FF)
144 #define CFGR_PPRE2_Set_Mask ((uint32_t)0x00003800)
145 #define CFGR_ADCPRE_Reset_Mask ((uint32_t)0xFFFF3FFF)
146 #define CFGR_ADCPRE_Set_Mask ((uint32_t)0x0000C000)
149 #define CSR_RMVF_Set ((uint32_t)0x01000000)
151 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
153 #define CFGR2_PREDIV1SRC ((uint32_t)0x00010000)
154 #define CFGR2_PREDIV1 ((uint32_t)0x0000000F)
157 #define CFGR2_PREDIV2 ((uint32_t)0x000000F0)
158 #define CFGR2_PLL2MUL ((uint32_t)0x00000F00)
159 #define CFGR2_PLL3MUL ((uint32_t)0x0000F000)
163 #define FLAG_Mask ((uint8_t)0x1F)
166 #define CIR_BYTE2_ADDRESS ((uint32_t)0x40021009)
169 #define CIR_BYTE3_ADDRESS ((uint32_t)0x4002100A)
172 #define CFGR_BYTE4_ADDRESS ((uint32_t)0x40021007)
175 #define BDCR_ADDRESS (PERIPH_BASE + BDCR_OFFSET)
193 static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
194 static __I uint8_t ADCPrescTable[4] = {2, 4, 6, 8};
220 RCC->CR |= (uint32_t)0x00000001;
224 RCC->CFGR &= (uint32_t)0xF8FF0000;
226 RCC->CFGR &= (uint32_t)0xF0FF0000;
230 RCC->CR &= (uint32_t)0xFEF6FFFF;
233 RCC->CR &= (uint32_t)0xFFFBFFFF;
236 RCC->CFGR &= (uint32_t)0xFF80FFFF;
240 RCC->CR &= (uint32_t)0xEBFFFFFF;
243 RCC->CIR = 0x00FF0000;
246 RCC->CFGR2 = 0x00000000;
247 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
249 RCC->CIR = 0x009F0000;
252 RCC->CFGR2 = 0x00000000;
255 RCC->CIR = 0x009F0000;
306 __IO uint32_t StartUpCounter = 0;
343 tmpreg |= (uint32_t)HSICalibrationValue << 3;
390 tmpreg |= RCC_PLLSource | RCC_PLLMul;
409 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
426 void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Source, uint32_t RCC_PREDIV1_Div)
431 assert_param(IS_RCC_PREDIV1_SOURCE(RCC_PREDIV1_Source));
436 tmpreg &= ~(CFGR2_PREDIV1 | CFGR2_PREDIV1SRC);
438 tmpreg |= RCC_PREDIV1_Source | RCC_PREDIV1_Div ;
454 void RCC_PREDIV2Config(uint32_t RCC_PREDIV2_Div)
463 tmpreg &= ~CFGR2_PREDIV2;
465 tmpreg |= RCC_PREDIV2_Div;
479 void RCC_PLL2Config(uint32_t RCC_PLL2Mul)
488 tmpreg &= ~CFGR2_PLL2MUL;
490 tmpreg |= RCC_PLL2Mul;
510 *(
__IO uint32_t *) CR_PLL2ON_BB = (uint32_t)NewState;
523 void RCC_PLL3Config(uint32_t RCC_PLL3Mul)
532 tmpreg &= ~CFGR2_PLL3MUL;
534 tmpreg |= RCC_PLL3Mul;
551 *(
__IO uint32_t *) CR_PLL3ON_BB = (uint32_t)NewState;
573 tmpreg |= RCC_SYSCLKSource;
617 tmpreg |= RCC_SYSCLK;
669 tmpreg |= RCC_HCLK << 3;
746 void RCC_OTGFSCLKConfig(uint32_t RCC_OTGFSCLKSource)
749 assert_param(IS_RCC_OTGFSCLK_SOURCE(RCC_OTGFSCLKSource));
751 *(
__IO uint32_t *) CFGR_OTGFSPRE_BB = RCC_OTGFSCLKSource;
792 void RCC_I2S2CLKConfig(uint32_t RCC_I2S2CLKSource)
797 *(
__IO uint32_t *) CFGR2_I2S2SRC_BB = RCC_I2S2CLKSource;
811 void RCC_I2S3CLKConfig(uint32_t RCC_I2S3CLKSource)
816 *(
__IO uint32_t *) CFGR2_I2S3SRC_BB = RCC_I2S3CLKSource;
884 RCC->BDCR |= RCC_RTCCLKSource;
910 uint32_t tmp = 0, pllmull = 0, pllsource = 0, presc = 0;
913 uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;
916 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
917 uint32_t prediv1factor = 0;
938 pllmull = ( pllmull >> 18) + 2;
940 if (pllsource == 0x00)
946 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
947 prediv1factor = (
RCC->CFGR2 & CFGR2_PREDIV1) + 1;
963 pllmull = pllmull >> 18;
974 if (pllsource == 0x00)
982 prediv1source =
RCC->CFGR2 & CFGR2_PREDIV1SRC;
983 prediv1factor = (
RCC->CFGR2 & CFGR2_PREDIV1) + 1;
985 if (prediv1source == 0)
993 prediv2factor = ((
RCC->CFGR2 & CFGR2_PREDIV2) >> 4) + 1;
994 pll2mull = ((
RCC->CFGR2 & CFGR2_PLL2MUL) >> 8 ) + 2;
1010 presc = APBAHBPrescTable[tmp];
1016 presc = APBAHBPrescTable[tmp];
1022 presc = APBAHBPrescTable[tmp];
1028 presc = ADCPrescTable[tmp];
1072 RCC->AHBENR |= RCC_AHBPeriph;
1076 RCC->AHBENR &= ~RCC_AHBPeriph;
1102 RCC->APB2ENR |= RCC_APB2Periph;
1106 RCC->APB2ENR &= ~RCC_APB2Periph;
1133 RCC->APB1ENR |= RCC_APB1Periph;
1137 RCC->APB1ENR &= ~RCC_APB1Periph;
1153 void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph,
FunctionalState NewState)
1161 RCC->AHBRSTR |= RCC_AHBPeriph;
1165 RCC->AHBRSTR &= ~RCC_AHBPeriph;
1192 RCC->APB2RSTR |= RCC_APB2Periph;
1196 RCC->APB2RSTR &= ~RCC_APB2Periph;
1223 RCC->APB1RSTR |= RCC_APB1Periph;
1227 RCC->APB1RSTR &= ~RCC_APB1Periph;
1329 uint32_t statusreg = 0;
1335 tmp = RCC_FLAG >> 5;
1338 statusreg =
RCC->CR;
1342 statusreg =
RCC->BDCR;
1346 statusreg =
RCC->CSR;
1351 if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)
RESET)
1409 if ((
RCC->CIR & RCC_IT) != (uint32_t)
RESET)