Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM32100E_EVAL/stm32100e_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 stm32100e_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 STM32100E-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 "stm32100e_eval.h" | |
28 #include "stm32f10x_spi.h" | |
29 #include "stm32f10x_i2c.h" | |
30 #include "stm32f10x_dma.h" | |
31 | |
32 /** @addtogroup Utilities | |
33 * @{ | |
34 */ | |
35 | |
36 /** @addtogroup STM32_EVAL | |
37 * @{ | |
38 */ | |
39 | |
40 /** @addtogroup STM32100E_EVAL | |
41 * @{ | |
42 */ | |
43 | |
44 /** @defgroup STM32100E_EVAL_LOW_LEVEL | |
45 * @brief This file provides firmware functions to manage Leds, push-buttons, | |
46 * COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE) | |
47 * and temperature sensor (LM75) available on STM32100E-EVAL evaluation | |
48 * board from STMicroelectronics. | |
49 * @{ | |
50 */ | |
51 | |
52 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_TypesDefinitions | |
53 * @{ | |
54 */ | |
55 /** | |
56 * @} | |
57 */ | |
58 | |
59 | |
60 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Defines | |
61 * @{ | |
62 */ | |
63 /** | |
64 * @} | |
65 */ | |
66 | |
67 | |
68 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Macros | |
69 * @{ | |
70 */ | |
71 /** | |
72 * @} | |
73 */ | |
74 | |
75 | |
76 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Variables | |
77 * @{ | |
78 */ | |
79 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT, | |
80 LED4_GPIO_PORT}; | |
81 const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN, | |
82 LED4_PIN}; | |
83 const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK, | |
84 LED4_GPIO_CLK}; | |
85 | |
86 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT, | |
87 KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT, | |
88 LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT, | |
89 DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT}; | |
90 | |
91 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN, | |
92 KEY_BUTTON_PIN, RIGHT_BUTTON_PIN, | |
93 LEFT_BUTTON_PIN, UP_BUTTON_PIN, | |
94 DOWN_BUTTON_PIN, SEL_BUTTON_PIN}; | |
95 | |
96 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK, | |
97 KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK, | |
98 LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK, | |
99 DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK}; | |
100 | |
101 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE, | |
102 TAMPER_BUTTON_EXTI_LINE, | |
103 KEY_BUTTON_EXTI_LINE, | |
104 RIGHT_BUTTON_EXTI_LINE, | |
105 LEFT_BUTTON_EXTI_LINE, | |
106 UP_BUTTON_EXTI_LINE, | |
107 DOWN_BUTTON_EXTI_LINE, | |
108 SEL_BUTTON_EXTI_LINE}; | |
109 | |
110 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE, | |
111 TAMPER_BUTTON_EXTI_PORT_SOURCE, | |
112 KEY_BUTTON_EXTI_PORT_SOURCE, | |
113 RIGHT_BUTTON_EXTI_PORT_SOURCE, | |
114 LEFT_BUTTON_EXTI_PORT_SOURCE, | |
115 UP_BUTTON_EXTI_PORT_SOURCE, | |
116 DOWN_BUTTON_EXTI_PORT_SOURCE, | |
117 SEL_BUTTON_EXTI_PORT_SOURCE}; | |
118 | |
119 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE, | |
120 TAMPER_BUTTON_EXTI_PIN_SOURCE, | |
121 KEY_BUTTON_EXTI_PIN_SOURCE, | |
122 RIGHT_BUTTON_EXTI_PIN_SOURCE, | |
123 LEFT_BUTTON_EXTI_PIN_SOURCE, | |
124 UP_BUTTON_EXTI_PIN_SOURCE, | |
125 DOWN_BUTTON_EXTI_PIN_SOURCE, | |
126 SEL_BUTTON_EXTI_PIN_SOURCE}; | |
127 | |
128 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn, | |
129 KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn, | |
130 LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn, | |
131 DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn}; | |
132 | |
133 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2}; | |
134 | |
135 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT}; | |
136 | |
137 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT}; | |
138 | |
139 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK}; | |
140 | |
141 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK}; | |
142 | |
143 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK}; | |
144 | |
145 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN}; | |
146 | |
147 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN}; | |
148 | |
149 DMA_InitTypeDef sEEDMA_InitStructure; | |
150 | |
151 /** | |
152 * @} | |
153 */ | |
154 | |
155 | |
156 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_FunctionPrototypes | |
157 * @{ | |
158 */ | |
159 | |
160 /** | |
161 * @} | |
162 */ | |
163 | |
164 | |
165 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Functions | |
166 * @{ | |
167 */ | |
168 | |
169 /** | |
170 * @brief Configures LED GPIO. | |
171 * @param Led: Specifies the Led to be configured. | |
172 * This parameter can be one of following parameters: | |
173 * @arg LED1 | |
174 * @arg LED2 | |
175 * @arg LED3 | |
176 * @arg LED4 | |
177 * @retval None | |
178 */ | |
179 void STM_EVAL_LEDInit(Led_TypeDef Led) | |
180 { | |
181 GPIO_InitTypeDef GPIO_InitStructure; | |
182 | |
183 /* Enable the GPIO_LED Clock */ | |
184 RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE); | |
185 | |
186 /* Configure the GPIO_LED pin */ | |
187 GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led]; | |
188 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
189 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
190 | |
191 GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure); | |
192 } | |
193 | |
194 /** | |
195 * @brief Turns selected LED On. | |
196 * @param Led: Specifies the Led to be set on. | |
197 * This parameter can be one of following parameters: | |
198 * @arg LED1 | |
199 * @arg LED2 | |
200 * @arg LED3 | |
201 * @arg LED4 | |
202 * @retval None | |
203 */ | |
204 void STM_EVAL_LEDOn(Led_TypeDef Led) | |
205 { | |
206 GPIO_PORT[Led]->BSRR = GPIO_PIN[Led]; | |
207 } | |
208 | |
209 /** | |
210 * @brief Turns selected LED Off. | |
211 * @param Led: Specifies the Led to be set off. | |
212 * This parameter can be one of following parameters: | |
213 * @arg LED1 | |
214 * @arg LED2 | |
215 * @arg LED3 | |
216 * @arg LED4 | |
217 * @retval None | |
218 */ | |
219 void STM_EVAL_LEDOff(Led_TypeDef Led) | |
220 { | |
221 GPIO_PORT[Led]->BRR = GPIO_PIN[Led]; | |
222 } | |
223 | |
224 /** | |
225 * @brief Toggles the selected LED. | |
226 * @param Led: Specifies the Led to be toggled. | |
227 * This parameter can be one of following parameters: | |
228 * @arg LED1 | |
229 * @arg LED2 | |
230 * @arg LED3 | |
231 * @arg LED4 | |
232 * @retval None | |
233 */ | |
234 void STM_EVAL_LEDToggle(Led_TypeDef Led) | |
235 { | |
236 GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led]; | |
237 } | |
238 | |
239 /** | |
240 * @brief Configures Button GPIO and EXTI Line. | |
241 * @param Button: Specifies the Button to be configured. | |
242 * This parameter can be one of following parameters: | |
243 * @arg BUTTON_WAKEUP: Wakeup Push Button | |
244 * @arg BUTTON_TAMPER: Tamper Push Button | |
245 * @arg BUTTON_KEY: Key Push Button | |
246 * @arg BUTTON_RIGHT: Joystick Right Push Button | |
247 * @arg BUTTON_LEFT: Joystick Left Push Button | |
248 * @arg BUTTON_UP: Joystick Up Push Button | |
249 * @arg BUTTON_DOWN: Joystick Down Push Button | |
250 * @arg BUTTON_SEL: Joystick Sel Push Button | |
251 * @param Button_Mode: Specifies Button mode. | |
252 * This parameter can be one of following parameters: | |
253 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO | |
254 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt | |
255 * generation capability | |
256 * @retval None | |
257 */ | |
258 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) | |
259 { | |
260 GPIO_InitTypeDef GPIO_InitStructure; | |
261 EXTI_InitTypeDef EXTI_InitStructure; | |
262 NVIC_InitTypeDef NVIC_InitStructure; | |
263 | |
264 /* Enable the BUTTON Clock */ | |
265 RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE); | |
266 | |
267 /* Configure Button pin as input floating */ | |
268 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
269 GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button]; | |
270 GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure); | |
271 | |
272 | |
273 if (Button_Mode == BUTTON_MODE_EXTI) | |
274 { | |
275 /* Connect Button EXTI Line to Button GPIO Pin */ | |
276 GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]); | |
277 | |
278 /* Configure Button EXTI line */ | |
279 EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button]; | |
280 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; | |
281 | |
282 if(Button != BUTTON_WAKEUP) | |
283 { | |
284 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; | |
285 } | |
286 else | |
287 { | |
288 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; | |
289 } | |
290 EXTI_InitStructure.EXTI_LineCmd = ENABLE; | |
291 EXTI_Init(&EXTI_InitStructure); | |
292 | |
293 /* Enable and set Button EXTI Interrupt to the lowest priority */ | |
294 NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button]; | |
295 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; | |
296 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; | |
297 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | |
298 | |
299 NVIC_Init(&NVIC_InitStructure); | |
300 } | |
301 } | |
302 | |
303 /** | |
304 * @brief Returns the selected Button state. | |
305 * @param Button: Specifies the Button to be checked. | |
306 * This parameter can be one of following parameters: | |
307 * @arg BUTTON_WAKEUP: Wakeup Push Button | |
308 * @arg BUTTON_TAMPER: Tamper Push Button | |
309 * @arg BUTTON_KEY: Key Push Button | |
310 * @arg BUTTON_RIGHT: Joystick Right Push Button | |
311 * @arg BUTTON_LEFT: Joystick Left Push Button | |
312 * @arg BUTTON_UP: Joystick Up Push Button | |
313 * @arg BUTTON_DOWN: Joystick Down Push Button | |
314 * @arg BUTTON_SEL: Joystick Sel Push Button | |
315 * @retval The Button GPIO pin value. | |
316 */ | |
317 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button) | |
318 { | |
319 return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]); | |
320 } | |
321 | |
322 /** | |
323 * @brief Configures COM port. | |
324 * @param COM: Specifies the COM port to be configured. | |
325 * This parameter can be one of following parameters: | |
326 * @arg COM1 | |
327 * @arg COM2 | |
328 * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that | |
329 * contains the configuration information for the specified USART peripheral. | |
330 * @retval None | |
331 */ | |
332 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct) | |
333 { | |
334 GPIO_InitTypeDef GPIO_InitStructure; | |
335 | |
336 /* Enable GPIO clock */ | |
337 RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE); | |
338 | |
339 /* Enable UART clock */ | |
340 if (COM == COM1) | |
341 { | |
342 RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); | |
343 } | |
344 else | |
345 { | |
346 RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE); | |
347 } | |
348 | |
349 /* Configure USART Tx as alternate function push-pull */ | |
350 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
351 GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM]; | |
352 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
353 GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure); | |
354 | |
355 /* Configure USART Rx as input floating */ | |
356 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
357 GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM]; | |
358 GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure); | |
359 | |
360 /* USART configuration */ | |
361 USART_Init(COM_USART[COM], USART_InitStruct); | |
362 | |
363 /* Enable USART */ | |
364 USART_Cmd(COM_USART[COM], ENABLE); | |
365 } | |
366 | |
367 /** | |
368 * @brief DeInitializes the SD/SD communication. | |
369 * @param None | |
370 * @retval None | |
371 */ | |
372 void SD_LowLevel_DeInit(void) | |
373 { | |
374 GPIO_InitTypeDef GPIO_InitStructure; | |
375 | |
376 SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */ | |
377 SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */ | |
378 | |
379 /*!< SD_SPI Periph clock disable */ | |
380 RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE); | |
381 | |
382 /*!< Configure SD_SPI pins: SCK */ | |
383 GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; | |
384 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
385 GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
386 | |
387 /*!< Configure SD_SPI pins: MISO */ | |
388 GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; | |
389 GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
390 | |
391 /*!< Configure SD_SPI pins: MOSI */ | |
392 GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; | |
393 GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
394 | |
395 /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ | |
396 GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; | |
397 GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); | |
398 | |
399 /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ | |
400 GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; | |
401 GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); | |
402 } | |
403 | |
404 /** | |
405 * @brief Initializes the SD_SPI and CS pins. | |
406 * @param None | |
407 * @retval None | |
408 */ | |
409 void SD_LowLevel_Init(void) | |
410 { | |
411 GPIO_InitTypeDef GPIO_InitStructure; | |
412 SPI_InitTypeDef SPI_InitStructure; | |
413 | |
414 /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO | |
415 and SD_SPI_SCK_GPIO Periph clock enable */ | |
416 RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK | | |
417 SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE); | |
418 | |
419 /*!< SD_SPI Periph clock enable */ | |
420 RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE); | |
421 | |
422 /*!< Configure SD_SPI pins: SCK */ | |
423 GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; | |
424 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
425 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
426 GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
427 | |
428 /*!< Configure SD_SPI pins: MOSI */ | |
429 GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; | |
430 GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
431 | |
432 /*!< Configure SD_SPI pins: MISO */ | |
433 GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; | |
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_2; | |
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 peripherals used by the I2C EEPROM driver. | |
463 * @param None | |
464 * @retval None | |
465 */ | |
466 void sEE_LowLevel_DeInit(void) | |
467 { | |
468 GPIO_InitTypeDef GPIO_InitStructure; | |
469 NVIC_InitTypeDef NVIC_InitStructure; | |
470 | |
471 /* sEE_I2C Peripheral Disable */ | |
472 I2C_Cmd(sEE_I2C, DISABLE); | |
473 | |
474 /* sEE_I2C DeInit */ | |
475 I2C_DeInit(sEE_I2C); | |
476 | |
477 /*!< sEE_I2C Periph clock disable */ | |
478 RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE); | |
479 | |
480 /*!< GPIO configuration */ | |
481 /*!< Configure sEE_I2C pins: SCL */ | |
482 GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN; | |
483 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
484 GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
485 | |
486 /*!< Configure sEE_I2C pins: SDA */ | |
487 GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN; | |
488 GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
489 | |
490 /* Configure and enable I2C DMA TX Channel interrupt */ | |
491 NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn; | |
492 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO; | |
493 NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO; | |
494 NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; | |
495 NVIC_Init(&NVIC_InitStructure); | |
496 | |
497 /* Configure and enable I2C DMA RX Channel interrupt */ | |
498 NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn; | |
499 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO; | |
500 NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO; | |
501 NVIC_Init(&NVIC_InitStructure); | |
502 | |
503 /* Disable and Deinitialize the DMA channels */ | |
504 DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE); | |
505 DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE); | |
506 DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX); | |
507 DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX); | |
508 } | |
509 | |
510 /** | |
511 * @brief Initializes peripherals used by the I2C EEPROM driver. | |
512 * @param None | |
513 * @retval None | |
514 */ | |
515 void sEE_LowLevel_Init(void) | |
516 { | |
517 GPIO_InitTypeDef GPIO_InitStructure; | |
518 NVIC_InitTypeDef NVIC_InitStructure; | |
519 | |
520 /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */ | |
521 RCC_APB2PeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE); | |
522 | |
523 /*!< sEE_I2C Periph clock enable */ | |
524 RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE); | |
525 | |
526 /*!< GPIO configuration */ | |
527 /*!< Configure sEE_I2C pins: SCL */ | |
528 GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN; | |
529 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
530 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; | |
531 GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
532 | |
533 /*!< Configure sEE_I2C pins: SDA */ | |
534 GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN; | |
535 GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
536 | |
537 /* Configure and enable I2C DMA TX Channel interrupt */ | |
538 NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn; | |
539 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO; | |
540 NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO; | |
541 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | |
542 NVIC_Init(&NVIC_InitStructure); | |
543 | |
544 /* Configure and enable I2C DMA RX Channel interrupt */ | |
545 NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn; | |
546 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO; | |
547 NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO; | |
548 NVIC_Init(&NVIC_InitStructure); | |
549 | |
550 /*!< I2C DMA TX and RX channels configuration */ | |
551 /* Enable the DMA clock */ | |
552 RCC_AHBPeriphClockCmd(sEE_I2C_DMA_CLK, ENABLE); | |
553 | |
554 /* I2C TX DMA Channel configuration */ | |
555 DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX); | |
556 sEEDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)sEE_I2C_DR_Address; | |
557 sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0; /* This parameter will be configured durig communication */ | |
558 sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; /* This parameter will be configured durig communication */ | |
559 sEEDMA_InitStructure.DMA_BufferSize = 0xFFFF; /* This parameter will be configured durig communication */ | |
560 sEEDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; | |
561 sEEDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; | |
562 sEEDMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte; | |
563 sEEDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; | |
564 sEEDMA_InitStructure.DMA_Mode = DMA_Mode_Normal; | |
565 sEEDMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; | |
566 sEEDMA_InitStructure.DMA_M2M = DMA_M2M_Disable; | |
567 DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure); | |
568 | |
569 /* I2C RX DMA Channel configuration */ | |
570 DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX); | |
571 DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure); | |
572 | |
573 /* Enable the DMA Channels Interrupts */ | |
574 DMA_ITConfig(sEE_I2C_DMA_CHANNEL_TX, DMA_IT_TC, ENABLE); | |
575 DMA_ITConfig(sEE_I2C_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE); | |
576 } | |
577 | |
578 /** | |
579 * @brief Initializes DMA channel used by the I2C EEPROM driver. | |
580 * @param None | |
581 * @retval None | |
582 */ | |
583 void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction) | |
584 { | |
585 /* Initialize the DMA with the new parameters */ | |
586 if (Direction == sEE_DIRECTION_TX) | |
587 { | |
588 /* Configure the DMA Tx Channel with the buffer address and the buffer size */ | |
589 sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer; | |
590 sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; | |
591 sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize; | |
592 DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure); | |
593 } | |
594 else | |
595 { | |
596 /* Configure the DMA Rx Channel with the buffer address and the buffer size */ | |
597 sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer; | |
598 sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; | |
599 sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize; | |
600 DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure); | |
601 } | |
602 } | |
603 | |
604 /** | |
605 * @brief DeInitializes the peripherals used by the SPI FLASH driver. | |
606 * @param None | |
607 * @retval None | |
608 */ | |
609 void sFLASH_LowLevel_DeInit(void) | |
610 { | |
611 GPIO_InitTypeDef GPIO_InitStructure; | |
612 | |
613 /*!< Disable the sFLASH_SPI */ | |
614 SPI_Cmd(sFLASH_SPI, DISABLE); | |
615 | |
616 /*!< DeInitializes the sFLASH_SPI */ | |
617 SPI_I2S_DeInit(sFLASH_SPI); | |
618 | |
619 /*!< sFLASH_SPI Periph clock disable */ | |
620 RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE); | |
621 | |
622 /*!< Configure sFLASH_SPI pins: SCK */ | |
623 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN; | |
624 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
625 GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
626 | |
627 /*!< Configure sFLASH_SPI pins: MISO */ | |
628 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN; | |
629 GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
630 | |
631 /*!< Configure sFLASH_SPI pins: MOSI */ | |
632 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN; | |
633 GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
634 | |
635 /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ | |
636 GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; | |
637 GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); | |
638 } | |
639 | |
640 /** | |
641 * @brief Initializes the peripherals used by the SPI FLASH driver. | |
642 * @param None | |
643 * @retval None | |
644 */ | |
645 void sFLASH_LowLevel_Init(void) | |
646 { | |
647 GPIO_InitTypeDef GPIO_InitStructure; | |
648 | |
649 /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO | |
650 and sFLASH_SPI_SCK_GPIO Periph clock enable */ | |
651 RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK | | |
652 sFLASH_SPI_SCK_GPIO_CLK, ENABLE); | |
653 | |
654 /*!< sFLASH_SPI Periph clock enable */ | |
655 RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE); | |
656 | |
657 /*!< Configure sFLASH_SPI pins: SCK */ | |
658 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN; | |
659 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
660 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | |
661 GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
662 | |
663 /*!< Configure sFLASH_SPI pins: MOSI */ | |
664 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN; | |
665 GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
666 | |
667 /*!< Configure sFLASH_SPI pins: MISO */ | |
668 GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN; | |
669 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
670 GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
671 | |
672 /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ | |
673 GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; | |
674 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
675 GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); | |
676 } | |
677 | |
678 /** | |
679 * @brief DeInitializes the LM75_I2C. | |
680 * @param None | |
681 * @retval None | |
682 */ | |
683 void LM75_LowLevel_DeInit(void) | |
684 { | |
685 GPIO_InitTypeDef GPIO_InitStructure; | |
686 | |
687 /*!< Disable LM75_I2C */ | |
688 I2C_Cmd(LM75_I2C, DISABLE); | |
689 /*!< DeInitializes the LM75_I2C */ | |
690 I2C_DeInit(LM75_I2C); | |
691 | |
692 /*!< LM75_I2C Periph clock disable */ | |
693 RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE); | |
694 | |
695 /*!< Configure LM75_I2C pins: SCL */ | |
696 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN; | |
697 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | |
698 GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
699 | |
700 /*!< Configure LM75_I2C pins: SDA */ | |
701 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN; | |
702 GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
703 | |
704 /*!< Configure LM75_I2C pin: SMBUS ALERT */ | |
705 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN; | |
706 GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); | |
707 } | |
708 | |
709 /** | |
710 * @brief Initializes the LM75_I2C.. | |
711 * @param None | |
712 * @retval None | |
713 */ | |
714 void LM75_LowLevel_Init(void) | |
715 { | |
716 GPIO_InitTypeDef GPIO_InitStructure; | |
717 | |
718 /*!< LM75_I2C Periph clock enable */ | |
719 RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE); | |
720 | |
721 /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK | |
722 and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */ | |
723 RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK | | |
724 LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE); | |
725 | |
726 /*!< Configure LM75_I2C pins: SCL */ | |
727 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN; | |
728 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
729 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; | |
730 GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); | |
731 | |
732 /*!< Configure LM75_I2C pins: SDA */ | |
733 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN; | |
734 GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); | |
735 | |
736 /*!< Configure LM75_I2C pin: SMBUS ALERT */ | |
737 GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN; | |
738 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; | |
739 GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); | |
740 } | |
741 | |
742 /** | |
743 * @} | |
744 */ | |
745 | |
746 /** | |
747 * @} | |
748 */ | |
749 | |
750 /** | |
751 * @} | |
752 */ | |
753 | |
754 /** | |
755 * @} | |
756 */ | |
757 | |
758 /** | |
759 * @} | |
760 */ | |
761 | |
762 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |