Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm3210b_eval.c | |
4 * @author MCD Application Team | |
5 * @version V4.5.0 | |
6 * @date 07-March-2011 | |
7 * @brief This file provides | |
8 * - set of firmware functions to manage Leds, push-button and COM ports | |
9 * - low level initialization functions for SD card (on SPI), SPI serial | |
10 * flash (sFLASH) and temperature sensor (LM75) | |
11 * available on STM3210B-EVAL evaluation board from STMicroelectronics. | |
12 ****************************************************************************** | |
13 * @attention | |
14 * | |
15 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
16 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
17 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
18 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
19 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
20 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
21 * | |
22 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
23 ****************************************************************************** | |
24 */ | |
25 | |
26 /* Includes ------------------------------------------------------------------*/ | |
27 #include "stm3210b_eval.h" | |
28 | |
29 /** @addtogroup Utilities | |
30 * @{ | |
31 */ | |
32 | |
33 /** @addtogroup STM32_EVAL | |
34 * @{ | |
35 */ | |
36 | |
37 /** @addtogroup STM3210B_EVAL | |
38 * @{ | |
39 */ | |
40 | |
41 /** @defgroup STM3210B_EVAL_LOW_LEVEL | |
42 * @brief This file provides firmware functions to manage Leds, push-buttons, | |
43 * COM ports, SD card on SPI, serial flash (sFLASH), serial EEPROM (sEE) | |
44 * and temperature sensor (LM75) available on STM3210B-EVAL evaluation | |
45 * board from STMicroelectronics. | |
46 * @{ | |
47 */ | |
48 | |
49 /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_TypesDefinitions | |
50 * @{ | |
51 */ | |
52 /** | |
53 * @} | |
54 */ | |
55 | |
56 | |
57 /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Defines | |
58 * @{ | |
59 */ | |
60 /** | |
61 * @} | |
62 */ | |
63 | |
64 | |
65 /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Macros | |
66 * @{ | |
67 */ | |
68 /** | |
69 * @} | |
70 */ | |
71 | |
72 | |
73 /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Variables | |
74 * @{ | |
75 */ | |
76 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT, | |
77 LED4_GPIO_PORT}; | |
78 const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN, | |
79 LED4_PIN}; | |
80 const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK, | |
81 LED4_GPIO_CLK}; | |
82 | |
83 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT, | |
84 KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT, | |
85 LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT, | |
86 DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT}; | |
87 | |
88 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN, | |
89 KEY_BUTTON_PIN, RIGHT_BUTTON_PIN, | |
90 LEFT_BUTTON_PIN, UP_BUTTON_PIN, | |
91 DOWN_BUTTON_PIN, SEL_BUTTON_PIN}; | |
92 | |
93 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK, | |
94 KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK, | |
95 LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK, | |
96 DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK}; | |
97 | |
98 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE, | |
99 TAMPER_BUTTON_EXTI_LINE, | |
100 KEY_BUTTON_EXTI_LINE, | |
101 RIGHT_BUTTON_EXTI_LINE, | |
102 LEFT_BUTTON_EXTI_LINE, | |
103 UP_BUTTON_EXTI_LINE, | |
104 DOWN_BUTTON_EXTI_LINE, | |
105 SEL_BUTTON_EXTI_LINE}; | |
106 | |
107 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE, | |
108 TAMPER_BUTTON_EXTI_PORT_SOURCE, | |
109 KEY_BUTTON_EXTI_PORT_SOURCE, | |
110 RIGHT_BUTTON_EXTI_PORT_SOURCE, | |
111 LEFT_BUTTON_EXTI_PORT_SOURCE, | |
112 UP_BUTTON_EXTI_PORT_SOURCE, | |
113 DOWN_BUTTON_EXTI_PORT_SOURCE, | |
114 SEL_BUTTON_EXTI_PORT_SOURCE}; | |
115 | |
116 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE, | |
117 TAMPER_BUTTON_EXTI_PIN_SOURCE, | |
118 KEY_BUTTON_EXTI_PIN_SOURCE, | |
119 RIGHT_BUTTON_EXTI_PIN_SOURCE, | |
120 LEFT_BUTTON_EXTI_PIN_SOURCE, | |
121 UP_BUTTON_EXTI_PIN_SOURCE, | |
122 DOWN_BUTTON_EXTI_PIN_SOURCE, | |
123 SEL_BUTTON_EXTI_PIN_SOURCE}; | |
124 | |
125 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn, | |
126 KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn, | |
127 LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn, | |
128 DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn}; | |
129 | |
130 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2}; | |
131 | |
132 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT}; | |
133 | |
134 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT}; | |
135 | |
136 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK}; | |
137 | |
138 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK}; | |
139 | |
140 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK}; | |
141 | |
142 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN}; | |
143 | |
144 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN}; | |
145 | |
146 | |
147 /** | |
148 * @} | |
149 */ | |
150 | |
151 | |
152 /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_FunctionPrototypes | |
153 * @{ | |
154 */ | |
155 | |
156 /** | |
157 * @} | |
158 */ | |
159 | |
160 | |
161 /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Functions | |
162 * @{ | |
163 */ | |
164 | |
165 /** | |
166 * @brief Configures LED GPIO. | |
167 * @param Led: Specifies the Led to be configured. | |
168 * This parameter can be one of following parameters: | |
169 * @arg LED1 | |
170 * @arg LED2 | |
171 * @arg LED3 | |
172 * @arg LED4 | |
173 * @retval None | |
174 */ | |
175 void STM_EVAL_LEDInit(Led_TypeDef Led) | |
176 { | |
177 GPIO_InitTypeDef GPIO_InitStructure; | |
178 | |
179 /* Enable the GPIO_LED Clock */ | |
180 RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE); | |
181 | |
182 /* Configure the GPIO_LED pin */ | |
183 GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led]; | |
184 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
185 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
186 | |
187 GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure); | |
188 } | |
189 | |
190 /** | |
191 * @brief Turns selected LED On. | |
192 * @param Led: Specifies the Led to be set on. | |
193 * This parameter can be one of following parameters: | |
194 * @arg LED1 | |
195 * @arg LED2 | |
196 * @arg LED3 | |
197 * @arg LED4 | |
198 * @retval None | |
199 */ | |
200 void STM_EVAL_LEDOn(Led_TypeDef Led) | |
201 { | |
202 GPIO_PORT[Led]->BSRR = GPIO_PIN[Led]; | |
203 } | |
204 | |
205 /** | |
206 * @brief Turns selected LED Off. | |
207 * @param Led: Specifies the Led to be set off. | |
208 * This parameter can be one of following parameters: | |
209 * @arg LED1 | |
210 * @arg LED2 | |
211 * @arg LED3 | |
212 * @arg LED4 | |
213 * @retval None | |
214 */ | |
215 void STM_EVAL_LEDOff(Led_TypeDef Led) | |
216 { | |
217 GPIO_PORT[Led]->BRR = GPIO_PIN[Led]; | |
218 } | |
219 | |
220 /** | |
221 * @brief Toggles the selected LED. | |
222 * @param Led: Specifies the Led to be toggled. | |
223 * This parameter can be one of following parameters: | |
224 * @arg LED1 | |
225 * @arg LED2 | |
226 * @arg LED3 | |
227 * @arg LED4 | |
228 * @retval None | |
229 */ | |
230 void STM_EVAL_LEDToggle(Led_TypeDef Led) | |
231 { | |
232 GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led]; | |
233 } | |
234 | |
235 /** | |
236 * @brief Configures Button GPIO and EXTI Line. | |
237 * @param Button: Specifies the Button to be configured. | |
238 * This parameter can be one of following parameters: | |
239 * @arg BUTTON_WAKEUP: Wakeup Push Button | |
240 * @arg BUTTON_TAMPER: Tamper Push Button | |
241 * @arg BUTTON_KEY: Key Push Button | |
242 * @arg BUTTON_RIGHT: Joystick Right Push Button | |
243 * @arg BUTTON_LEFT: Joystick Left Push Button | |
244 * @arg BUTTON_UP: Joystick Up Push Button | |
245 * @arg BUTTON_DOWN: Joystick Down Push Button | |
246 * @arg BUTTON_SEL: Joystick Sel Push Button | |
247 * @param Button_Mode: Specifies Button mode. | |
248 * This parameter can be one of following parameters: | |
249 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO | |
250 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt | |
251 * generation capability | |
252 * @retval None | |
253 */ | |
254 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) | |
255 { | |
256 GPIO_InitTypeDef GPIO_InitStructure; | |
257 EXTI_InitTypeDef EXTI_InitStructure; | |
258 NVIC_InitTypeDef NVIC_InitStructure; | |
259 | |
260 /* Enable the BUTTON Clock */ | |
261 RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE); | |
262 | |
263 /* Configure Button pin as input floating */ | |
264 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
265 GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button]; | |
266 GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure); | |
267 | |
268 | |
269 if (Button_Mode == BUTTON_MODE_EXTI) | |
270 { | |
271 /* Connect Button EXTI Line to Button GPIO Pin */ | |
272 GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]); | |
273 | |
274 /* Configure Button EXTI line */ | |
275 EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button]; | |
276 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; | |
277 | |
278 if(Button != BUTTON_WAKEUP) | |
279 { | |
280 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; | |
281 } | |
282 else | |
283 { | |
284 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; | |
285 } | |
286 EXTI_InitStructure.EXTI_LineCmd = ENABLE; | |
287 EXTI_Init(&EXTI_InitStructure); | |
288 | |
289 /* Enable and set Button EXTI Interrupt to the lowest priority */ | |
290 NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button]; | |
291 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; | |
292 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; | |
293 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | |
294 | |
295 NVIC_Init(&NVIC_InitStructure); | |
296 } | |
297 } | |
298 | |
299 /** | |
300 * @brief Returns the selected Button state. | |
301 * @param Button: Specifies the Button to be checked. | |
302 * This parameter can be one of following parameters: | |
303 * @arg BUTTON_WAKEUP: Wakeup Push Button | |
304 * @arg BUTTON_TAMPER: Tamper Push Button | |
305 * @arg BUTTON_KEY: Key Push Button | |
306 * @arg BUTTON_RIGHT: Joystick Right Push Button | |
307 * @arg BUTTON_LEFT: Joystick Left Push Button | |
308 * @arg BUTTON_UP: Joystick Up Push Button | |
309 * @arg BUTTON_DOWN: Joystick Down Push Button | |
310 * @arg BUTTON_SEL: Joystick Sel Push Button | |
311 * @retval The Button GPIO pin value. | |
312 */ | |
313 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button) | |
314 { | |
315 return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]); | |
316 } | |
317 | |
318 /** | |
319 * @brief Configures COM port. | |
320 * @param COM: Specifies the COM port to be configured. | |
321 * This parameter can be one of following parameters: | |
322 * @arg COM1 | |
323 * @arg COM2 | |
324 * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that | |
325 * contains the configuration information for the specified USART peripheral. | |
326 * @retval None | |
327 */ | |
328 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct) | |
329 { | |
330 GPIO_InitTypeDef GPIO_InitStructure; | |
331 | |
332 /* Enable GPIO clock */ | |
333 RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE); | |
334 | |
335 if (COM == COM1) | |
336 { | |
337 RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); | |
338 } | |
339 else | |
340 { | |
341 /* Enable the USART2 Pins Software Remapping */ | |
342 GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); | |
343 RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE); | |
344 } | |
345 | |
346 /* Configure USART Tx as alternate function push-pull */ | |
347 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
348 GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM]; | |
349 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
350 GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure); | |
351 | |
352 | |
353 /* Configure USART Rx as input floating */ | |
354 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
355 GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM]; | |
356 GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure); | |
357 | |
358 /* USART configuration */ | |
359 USART_Init(COM_USART[COM], USART_InitStruct); | |
360 | |
361 /* Enable USART */ | |
362 USART_Cmd(COM_USART[COM], ENABLE); | |
363 } | |
364 | |
365 /** | |
366 * @brief DeInitializes the SD/SD communication. | |
367 * @param None | |
368 * @retval None | |
369 */ | |
370 void SD_LowLevel_DeInit(void) | |
371 { | |
372 GPIO_InitTypeDef GPIO_InitStructure; | |
373 | |
374 SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */ | |
375 SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */ | |
376 | |
377 /*!< SD_SPI Periph clock disable */ | |
378 RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE); | |
379 | |
380 /*!< Configure SD_SPI pins: SCK */ | |
381 GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; | |
382 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
383 GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
384 | |
385 /*!< Configure SD_SPI pins: MISO */ | |
386 GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; | |
387 GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
388 | |
389 /*!< Configure SD_SPI pins: MOSI */ | |
390 GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; | |
391 GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
392 | |
393 /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ | |
394 GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; | |
395 GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); | |
396 | |
397 /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ | |
398 GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; | |
399 GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); | |
400 } | |
401 | |
402 /** | |
403 * @brief Initializes the SD_SPI and CS pins. | |
404 * @param None | |
405 * @retval None | |
406 */ | |
407 void SD_LowLevel_Init(void) | |
408 { | |
409 GPIO_InitTypeDef GPIO_InitStructure; | |
410 SPI_InitTypeDef SPI_InitStructure; | |
411 | |
412 /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO | |
413 and SD_SPI_SCK_GPIO Periph clock enable */ | |
414 RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK | | |
415 SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE); | |
416 | |
417 /*!< SD_SPI Periph clock enable */ | |
418 RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE); | |
419 | |
420 | |
421 /*!< Configure SD_SPI pins: SCK */ | |
422 GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; | |
423 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
424 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
425 GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
426 | |
427 /*!< Configure SD_SPI pins: MOSI */ | |
428 GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; | |
429 GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
430 | |
431 /*!< Configure SD_SPI pins: MISO */ | |
432 GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; | |
433 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
434 GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
435 | |
436 /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ | |
437 GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; | |
438 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
439 GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); | |
440 | |
441 /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ | |
442 GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; | |
443 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; | |
444 GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); | |
445 | |
446 /*!< SD_SPI Config */ | |
447 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; | |
448 SPI_InitStructure.SPI_Mode = SPI_Mode_Master; | |
449 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; | |
450 SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; | |
451 SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; | |
452 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; | |
453 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; | |
454 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; | |
455 SPI_InitStructure.SPI_CRCPolynomial = 7; | |
456 SPI_Init(SD_SPI, &SPI_InitStructure); | |
457 | |
458 SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */ | |
459 } | |
460 | |
461 /** | |
462 * @brief DeInitializes the peripherals used by the SPI FLASH driver. | |
463 * @param None | |
464 * @retval None | |
465 */ | |
466 void sFLASH_LowLevel_DeInit(void) | |
467 { | |
468 GPIO_InitTypeDef GPIO_InitStructure; | |
469 | |
470 /*!< Disable the sFLASH_SPI */ | |
471 SPI_Cmd(sFLASH_SPI, DISABLE); | |
472 | |
473 /*!< DeInitializes the sFLASH_SPI */ | |
474 SPI_I2S_DeInit(sFLASH_SPI); | |
475 | |
476 /*!< sFLASH_SPI Periph clock disable */ | |
477 RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE); | |
478 | |
479 /*!< Configure sFLASH_SPI pins: SCK */ | |
480 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN; | |
481 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
482 GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
483 | |
484 /*!< Configure sFLASH_SPI pins: MISO */ | |
485 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN; | |
486 GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
487 | |
488 /*!< Configure sFLASH_SPI pins: MOSI */ | |
489 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN; | |
490 GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
491 | |
492 /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ | |
493 GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; | |
494 GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); | |
495 } | |
496 | |
497 /** | |
498 * @brief Initializes the peripherals used by the SPI FLASH driver. | |
499 * @param None | |
500 * @retval None | |
501 */ | |
502 void sFLASH_LowLevel_Init(void) | |
503 { | |
504 GPIO_InitTypeDef GPIO_InitStructure; | |
505 | |
506 /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO | |
507 and sFLASH_SPI_SCK_GPIO Periph clock enable */ | |
508 RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK | | |
509 sFLASH_SPI_SCK_GPIO_CLK, ENABLE); | |
510 | |
511 /*!< sFLASH_SPI Periph clock enable */ | |
512 RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE); | |
513 | |
514 /*!< Configure sFLASH_SPI pins: SCK */ | |
515 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN; | |
516 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
517 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
518 GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
519 | |
520 /*!< Configure sFLASH_SPI pins: MOSI */ | |
521 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN; | |
522 GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
523 | |
524 /*!< Configure sFLASH_SPI pins: MISO */ | |
525 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN; | |
526 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
527 GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
528 | |
529 /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ | |
530 GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; | |
531 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
532 GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); | |
533 } | |
534 | |
535 /** | |
536 * @brief DeInitializes the LM75_I2C. | |
537 * @param None | |
538 * @retval None | |
539 */ | |
540 void LM75_LowLevel_DeInit(void) | |
541 { | |
542 GPIO_InitTypeDef GPIO_InitStructure; | |
543 | |
544 /*!< Disable LM75_I2C */ | |
545 I2C_Cmd(LM75_I2C, DISABLE); | |
546 /*!< DeInitializes the LM75_I2C */ | |
547 I2C_DeInit(LM75_I2C); | |
548 | |
549 /*!< LM75_I2C Periph clock disable */ | |
550 RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE); | |
551 | |
552 /*!< Configure LM75_I2C pins: SCL */ | |
553 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN; | |
554 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
555 GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
556 | |
557 /*!< Configure LM75_I2C pins: SDA */ | |
558 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN; | |
559 GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
560 | |
561 /*!< Configure LM75_I2C pin: SMBUS ALERT */ | |
562 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN; | |
563 GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); | |
564 } | |
565 | |
566 /** | |
567 * @brief Initializes the LM75_I2C. | |
568 * @param None | |
569 * @retval None | |
570 */ | |
571 void LM75_LowLevel_Init(void) | |
572 { | |
573 GPIO_InitTypeDef GPIO_InitStructure; | |
574 | |
575 /*!< LM75_I2C Periph clock enable */ | |
576 RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE); | |
577 | |
578 /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK | |
579 and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */ | |
580 RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK | | |
581 LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE); | |
582 | |
583 /*!< Configure LM75_I2C pins: SCL */ | |
584 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN; | |
585 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
586 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; | |
587 GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
588 | |
589 /*!< Configure LM75_I2C pins: SDA */ | |
590 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN; | |
591 GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
592 | |
593 /*!< Configure LM75_I2C pin: SMBUS ALERT */ | |
594 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN; | |
595 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; | |
596 GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); | |
597 } | |
598 | |
599 /** | |
600 * @} | |
601 */ | |
602 | |
603 | |
604 /** | |
605 * @} | |
606 */ | |
607 | |
608 /** | |
609 * @} | |
610 */ | |
611 | |
612 /** | |
613 * @} | |
614 */ | |
615 | |
616 /** | |
617 * @} | |
618 */ | |
619 | |
620 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |