stm3210c_eval.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm3210c_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) and I2C
00010   *              serial EEPROM (sEE)
00011   *          available on STM3210C-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 "stm3210c_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 STM3210C_EVAL
00040   * @{
00041   */ 
00042       
00043 /** @defgroup STM3210C_EVAL_LOW_LEVEL 
00044   * @brief This file provides firmware functions to manage Leds, push-buttons, 
00045   *        COM ports, SD card on SPI and EEPROM (sEE) available on STM3210C-EVAL 
00046   *        evaluation board from STMicroelectronics.
00047   * @{
00048   */ 
00049 
00050 /** @defgroup STM3210C_EVAL_LOW_LEVEL_Private_TypesDefinitions
00051   * @{
00052   */ 
00053 /**
00054   * @}
00055   */ 
00056 
00057 
00058 /** @defgroup STM3210C_EVAL_LOW_LEVEL_Private_Defines
00059   * @{
00060   */ 
00061 /**
00062   * @}
00063   */ 
00064 
00065 
00066 /** @defgroup STM3210C_EVAL_LOW_LEVEL_Private_Macros
00067   * @{
00068   */ 
00069 /**
00070   * @}
00071   */ 
00072 
00073 
00074 /** @defgroup STM3210C_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}; 
00086 
00087 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN,
00088                                       KEY_BUTTON_PIN}; 
00089 
00090 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
00091                                       KEY_BUTTON_GPIO_CLK};
00092 
00093 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
00094                                             TAMPER_BUTTON_EXTI_LINE, 
00095                                             KEY_BUTTON_EXTI_LINE};
00096 
00097 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
00098                                               TAMPER_BUTTON_EXTI_PORT_SOURCE, 
00099                                               KEY_BUTTON_EXTI_PORT_SOURCE};
00100                                                                  
00101 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
00102                                              TAMPER_BUTTON_EXTI_PIN_SOURCE, 
00103                                              KEY_BUTTON_EXTI_PIN_SOURCE}; 
00104 
00105 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn,
00106                                        KEY_BUTTON_EXTI_IRQn};
00107 
00108 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1}; 
00109 
00110 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
00111 
00112 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
00113 
00114 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK};
00115 
00116 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK};
00117  
00118 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK};
00119 
00120 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
00121 
00122 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
00123  
00124 DMA_InitTypeDef   sEEDMA_InitStructure; 
00125 
00126 /**
00127   * @}
00128   */ 
00129 
00130 
00131 /** @defgroup STM3210C_EVAL_LOW_LEVEL_Private_FunctionPrototypes
00132   * @{
00133   */ 
00134 /**
00135   * @}
00136   */ 
00137 
00138 /** @defgroup STM3210C_EVAL_LOW_LEVEL_Private_Functions
00139   * @{
00140   */ 
00141 
00142 /**
00143   * @brief  Configures LED GPIO.
00144   * @param  Led: Specifies the Led to be configured. 
00145   *   This parameter can be one of following parameters:
00146   *     @arg LED1
00147   *     @arg LED2
00148   *     @arg LED3
00149   *     @arg LED4
00150   * @retval None
00151   */
00152 void STM_EVAL_LEDInit(Led_TypeDef Led)
00153 {
00154   GPIO_InitTypeDef  GPIO_InitStructure;
00155   
00156   /* Enable the GPIO_LED Clock */
00157   RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
00158 
00159   /* Configure the GPIO_LED pin */
00160   GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
00161   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00162   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00163 
00164   GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
00165 }
00166 
00167 /**
00168   * @brief  Turns selected LED On.
00169   * @param  Led: Specifies the Led to be set on. 
00170   *   This parameter can be one of following parameters:
00171   *     @arg LED1
00172   *     @arg LED2
00173   *     @arg LED3
00174   *     @arg LED4  
00175   * @retval None
00176   */
00177 void STM_EVAL_LEDOn(Led_TypeDef Led)
00178 {
00179   GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];     
00180 }
00181 
00182 /**
00183   * @brief  Turns selected LED Off.
00184   * @param  Led: Specifies the Led to be set off. 
00185   *   This parameter can be one of following parameters:
00186   *     @arg LED1
00187   *     @arg LED2
00188   *     @arg LED3
00189   *     @arg LED4 
00190   * @retval None
00191   */
00192 void STM_EVAL_LEDOff(Led_TypeDef Led)
00193 {
00194   GPIO_PORT[Led]->BRR = GPIO_PIN[Led];  
00195 }
00196 
00197 /**
00198   * @brief  Toggles the selected LED.
00199   * @param  Led: Specifies the Led to be toggled. 
00200   *   This parameter can be one of following parameters:
00201   *     @arg LED1
00202   *     @arg LED2
00203   *     @arg LED3
00204   *     @arg LED4  
00205   * @retval None
00206   */
00207 void STM_EVAL_LEDToggle(Led_TypeDef Led)
00208 {
00209   GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
00210 }
00211 
00212 /**
00213   * @brief  Configures Button GPIO and EXTI Line.
00214   * @param  Button: Specifies the Button to be configured.
00215   *   This parameter can be one of following parameters:   
00216   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00217   *     @arg BUTTON_TAMPER: Tamper Push Button  
00218   *     @arg BUTTON_KEY: Key Push Button 
00219   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00220   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00221   *     @arg BUTTON_UP: Joystick Up Push Button 
00222   *     @arg BUTTON_DOWN: Joystick Down Push Button
00223   *     @arg BUTTON_SEL: Joystick Sel Push Button
00224   * @param  Button_Mode: Specifies Button mode.
00225   *   This parameter can be one of following parameters:   
00226   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO 
00227   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
00228   *                     generation capability  
00229   * @retval None
00230   */
00231 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00232 {
00233   GPIO_InitTypeDef GPIO_InitStructure;
00234   EXTI_InitTypeDef EXTI_InitStructure;
00235   NVIC_InitTypeDef NVIC_InitStructure;
00236 
00237   /* Enable the BUTTON Clock */
00238   RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
00239 
00240   /* Configure Button pin as input floating */
00241   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00242   GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
00243   GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
00244 
00245 
00246   if (Button_Mode == BUTTON_MODE_EXTI)
00247   {
00248     /* Connect Button EXTI Line to Button GPIO Pin */
00249     GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
00250 
00251     /* Configure Button EXTI line */
00252     EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
00253     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00254 
00255     if(Button != BUTTON_WAKEUP)
00256     {
00257       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  
00258     }
00259     else
00260     {
00261       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
00262     }
00263     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00264     EXTI_Init(&EXTI_InitStructure);
00265 
00266     /* Enable and set Button EXTI Interrupt to the lowest priority */
00267     NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
00268     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
00269     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
00270     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00271 
00272     NVIC_Init(&NVIC_InitStructure); 
00273   }
00274 }
00275 
00276 /**
00277   * @brief  Returns the selected Button state.
00278   * @param  Button: Specifies the Button to be checked.
00279   *   This parameter can be one of following parameters:    
00280   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00281   *     @arg BUTTON_TAMPER: Tamper Push Button  
00282   *     @arg BUTTON_KEY: Key Push Button 
00283   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00284   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00285   *     @arg BUTTON_UP: Joystick Up Push Button 
00286   *     @arg BUTTON_DOWN: Joystick Down Push Button
00287   *     @arg BUTTON_SEL: Joystick Sel Push Button    
00288   * @retval The Button GPIO pin value.
00289   */
00290 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
00291 {
00292   return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00293 }
00294 
00295 
00296 /**
00297   * @brief  Configures COM port.
00298   * @param  COM: Specifies the COM port to be configured.
00299   *   This parameter can be one of following parameters:    
00300   *     @arg COM1
00301   *     @arg COM2  
00302   * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that
00303   *   contains the configuration information for the specified USART peripheral.
00304   * @retval None
00305   */
00306 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
00307 {
00308   GPIO_InitTypeDef GPIO_InitStructure;
00309 
00310   /* Enable GPIO clock */
00311   RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
00312 
00313   if (COM == COM1)
00314   {
00315     /* Enable the USART2 Pins Software Remapping */
00316     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
00317     RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
00318   }
00319 
00320   /* Configure USART Tx as alternate function push-pull */
00321   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00322   GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
00323   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00324   GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
00325 
00326   /* Configure USART Rx as input floating */
00327   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00328   GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
00329   GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
00330 
00331   /* USART configuration */
00332   USART_Init(COM_USART[COM], USART_InitStruct);
00333     
00334   /* Enable USART */
00335   USART_Cmd(COM_USART[COM], ENABLE);
00336 }
00337 
00338 /**
00339   * @brief  DeInitializes the SD/SD communication.
00340   * @param  None
00341   * @retval None
00342   */
00343 void SD_LowLevel_DeInit(void)
00344 {
00345   GPIO_InitTypeDef  GPIO_InitStructure;
00346   
00347   SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
00348   SPI_I2S_DeInit(SD_SPI);   /*!< DeInitializes the SD_SPI */
00349   
00350   /*!< SD_SPI Periph clock disable */
00351   RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE);
00352   /*!< DeRemap SPI3 Pins */
00353   GPIO_PinRemapConfig(GPIO_Remap_SPI3, DISABLE);  
00354   
00355   /*!< Configure SD_SPI pins: SCK */
00356   GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
00357   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00358   GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00359 
00360   /*!< Configure SD_SPI pins: MISO */
00361   GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
00362   GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00363 
00364   /*!< Configure SD_SPI pins: MOSI */
00365   GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
00366   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00367 
00368   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00369   GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
00370   GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
00371 
00372   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00373   GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
00374   GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
00375 }
00376 
00377 /**
00378   * @brief  Initializes the SD_SPI and CS pins.
00379   * @param  None
00380   * @retval None
00381   */
00382 void SD_LowLevel_Init(void)
00383 {
00384   GPIO_InitTypeDef  GPIO_InitStructure;
00385   SPI_InitTypeDef   SPI_InitStructure;
00386 
00387   /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO 
00388        and SD_SPI_SCK_GPIO Periph clock enable */
00389   RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
00390                          SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
00391 
00392   /*!< SD_SPI Periph clock enable */
00393   RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
00394   /*!< AFIO Periph clock enable */
00395   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
00396   /*!< Remap SPI3 Pins */
00397   GPIO_PinRemapConfig(GPIO_Remap_SPI3,ENABLE);  
00398   
00399   /*!< Configure SD_SPI pins: SCK */
00400   GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
00401   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00402   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00403   GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00404 
00405   /*!< Configure SD_SPI pins: MOSI */
00406   GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
00407   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00408 
00409   /*!< Configure SD_SPI pins: MISO */
00410   GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
00411   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
00412   GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00413   
00414   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00415   GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
00416   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00417   GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
00418 
00419   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00420   GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
00421   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
00422   GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
00423 
00424   /*!< SD_SPI Config */
00425   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
00426   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
00427   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
00428   SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
00429   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
00430   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
00431   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
00432   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
00433   SPI_InitStructure.SPI_CRCPolynomial = 7;
00434   SPI_Init(SD_SPI, &SPI_InitStructure);
00435   
00436   SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
00437 }
00438 
00439 /**
00440   * @brief  DeInitializes peripherals used by the I2C EEPROM driver.
00441   * @param  None
00442   * @retval None
00443   */
00444 void sEE_LowLevel_DeInit(void)
00445 {
00446   GPIO_InitTypeDef  GPIO_InitStructure; 
00447   NVIC_InitTypeDef NVIC_InitStructure;    
00448    
00449   /* sEE_I2C Peripheral Disable */
00450   I2C_Cmd(sEE_I2C, DISABLE);
00451  
00452   /* sEE_I2C DeInit */
00453   I2C_DeInit(sEE_I2C);
00454 
00455   /*!< sEE_I2C Periph clock disable */
00456   RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
00457     
00458   /*!< GPIO configuration */  
00459   /*!< Configure sEE_I2C pins: SCL */
00460   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
00461   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00462   GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00463 
00464   /*!< Configure sEE_I2C pins: SDA */
00465   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
00466   GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00467   
00468   /* Configure and enable I2C DMA TX Channel interrupt */
00469   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
00470   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00471   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00472   NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
00473   NVIC_Init(&NVIC_InitStructure);
00474 
00475   /* Configure and enable I2C DMA RX Channel interrupt */
00476   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
00477   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00478   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00479   NVIC_Init(&NVIC_InitStructure);   
00480   
00481   /* Disable and Deinitialize the DMA channels */
00482   DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
00483   DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE);
00484   DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
00485   DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
00486 }
00487 
00488 /**
00489   * @brief  Initializes peripherals used by the I2C EEPROM driver.
00490   * @param  None
00491   * @retval None
00492   */
00493 void sEE_LowLevel_Init(void)
00494 {
00495   GPIO_InitTypeDef  GPIO_InitStructure;
00496   NVIC_InitTypeDef NVIC_InitStructure;  
00497     
00498   /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
00499   RCC_APB2PeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
00500 
00501   /*!< sEE_I2C Periph clock enable */
00502   RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
00503     
00504   /*!< GPIO configuration */  
00505   /*!< Configure sEE_I2C pins: SCL */
00506   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
00507   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00508   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00509   GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00510 
00511   /*!< Configure sEE_I2C pins: SDA */
00512   GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
00513   GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); 
00514 
00515   /* Configure and enable I2C DMA TX Channel interrupt */
00516   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
00517   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00518   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00519   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00520   NVIC_Init(&NVIC_InitStructure);
00521 
00522   /* Configure and enable I2C DMA RX Channel interrupt */
00523   NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
00524   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
00525   NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
00526   NVIC_Init(&NVIC_InitStructure);  
00527   
00528   /*!< I2C DMA TX and RX channels configuration */
00529   /* Enable the DMA clock */
00530   RCC_AHBPeriphClockCmd(sEE_I2C_DMA_CLK, ENABLE);
00531 
00532   /* I2C TX DMA Channel configuration */
00533   DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
00534   sEEDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)sEE_I2C_DR_Address;
00535   sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0;   /* This parameter will be configured durig communication */
00536   sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;    /* This parameter will be configured durig communication */
00537   sEEDMA_InitStructure.DMA_BufferSize = 0xFFFF;            /* This parameter will be configured durig communication */
00538   sEEDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00539   sEEDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00540   sEEDMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte;
00541   sEEDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
00542   sEEDMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
00543   sEEDMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
00544   sEEDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00545   DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);  
00546   
00547   /* I2C RX DMA Channel configuration */
00548   DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
00549   DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);  
00550   
00551   /* Enable the DMA Channels Interrupts */
00552   DMA_ITConfig(sEE_I2C_DMA_CHANNEL_TX, DMA_IT_TC, ENABLE);
00553   DMA_ITConfig(sEE_I2C_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE);    
00554 }
00555 
00556 
00557 /**
00558   * @brief  Initializes DMA channel used by the I2C EEPROM driver.
00559   * @param  None
00560   * @retval None
00561   */
00562 void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction)
00563 { 
00564   /* Initialize the DMA with the new parameters */
00565   if (Direction == sEE_DIRECTION_TX)
00566   {
00567     /* Configure the DMA Tx Channel with the buffer address and the buffer size */
00568     sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
00569     sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;    
00570     sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;  
00571     DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);  
00572   }
00573   else
00574   { 
00575     /* Configure the DMA Rx Channel with the buffer address and the buffer size */
00576     sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
00577     sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
00578     sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;      
00579     DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);    
00580   }
00581 }
00582 
00583 /**
00584   * @}
00585   */ 
00586 
00587 /**
00588   * @}
00589   */ 
00590 
00591 /**
00592   * @}
00593   */ 
00594 
00595 /**
00596   * @}
00597   */   
00598 
00599 /**
00600   * @}
00601   */ 
00602     
00603 /******************* (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