Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_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 stm3210e_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 SDIO), SPI serial | |
10 * flash (sFLASH) and temperature sensor (LM75) | |
11 * available on STM3210E-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 "stm3210e_eval.h" | |
28 #include "stm32f10x_spi.h" | |
29 #include "stm32f10x_i2c.h" | |
30 #include "stm32f10x_sdio.h" | |
31 #include "stm32f10x_dma.h" | |
32 | |
33 /** @addtogroup Utilities | |
34 * @{ | |
35 */ | |
36 | |
37 /** @addtogroup STM32_EVAL | |
38 * @{ | |
39 */ | |
40 | |
41 /** @addtogroup STM3210E_EVAL | |
42 * @{ | |
43 */ | |
44 | |
45 /** @defgroup STM3210E_EVAL_LOW_LEVEL | |
46 * @brief This file provides firmware functions to manage Leds, push-buttons, | |
47 * COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE) | |
48 * and temperature sensor (LM75) available on STM3210E-EVAL evaluation | |
49 * board from STMicroelectronics. | |
50 * @{ | |
51 */ | |
52 | |
53 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_TypesDefinitions | |
54 * @{ | |
55 */ | |
56 /** | |
57 * @} | |
58 */ | |
59 | |
60 | |
61 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Defines | |
62 * @{ | |
63 */ | |
64 /** | |
65 * @} | |
66 */ | |
67 | |
68 | |
69 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Macros | |
70 * @{ | |
71 */ | |
72 /** | |
73 * @} | |
74 */ | |
75 | |
76 | |
77 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Variables | |
78 * @{ | |
79 */ | |
80 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT, | |
81 LED4_GPIO_PORT}; | |
82 const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN, | |
83 LED4_PIN}; | |
84 const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK, | |
85 LED4_GPIO_CLK}; | |
86 | |
87 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT, | |
88 KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT, | |
89 LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT, | |
90 DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT}; | |
91 | |
92 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN, | |
93 KEY_BUTTON_PIN, RIGHT_BUTTON_PIN, | |
94 LEFT_BUTTON_PIN, UP_BUTTON_PIN, | |
95 DOWN_BUTTON_PIN, SEL_BUTTON_PIN}; | |
96 | |
97 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK, | |
98 KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK, | |
99 LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK, | |
100 DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK}; | |
101 | |
102 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE, | |
103 TAMPER_BUTTON_EXTI_LINE, | |
104 KEY_BUTTON_EXTI_LINE, | |
105 RIGHT_BUTTON_EXTI_LINE, | |
106 LEFT_BUTTON_EXTI_LINE, | |
107 UP_BUTTON_EXTI_LINE, | |
108 DOWN_BUTTON_EXTI_LINE, | |
109 SEL_BUTTON_EXTI_LINE}; | |
110 | |
111 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE, | |
112 TAMPER_BUTTON_EXTI_PORT_SOURCE, | |
113 KEY_BUTTON_EXTI_PORT_SOURCE, | |
114 RIGHT_BUTTON_EXTI_PORT_SOURCE, | |
115 LEFT_BUTTON_EXTI_PORT_SOURCE, | |
116 UP_BUTTON_EXTI_PORT_SOURCE, | |
117 DOWN_BUTTON_EXTI_PORT_SOURCE, | |
118 SEL_BUTTON_EXTI_PORT_SOURCE}; | |
119 | |
120 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE, | |
121 TAMPER_BUTTON_EXTI_PIN_SOURCE, | |
122 KEY_BUTTON_EXTI_PIN_SOURCE, | |
123 RIGHT_BUTTON_EXTI_PIN_SOURCE, | |
124 LEFT_BUTTON_EXTI_PIN_SOURCE, | |
125 UP_BUTTON_EXTI_PIN_SOURCE, | |
126 DOWN_BUTTON_EXTI_PIN_SOURCE, | |
127 SEL_BUTTON_EXTI_PIN_SOURCE}; | |
128 | |
129 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn, | |
130 KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn, | |
131 LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn, | |
132 DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn}; | |
133 | |
134 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2}; | |
135 | |
136 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT}; | |
137 | |
138 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT}; | |
139 | |
140 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK}; | |
141 | |
142 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK}; | |
143 | |
144 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK}; | |
145 | |
146 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN}; | |
147 | |
148 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN}; | |
149 | |
150 /** | |
151 * @} | |
152 */ | |
153 | |
154 | |
155 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_FunctionPrototypes | |
156 * @{ | |
157 */ | |
158 | |
159 /** | |
160 * @} | |
161 */ | |
162 | |
163 | |
164 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Functions | |
165 * @{ | |
166 */ | |
167 | |
168 /** | |
169 * @brief Configures LED GPIO. | |
170 * @param Led: Specifies the Led to be configured. | |
171 * This parameter can be one of following parameters: | |
172 * @arg LED1 | |
173 * @arg LED2 | |
174 * @arg LED3 | |
175 * @arg LED4 | |
176 * @retval None | |
177 */ | |
178 void STM_EVAL_LEDInit(Led_TypeDef Led) | |
179 { | |
180 GPIO_InitTypeDef GPIO_InitStructure; | |
181 | |
182 /* Enable the GPIO_LED Clock */ | |
183 RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE); | |
184 | |
185 /* Configure the GPIO_LED pin */ | |
186 GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led]; | |
187 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
188 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
189 | |
190 GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure); | |
191 } | |
192 | |
193 /** | |
194 * @brief Turns selected LED On. | |
195 * @param Led: Specifies the Led to be set on. | |
196 * This parameter can be one of following parameters: | |
197 * @arg LED1 | |
198 * @arg LED2 | |
199 * @arg LED3 | |
200 * @arg LED4 | |
201 * @retval None | |
202 */ | |
203 void STM_EVAL_LEDOn(Led_TypeDef Led) | |
204 { | |
205 GPIO_PORT[Led]->BSRR = GPIO_PIN[Led]; | |
206 } | |
207 | |
208 /** | |
209 * @brief Turns selected LED Off. | |
210 * @param Led: Specifies the Led to be set off. | |
211 * This parameter can be one of following parameters: | |
212 * @arg LED1 | |
213 * @arg LED2 | |
214 * @arg LED3 | |
215 * @arg LED4 | |
216 * @retval None | |
217 */ | |
218 void STM_EVAL_LEDOff(Led_TypeDef Led) | |
219 { | |
220 GPIO_PORT[Led]->BRR = GPIO_PIN[Led]; | |
221 } | |
222 | |
223 /** | |
224 * @brief Toggles the selected LED. | |
225 * @param Led: Specifies the Led to be toggled. | |
226 * This parameter can be one of following parameters: | |
227 * @arg LED1 | |
228 * @arg LED2 | |
229 * @arg LED3 | |
230 * @arg LED4 | |
231 * @retval None | |
232 */ | |
233 void STM_EVAL_LEDToggle(Led_TypeDef Led) | |
234 { | |
235 GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led]; | |
236 } | |
237 | |
238 /** | |
239 * @brief Configures Button GPIO and EXTI Line. | |
240 * @param Button: Specifies the Button to be configured. | |
241 * This parameter can be one of following parameters: | |
242 * @arg BUTTON_WAKEUP: Wakeup Push Button | |
243 * @arg BUTTON_TAMPER: Tamper Push Button | |
244 * @arg BUTTON_KEY: Key Push Button | |
245 * @arg BUTTON_RIGHT: Joystick Right Push Button | |
246 * @arg BUTTON_LEFT: Joystick Left Push Button | |
247 * @arg BUTTON_UP: Joystick Up Push Button | |
248 * @arg BUTTON_DOWN: Joystick Down Push Button | |
249 * @arg BUTTON_SEL: Joystick Sel Push Button | |
250 * @param Button_Mode: Specifies Button mode. | |
251 * This parameter can be one of following parameters: | |
252 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO | |
253 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt | |
254 * generation capability | |
255 * @retval None | |
256 */ | |
257 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) | |
258 { | |
259 GPIO_InitTypeDef GPIO_InitStructure; | |
260 EXTI_InitTypeDef EXTI_InitStructure; | |
261 NVIC_InitTypeDef NVIC_InitStructure; | |
262 | |
263 /* Enable the BUTTON Clock */ | |
264 RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE); | |
265 | |
266 /* Configure Button pin as input floating */ | |
267 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
268 GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button]; | |
269 GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure); | |
270 | |
271 | |
272 if (Button_Mode == BUTTON_MODE_EXTI) | |
273 { | |
274 /* Connect Button EXTI Line to Button GPIO Pin */ | |
275 GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]); | |
276 | |
277 /* Configure Button EXTI line */ | |
278 EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button]; | |
279 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; | |
280 | |
281 if(Button != BUTTON_WAKEUP) | |
282 { | |
283 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; | |
284 } | |
285 else | |
286 { | |
287 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; | |
288 } | |
289 EXTI_InitStructure.EXTI_LineCmd = ENABLE; | |
290 EXTI_Init(&EXTI_InitStructure); | |
291 | |
292 /* Enable and set Button EXTI Interrupt to the lowest priority */ | |
293 NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button]; | |
294 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; | |
295 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; | |
296 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | |
297 | |
298 NVIC_Init(&NVIC_InitStructure); | |
299 } | |
300 } | |
301 | |
302 /** | |
303 * @brief Returns the selected Button state. | |
304 * @param Button: Specifies the Button to be checked. | |
305 * This parameter can be one of following parameters: | |
306 * @arg BUTTON_WAKEUP: Wakeup Push Button | |
307 * @arg BUTTON_TAMPER: Tamper Push Button | |
308 * @arg BUTTON_KEY: Key Push Button | |
309 * @arg BUTTON_RIGHT: Joystick Right Push Button | |
310 * @arg BUTTON_LEFT: Joystick Left Push Button | |
311 * @arg BUTTON_UP: Joystick Up Push Button | |
312 * @arg BUTTON_DOWN: Joystick Down Push Button | |
313 * @arg BUTTON_SEL: Joystick Sel Push Button | |
314 * @retval The Button GPIO pin value. | |
315 */ | |
316 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button) | |
317 { | |
318 return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]); | |
319 } | |
320 | |
321 /** | |
322 * @brief Configures COM port. | |
323 * @param COM: Specifies the COM port to be configured. | |
324 * This parameter can be one of following parameters: | |
325 * @arg COM1 | |
326 * @arg COM2 | |
327 * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that | |
328 * contains the configuration information for the specified USART peripheral. | |
329 * @retval None | |
330 */ | |
331 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct) | |
332 { | |
333 GPIO_InitTypeDef GPIO_InitStructure; | |
334 | |
335 /* Enable GPIO clock */ | |
336 RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE); | |
337 | |
338 /* Enable UART clock */ | |
339 if (COM == COM1) | |
340 { | |
341 RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); | |
342 } | |
343 else | |
344 { | |
345 RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE); | |
346 } | |
347 | |
348 /* Configure USART Tx as alternate function push-pull */ | |
349 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
350 GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM]; | |
351 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
352 GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure); | |
353 | |
354 /* Configure USART Rx as input floating */ | |
355 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
356 GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM]; | |
357 GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure); | |
358 | |
359 /* USART configuration */ | |
360 USART_Init(COM_USART[COM], USART_InitStruct); | |
361 | |
362 /* Enable USART */ | |
363 USART_Cmd(COM_USART[COM], ENABLE); | |
364 } | |
365 | |
366 /** | |
367 * @brief DeInitializes the SDIO interface. | |
368 * @param None | |
369 * @retval None | |
370 */ | |
371 void SD_LowLevel_DeInit(void) | |
372 { | |
373 GPIO_InitTypeDef GPIO_InitStructure; | |
374 | |
375 /*!< Disable SDIO Clock */ | |
376 SDIO_ClockCmd(DISABLE); | |
377 | |
378 /*!< Set Power State to OFF */ | |
379 SDIO_SetPowerState(SDIO_PowerState_OFF); | |
380 | |
381 /*!< DeInitializes the SDIO peripheral */ | |
382 SDIO_DeInit(); | |
383 | |
384 /*!< Disable the SDIO AHB Clock */ | |
385 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, DISABLE); | |
386 | |
387 /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */ | |
388 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; | |
389 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
390 GPIO_Init(GPIOC, &GPIO_InitStructure); | |
391 | |
392 /*!< Configure PD.02 CMD line */ | |
393 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; | |
394 GPIO_Init(GPIOD, &GPIO_InitStructure); | |
395 } | |
396 | |
397 /** | |
398 * @brief Initializes the SD Card and put it into StandBy State (Ready for | |
399 * data transfer). | |
400 * @param None | |
401 * @retval None | |
402 */ | |
403 void SD_LowLevel_Init(void) | |
404 { | |
405 GPIO_InitTypeDef GPIO_InitStructure; | |
406 | |
407 /*!< GPIOC and GPIOD Periph clock enable */ | |
408 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE); | |
409 | |
410 /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */ | |
411 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; | |
412 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
413 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
414 GPIO_Init(GPIOC, &GPIO_InitStructure); | |
415 | |
416 /*!< Configure PD.02 CMD line */ | |
417 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; | |
418 GPIO_Init(GPIOD, &GPIO_InitStructure); | |
419 | |
420 /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ | |
421 GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; | |
422 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; | |
423 GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); | |
424 | |
425 /*!< Enable the SDIO AHB Clock */ | |
426 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE); | |
427 | |
428 /*!< Enable the DMA2 Clock */ | |
429 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); | |
430 } | |
431 | |
432 /** | |
433 * @brief Configures the DMA2 Channel4 for SDIO Tx request. | |
434 * @param BufferSRC: pointer to the source buffer | |
435 * @param BufferSize: buffer size | |
436 * @retval None | |
437 */ | |
438 void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize) | |
439 { | |
440 | |
441 DMA_InitTypeDef DMA_InitStructure; | |
442 | |
443 DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4); | |
444 | |
445 /*!< DMA2 Channel4 disable */ | |
446 DMA_Cmd(DMA2_Channel4, DISABLE); | |
447 | |
448 /*!< DMA2 Channel4 Config */ | |
449 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS; | |
450 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferSRC; | |
451 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; | |
452 DMA_InitStructure.DMA_BufferSize = BufferSize / 4; | |
453 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; | |
454 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; | |
455 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; | |
456 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; | |
457 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; | |
458 DMA_InitStructure.DMA_Priority = DMA_Priority_High; | |
459 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; | |
460 DMA_Init(DMA2_Channel4, &DMA_InitStructure); | |
461 | |
462 /*!< DMA2 Channel4 enable */ | |
463 DMA_Cmd(DMA2_Channel4, ENABLE); | |
464 } | |
465 | |
466 /** | |
467 * @brief Configures the DMA2 Channel4 for SDIO Rx request. | |
468 * @param BufferDST: pointer to the destination buffer | |
469 * @param BufferSize: buffer size | |
470 * @retval None | |
471 */ | |
472 void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize) | |
473 { | |
474 DMA_InitTypeDef DMA_InitStructure; | |
475 | |
476 DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4); | |
477 | |
478 /*!< DMA2 Channel4 disable */ | |
479 DMA_Cmd(DMA2_Channel4, DISABLE); | |
480 | |
481 /*!< DMA2 Channel4 Config */ | |
482 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS; | |
483 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST; | |
484 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; | |
485 DMA_InitStructure.DMA_BufferSize = BufferSize / 4; | |
486 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; | |
487 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; | |
488 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; | |
489 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; | |
490 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; | |
491 DMA_InitStructure.DMA_Priority = DMA_Priority_High; | |
492 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; | |
493 DMA_Init(DMA2_Channel4, &DMA_InitStructure); | |
494 | |
495 /*!< DMA2 Channel4 enable */ | |
496 DMA_Cmd(DMA2_Channel4, ENABLE); | |
497 } | |
498 | |
499 /** | |
500 * @brief Returns the DMA End Of Transfer Status. | |
501 * @param None | |
502 * @retval DMA SDIO Channel Status. | |
503 */ | |
504 uint32_t SD_DMAEndOfTransferStatus(void) | |
505 { | |
506 return (uint32_t)DMA_GetFlagStatus(DMA2_FLAG_TC4); | |
507 } | |
508 | |
509 /** | |
510 * @brief DeInitializes the peripherals used by the SPI FLASH driver. | |
511 * @param None | |
512 * @retval None | |
513 */ | |
514 void sFLASH_LowLevel_DeInit(void) | |
515 { | |
516 GPIO_InitTypeDef GPIO_InitStructure; | |
517 | |
518 /*!< Disable the sFLASH_SPI */ | |
519 SPI_Cmd(sFLASH_SPI, DISABLE); | |
520 | |
521 /*!< DeInitializes the sFLASH_SPI */ | |
522 SPI_I2S_DeInit(sFLASH_SPI); | |
523 | |
524 /*!< sFLASH_SPI Periph clock disable */ | |
525 RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE); | |
526 | |
527 /*!< Configure sFLASH_SPI pins: SCK */ | |
528 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN; | |
529 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
530 GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
531 | |
532 /*!< Configure sFLASH_SPI pins: MISO */ | |
533 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN; | |
534 GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
535 | |
536 /*!< Configure sFLASH_SPI pins: MOSI */ | |
537 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN; | |
538 GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
539 | |
540 /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ | |
541 GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; | |
542 GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); | |
543 } | |
544 | |
545 /** | |
546 * @brief Initializes the peripherals used by the SPI FLASH driver. | |
547 * @param None | |
548 * @retval None | |
549 */ | |
550 void sFLASH_LowLevel_Init(void) | |
551 { | |
552 GPIO_InitTypeDef GPIO_InitStructure; | |
553 | |
554 /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO | |
555 and sFLASH_SPI_SCK_GPIO Periph clock enable */ | |
556 RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK | | |
557 sFLASH_SPI_SCK_GPIO_CLK, ENABLE); | |
558 | |
559 /*!< sFLASH_SPI Periph clock enable */ | |
560 RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE); | |
561 | |
562 /*!< Configure sFLASH_SPI pins: SCK */ | |
563 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN; | |
564 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
565 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
566 GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
567 | |
568 /*!< Configure sFLASH_SPI pins: MOSI */ | |
569 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN; | |
570 GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
571 | |
572 /*!< Configure sFLASH_SPI pins: MISO */ | |
573 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN; | |
574 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
575 GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
576 | |
577 /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ | |
578 GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; | |
579 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
580 GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); | |
581 } | |
582 | |
583 /** | |
584 * @brief DeInitializes the LM75_I2C. | |
585 * @param None | |
586 * @retval None | |
587 */ | |
588 void LM75_LowLevel_DeInit(void) | |
589 { | |
590 GPIO_InitTypeDef GPIO_InitStructure; | |
591 | |
592 /*!< Disable LM75_I2C */ | |
593 I2C_Cmd(LM75_I2C, DISABLE); | |
594 /*!< DeInitializes the LM75_I2C */ | |
595 I2C_DeInit(LM75_I2C); | |
596 | |
597 /*!< LM75_I2C Periph clock disable */ | |
598 RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE); | |
599 | |
600 /*!< Configure LM75_I2C pins: SCL */ | |
601 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN; | |
602 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
603 GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
604 | |
605 /*!< Configure LM75_I2C pins: SDA */ | |
606 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN; | |
607 GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
608 | |
609 /*!< Configure LM75_I2C pin: SMBUS ALERT */ | |
610 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN; | |
611 GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); | |
612 } | |
613 | |
614 /** | |
615 * @brief Initializes the LM75_I2C.. | |
616 * @param None | |
617 * @retval None | |
618 */ | |
619 void LM75_LowLevel_Init(void) | |
620 { | |
621 GPIO_InitTypeDef GPIO_InitStructure; | |
622 | |
623 /*!< LM75_I2C Periph clock enable */ | |
624 RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE); | |
625 | |
626 /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK | |
627 and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */ | |
628 RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK | | |
629 LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE); | |
630 | |
631 /*!< Configure LM75_I2C pins: SCL */ | |
632 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN; | |
633 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
634 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; | |
635 GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
636 | |
637 /*!< Configure LM75_I2C pins: SDA */ | |
638 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN; | |
639 GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
640 | |
641 /*!< Configure LM75_I2C pin: SMBUS ALERT */ | |
642 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN; | |
643 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; | |
644 GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); | |
645 } | |
646 | |
647 /** | |
648 * @} | |
649 */ | |
650 | |
651 /** | |
652 * @} | |
653 */ | |
654 | |
655 /** | |
656 * @} | |
657 */ | |
658 | |
659 /** | |
660 * @} | |
661 */ | |
662 | |
663 /** | |
664 * @} | |
665 */ | |
666 | |
667 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |