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