stm32100b_eval.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32100b_eval.c
00004   * @author  MCD Application Team
00005   * @version V4.3.0
00006   * @date    10/15/2010
00007   * @brief   This file provides
00008   *            - set of firmware functions to manage Leds, push-button and COM ports
00009   *            - low level initialization functions for SD card (on SPI), SPI serial
00010   *              flash (sFLASH) and temperature sensor (LM75)
00011   *          available on STM32100B-EVAL evaluation board from STMicroelectronics. 
00012   ******************************************************************************
00013   * @copy
00014   *
00015   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00016   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00017   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00018   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00019   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00020   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00021   *
00022   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00023   */ 
00024   
00025 /* Includes ------------------------------------------------------------------*/
00026 #include "stm32100b_eval.h"
00027 #include "stm32f10x_spi.h"
00028 #include "stm32f10x_i2c.h"
00029 
00030 /** @addtogroup Utilities
00031   * @{
00032   */ 
00033 
00034 /** @addtogroup STM32_EVAL
00035   * @{
00036   */ 
00037 
00038 /** @addtogroup STM32100B_EVAL
00039   * @{
00040   */
00041       
00042 /** @defgroup STM32100B_EVAL_LOW_LEVEL 
00043   * @brief This file provides firmware functions to manage Leds, push-buttons, 
00044   *        COM ports, SD card on SPI, serial flash (sFLASH) and temperature 
00045   *        sensor (LM75) available on STM32100B-EVAL evaluation board from 
00046   *        STMicroelectronics.
00047   * @{
00048   */ 
00049 
00050 /** @defgroup STM32100B_EVAL_LOW_LEVEL_Private_TypesDefinitions
00051   * @{
00052   */ 
00053 /**
00054   * @}
00055   */ 
00056 
00057 
00058 /** @defgroup STM32100B_EVAL_LOW_LEVEL_Private_Defines
00059   * @{
00060   */ 
00061 /**
00062   * @}
00063   */ 
00064 
00065 
00066 /** @defgroup STM32100B_EVAL_LOW_LEVEL_Private_Macros
00067   * @{
00068   */ 
00069 /**
00070   * @}
00071   */ 
00072 
00073 
00074 /** @defgroup STM32100B_EVAL_LOW_LEVEL_Private_Variables
00075   * @{
00076   */ 
00077 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
00078                                  LED4_GPIO_PORT};
00079 const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
00080                                  LED4_PIN};
00081 const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
00082                                  LED4_GPIO_CLK};
00083 
00084 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT, 
00085                                       KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
00086                                       LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
00087                                       DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT}; 
00088 
00089 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN, 
00090                                       KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
00091                                       LEFT_BUTTON_PIN, UP_BUTTON_PIN,
00092                                       DOWN_BUTTON_PIN, SEL_BUTTON_PIN}; 
00093 
00094 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
00095                                       KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
00096                                       LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
00097                                       DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
00098 
00099 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
00100                                             TAMPER_BUTTON_EXTI_LINE, 
00101                                             KEY_BUTTON_EXTI_LINE,
00102                                             RIGHT_BUTTON_EXTI_LINE,
00103                                             LEFT_BUTTON_EXTI_LINE,
00104                                             UP_BUTTON_EXTI_LINE,
00105                                             DOWN_BUTTON_EXTI_LINE,
00106                                             SEL_BUTTON_EXTI_LINE};
00107 
00108 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
00109                                               TAMPER_BUTTON_EXTI_PORT_SOURCE, 
00110                                               KEY_BUTTON_EXTI_PORT_SOURCE,
00111                                               RIGHT_BUTTON_EXTI_PORT_SOURCE,
00112                                               LEFT_BUTTON_EXTI_PORT_SOURCE,
00113                                               UP_BUTTON_EXTI_PORT_SOURCE,
00114                                               DOWN_BUTTON_EXTI_PORT_SOURCE,
00115                                               SEL_BUTTON_EXTI_PORT_SOURCE};
00116                                                                  
00117 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
00118                                              TAMPER_BUTTON_EXTI_PIN_SOURCE, 
00119                                              KEY_BUTTON_EXTI_PIN_SOURCE,
00120                                              RIGHT_BUTTON_EXTI_PIN_SOURCE,
00121                                              LEFT_BUTTON_EXTI_PIN_SOURCE,
00122                                              UP_BUTTON_EXTI_PIN_SOURCE,
00123                                              DOWN_BUTTON_EXTI_PIN_SOURCE,
00124                                              SEL_BUTTON_EXTI_PIN_SOURCE}; 
00125 
00126 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn, 
00127                                        KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
00128                                        LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
00129                                        DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
00130 
00131 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2}; 
00132 
00133 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
00134  
00135 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
00136  
00137 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
00138 
00139 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
00140  
00141 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
00142 
00143 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
00144 
00145 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
00146 
00147 /**
00148   * @}
00149   */ 
00150 
00151 
00152 /** @defgroup STM32100B_EVAL_LOW_LEVEL_Private_FunctionPrototypes
00153   * @{
00154   */ 
00155 
00156 /**
00157   * @}
00158   */ 
00159 
00160 
00161 /** @defgroup STM32100B_EVAL_LOW_LEVEL_Private_Functions
00162   * @{
00163   */ 
00164 
00165 /**
00166   * @brief  Configures LED GPIO.
00167   * @param  Led: Specifies the Led to be configured. 
00168   *   This parameter can be one of following parameters:
00169   *     @arg LED1
00170   *     @arg LED2
00171   *     @arg LED3
00172   *     @arg LED4
00173   * @retval None
00174   */
00175 void STM_EVAL_LEDInit(Led_TypeDef Led)
00176 {
00177   GPIO_InitTypeDef  GPIO_InitStructure;
00178   
00179   /* Enable the GPIO_LED Clock */
00180   RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
00181 
00182   /* Configure the GPIO_LED pin */
00183   GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
00184   
00185   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00186   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00187   GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
00188 }
00189 
00190 /**
00191   * @brief  Turns selected LED On.
00192   * @param  Led: Specifies the Led to be set on. 
00193   *   This parameter can be one of following parameters:
00194   *     @arg LED1
00195   *     @arg LED2
00196   *     @arg LED3
00197   *     @arg LED4  
00198   * @retval None
00199   */
00200 void STM_EVAL_LEDOn(Led_TypeDef Led)
00201 {
00202   GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];   
00203 }
00204 
00205 /**
00206   * @brief  Turns selected LED Off.
00207   * @param  Led: Specifies the Led to be set off. 
00208   *   This parameter can be one of following parameters:
00209   *     @arg LED1
00210   *     @arg LED2
00211   *     @arg LED3
00212   *     @arg LED4 
00213   * @retval None
00214   */
00215 void STM_EVAL_LEDOff(Led_TypeDef Led)
00216 {
00217   GPIO_PORT[Led]->BRR = GPIO_PIN[Led];   
00218 }
00219 
00220 /**
00221   * @brief  Toggles the selected LED.
00222   * @param  Led: Specifies the Led to be toggled. 
00223   *   This parameter can be one of following parameters:
00224   *     @arg LED1
00225   *     @arg LED2
00226   *     @arg LED3
00227   *     @arg LED4  
00228   * @retval None
00229   */
00230 void STM_EVAL_LEDToggle(Led_TypeDef Led)
00231 {
00232   GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
00233 }
00234 
00235 /**
00236   * @brief  Configures Button GPIO and EXTI Line.
00237   * @param  Button: Specifies the Button to be configured.
00238   *   This parameter can be one of following parameters:   
00239   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00240   *     @arg BUTTON_TAMPER: Tamper Push Button  
00241   *     @arg BUTTON_KEY: Key Push Button 
00242   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00243   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00244   *     @arg BUTTON_UP: Joystick Up Push Button 
00245   *     @arg BUTTON_DOWN: Joystick Down Push Button
00246   *     @arg BUTTON_SEL: Joystick Sel Push Button
00247   * @param  Button_Mode: Specifies Button mode.
00248   *   This parameter can be one of following parameters:   
00249   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO 
00250   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
00251   *                     generation capability  
00252   * @retval None
00253   */
00254 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00255 {
00256   GPIO_InitTypeDef GPIO_InitStructure;
00257   EXTI_InitTypeDef EXTI_InitStructure;
00258   NVIC_InitTypeDef NVIC_InitStructure;
00259 
00260   /* Enable the BUTTON Clock */
00261   RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
00262 
00263   /* Configure Button pin as input floating */
00264   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00265   GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
00266   GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
00267 
00268 
00269   if (Button_Mode == BUTTON_MODE_EXTI)
00270   {
00271     /* Connect Button EXTI Line to Button GPIO Pin */
00272     GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
00273 
00274     /* Configure Button EXTI line */
00275     EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
00276     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00277 
00278     if(Button != BUTTON_WAKEUP)
00279     {
00280       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  
00281     }
00282     else
00283     {
00284       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
00285     }
00286     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00287     EXTI_Init(&EXTI_InitStructure);
00288 
00289     /* Enable and set Button EXTI Interrupt to the lowest priority */
00290     NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
00291     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
00292     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
00293     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00294 
00295     NVIC_Init(&NVIC_InitStructure); 
00296   }
00297 }
00298 
00299 /**
00300   * @brief  Returns the selected Button state.
00301   * @param  Button: Specifies the Button to be checked.
00302   *   This parameter can be one of following parameters:    
00303   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00304   *     @arg BUTTON_TAMPER: Tamper Push Button  
00305   *     @arg BUTTON_KEY: Key Push Button 
00306   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00307   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00308   *     @arg BUTTON_UP: Joystick Up Push Button 
00309   *     @arg BUTTON_DOWN: Joystick Down Push Button
00310   *     @arg BUTTON_SEL: Joystick Sel Push Button    
00311   * @retval The Button GPIO pin value.
00312   */
00313 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
00314 {
00315   return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00316 }
00317 
00318 
00319 /**
00320   * @brief  Configures COM port.
00321   * @param  COM: Specifies the COM port to be configured.
00322   *   This parameter can be one of following parameters:    
00323   *     @arg COM1
00324   *     @arg COM2  
00325   * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that
00326   *   contains the configuration information for the specified USART peripheral.
00327   * @retval None
00328   */
00329 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
00330 {
00331   GPIO_InitTypeDef GPIO_InitStructure;
00332 
00333   /* Enable GPIO clock */
00334   RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
00335 
00336 
00337   /* Enable UART clock */
00338   if (COM == COM1)
00339   {
00340     RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); 
00341   }
00342   else
00343   {
00344     /* Enable the USART2 Pins Software Remapping */
00345     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
00346     RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
00347   }
00348 
00349   /* Configure USART Tx as alternate function push-pull */
00350   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00351   GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
00352   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00353   GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
00354 
00355   /* Configure USART Rx as input floating */
00356   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00357   GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
00358   GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
00359 
00360   /* USART configuration */
00361   USART_Init(COM_USART[COM], USART_InitStruct);
00362     
00363   /* Enable USART */
00364   USART_Cmd(COM_USART[COM], ENABLE);
00365 }
00366 
00367 /**
00368   * @brief  DeInitializes the SD/SD communication.
00369   * @param  None
00370   * @retval None
00371   */
00372 void SD_LowLevel_DeInit(void)
00373 {
00374   GPIO_InitTypeDef  GPIO_InitStructure;
00375   
00376   SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
00377   SPI_I2S_DeInit(SD_SPI);   /*!< DeInitializes the SD_SPI */
00378   
00379   /*!< SD_SPI Periph clock disable */
00380   RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE); 
00381 
00382   /*!< Configure SD_SPI pins: SCK */
00383   GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
00384   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00385   GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00386 
00387   /*!< Configure SD_SPI pins: MISO */
00388   GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
00389   GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00390 
00391   /*!< Configure SD_SPI pins: MOSI */
00392   GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
00393   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00394 
00395   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00396   GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
00397   GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
00398 
00399   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00400   GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
00401   GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
00402 }
00403 
00404 /**
00405   * @brief  Initializes the SD_SPI and CS pins.
00406   * @param  None
00407   * @retval None
00408   */
00409 void SD_LowLevel_Init(void)
00410 {
00411   GPIO_InitTypeDef  GPIO_InitStructure;
00412   SPI_InitTypeDef   SPI_InitStructure;
00413 
00414   /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO 
00415        and SD_SPI_SCK_GPIO Periph clock enable */
00416   RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
00417                          SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
00418 
00419   /*!< SD_SPI Periph clock enable */
00420   RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE); 
00421 
00422   
00423   /*!< Configure SD_SPI pins: SCK */
00424   GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
00425   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00426   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00427   GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00428 
00429   /*!< Configure SD_SPI pins: MOSI */
00430   GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
00431   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00432 
00433   /*!< Configure SD_SPI pins: MISO */
00434   GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
00435   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
00436   GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00437   
00438   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00439   GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
00440   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00441   GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
00442 
00443   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00444   GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
00445   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
00446   GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
00447 
00448   /*!< SD_SPI Config */
00449   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
00450   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
00451   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
00452   SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
00453   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
00454   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
00455   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
00456 
00457   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
00458   SPI_InitStructure.SPI_CRCPolynomial = 7;
00459   SPI_Init(SD_SPI, &SPI_InitStructure);
00460   
00461   SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
00462 }
00463 
00464 /**
00465   * @brief  DeInitializes the peripherals used by the SPI FLASH driver.
00466   * @param  None
00467   * @retval None
00468   */
00469 void sFLASH_LowLevel_DeInit(void)
00470 {
00471   GPIO_InitTypeDef GPIO_InitStructure;
00472 
00473   /*!< Disable the sFLASH_SPI  */
00474   SPI_Cmd(sFLASH_SPI, DISABLE);
00475   
00476   /*!< DeInitializes the sFLASH_SPI */
00477   SPI_I2S_DeInit(sFLASH_SPI);
00478   
00479   /*!< sFLASH_SPI Periph clock disable */
00480   RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE);
00481   
00482   /*!< Configure sFLASH_SPI pins: SCK */
00483   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
00484   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00485   GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00486 
00487   /*!< Configure sFLASH_SPI pins: MISO */
00488   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
00489   GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00490 
00491   /*!< Configure sFLASH_SPI pins: MOSI */
00492   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
00493   GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00494 
00495   /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
00496   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
00497   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
00498 }
00499 
00500 /**
00501   * @brief  Initializes the peripherals used by the SPI FLASH driver.
00502   * @param  None
00503   * @retval None
00504   */
00505 void sFLASH_LowLevel_Init(void)
00506 {
00507   GPIO_InitTypeDef GPIO_InitStructure;
00508 
00509   /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO 
00510        and sFLASH_SPI_SCK_GPIO Periph clock enable */
00511   RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK |
00512                          sFLASH_SPI_SCK_GPIO_CLK, ENABLE);
00513 
00514   /*!< sFLASH_SPI Periph clock enable */
00515   RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);
00516   
00517   /*!< Configure sFLASH_SPI pins: SCK */
00518   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
00519   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00520   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00521   GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00522 
00523   /*!< Configure sFLASH_SPI pins: MOSI */
00524   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
00525   GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00526 
00527   /*!< Configure sFLASH_SPI pins: MISO */
00528   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
00529   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
00530   GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00531   
00532   /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
00533   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
00534   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00535   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
00536 }
00537 
00538 /**
00539   * @brief  DeInitializes the LM75_I2C.
00540   * @param  None
00541   * @retval None
00542   */
00543 void LM75_LowLevel_DeInit(void)
00544 {
00545   GPIO_InitTypeDef  GPIO_InitStructure;
00546 
00547   /*!< Disable LM75_I2C */
00548   I2C_Cmd(LM75_I2C, DISABLE);
00549   /*!< DeInitializes the LM75_I2C */
00550   I2C_DeInit(LM75_I2C);
00551   
00552   /*!< LM75_I2C Periph clock disable */
00553   RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
00554     
00555   /*!< Configure LM75_I2C pins: SCL */
00556   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
00557   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00558   GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00559 
00560   /*!< Configure LM75_I2C pins: SDA */
00561   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
00562   GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00563 
00564   /*!< Configure LM75_I2C pin: SMBUS ALERT */
00565   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
00566   GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
00567 }
00568 
00569 /**
00570   * @brief  Initializes the LM75_I2C..
00571   * @param  None
00572   * @retval None
00573   */
00574 void LM75_LowLevel_Init(void)
00575 {
00576   GPIO_InitTypeDef  GPIO_InitStructure;
00577 
00578   /*!< LM75_I2C Periph clock enable */
00579   RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
00580     
00581   /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK 
00582        and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
00583   RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
00584                          LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
00585   
00586   /*!< Configure LM75_I2C pins: SCL */
00587   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
00588   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00589   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00590   GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00591 
00592   /*!< Configure LM75_I2C pins: SDA */
00593   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
00594   GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00595 
00596   /*!< Configure LM75_I2C pin: SMBUS ALERT */
00597   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
00598   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
00599   GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); 
00600 }
00601 
00602 /**
00603   * @}
00604   */ 
00605 
00606 
00607 /**
00608   * @}
00609   */ 
00610 
00611 /**
00612   * @}
00613   */
00614 
00615 /**
00616   * @}
00617   */  
00618 
00619 /**
00620   * @}
00621   */ 
00622      
00623 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32