OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32L152_IAR/] [system_and_ST_code/] [STM32L152_EVAL/] [stm32l152_eval.c] - Blame information for rev 582

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 jeremybenn
/**
2
  ******************************************************************************
3
  * @file    stm32l152_eval.c
4
  * @author  MCD Application Team
5
  * @version V4.4.0RC1
6
  * @date    07/02/2010
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) and
10
  *              temperature sensor (LM75)
11
  *          available on STM32L152-EVAL evaluation board from STMicroelectronics.
12
  ******************************************************************************
13
  * @copy
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>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
23
  */
24
 
25
/* Includes ------------------------------------------------------------------*/
26
#include "stm32l152_eval.h"
27
#include "stm32l1xx_spi.h"
28
#include "stm32l1xx_i2c.h"
29
 
30
/** @addtogroup Utilities
31
  * @{
32
  */
33
 
34
/** @addtogroup STM32_EVAL
35
  * @{
36
  */
37
 
38
/** @addtogroup STM32L152_EVAL
39
  * @{
40
  */
41
 
42
/** @defgroup STM32L152_EVAL_LOW_LEVEL
43
  * @brief This file provides firmware functions to manage Leds, push-buttons,
44
  *        COM ports, SD card on SPI and temperature sensor (LM75) available on
45
  *        STM32L152-EVAL evaluation board from STMicroelectronics.
46
  * @{
47
  */
48
 
49
/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_TypesDefinitions
50
  * @{
51
  */
52
/**
53
  * @}
54
  */
55
 
56
 
57
/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Defines
58
  * @{
59
  */
60
/**
61
  * @}
62
  */
63
 
64
 
65
/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Macros
66
  * @{
67
  */
68
/**
69
  * @}
70
  */
71
 
72
 
73
/** @defgroup STM32L152_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
const uint16_t COM_TX_PIN_SOURCE[COMn] = {EVAL_COM1_TX_SOURCE, EVAL_COM2_TX_SOURCE};
147
 
148
const uint16_t COM_RX_PIN_SOURCE[COMn] = {EVAL_COM1_RX_SOURCE, EVAL_COM2_RX_SOURCE};
149
 
150
const uint16_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF, EVAL_COM2_TX_AF};
151
 
152
const uint16_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF, EVAL_COM2_RX_AF};
153
 
154
/**
155
  * @}
156
  */
157
 
158
 
159
/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_FunctionPrototypes
160
  * @{
161
  */
162
 
163
/**
164
  * @}
165
  */
166
 
167
/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Functions
168
  * @{
169
  */
170
 
171
/**
172
  * @brief  Configures LED GPIO.
173
  * @param  Led: Specifies the Led to be configured.
174
  *   This parameter can be one of following parameters:
175
  *     @arg LED1
176
  *     @arg LED2
177
  *     @arg LED3
178
  *     @arg LED4
179
  * @retval None
180
  */
181
void STM_EVAL_LEDInit(Led_TypeDef Led)
182
{
183
  GPIO_InitTypeDef  GPIO_InitStructure;
184
 
185
  /* Enable the GPIO_LED Clock */
186
  RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
187
 
188
  /* Configure the GPIO_LED pin */
189
  GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
190
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
191
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
192
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
193
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
194
  GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
195
  GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
196
}
197
 
198
/**
199
  * @brief  Turns selected LED On.
200
  * @param  Led: Specifies the Led to be set on.
201
  *   This parameter can be one of following parameters:
202
  *     @arg LED1
203
  *     @arg LED2
204
  *     @arg LED3
205
  *     @arg LED4
206
  * @retval None
207
  */
208
void STM_EVAL_LEDOn(Led_TypeDef Led)
209
{
210
  GPIO_PORT[Led]->BSRRH = GPIO_PIN[Led];
211
}
212
 
213
/**
214
  * @brief  Turns selected LED Off.
215
  * @param  Led: Specifies the Led to be set off.
216
  *   This parameter can be one of following parameters:
217
  *     @arg LED1
218
  *     @arg LED2
219
  *     @arg LED3
220
  *     @arg LED4
221
  * @retval None
222
  */
223
void STM_EVAL_LEDOff(Led_TypeDef Led)
224
{
225
  GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
226
}
227
 
228
/**
229
  * @brief  Toggles the selected LED.
230
  * @param  Led: Specifies the Led to be toggled.
231
  *   This parameter can be one of following parameters:
232
  *     @arg LED1
233
  *     @arg LED2
234
  *     @arg LED3
235
  *     @arg LED4
236
  * @retval None
237
  */
238
void STM_EVAL_LEDToggle(Led_TypeDef Led)
239
{
240
  GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
241
}
242
 
243
/**
244
  * @brief  Configures Button GPIO and EXTI Line.
245
  * @param  Button: Specifies the Button to be configured.
246
  *   This parameter can be one of following parameters:
247
  *     @arg BUTTON_WAKEUP: Wakeup Push Button
248
  *     @arg BUTTON_TAMPER: Tamper Push Button
249
  *     @arg BUTTON_KEY: Key Push Button
250
  *     @arg BUTTON_RIGHT: Joystick Right Push Button
251
  *     @arg BUTTON_LEFT: Joystick Left Push Button
252
  *     @arg BUTTON_UP: Joystick Up Push Button
253
  *     @arg BUTTON_DOWN: Joystick Down Push Button
254
  *     @arg BUTTON_SEL: Joystick Sel Push Button
255
  * @param  Button_Mode: Specifies Button mode.
256
  *   This parameter can be one of following parameters:
257
  *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO
258
  *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
259
  *                     generation capability
260
  * @retval None
261
  */
262
void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
263
{
264
  GPIO_InitTypeDef GPIO_InitStructure;
265
  EXTI_InitTypeDef EXTI_InitStructure;
266
  NVIC_InitTypeDef NVIC_InitStructure;
267
 
268
  /* Enable the BUTTON Clock */
269
  RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
270
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
271
 
272
  /* Configure Button pin as input */
273
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
274
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
275
  GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
276
  GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
277
 
278
 
279
  if (Button_Mode == BUTTON_MODE_EXTI)
280
  {
281
    /* Connect Button EXTI Line to Button GPIO Pin */
282
    SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
283
 
284
    /* Configure Button EXTI line */
285
    EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
286
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
287
 
288
    if((Button != BUTTON_WAKEUP) && (Button != BUTTON_KEY) && (Button != BUTTON_TAMPER))
289
    {
290
      EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
291
    }
292
    else
293
    {
294
      EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
295
    }
296
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
297
    EXTI_Init(&EXTI_InitStructure);
298
 
299
    /* Enable and set Button EXTI Interrupt to the lowest priority */
300
    NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
301
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
302
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
303
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
304
 
305
    NVIC_Init(&NVIC_InitStructure);
306
  }
307
}
308
 
309
/**
310
  * @brief  Returns the selected Button state.
311
  * @param  Button: Specifies the Button to be checked.
312
  *   This parameter can be one of following parameters:
313
  *     @arg BUTTON_WAKEUP: Wakeup Push Button
314
  *     @arg BUTTON_TAMPER: Tamper Push Button
315
  *     @arg BUTTON_KEY: Key Push Button
316
  *     @arg BUTTON_RIGHT: Joystick Right Push Button
317
  *     @arg BUTTON_LEFT: Joystick Left Push Button
318
  *     @arg BUTTON_UP: Joystick Up Push Button
319
  *     @arg BUTTON_DOWN: Joystick Down Push Button
320
  *     @arg BUTTON_SEL: Joystick Sel Push Button
321
  * @retval The Button GPIO pin value.
322
  */
323
uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
324
{
325
  return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
326
}
327
 
328
 
329
/**
330
  * @brief  Configures COM port.
331
  * @param  COM: Specifies the COM port to be configured.
332
  *   This parameter can be one of following parameters:
333
  *     @arg COM1
334
  *     @arg COM2
335
  * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that
336
  *   contains the configuration information for the specified USART peripheral.
337
  * @retval None
338
  */
339
void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
340
{
341
  GPIO_InitTypeDef GPIO_InitStructure;
342
 
343
  /* Enable GPIO clock */
344
  RCC_AHBPeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
345
 
346
  /* Enable UART clock */
347
  RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
348
 
349
  /* Connect PXx to USARTx_Tx*/
350
  GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
351
 
352
  /* Connect PXx to USARTx_Rx*/
353
  GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
354
 
355
  /* Configure USART Tx as alternate function push-pull */
356
  GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
357
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
358
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
359
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
360
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
361
  GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
362
 
363
  /* Configure USART Rx as input floating */
364
  GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
365
  GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
366
 
367
  /* USART configuration */
368
  USART_Init(COM_USART[COM], USART_InitStruct);
369
 
370
  /* Enable USART */
371
  USART_Cmd(COM_USART[COM], ENABLE);
372
}
373
 
374
/**
375
  * @brief  DeInitializes the SPI interface.
376
  * @param  None
377
  * @retval None
378
  */
379
void SD_LowLevel_DeInit(void)
380
{
381
  GPIO_InitTypeDef  GPIO_InitStructure;
382
 
383
  SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
384
  SPI_DeInit(SD_SPI);   /*!< DeInitializes the SD_SPI */
385
 
386
  /*!< SD_SPI Periph clock disable */
387
  RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE);
388
 
389
  /*!< Configure SD_SPI pins: SCK */
390
  GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
391
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
392
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
393
  GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
394
 
395
  /*!< Configure SD_SPI pins: MISO */
396
  GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
397
  GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
398
 
399
  /*!< Configure SD_SPI pins: MOSI */
400
  GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
401
  GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
402
 
403
  /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
404
  GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
405
  GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
406
 
407
  /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
408
  GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
409
  GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
410
}
411
 
412
/**
413
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for
414
  *         data transfer).
415
  * @param  None
416
  * @retval None
417
  */
418
void SD_LowLevel_Init(void)
419
{
420
  GPIO_InitTypeDef  GPIO_InitStructure;
421
  SPI_InitTypeDef   SPI_InitStructure;
422
 
423
  /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
424
       and SD_SPI_SCK_GPIO Periph clock enable */
425
  RCC_AHBPeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
426
                        SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
427
 
428
  /*!< SD_SPI Periph clock enable */
429
  RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
430
 
431
  /*!< Configure SD_SPI pins: SCK */
432
  GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
433
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
434
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
435
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
436
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
437
  GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
438
 
439
  /*!< Configure SD_SPI pins: MISO */
440
  GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
441
  GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
442
 
443
  /*!< Configure SD_SPI pins: MOSI */
444
  GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
445
  GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
446
 
447
  /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
448
  GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
449
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
450
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
451
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
452
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
453
  GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
454
 
455
  /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
456
  GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
457
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
458
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
459
  GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
460
 
461
  /* Connect PXx to SD_SPI_SCK */
462
  GPIO_PinAFConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_SCK_SOURCE, SD_SPI_SCK_AF);
463
 
464
  /* Connect PXx to SD_SPI_MISO */
465
  GPIO_PinAFConfig(SD_SPI_MISO_GPIO_PORT, SD_SPI_MISO_SOURCE, SD_SPI_MISO_AF);
466
 
467
  /* Connect PXx to SD_SPI_MOSI */
468
  GPIO_PinAFConfig(SD_SPI_MOSI_GPIO_PORT, SD_SPI_MOSI_SOURCE, SD_SPI_MOSI_AF);
469
 
470
  /*!< SD_SPI Config */
471
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
472
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
473
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
474
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
475
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
476
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
477
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
478
 
479
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
480
  SPI_InitStructure.SPI_CRCPolynomial = 7;
481
  SPI_Init(SD_SPI, &SPI_InitStructure);
482
 
483
  SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
484
}
485
 
486
/**
487
  * @brief  DeInitializes the LM75_I2C.
488
  * @param  None
489
  * @retval None
490
  */
491
void LM75_LowLevel_DeInit(void)
492
{
493
  GPIO_InitTypeDef  GPIO_InitStructure;
494
 
495
  /*!< Disable LM75_I2C */
496
  I2C_Cmd(LM75_I2C, DISABLE);
497
 
498
  /*!< DeInitializes the LM75_I2C */
499
  I2C_DeInit(LM75_I2C);
500
 
501
  /*!< LM75_I2C Periph clock disable */
502
  RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
503
 
504
  /*!< Configure LM75_I2C pins: SCL */
505
  GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
506
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
507
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
508
  GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
509
 
510
  /*!< Configure LM75_I2C pins: SDA */
511
  GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
512
  GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
513
 
514
  /*!< Configure LM75_I2C pin: SMBUS ALERT */
515
  GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
516
  GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
517
}
518
 
519
/**
520
  * @brief  Initializes the LM75_I2C.
521
  * @param  None
522
  * @retval None
523
  */
524
void LM75_LowLevel_Init(void)
525
{
526
  GPIO_InitTypeDef  GPIO_InitStructure;
527
 
528
  /*!< LM75_I2C Periph clock enable */
529
  RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
530
 
531
  /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
532
       and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
533
  RCC_AHBPeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
534
                        LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
535
 
536
  /*!< Configure LM75_I2C pins: SCL */
537
  GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
538
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
539
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
540
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
541
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
542
  GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
543
 
544
  /*!< Configure LM75_I2C pins: SDA */
545
  GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
546
  GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
547
 
548
  /*!< Configure LM75_I2C pin: SMBUS ALERT */
549
  GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
550
  GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
551
 
552
 
553
  /* Connect PXx to I2C_SCL */
554
  GPIO_PinAFConfig(LM75_I2C_SCL_GPIO_PORT, LM75_I2C_SCL_SOURCE, LM75_I2C_SCL_AF);
555
 
556
  /* Connect PXx to I2C_SDA */
557
  GPIO_PinAFConfig(LM75_I2C_SDA_GPIO_PORT, LM75_I2C_SDA_SOURCE, LM75_I2C_SDA_AF);
558
 
559
  /* Connect PXx to I2C_SMBUSALER */
560
  GPIO_PinAFConfig(LM75_I2C_SMBUSALERT_GPIO_PORT, LM75_I2C_SMBUSALERT_SOURCE, LM75_I2C_SMBUSALERT_AF);
561
}
562
 
563
/**
564
  * @}
565
  */
566
 
567
 
568
/**
569
  * @}
570
  */
571
 
572
/**
573
  * @}
574
  */
575
 
576
/**
577
  * @}
578
  */
579
 
580
/**
581
  * @}
582
  */
583
 
584
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.