2067 |
kakl |
1 |
|
|
|
2 |
#include "stm32f10x_it.h" |
|
|
3 |
|
|
|
4 |
|
|
|
5 |
GPIO_InitTypeDef GPIO_InitStructure; |
|
|
6 |
ErrorStatus HSEStartUpStatus; |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
void RCC_Configuration(void); |
|
|
10 |
void Delay(vu32 nCount); |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
void SystemInit() |
|
|
15 |
{ |
|
|
16 |
|
|
|
17 |
/* Configure the system clocks */ |
|
|
18 |
RCC_Configuration(); |
|
|
19 |
|
|
|
20 |
/* NVIC Configuration */ |
|
|
21 |
// NVIC_Configuration(); |
|
|
22 |
|
|
|
23 |
/* Enable GPIOC clock */ |
|
|
24 |
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); |
|
|
25 |
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); |
|
|
26 |
|
|
|
27 |
/* Configure PC.4 as Output push-pull */ |
|
|
28 |
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; |
|
|
29 |
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; |
|
|
30 |
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
|
|
31 |
GPIO_Init(GPIOC, &GPIO_InitStructure); |
|
|
32 |
|
|
|
33 |
/* Configure PC.4 as Output push-pull */ |
|
|
34 |
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8; |
|
|
35 |
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; |
|
|
36 |
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
|
|
37 |
GPIO_Init(GPIOB, &GPIO_InitStructure); |
|
|
38 |
|
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
int main(void) |
|
|
43 |
{ |
|
|
44 |
while (1) |
|
|
45 |
{ |
|
|
46 |
GPIO_SetBits(GPIOC, GPIO_Pin_5); |
|
|
47 |
GPIO_ResetBits(GPIOC, GPIO_Pin_4); |
|
|
48 |
GPIO_SetBits(GPIOB, GPIO_Pin_7); |
|
|
49 |
GPIO_ResetBits(GPIOB, GPIO_Pin_8); |
2079 |
kakl |
50 |
Delay(0xffFFFF); |
2067 |
kakl |
51 |
|
|
|
52 |
GPIO_SetBits(GPIOC, GPIO_Pin_4); |
|
|
53 |
GPIO_ResetBits(GPIOC, GPIO_Pin_5); |
|
|
54 |
GPIO_SetBits(GPIOB, GPIO_Pin_8); |
|
|
55 |
GPIO_ResetBits(GPIOB, GPIO_Pin_7); |
2079 |
kakl |
56 |
Delay(0xffFFFF); |
2067 |
kakl |
57 |
} |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
/******************************************************************************* |
|
|
61 |
* Function Name : RCC_Configuration |
|
|
62 |
* Description : Configures the different system clocks. |
|
|
63 |
* Input : None |
|
|
64 |
* Output : None |
|
|
65 |
* Return : None |
|
|
66 |
*******************************************************************************/ |
|
|
67 |
void RCC_Configuration(void) |
|
|
68 |
{ |
|
|
69 |
/* RCC system reset(for debug purpose) */ |
|
|
70 |
RCC_DeInit(); |
|
|
71 |
|
|
|
72 |
/* Enable HSE */ |
|
|
73 |
RCC_HSEConfig(RCC_HSE_ON); |
|
|
74 |
|
|
|
75 |
/* Wait till HSE is ready */ |
|
|
76 |
HSEStartUpStatus = RCC_WaitForHSEStartUp(); |
|
|
77 |
|
|
|
78 |
if(HSEStartUpStatus == SUCCESS) |
|
|
79 |
{ |
|
|
80 |
/* Enable Prefetch Buffer */ |
|
|
81 |
// FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); |
|
|
82 |
|
|
|
83 |
/* Flash 2 wait state */ |
|
|
84 |
// FLASH_SetLatency(FLASH_Latency_2); |
|
|
85 |
|
|
|
86 |
/* HCLK = SYSCLK */ |
|
|
87 |
RCC_HCLKConfig(RCC_SYSCLK_Div1); |
|
|
88 |
|
|
|
89 |
/* PCLK2 = HCLK */ |
|
|
90 |
RCC_PCLK2Config(RCC_HCLK_Div1); |
|
|
91 |
|
|
|
92 |
/* PCLK1 = HCLK/2 */ |
|
|
93 |
RCC_PCLK1Config(RCC_HCLK_Div2); |
|
|
94 |
|
|
|
95 |
/* PLLCLK = 8MHz * 4 = 32 MHz */ |
|
|
96 |
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_2); |
|
|
97 |
|
|
|
98 |
/* Enable PLL */ |
|
|
99 |
RCC_PLLCmd(ENABLE); |
|
|
100 |
|
|
|
101 |
/* Wait till PLL is ready */ |
|
|
102 |
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) |
|
|
103 |
{ |
|
|
104 |
} |
|
|
105 |
|
|
|
106 |
/* Select PLL as system clock source */ |
|
|
107 |
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); |
|
|
108 |
|
|
|
109 |
/* Wait till PLL is used as system clock source */ |
|
|
110 |
while(RCC_GetSYSCLKSource() != 0x08) |
|
|
111 |
{ |
|
|
112 |
} |
|
|
113 |
} |
|
|
114 |
} |
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
/******************************************************************************* |
|
|
119 |
* Function Name : Delay |
|
|
120 |
* Description : Inserts a delay time. |
|
|
121 |
* Input : nCount: specifies the delay time length. |
|
|
122 |
* Output : None |
|
|
123 |
* Return : None |
|
|
124 |
*******************************************************************************/ |
|
|
125 |
void Delay(vu32 nCount) |
|
|
126 |
{ |
|
|
127 |
for(; nCount != 0; nCount--); |
|
|
128 |
} |
|
|
129 |
|