stm32100e_eval.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32100e_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 SDIO), SPI serial
00010   *              flash (sFLASH) and temperature sensor (LM75)
00011   *          available on STM32100E-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 "stm32100e_eval.h"
00027 #include "stm32f10x_spi.h"
00028 #include "stm32f10x_i2c.h"
00029 #include "stm32f10x_dma.h"
00030 
00031 /** @addtogroup Utilities
00032   * @{
00033   */ 
00034 
00035 /** @addtogroup STM32_EVAL
00036   * @{
00037   */ 
00038 
00039 /** @addtogroup STM32100E_EVAL
00040   * @{
00041   */ 
00042       
00043 /** @defgroup STM32100E_EVAL_LOW_LEVEL 
00044   * @brief This file provides firmware functions to manage Leds, push-buttons, 
00045   *        COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE) 
00046   *        and temperature sensor (LM75) available on STM32100E-EVAL evaluation 
00047   *        board from STMicroelectronics.
00048   * @{
00049   */ 
00050 
00051 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_TypesDefinitions
00052   * @{
00053   */ 
00054 /**
00055   * @}
00056   */ 
00057 
00058 
00059 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Defines
00060   * @{
00061   */ 
00062 /**
00063   * @}
00064   */ 
00065 
00066 
00067 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Macros
00068   * @{
00069   */ 
00070 /**
00071   * @}
00072   */ 
00073 
00074 
00075 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Variables
00076   * @{
00077   */ 
00078 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
00079                                  LED4_GPIO_PORT};
00080 const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
00081                                  LED4_PIN};
00082 const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
00083                                  LED4_GPIO_CLK};
00084 
00085 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT, 
00086                                       KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
00087                                       LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
00088                                       DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT}; 
00089 
00090 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN, 
00091                                       KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
00092                                       LEFT_BUTTON_PIN, UP_BUTTON_PIN,
00093                                       DOWN_BUTTON_PIN, SEL_BUTTON_PIN}; 
00094 
00095 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
00096                                       KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
00097                                       LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
00098                                       DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
00099 
00100 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
00101                                             TAMPER_BUTTON_EXTI_LINE, 
00102                                             KEY_BUTTON_EXTI_LINE,
00103                                             RIGHT_BUTTON_EXTI_LINE,
00104                                             LEFT_BUTTON_EXTI_LINE,
00105                                             UP_BUTTON_EXTI_LINE,
00106                                             DOWN_BUTTON_EXTI_LINE,
00107                                             SEL_BUTTON_EXTI_LINE};
00108 
00109 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
00110                                               TAMPER_BUTTON_EXTI_PORT_SOURCE, 
00111                                               KEY_BUTTON_EXTI_PORT_SOURCE,
00112                                               RIGHT_BUTTON_EXTI_PORT_SOURCE,
00113                                               LEFT_BUTTON_EXTI_PORT_SOURCE,
00114                                               UP_BUTTON_EXTI_PORT_SOURCE,
00115                                               DOWN_BUTTON_EXTI_PORT_SOURCE,
00116                                               SEL_BUTTON_EXTI_PORT_SOURCE};
00117                                                                  
00118 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
00119                                              TAMPER_BUTTON_EXTI_PIN_SOURCE, 
00120                                              KEY_BUTTON_EXTI_PIN_SOURCE,
00121                                              RIGHT_BUTTON_EXTI_PIN_SOURCE,
00122                                              LEFT_BUTTON_EXTI_PIN_SOURCE,
00123                                              UP_BUTTON_EXTI_PIN_SOURCE,
00124                                              DOWN_BUTTON_EXTI_PIN_SOURCE,
00125                                              SEL_BUTTON_EXTI_PIN_SOURCE}; 
00126 
00127 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn, 
00128                                        KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
00129                                        LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
00130                                        DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
00131 
00132 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2}; 
00133 
00134 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
00135  
00136 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
00137  
00138 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
00139 
00140 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
00141  
00142 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
00143 
00144 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
00145 
00146 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
00147 
00148 DMA_InitTypeDef   sEEDMA_InitStructure;
00149 
00150 /**
00151   * @}
00152   */ 
00153 
00154 
00155 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_FunctionPrototypes
00156   * @{
00157   */ 
00158 
00159 /**
00160   * @}
00161   */ 
00162 
00163 
00164 /** @defgroup STM32100E_EVAL_LOW_LEVEL_Private_Functions
00165   * @{
00166   */ 
00167 
00168 /**
00169   * @brief  Configures LED GPIO.
00170   * @param  Led: Specifies the Led to be configured. 
00171   *   This parameter can be one of following parameters:
00172   *     @arg LED1
00173   *     @arg LED2
00174   *     @arg LED3
00175   *     @arg LED4
00176   * @retval None
00177   */
00178 void STM_EVAL_LEDInit(Led_TypeDef Led)
00179 {
00180   GPIO_InitTypeDef  GPIO_InitStructure;
00181   
00182   /* Enable the GPIO_LED Clock */
00183   RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
00184 
00185   /* Configure the GPIO_LED pin */
00186   GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
00187   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00188   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00189 
00190   GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
00191 }
00192 
00193 /**
00194   * @brief  Turns selected LED On.
00195   * @param  Led: Specifies the Led to be set on. 
00196   *   This parameter can be one of following parameters:
00197   *     @arg LED1
00198   *     @arg LED2
00199   *     @arg LED3
00200   *     @arg LED4  
00201   * @retval None
00202   */
00203 void STM_EVAL_LEDOn(Led_TypeDef Led)
00204 {
00205   GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];     
00206 }
00207 
00208 /**
00209   * @brief  Turns selected LED Off.
00210   * @param  Led: Specifies the Led to be set off. 
00211   *   This parameter can be one of following parameters:
00212   *     @arg LED1
00213   *     @arg LED2
00214   *     @arg LED3
00215   *     @arg LED4 
00216   * @retval None
00217   */
00218 void STM_EVAL_LEDOff(Led_TypeDef Led)
00219 {
00220   GPIO_PORT[Led]->BRR = GPIO_PIN[Led];    
00221 }
00222 
00223 /**
00224   * @brief  Toggles the selected LED.
00225   * @param  Led: Specifies the Led to be toggled. 
00226   *   This parameter can be one of following parameters:
00227   *     @arg LED1
00228   *     @arg LED2
00229   *     @arg LED3
00230   *     @arg LED4  
00231   * @retval None
00232   */
00233 void STM_EVAL_LEDToggle(Led_TypeDef Led)
00234 {
00235   GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
00236 }
00237 
00238 /**
00239   * @brief  Configures Button GPIO and EXTI Line.
00240   * @param  Button: Specifies the Button to be configured.
00241   *   This parameter can be one of following parameters:   
00242   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00243   *     @arg BUTTON_TAMPER: Tamper Push Button  
00244   *     @arg BUTTON_KEY: Key Push Button 
00245   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00246   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00247   *     @arg BUTTON_UP: Joystick Up Push Button 
00248   *     @arg BUTTON_DOWN: Joystick Down Push Button
00249   *     @arg BUTTON_SEL: Joystick Sel Push Button
00250   * @param  Button_Mode: Specifies Button mode.
00251   *   This parameter can be one of following parameters:   
00252   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO 
00253   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
00254   *                     generation capability  
00255   * @retval None
00256   */
00257 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00258 {
00259   GPIO_InitTypeDef GPIO_InitStructure;
00260   EXTI_InitTypeDef EXTI_InitStructure;
00261   NVIC_InitTypeDef NVIC_InitStructure;
00262 
00263   /* Enable the BUTTON Clock */
00264   RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
00265 
00266   /* Configure Button pin as input floating */
00267   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00268   GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
00269   GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
00270 
00271 
00272   if (Button_Mode == BUTTON_MODE_EXTI)
00273   {
00274     /* Connect Button EXTI Line to Button GPIO Pin */
00275     GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
00276 
00277     /* Configure Button EXTI line */
00278     EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
00279     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00280 
00281     if(Button != BUTTON_WAKEUP)
00282     {
00283       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  
00284     }
00285     else
00286     {
00287       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
00288     }
00289     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00290     EXTI_Init(&EXTI_InitStructure);
00291 
00292     /* Enable and set Button EXTI Interrupt to the lowest priority */
00293     NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
00294     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
00295     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
00296     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00297 
00298     NVIC_Init(&NVIC_InitStructure); 
00299   }
00300 }
00301 
00302 /**
00303   * @brief  Returns the selected Button state.
00304   * @param  Button: Specifies the Button to be checked.
00305   *   This parameter can be one of following parameters:    
00306   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00307   *     @arg BUTTON_TAMPER: Tamper Push Button  
00308   *     @arg BUTTON_KEY: Key Push Button 
00309   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00310   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00311   *     @arg BUTTON_UP: Joystick Up Push Button 
00312   *     @arg BUTTON_DOWN: Joystick Down Push Button
00313   *     @arg BUTTON_SEL: Joystick Sel Push Button    
00314   * @retval The Button GPIO pin value.
00315   */
00316 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
00317 {
00318   return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00319 }
00320 
00321 /**
00322   * @brief  Configures COM port.
00323   * @param  COM: Specifies the COM port to be configured.
00324   *   This parameter can be one of following parameters:    
00325   *     @arg COM1
00326   *     @arg COM2  
00327   * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that
00328   *   contains the configuration information for the specified USART peripheral.
00329   * @retval None
00330   */
00331 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
00332 {
00333   GPIO_InitTypeDef GPIO_InitStructure;
00334 
00335   /* Enable GPIO clock */
00336   RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
00337 
00338   /* Enable UART clock */
00339   if (COM == COM1)
00340   {
00341     RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); 
00342   }
00343   else
00344   {
00345     RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
00346   }
00347 
00348   /* Configure USART Tx as alternate function push-pull */
00349   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00350   GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
00351   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00352   GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
00353 
00354   /* Configure USART Rx as input floating */
00355   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00356   GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
00357   GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
00358 
00359   /* USART configuration */
00360   USART_Init(COM_USART[COM], USART_InitStruct);
00361     
00362   /* Enable USART */
00363   USART_Cmd(COM_USART[COM], ENABLE);
00364 }
00365 
00366 /**
00367   * @brief  DeInitializes the SD/SD communication.
00368   * @param  None
00369   * @retval None
00370   */
00371 void SD_LowLevel_DeInit(void)
00372 {
00373   GPIO_InitTypeDef  GPIO_InitStructure;
00374   
00375   SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
00376   SPI_I2S_DeInit(SD_SPI);   /*!< DeInitializes the SD_SPI */
00377   
00378   /*!< SD_SPI Periph clock disable */
00379   RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE);
00380   
00381   /*!< Configure SD_SPI pins: SCK */
00382   GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
00383   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00384   GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00385 
00386   /*!< Configure SD_SPI pins: MISO */
00387   GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
00388   GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00389 
00390   /*!< Configure SD_SPI pins: MOSI */
00391   GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
00392   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00393 
00394   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00395   GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
00396   GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
00397 
00398   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00399   GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
00400   GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
00401 }
00402 
00403 /**
00404   * @brief  Initializes the SD_SPI and CS pins.
00405   * @param  None
00406   * @retval None
00407   */
00408 void SD_LowLevel_Init(void)
00409 {
00410   GPIO_InitTypeDef  GPIO_InitStructure;
00411   SPI_InitTypeDef   SPI_InitStructure;
00412 
00413   /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO 
00414        and SD_SPI_SCK_GPIO Periph clock enable */
00415   RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
00416                          SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
00417 
00418   /*!< SD_SPI Periph clock enable */
00419   RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
00420   
00421   /*!< Configure SD_SPI pins: SCK */
00422   GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
00423   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00424   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00425   GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00426 
00427   /*!< Configure SD_SPI pins: MOSI */
00428   GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
00429   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00430 
00431   /*!< Configure SD_SPI pins: MISO */
00432   GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
00433   GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00434   
00435   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00436   GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
00437   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00438   GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
00439 
00440   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00441   GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
00442   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
00443   GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
00444 
00445   /*!< SD_SPI Config */
00446   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
00447   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
00448   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
00449   SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
00450   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
00451   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
00452   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
00453   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
00454   SPI_InitStructure.SPI_CRCPolynomial = 7;
00455   SPI_Init(SD_SPI, &SPI_InitStructure);
00456   
00457   SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
00458 }
00459 
00460 /**
00461   * @brief  DeInitializes peripherals used by the I2C EEPROM driver.
00462   * @param  None
00463   * @retval None
00464   */
00465 void sEE_LowLevel_DeInit(void)
00466 {
00467   GPIO_InitTypeDef  GPIO_InitStructure; 
00468   NVIC_InitTypeDef NVIC_InitStructure;    
00469    
00470   /* sEE_I2C Peripheral Disable */
00471   I2C_Cmd(sEE_I2C, DISABLE);
00472  
00473   /* sEE_I2C DeInit */
00474   I2C_DeInit(sEE_I2C);
00475 
00476   /*!< sEE_I2C Periph clock disable */
00477   RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
00478     
00479   /*!< GPIO configuration */  
00480   /*!< Configure sEE_I2C pins: SCL */
00481   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
00482   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00483   GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00484 
00485   /*!< Configure sEE_I2C pins: SDA */
00486   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
00487   GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00488   
00489   /* Configure and enable I2C DMA TX Channel interrupt */
00490   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
00491   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00492   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00493   NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
00494   NVIC_Init(&NVIC_InitStructure);
00495 
00496   /* Configure and enable I2C DMA RX Channel interrupt */
00497   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
00498   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00499   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00500   NVIC_Init(&NVIC_InitStructure);   
00501   
00502   /* Disable and Deinitialize the DMA channels */
00503   DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
00504   DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE);
00505   DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
00506   DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
00507 }
00508 
00509 /**
00510   * @brief  Initializes peripherals used by the I2C EEPROM driver.
00511   * @param  None
00512   * @retval None
00513   */
00514 void sEE_LowLevel_Init(void)
00515 {
00516   GPIO_InitTypeDef  GPIO_InitStructure;
00517   NVIC_InitTypeDef NVIC_InitStructure;  
00518     
00519   /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
00520   RCC_APB2PeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
00521 
00522   /*!< sEE_I2C Periph clock enable */
00523   RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
00524     
00525   /*!< GPIO configuration */  
00526   /*!< Configure sEE_I2C pins: SCL */
00527   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
00528   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00529   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00530   GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00531 
00532   /*!< Configure sEE_I2C pins: SDA */
00533   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
00534   GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); 
00535 
00536   /* Configure and enable I2C DMA TX Channel interrupt */
00537   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
00538   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00539   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00540   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00541   NVIC_Init(&NVIC_InitStructure);
00542 
00543   /* Configure and enable I2C DMA RX Channel interrupt */
00544   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
00545   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00546   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00547   NVIC_Init(&NVIC_InitStructure);  
00548   
00549   /*!< I2C DMA TX and RX channels configuration */
00550   /* Enable the DMA clock */
00551   RCC_AHBPeriphClockCmd(sEE_I2C_DMA_CLK, ENABLE);
00552 
00553   /* I2C TX DMA Channel configuration */
00554   DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
00555   sEEDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)sEE_I2C_DR_Address;
00556   sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0;   /* This parameter will be configured durig communication */
00557   sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;    /* This parameter will be configured durig communication */
00558   sEEDMA_InitStructure.DMA_BufferSize = 0xFFFF;            /* This parameter will be configured durig communication */
00559   sEEDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00560   sEEDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00561   sEEDMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte;
00562   sEEDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
00563   sEEDMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
00564   sEEDMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
00565   sEEDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00566   DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);  
00567   
00568   /* I2C RX DMA Channel configuration */
00569   DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
00570   DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);  
00571   
00572   /* Enable the DMA Channels Interrupts */
00573   DMA_ITConfig(sEE_I2C_DMA_CHANNEL_TX, DMA_IT_TC, ENABLE);
00574   DMA_ITConfig(sEE_I2C_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE);    
00575 }
00576 
00577 /**
00578   * @brief  Initializes DMA channel used by the I2C EEPROM driver.
00579   * @param  None
00580   * @retval None
00581   */
00582 void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction)
00583 { 
00584   /* Initialize the DMA with the new parameters */
00585   if (Direction == sEE_DIRECTION_TX)
00586   {
00587     /* Configure the DMA Tx Channel with the buffer address and the buffer size */
00588     sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
00589     sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;    
00590     sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;  
00591     DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);  
00592   }
00593   else
00594   { 
00595     /* Configure the DMA Rx Channel with the buffer address and the buffer size */
00596     sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
00597     sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
00598     sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;      
00599     DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);    
00600   }
00601 }
00602 
00603 /**
00604   * @brief  DeInitializes the peripherals used by the SPI FLASH driver.
00605   * @param  None
00606   * @retval None
00607   */
00608 void sFLASH_LowLevel_DeInit(void)
00609 {
00610   GPIO_InitTypeDef GPIO_InitStructure;
00611 
00612   /*!< Disable the sFLASH_SPI  */
00613   SPI_Cmd(sFLASH_SPI, DISABLE);
00614   
00615   /*!< DeInitializes the sFLASH_SPI */
00616   SPI_I2S_DeInit(sFLASH_SPI);
00617   
00618   /*!< sFLASH_SPI Periph clock disable */
00619   RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE);
00620   
00621   /*!< Configure sFLASH_SPI pins: SCK */
00622   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
00623   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00624   GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00625 
00626   /*!< Configure sFLASH_SPI pins: MISO */
00627   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
00628   GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00629 
00630   /*!< Configure sFLASH_SPI pins: MOSI */
00631   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
00632   GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00633 
00634   /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
00635   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
00636   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
00637 }
00638 
00639 /**
00640   * @brief  Initializes the peripherals used by the SPI FLASH driver.
00641   * @param  None
00642   * @retval None
00643   */
00644 void sFLASH_LowLevel_Init(void)
00645 {
00646   GPIO_InitTypeDef GPIO_InitStructure;
00647 
00648   /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO 
00649        and sFLASH_SPI_SCK_GPIO Periph clock enable */
00650   RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK |
00651                          sFLASH_SPI_SCK_GPIO_CLK, ENABLE);
00652 
00653   /*!< sFLASH_SPI Periph clock enable */
00654   RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);
00655   
00656   /*!< Configure sFLASH_SPI pins: SCK */
00657   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
00658   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00659   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00660   GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00661 
00662   /*!< Configure sFLASH_SPI pins: MOSI */
00663   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
00664   GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00665 
00666   /*!< Configure sFLASH_SPI pins: MISO */
00667   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
00668   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
00669   GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00670   
00671   /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
00672   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
00673   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00674   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
00675 }
00676 
00677 /**
00678   * @brief  DeInitializes the LM75_I2C.
00679   * @param  None
00680   * @retval None
00681   */
00682 void LM75_LowLevel_DeInit(void)
00683 {
00684   GPIO_InitTypeDef  GPIO_InitStructure;
00685 
00686   /*!< Disable LM75_I2C */
00687   I2C_Cmd(LM75_I2C, DISABLE);
00688   /*!< DeInitializes the LM75_I2C */
00689   I2C_DeInit(LM75_I2C);
00690   
00691   /*!< LM75_I2C Periph clock disable */
00692   RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
00693     
00694   /*!< Configure LM75_I2C pins: SCL */
00695   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
00696   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00697   GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00698 
00699   /*!< Configure LM75_I2C pins: SDA */
00700   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
00701   GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00702 
00703   /*!< Configure LM75_I2C pin: SMBUS ALERT */
00704   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
00705   GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
00706 }
00707 
00708 /**
00709   * @brief  Initializes the LM75_I2C..
00710   * @param  None
00711   * @retval None
00712   */
00713 void LM75_LowLevel_Init(void)
00714 {
00715   GPIO_InitTypeDef  GPIO_InitStructure;
00716 
00717   /*!< LM75_I2C Periph clock enable */
00718   RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
00719     
00720   /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK 
00721        and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
00722   RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
00723                          LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
00724   
00725   /*!< Configure LM75_I2C pins: SCL */
00726   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
00727   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00728   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00729   GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00730 
00731   /*!< Configure LM75_I2C pins: SDA */
00732   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
00733   GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00734 
00735   /*!< Configure LM75_I2C pin: SMBUS ALERT */
00736   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
00737   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
00738   GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); 
00739 }
00740 
00741 /**
00742   * @}
00743   */ 
00744 
00745 /**
00746   * @}
00747   */ 
00748 
00749 /**
00750   * @}
00751   */
00752 
00753 /**
00754   * @}
00755   */    
00756 
00757 /**
00758   * @}
00759   */ 
00760     
00761 /******************* (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