Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : hw_config.c |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 10/01/2006 : V1.0 |
||
5 | * Description : Hardware Configuration & Setup |
||
6 | ******************************************************************************** |
||
7 | * History: |
||
8 | * 10/01/2006 : V1.0 |
||
9 | ******************************************************************************** |
||
10 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
||
11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
||
12 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
||
13 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
||
14 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
||
15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
16 | *******************************************************************************/ |
||
17 | /* Includes ------------------------------------------------------------------*/ |
||
18 | #include "91x_lib.h" |
||
19 | #include "usb_lib.h" |
||
20 | #include "usb_prop.h" |
||
21 | #include "hw_config.h" |
||
22 | #include "usb_mem.h" |
||
23 | /* Private typedef -----------------------------------------------------------*/ |
||
24 | /* Private define ------------------------------------------------------------*/ |
||
25 | /* Private macro -------------------------------------------------------------*/ |
||
26 | /* Private variables ---------------------------------------------------------*/ |
||
27 | GPIO_InitTypeDef GPIO_InitStructure; |
||
28 | UART_InitTypeDef UART_InitStructure; |
||
29 | /* External variables --------------------------------------------------------*/ |
||
30 | extern u8 buffer_in[]; |
||
31 | extern u32 count_in; |
||
32 | extern LINE_CODING linecoding; |
||
33 | /* Private function prototypes -----------------------------------------------*/ |
||
34 | /* Private functions ---------------------------------------------------------*/ |
||
35 | /******************************************************************************* |
||
36 | * Function Name : Set_System. |
||
37 | * Description : Configures Main system clocks & power |
||
38 | * Input : None. |
||
39 | * Return : None. |
||
40 | *******************************************************************************/ |
||
41 | void Set_System(void) |
||
42 | { |
||
43 | /* SCU_MCLKSourceConfig(SCU_MCLK_OSC); |
||
44 | FMI_Config(FMI_READ_WAIT_STATE_2,FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE,\ |
||
45 | FMI_LVD_ENABLE,FMI_FREQ_HIGH); |
||
46 | SCU_PLLFactorsConfig(192,25,2); |
||
47 | SCU_PLLCmd(ENABLE); |
||
48 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); |
||
49 | |||
50 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); |
||
51 | SCU_AHBPeriphReset(__VIC,DISABLE);*/ |
||
52 | /*USB clock = MCLK= 48MHz*/ |
||
53 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
||
54 | /*Enable USB clock*/ |
||
55 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
||
56 | SCU_AHBPeriphReset(__USB,DISABLE); |
||
57 | |||
58 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
||
59 | |||
60 | /* Enable the UART0 Clock */ |
||
61 | SCU_APBPeriphClockConfig(__UART0, ENABLE); |
||
62 | SCU_AHBPeriphReset(__UART0,DISABLE); |
||
63 | |||
64 | /* Enable the GPIO2 Clock */ |
||
65 | SCU_APBPeriphClockConfig(__GPIO2, ENABLE); |
||
66 | SCU_AHBPeriphReset(__GPIO2,DISABLE); |
||
67 | /* Enable the GPIO3 Clock */ |
||
68 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); |
||
69 | SCU_AHBPeriphReset(__GPIO3,DISABLE); |
||
70 | /* Enable the GPIO5 Clock */ |
||
71 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
||
72 | SCU_AHBPeriphReset(__GPIO5,DISABLE); |
||
73 | |||
74 | /*Configure GPIO0 (D+ Pull-Up on P0.1)*/ |
||
75 | |||
76 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
||
77 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
||
78 | |||
79 | GPIO_DeInit(GPIO0); |
||
80 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
81 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
||
82 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
||
83 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
||
84 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
||
85 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
||
86 | |||
87 | /*Configure UART0_CTS P2.0*/ |
||
88 | GPIO_DeInit(GPIO2); |
||
89 | /*After DeInit function P2.0 = UART0_CTS (defaut configuration)*/ |
||
90 | |||
91 | GPIO_DeInit(GPIO5); |
||
92 | /*Gonfigure UART0_Rx pin GPIO5.1*/ |
||
93 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
||
94 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
||
95 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
||
96 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
||
97 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
||
98 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
||
99 | |||
100 | GPIO_DeInit(GPIO3); |
||
101 | /*Gonfigure UART0_Tx pin GPIO3.4*/ |
||
102 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
||
103 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
||
104 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
||
105 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; |
||
106 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
||
107 | |||
108 | /*Gonfigure UART0_RTS pin GPIO3.3*/ |
||
109 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
110 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
||
111 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
||
112 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
||
113 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; |
||
114 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
||
115 | |||
116 | UART_DeInit(UART0); |
||
117 | /* Enable the UART Receive interrupt: this interrupt is generated when the UART0 |
||
118 | receive FIFO hold two data */ |
||
119 | UART_ITConfig(UART0, UART_IT_Receive, ENABLE); |
||
120 | |||
121 | VIC_DeInit(); |
||
122 | VIC_Config(UART0_ITLine, VIC_IRQ, 2); |
||
123 | VIC_ITCmd(UART0_ITLine, ENABLE); |
||
124 | } |
||
125 | /******************************************************************************* |
||
126 | * Function Name : USB_Cable_Config |
||
127 | * Description : Software Connection/Disconnection of USB Cable |
||
128 | * Input : None. |
||
129 | * Return : Status |
||
130 | *******************************************************************************/ |
||
131 | void USB_Cable_Config (FunctionalState NewState) |
||
132 | { |
||
133 | |||
134 | if (NewState == ENABLE) |
||
135 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
||
136 | else |
||
137 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
||
138 | |||
139 | } |
||
140 | /******************************************************************************* |
||
141 | * Function Name : Enter_LowPowerMode. |
||
142 | * Description : |
||
143 | * Input : None. |
||
144 | * Return : None. |
||
145 | *******************************************************************************/ |
||
146 | void Enter_LowPowerMode(void) |
||
147 | { |
||
148 | } |
||
149 | /******************************************************************************* |
||
150 | * Function Name : Leave_LowPowerMode. |
||
151 | * Description : |
||
152 | * Input : None. |
||
153 | * Return : None. |
||
154 | *******************************************************************************/ |
||
155 | void Leave_LowPowerMode(void) |
||
156 | { |
||
157 | } |
||
158 | /******************************************************************************* |
||
159 | * Function Name : USB_Interrupts_Config. |
||
160 | * Description : configure and enable the USB interrupt Lines. |
||
161 | * Input : None. |
||
162 | * Return : None. |
||
163 | *******************************************************************************/ |
||
164 | void USB_Interrupts_Config(void) |
||
165 | { |
||
166 | |||
167 | } |
||
168 | /******************************************************************************* |
||
169 | * Function Name : UART0_Config_Default. |
||
170 | * Description : configure the UART 0 with default values. |
||
171 | * Input : None. |
||
172 | * Return : None. |
||
173 | *******************************************************************************/ |
||
174 | void UART0_Config_Default (void) |
||
175 | { |
||
176 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
||
177 | UART_InitStructure.UART_Parity = UART_Parity_No; |
||
178 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
||
179 | UART_InitStructure.UART_BaudRate = 115200; |
||
180 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RTS_CTS; |
||
181 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
||
182 | UART_InitStructure.UART_FIFO = UART_FIFO_Disable; |
||
183 | UART_Init(UART0, &UART_InitStructure); |
||
184 | UART_Cmd(UART0, ENABLE); |
||
185 | } |
||
186 | /******************************************************************************* |
||
187 | * Function Name : UART0_Config. |
||
188 | * Description : Configure the UART 0 according to the linecoding structure. |
||
189 | * Input : None. |
||
190 | * Return : Configuration status |
||
191 | TRUE : configuration done with success |
||
192 | FALSE : configuration aborted. |
||
193 | *******************************************************************************/ |
||
194 | bool UART0_Config(void) |
||
195 | { |
||
196 | /* set the bit rate*/ |
||
197 | if (linecoding.bitrate > 460800) |
||
198 | { |
||
199 | UART0_Config_Default(); |
||
200 | return (FALSE); |
||
201 | } |
||
202 | /* set the Stop bit*/ |
||
203 | switch (linecoding.format) |
||
204 | { |
||
205 | case 0: UART_InitStructure.UART_StopBits = UART_StopBits_1; |
||
206 | break; |
||
207 | case 2: UART_InitStructure.UART_StopBits = UART_StopBits_2; |
||
208 | break; |
||
209 | default : |
||
210 | { |
||
211 | UART0_Config_Default(); |
||
212 | return (FALSE); |
||
213 | } |
||
214 | } |
||
215 | /* set the parity bit*/ |
||
216 | switch (linecoding.paritytype) |
||
217 | { |
||
218 | case 0: UART_InitStructure.UART_Parity = UART_Parity_No; |
||
219 | break; |
||
220 | case 1: UART_InitStructure.UART_Parity = UART_Parity_Even; |
||
221 | break; |
||
222 | case 2: UART_InitStructure.UART_Parity = UART_Parity_Odd; |
||
223 | break; |
||
224 | case 3: UART_InitStructure.UART_Parity = UART_Parity_OddStick; |
||
225 | break; |
||
226 | case 4: UART_InitStructure.UART_Parity = UART_Parity_EvenStick; |
||
227 | break; |
||
228 | default : |
||
229 | { |
||
230 | UART0_Config_Default(); |
||
231 | return (FALSE); |
||
232 | } |
||
233 | } |
||
234 | /*set the data type*/ |
||
235 | switch (linecoding.datatype) |
||
236 | { |
||
237 | case 0x08: UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
||
238 | break; |
||
239 | case 0x07: UART_InitStructure.UART_WordLength = UART_WordLength_7D; |
||
240 | break; |
||
241 | case 0x06: UART_InitStructure.UART_WordLength = UART_WordLength_6D; |
||
242 | break; |
||
243 | case 0x05: UART_InitStructure.UART_WordLength = UART_WordLength_5D; |
||
244 | break; |
||
245 | default : |
||
246 | { |
||
247 | UART0_Config_Default(); |
||
248 | return (FALSE); |
||
249 | } |
||
250 | } |
||
251 | |||
252 | UART_InitStructure.UART_BaudRate = linecoding.bitrate; |
||
253 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RTS_CTS; |
||
254 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
||
255 | UART_InitStructure.UART_FIFO = UART_FIFO_Disable; |
||
256 | UART_Init(UART0, &UART_InitStructure); |
||
257 | UART_Cmd(UART0, ENABLE); |
||
258 | return (TRUE); |
||
259 | } |
||
260 | /******************************************************************************* |
||
261 | * Function Name : USB_To_UART_Send_Data. |
||
262 | * Description : send the received data from USB to the UART 0. |
||
263 | * Input : data_buffer: data address. |
||
264 | Nb_bytes: number of bytes to send. |
||
265 | * Return : none. |
||
266 | *******************************************************************************/ |
||
267 | void USB_To_UART_Send_Data(u8* data_buffer, u8 Nb_bytes) |
||
268 | { |
||
269 | u32 i; |
||
270 | |||
271 | for(i=0;i<Nb_bytes;i++) |
||
272 | { |
||
273 | UART_SendData(UART0, *(data_buffer + i)); |
||
274 | } |
||
275 | } |
||
276 | /******************************************************************************* |
||
277 | * Function Name : UART_To_USB_Send_Data. |
||
278 | * Description : send the received data from UART 0 to USB. |
||
279 | * Input : None. |
||
280 | * Return : none. |
||
281 | *******************************************************************************/ |
||
282 | void UART_To_USB_Send_Data(void) |
||
283 | { |
||
284 | buffer_in[count_in] = UART_ReceiveData(UART0); |
||
285 | count_in++; |
||
286 | UserToPMABufferCopy(buffer_in, ENDP1_TXADDR, count_in); |
||
287 | SetEPTxCount(ENDP1,count_in); |
||
288 | SetEPTxValid(ENDP1); |
||
289 | } |
||
290 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
||
291 | |||
292 |