stm3210e_eval.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm3210e_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 STM3210E-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 "stm3210e_eval.h"
00027 #include "stm32f10x_spi.h"
00028 #include "stm32f10x_i2c.h"
00029 #include "stm32f10x_sdio.h"
00030 #include "stm32f10x_dma.h"
00031 
00032 /** @addtogroup Utilities
00033   * @{
00034   */ 
00035 
00036 /** @addtogroup STM32_EVAL
00037   * @{
00038   */ 
00039 
00040 /** @addtogroup STM3210E_EVAL
00041   * @{
00042   */ 
00043       
00044 /** @defgroup STM3210E_EVAL_LOW_LEVEL 
00045   * @brief This file provides firmware functions to manage Leds, push-buttons, 
00046   *        COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE) 
00047   *        and temperature sensor (LM75) available on STM3210E-EVAL evaluation 
00048   *        board from STMicroelectronics.
00049   * @{
00050   */ 
00051 
00052 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_TypesDefinitions
00053   * @{
00054   */ 
00055 /**
00056   * @}
00057   */ 
00058 
00059 
00060 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Defines
00061   * @{
00062   */ 
00063 /**
00064   * @}
00065   */ 
00066 
00067 
00068 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Macros
00069   * @{
00070   */ 
00071 /**
00072   * @}
00073   */ 
00074 
00075 
00076 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Variables
00077   * @{
00078   */ 
00079 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
00080                                  LED4_GPIO_PORT};
00081 const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
00082                                  LED4_PIN};
00083 const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
00084                                  LED4_GPIO_CLK};
00085 
00086 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT, 
00087                                       KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
00088                                       LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
00089                                       DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT}; 
00090 
00091 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN, 
00092                                       KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
00093                                       LEFT_BUTTON_PIN, UP_BUTTON_PIN,
00094                                       DOWN_BUTTON_PIN, SEL_BUTTON_PIN}; 
00095 
00096 const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
00097                                       KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
00098                                       LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
00099                                       DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
00100 
00101 const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
00102                                             TAMPER_BUTTON_EXTI_LINE, 
00103                                             KEY_BUTTON_EXTI_LINE,
00104                                             RIGHT_BUTTON_EXTI_LINE,
00105                                             LEFT_BUTTON_EXTI_LINE,
00106                                             UP_BUTTON_EXTI_LINE,
00107                                             DOWN_BUTTON_EXTI_LINE,
00108                                             SEL_BUTTON_EXTI_LINE};
00109 
00110 const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
00111                                               TAMPER_BUTTON_EXTI_PORT_SOURCE, 
00112                                               KEY_BUTTON_EXTI_PORT_SOURCE,
00113                                               RIGHT_BUTTON_EXTI_PORT_SOURCE,
00114                                               LEFT_BUTTON_EXTI_PORT_SOURCE,
00115                                               UP_BUTTON_EXTI_PORT_SOURCE,
00116                                               DOWN_BUTTON_EXTI_PORT_SOURCE,
00117                                               SEL_BUTTON_EXTI_PORT_SOURCE};
00118                                                                  
00119 const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
00120                                              TAMPER_BUTTON_EXTI_PIN_SOURCE, 
00121                                              KEY_BUTTON_EXTI_PIN_SOURCE,
00122                                              RIGHT_BUTTON_EXTI_PIN_SOURCE,
00123                                              LEFT_BUTTON_EXTI_PIN_SOURCE,
00124                                              UP_BUTTON_EXTI_PIN_SOURCE,
00125                                              DOWN_BUTTON_EXTI_PIN_SOURCE,
00126                                              SEL_BUTTON_EXTI_PIN_SOURCE}; 
00127 
00128 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn, 
00129                                        KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
00130                                        LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
00131                                        DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
00132 
00133 USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2}; 
00134 
00135 GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
00136  
00137 GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
00138  
00139 const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
00140 
00141 const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
00142  
00143 const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
00144 
00145 const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
00146 
00147 const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
00148 
00149 /**
00150   * @}
00151   */ 
00152 
00153 
00154 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_FunctionPrototypes
00155   * @{
00156   */ 
00157 
00158 /**
00159   * @}
00160   */ 
00161 
00162 
00163 /** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Functions
00164   * @{
00165   */ 
00166 
00167 /**
00168   * @brief  Configures LED GPIO.
00169   * @param  Led: Specifies the Led to be configured. 
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_LEDInit(Led_TypeDef Led)
00178 {
00179   GPIO_InitTypeDef  GPIO_InitStructure;
00180   
00181   /* Enable the GPIO_LED Clock */
00182   RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
00183 
00184   /* Configure the GPIO_LED pin */
00185   GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
00186   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00187   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00188 
00189   GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
00190 }
00191 
00192 /**
00193   * @brief  Turns selected LED On.
00194   * @param  Led: Specifies the Led to be set on. 
00195   *   This parameter can be one of following parameters:
00196   *     @arg LED1
00197   *     @arg LED2
00198   *     @arg LED3
00199   *     @arg LED4  
00200   * @retval None
00201   */
00202 void STM_EVAL_LEDOn(Led_TypeDef Led)
00203 {
00204   GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];     
00205 }
00206 
00207 /**
00208   * @brief  Turns selected LED Off.
00209   * @param  Led: Specifies the Led to be set off. 
00210   *   This parameter can be one of following parameters:
00211   *     @arg LED1
00212   *     @arg LED2
00213   *     @arg LED3
00214   *     @arg LED4 
00215   * @retval None
00216   */
00217 void STM_EVAL_LEDOff(Led_TypeDef Led)
00218 {
00219   GPIO_PORT[Led]->BRR = GPIO_PIN[Led];    
00220 }
00221 
00222 /**
00223   * @brief  Toggles the selected LED.
00224   * @param  Led: Specifies the Led to be toggled. 
00225   *   This parameter can be one of following parameters:
00226   *     @arg LED1
00227   *     @arg LED2
00228   *     @arg LED3
00229   *     @arg LED4  
00230   * @retval None
00231   */
00232 void STM_EVAL_LEDToggle(Led_TypeDef Led)
00233 {
00234   GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
00235 }
00236 
00237 /**
00238   * @brief  Configures Button GPIO and EXTI Line.
00239   * @param  Button: Specifies the Button to be configured.
00240   *   This parameter can be one of following parameters:   
00241   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00242   *     @arg BUTTON_TAMPER: Tamper Push Button  
00243   *     @arg BUTTON_KEY: Key Push Button 
00244   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00245   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00246   *     @arg BUTTON_UP: Joystick Up Push Button 
00247   *     @arg BUTTON_DOWN: Joystick Down Push Button
00248   *     @arg BUTTON_SEL: Joystick Sel Push Button
00249   * @param  Button_Mode: Specifies Button mode.
00250   *   This parameter can be one of following parameters:   
00251   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO 
00252   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
00253   *                     generation capability  
00254   * @retval None
00255   */
00256 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00257 {
00258   GPIO_InitTypeDef GPIO_InitStructure;
00259   EXTI_InitTypeDef EXTI_InitStructure;
00260   NVIC_InitTypeDef NVIC_InitStructure;
00261 
00262   /* Enable the BUTTON Clock */
00263   RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
00264 
00265   /* Configure Button pin as input floating */
00266   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00267   GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
00268   GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
00269 
00270 
00271   if (Button_Mode == BUTTON_MODE_EXTI)
00272   {
00273     /* Connect Button EXTI Line to Button GPIO Pin */
00274     GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
00275 
00276     /* Configure Button EXTI line */
00277     EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
00278     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00279 
00280     if(Button != BUTTON_WAKEUP)
00281     {
00282       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  
00283     }
00284     else
00285     {
00286       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
00287     }
00288     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00289     EXTI_Init(&EXTI_InitStructure);
00290 
00291     /* Enable and set Button EXTI Interrupt to the lowest priority */
00292     NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
00293     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
00294     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
00295     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00296 
00297     NVIC_Init(&NVIC_InitStructure); 
00298   }
00299 }
00300 
00301 /**
00302   * @brief  Returns the selected Button state.
00303   * @param  Button: Specifies the Button to be checked.
00304   *   This parameter can be one of following parameters:    
00305   *     @arg BUTTON_WAKEUP: Wakeup Push Button
00306   *     @arg BUTTON_TAMPER: Tamper Push Button  
00307   *     @arg BUTTON_KEY: Key Push Button 
00308   *     @arg BUTTON_RIGHT: Joystick Right Push Button 
00309   *     @arg BUTTON_LEFT: Joystick Left Push Button 
00310   *     @arg BUTTON_UP: Joystick Up Push Button 
00311   *     @arg BUTTON_DOWN: Joystick Down Push Button
00312   *     @arg BUTTON_SEL: Joystick Sel Push Button    
00313   * @retval The Button GPIO pin value.
00314   */
00315 uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
00316 {
00317   return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00318 }
00319 
00320 /**
00321   * @brief  Configures COM port.
00322   * @param  COM: Specifies the COM port to be configured.
00323   *   This parameter can be one of following parameters:    
00324   *     @arg COM1
00325   *     @arg COM2  
00326   * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that
00327   *   contains the configuration information for the specified USART peripheral.
00328   * @retval None
00329   */
00330 void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
00331 {
00332   GPIO_InitTypeDef GPIO_InitStructure;
00333 
00334   /* Enable GPIO clock */
00335   RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
00336 
00337   /* Enable UART clock */
00338   if (COM == COM1)
00339   {
00340     RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); 
00341   }
00342   else
00343   {
00344     RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
00345   }
00346 
00347   /* Configure USART Tx as alternate function push-pull */
00348   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00349   GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
00350   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00351   GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
00352 
00353   /* Configure USART Rx as input floating */
00354   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00355   GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
00356   GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
00357 
00358   /* USART configuration */
00359   USART_Init(COM_USART[COM], USART_InitStruct);
00360     
00361   /* Enable USART */
00362   USART_Cmd(COM_USART[COM], ENABLE);
00363 }
00364 
00365 /**
00366   * @brief  DeInitializes the SDIO interface.
00367   * @param  None
00368   * @retval None
00369   */
00370 void SD_LowLevel_DeInit(void)
00371 {
00372   GPIO_InitTypeDef  GPIO_InitStructure;
00373   
00374   /*!< Disable SDIO Clock */
00375   SDIO_ClockCmd(DISABLE);
00376   
00377   /*!< Set Power State to OFF */
00378   SDIO_SetPowerState(SDIO_PowerState_OFF);
00379 
00380   /*!< DeInitializes the SDIO peripheral */
00381   SDIO_DeInit();
00382   
00383   /*!< Disable the SDIO AHB Clock */
00384   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, DISABLE);
00385 
00386   /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
00387   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
00388   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00389   GPIO_Init(GPIOC, &GPIO_InitStructure);
00390 
00391   /*!< Configure PD.02 CMD line */
00392   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
00393   GPIO_Init(GPIOD, &GPIO_InitStructure);
00394 }
00395 
00396 /**
00397   * @brief  Initializes the SD Card and put it into StandBy State (Ready for 
00398   *         data transfer).
00399   * @param  None
00400   * @retval None
00401   */
00402 void SD_LowLevel_Init(void)
00403 {
00404   GPIO_InitTypeDef  GPIO_InitStructure;
00405 
00406   /*!< GPIOC and GPIOD Periph clock enable */
00407   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);
00408 
00409   /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
00410   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
00411   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00412   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00413   GPIO_Init(GPIOC, &GPIO_InitStructure);
00414 
00415   /*!< Configure PD.02 CMD line */
00416   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
00417   GPIO_Init(GPIOD, &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   /*!< Enable the SDIO AHB Clock */
00425   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);
00426 
00427   /*!< Enable the DMA2 Clock */
00428   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
00429 }
00430 
00431 /**
00432   * @brief  Configures the DMA2 Channel4 for SDIO Tx request.
00433   * @param  BufferSRC: pointer to the source buffer
00434   * @param  BufferSize: buffer size
00435   * @retval None
00436   */
00437 void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize)
00438 {
00439 
00440   DMA_InitTypeDef DMA_InitStructure;
00441 
00442   DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4);
00443 
00444   /*!< DMA2 Channel4 disable */
00445   DMA_Cmd(DMA2_Channel4, DISABLE);
00446 
00447   /*!< DMA2 Channel4 Config */
00448   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
00449   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferSRC;
00450   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
00451   DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
00452   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00453   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00454   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
00455   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
00456   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
00457   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
00458   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00459   DMA_Init(DMA2_Channel4, &DMA_InitStructure);
00460 
00461   /*!< DMA2 Channel4 enable */
00462   DMA_Cmd(DMA2_Channel4, ENABLE);  
00463 }
00464 
00465 /**
00466   * @brief  Configures the DMA2 Channel4 for SDIO Rx request.
00467   * @param  BufferDST: pointer to the destination buffer
00468   * @param  BufferSize: buffer size
00469   * @retval None
00470   */
00471 void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize)
00472 {
00473   DMA_InitTypeDef DMA_InitStructure;
00474 
00475   DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4);
00476 
00477   /*!< DMA2 Channel4 disable */
00478   DMA_Cmd(DMA2_Channel4, DISABLE);
00479 
00480   /*!< DMA2 Channel4 Config */
00481   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
00482   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST;
00483   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
00484   DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
00485   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00486   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00487   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
00488   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
00489   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
00490   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
00491   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00492   DMA_Init(DMA2_Channel4, &DMA_InitStructure);
00493 
00494   /*!< DMA2 Channel4 enable */
00495   DMA_Cmd(DMA2_Channel4, ENABLE); 
00496 }
00497 
00498 /**
00499   * @brief  Returns the DMA End Of Transfer Status.
00500   * @param  None
00501   * @retval DMA SDIO Channel Status.
00502   */
00503 uint32_t SD_DMAEndOfTransferStatus(void)
00504 {
00505   return (uint32_t)DMA_GetFlagStatus(DMA2_FLAG_TC4);
00506 }
00507 
00508 /**
00509   * @brief  DeInitializes the peripherals used by the SPI FLASH driver.
00510   * @param  None
00511   * @retval None
00512   */
00513 void sFLASH_LowLevel_DeInit(void)
00514 {
00515   GPIO_InitTypeDef GPIO_InitStructure;
00516 
00517   /*!< Disable the sFLASH_SPI  */
00518   SPI_Cmd(sFLASH_SPI, DISABLE);
00519   
00520   /*!< DeInitializes the sFLASH_SPI */
00521   SPI_I2S_DeInit(sFLASH_SPI);
00522   
00523   /*!< sFLASH_SPI Periph clock disable */
00524   RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE);
00525   
00526   /*!< Configure sFLASH_SPI pins: SCK */
00527   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
00528   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00529   GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00530 
00531   /*!< Configure sFLASH_SPI pins: MISO */
00532   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
00533   GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00534 
00535   /*!< Configure sFLASH_SPI pins: MOSI */
00536   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
00537   GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00538 
00539   /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
00540   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
00541   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
00542 }
00543 
00544 /**
00545   * @brief  Initializes the peripherals used by the SPI FLASH driver.
00546   * @param  None
00547   * @retval None
00548   */
00549 void sFLASH_LowLevel_Init(void)
00550 {
00551   GPIO_InitTypeDef GPIO_InitStructure;
00552 
00553   /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO 
00554        and sFLASH_SPI_SCK_GPIO Periph clock enable */
00555   RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK |
00556                          sFLASH_SPI_SCK_GPIO_CLK, ENABLE);
00557 
00558   /*!< sFLASH_SPI Periph clock enable */
00559   RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);
00560   
00561   /*!< Configure sFLASH_SPI pins: SCK */
00562   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
00563   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00564   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00565   GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00566 
00567   /*!< Configure sFLASH_SPI pins: MOSI */
00568   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
00569   GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00570 
00571   /*!< Configure sFLASH_SPI pins: MISO */
00572   GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
00573   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
00574   GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00575   
00576   /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
00577   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
00578   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00579   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
00580 }
00581 
00582 /**
00583   * @brief  DeInitializes the LM75_I2C.
00584   * @param  None
00585   * @retval None
00586   */
00587 void LM75_LowLevel_DeInit(void)
00588 {
00589   GPIO_InitTypeDef  GPIO_InitStructure;
00590 
00591   /*!< Disable LM75_I2C */
00592   I2C_Cmd(LM75_I2C, DISABLE);
00593   /*!< DeInitializes the LM75_I2C */
00594   I2C_DeInit(LM75_I2C);
00595   
00596   /*!< LM75_I2C Periph clock disable */
00597   RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
00598     
00599   /*!< Configure LM75_I2C pins: SCL */
00600   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
00601   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00602   GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00603 
00604   /*!< Configure LM75_I2C pins: SDA */
00605   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
00606   GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00607 
00608   /*!< Configure LM75_I2C pin: SMBUS ALERT */
00609   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
00610   GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
00611 }
00612 
00613 /**
00614   * @brief  Initializes the LM75_I2C..
00615   * @param  None
00616   * @retval None
00617   */
00618 void LM75_LowLevel_Init(void)
00619 {
00620   GPIO_InitTypeDef  GPIO_InitStructure;
00621 
00622   /*!< LM75_I2C Periph clock enable */
00623   RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
00624     
00625   /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK 
00626        and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
00627   RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
00628                          LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
00629   
00630   /*!< Configure LM75_I2C pins: SCL */
00631   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
00632   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00633   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00634   GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
00635 
00636   /*!< Configure LM75_I2C pins: SDA */
00637   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
00638   GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
00639 
00640   /*!< Configure LM75_I2C pin: SMBUS ALERT */
00641   GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
00642   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
00643   GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure); 
00644 }
00645 
00646 /**
00647   * @}
00648   */ 
00649 
00650 /**
00651   * @}
00652   */ 
00653 
00654 /**
00655   * @}
00656   */
00657 
00658 /**
00659   * @}
00660   */    
00661 
00662 /**
00663   * @}
00664   */ 
00665     
00666 /******************* (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