mattia griotti / Mbed 2 deprecated HelloWorld_IKS01A1

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A1 mbed

Fork of HelloWorld_IKS01A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f4xx_gpio.c Source File

stm32f4xx_gpio.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_gpio.c
00004   * @author  MCD Application Team
00005   * @version V1.0.0
00006   * @date    30-September-2011
00007   * @brief   This file provides firmware functions to manage the following 
00008   *          functionalities of the GPIO peripheral:           
00009   *           - Initialization and Configuration
00010   *           - GPIO Read and Write
00011   *           - GPIO Alternate functions configuration
00012   * 
00013   *  @verbatim
00014   *
00015   *          ===================================================================
00016   *                                 How to use this driver
00017   *          ===================================================================       
00018   *           1. Enable the GPIO AHB clock using the following function
00019   *                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
00020   *             
00021   *           2. Configure the GPIO pin(s) using GPIO_Init()
00022   *              Four possible configuration are available for each pin:
00023   *                - Input: Floating, Pull-up, Pull-down.
00024   *                - Output: Push-Pull (Pull-up, Pull-down or no Pull)
00025   *                          Open Drain (Pull-up, Pull-down or no Pull).
00026   *                  In output mode, the speed is configurable: 2 MHz, 25 MHz,
00027   *                  50 MHz or 100 MHz.
00028   *                - Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull)
00029   *                                      Open Drain (Pull-up, Pull-down or no Pull).
00030   *                - Analog: required mode when a pin is to be used as ADC channel
00031   *                          or DAC output.
00032   * 
00033   *          3- Peripherals alternate function:
00034   *              - For ADC and DAC, configure the desired pin in analog mode using 
00035   *                  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN;
00036   *              - For other peripherals (TIM, USART...):
00037   *                 - Connect the pin to the desired peripherals' Alternate 
00038   *                   Function (AF) using GPIO_PinAFConfig() function
00039   *                 - Configure the desired pin in alternate function mode using
00040   *                   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
00041   *                 - Select the type, pull-up/pull-down and output speed via 
00042   *                   GPIO_PuPd, GPIO_OType and GPIO_Speed members
00043   *                 - Call GPIO_Init() function
00044   *        
00045   *          4. To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()
00046   *          
00047   *          5. To set/reset the level of a pin configured in output mode use
00048   *             GPIO_SetBits()/GPIO_ResetBits()
00049   *               
00050   *          6. During and just after reset, the alternate functions are not 
00051   *             active and the GPIO pins are configured in input floating mode
00052   *             (except JTAG pins).
00053   *
00054   *          7. The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as 
00055   *             general-purpose (PC14 and PC15, respectively) when the LSE
00056   *             oscillator is off. The LSE has priority over the GPIO function.
00057   *
00058   *          8. The HSE oscillator pins OSC_IN/OSC_OUT can be used as 
00059   *             general-purpose PH0 and PH1, respectively, when the HSE 
00060   *             oscillator is off. The HSE has priority over the GPIO function.
00061   *             
00062   *  @endverbatim        
00063   *
00064   ******************************************************************************
00065   * @attention
00066   *
00067   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00068   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00069   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00070   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00071   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00072   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00073   *
00074   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
00075   ******************************************************************************
00076   */
00077 
00078 /* Includes ------------------------------------------------------------------*/
00079 #include "stm32f4xx_gpio.h"
00080 #include "stm32f4xx_rcc.h"
00081 
00082 /** @addtogroup STM32F4xx_StdPeriph_Driver
00083   * @{
00084   */
00085 
00086 /** @defgroup GPIO 
00087   * @brief GPIO driver modules
00088   * @{
00089   */ 
00090 
00091 /* Private typedef -----------------------------------------------------------*/
00092 /* Private define ------------------------------------------------------------*/
00093 /* Private macro -------------------------------------------------------------*/
00094 /* Private variables ---------------------------------------------------------*/
00095 /* Private function prototypes -----------------------------------------------*/
00096 /* Private functions ---------------------------------------------------------*/
00097 
00098 /** @defgroup GPIO_Private_Functions
00099   * @{
00100   */ 
00101 
00102 /** @defgroup GPIO_Group1 Initialization and Configuration
00103  *  @brief   Initialization and Configuration
00104  *
00105 @verbatim   
00106  ===============================================================================
00107                         Initialization and Configuration
00108  ===============================================================================  
00109 
00110 @endverbatim
00111   * @{
00112   */
00113 
00114 /**
00115   * @brief  Deinitializes the GPIOx peripheral registers to their default reset values.
00116   * @note   By default, The GPIO pins are configured in input floating mode (except JTAG pins).
00117   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00118   * @retval None
00119   */
00120 void GPIO_DeInit(GPIO_TypeDef* GPIOx)
00121 {
00122   /* Check the parameters */
00123   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00124 
00125   if (GPIOx == GPIOA)
00126   {
00127     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, ENABLE);
00128     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, DISABLE);
00129   }
00130   else if (GPIOx == GPIOB)
00131   {
00132     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOB, ENABLE);
00133     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOB, DISABLE);
00134   }
00135   else if (GPIOx == GPIOC)
00136   {
00137     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOC, ENABLE);
00138     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOC, DISABLE);
00139   }
00140   else if (GPIOx == GPIOD)
00141   {
00142     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOD, ENABLE);
00143     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOD, DISABLE);
00144   }
00145   else if (GPIOx == GPIOE)
00146   {
00147     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE, ENABLE);
00148     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE, DISABLE);
00149   }
00150   else if (GPIOx == GPIOF)
00151   {
00152     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOF, ENABLE);
00153     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOF, DISABLE);
00154   }
00155   else if (GPIOx == GPIOG)
00156   {
00157     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOG, ENABLE);
00158     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOG, DISABLE);
00159   }
00160   else if (GPIOx == GPIOH)
00161   {
00162     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOH, ENABLE);
00163     RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOH, DISABLE);
00164   }
00165   else
00166   {
00167     if (GPIOx == GPIOI)
00168     {
00169       RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOI, ENABLE);
00170       RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOI, DISABLE);
00171     }
00172   }
00173 }
00174 
00175 /**
00176   * @brief  Initializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
00177   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00178   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that contains
00179   *         the configuration information for the specified GPIO peripheral.
00180   * @retval None
00181   */
00182 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
00183 {
00184   uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
00185 
00186   /* Check the parameters */
00187   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00188   assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
00189   assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
00190   assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
00191 
00192   /* -------------------------Configure the port pins---------------- */
00193   /*-- GPIO Mode Configuration --*/
00194   for (pinpos = 0x00; pinpos < 0x10; pinpos++)
00195   {
00196     pos = ((uint32_t)0x01) << pinpos;
00197     /* Get the port pins position */
00198     currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
00199 
00200     if (currentpin == pos)
00201     {
00202       GPIOx->MODER  &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
00203       GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
00204 
00205       if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
00206       {
00207         /* Check Speed mode parameters */
00208         assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
00209 
00210         /* Speed mode configuration */
00211         GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
00212         GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
00213 
00214         /* Check Output mode parameters */
00215         assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
00216 
00217         /* Output mode configuration*/
00218         GPIOx->OTYPER  &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;
00219         GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
00220       }
00221 
00222       /* Pull-up Pull down resistor configuration*/
00223       GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
00224       GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
00225     }
00226   }
00227 }
00228 
00229 /**
00230   * @brief  Fills each GPIO_InitStruct member with its default value.
00231   * @param  GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will be initialized.
00232   * @retval None
00233   */
00234 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
00235 {
00236   /* Reset GPIO init structure parameters values */
00237   GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
00238   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
00239   GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
00240   GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
00241   GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
00242 }
00243 
00244 /**
00245   * @brief  Locks GPIO Pins configuration registers.
00246   * @note   The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
00247   *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
00248   * @note   The configuration of the locked GPIO pins can no longer be modified
00249   *         until the next reset.
00250   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00251   * @param  GPIO_Pin: specifies the port bit to be locked.
00252   *          This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
00253   * @retval None
00254   */
00255 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00256 {
00257   __IO uint32_t tmp = 0x00010000;
00258 
00259   /* Check the parameters */
00260   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00261   assert_param(IS_GPIO_PIN(GPIO_Pin));
00262 
00263   tmp |= GPIO_Pin;
00264   /* Set LCKK bit */
00265   GPIOx->LCKR = tmp;
00266   /* Reset LCKK bit */
00267   GPIOx->LCKR =  GPIO_Pin;
00268   /* Set LCKK bit */
00269   GPIOx->LCKR = tmp;
00270   /* Read LCKK bit*/
00271   tmp = GPIOx->LCKR;
00272   /* Read LCKK bit*/
00273   tmp = GPIOx->LCKR;
00274 }
00275 
00276 /**
00277   * @}
00278   */
00279 
00280 /** @defgroup GPIO_Group2 GPIO Read and Write
00281  *  @brief   GPIO Read and Write
00282  *
00283 @verbatim   
00284  ===============================================================================
00285                               GPIO Read and Write
00286  ===============================================================================  
00287 
00288 @endverbatim
00289   * @{
00290   */
00291 
00292 /**
00293   * @brief  Reads the specified input port pin.
00294   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00295   * @param  GPIO_Pin: specifies the port bit to read.
00296   *         This parameter can be GPIO_Pin_x where x can be (0..15).
00297   * @retval The input port pin value.
00298   */
00299 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00300 {
00301   uint8_t bitstatus = 0x00;
00302 
00303   /* Check the parameters */
00304   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00305   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
00306 
00307   if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
00308   {
00309     bitstatus = (uint8_t)Bit_SET;
00310   }
00311   else
00312   {
00313     bitstatus = (uint8_t)Bit_RESET;
00314   }
00315   return bitstatus;
00316 }
00317 
00318 /**
00319   * @brief  Reads the specified GPIO input data port.
00320   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00321   * @retval GPIO input data port value.
00322   */
00323 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
00324 {
00325   /* Check the parameters */
00326   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00327 
00328   return ((uint16_t)GPIOx->IDR);
00329 }
00330 
00331 /**
00332   * @brief  Reads the specified output data port bit.
00333   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00334   * @param  GPIO_Pin: specifies the port bit to read.
00335   *          This parameter can be GPIO_Pin_x where x can be (0..15).
00336   * @retval The output port pin value.
00337   */
00338 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00339 {
00340   uint8_t bitstatus = 0x00;
00341 
00342   /* Check the parameters */
00343   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00344   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
00345 
00346   if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
00347   {
00348     bitstatus = (uint8_t)Bit_SET;
00349   }
00350   else
00351   {
00352     bitstatus = (uint8_t)Bit_RESET;
00353   }
00354   return bitstatus;
00355 }
00356 
00357 /**
00358   * @brief  Reads the specified GPIO output data port.
00359   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00360   * @retval GPIO output data port value.
00361   */
00362 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
00363 {
00364   /* Check the parameters */
00365   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00366 
00367   return ((uint16_t)GPIOx->ODR);
00368 }
00369 
00370 /**
00371   * @brief  Sets the selected data port bits.
00372   * @note   This functions uses GPIOx_BSRR register to allow atomic read/modify 
00373   *         accesses. In this way, there is no risk of an IRQ occurring between
00374   *         the read and the modify access.
00375   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00376   * @param  GPIO_Pin: specifies the port bits to be written.
00377   *          This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
00378   * @retval None
00379   */
00380 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00381 {
00382   /* Check the parameters */
00383   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00384   assert_param(IS_GPIO_PIN(GPIO_Pin));
00385 
00386   GPIOx->BSRRL = GPIO_Pin;
00387 }
00388 
00389 /**
00390   * @brief  Clears the selected data port bits.
00391   * @note   This functions uses GPIOx_BSRR register to allow atomic read/modify 
00392   *         accesses. In this way, there is no risk of an IRQ occurring between
00393   *         the read and the modify access.
00394   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00395   * @param  GPIO_Pin: specifies the port bits to be written.
00396   *          This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
00397   * @retval None
00398   */
00399 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00400 {
00401   /* Check the parameters */
00402   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00403   assert_param(IS_GPIO_PIN(GPIO_Pin));
00404 
00405   GPIOx->BSRRH = GPIO_Pin;
00406 }
00407 
00408 /**
00409   * @brief  Sets or clears the selected data port bit.
00410   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00411   * @param  GPIO_Pin: specifies the port bit to be written.
00412   *          This parameter can be one of GPIO_Pin_x where x can be (0..15).
00413   * @param  BitVal: specifies the value to be written to the selected bit.
00414   *          This parameter can be one of the BitAction enum values:
00415   *            @arg Bit_RESET: to clear the port pin
00416   *            @arg Bit_SET: to set the port pin
00417   * @retval None
00418   */
00419 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
00420 {
00421   /* Check the parameters */
00422   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00423   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
00424   assert_param(IS_GPIO_BIT_ACTION(BitVal));
00425 
00426   if (BitVal != Bit_RESET)
00427   {
00428     GPIOx->BSRRL = GPIO_Pin;
00429   }
00430   else
00431   {
00432     GPIOx->BSRRH = GPIO_Pin ;
00433   }
00434 }
00435 
00436 /**
00437   * @brief  Writes data to the specified GPIO data port.
00438   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00439   * @param  PortVal: specifies the value to be written to the port output data register.
00440   * @retval None
00441   */
00442 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
00443 {
00444   /* Check the parameters */
00445   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00446 
00447   GPIOx->ODR = PortVal;
00448 }
00449 
00450 /**
00451   * @brief  Toggles the specified GPIO pins..
00452   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00453   * @param  GPIO_Pin: Specifies the pins to be toggled.
00454   * @retval None
00455   */
00456 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00457 {
00458   /* Check the parameters */
00459   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00460 
00461   GPIOx->ODR ^= GPIO_Pin;
00462 }
00463 
00464 /**
00465   * @}
00466   */
00467 
00468 /** @defgroup GPIO_Group3 GPIO Alternate functions configuration function
00469  *  @brief   GPIO Alternate functions configuration function
00470  *
00471 @verbatim   
00472  ===============================================================================
00473                GPIO Alternate functions configuration function
00474  ===============================================================================  
00475 
00476 @endverbatim
00477   * @{
00478   */
00479 
00480 /**
00481   * @brief  Changes the mapping of the specified pin.
00482   * @param  GPIOx: where x can be (A..I) to select the GPIO peripheral.
00483   * @param  GPIO_PinSource: specifies the pin for the Alternate function.
00484   *         This parameter can be GPIO_PinSourcex where x can be (0..15).
00485   * @param  GPIO_AFSelection: selects the pin to used as Alternate function.
00486   *          This parameter can be one of the following values:
00487   *            @arg GPIO_AF_RTC_50Hz: Connect RTC_50Hz pin to AF0 (default after reset) 
00488   *            @arg GPIO_AF_MCO: Connect MCO pin (MCO1 and MCO2) to AF0 (default after reset) 
00489   *            @arg GPIO_AF_TAMPER: Connect TAMPER pins (TAMPER_1 and TAMPER_2) to AF0 (default after reset) 
00490   *            @arg GPIO_AF_SWJ: Connect SWJ pins (SWD and JTAG)to AF0 (default after reset) 
00491   *            @arg GPIO_AF_TRACE: Connect TRACE pins to AF0 (default after reset)
00492   *            @arg GPIO_AF_TIM1: Connect TIM1 pins to AF1
00493   *            @arg GPIO_AF_TIM2: Connect TIM2 pins to AF1
00494   *            @arg GPIO_AF_TIM3: Connect TIM3 pins to AF2
00495   *            @arg GPIO_AF_TIM4: Connect TIM4 pins to AF2
00496   *            @arg GPIO_AF_TIM5: Connect TIM5 pins to AF2
00497   *            @arg GPIO_AF_TIM8: Connect TIM8 pins to AF3
00498   *            @arg GPIO_AF_TIM9: Connect TIM9 pins to AF3
00499   *            @arg GPIO_AF_TIM10: Connect TIM10 pins to AF3
00500   *            @arg GPIO_AF_TIM11: Connect TIM11 pins to AF3
00501   *            @arg GPIO_AF_I2C1: Connect I2C1 pins to AF4
00502   *            @arg GPIO_AF_I2C2: Connect I2C2 pins to AF4
00503   *            @arg GPIO_AF_I2C3: Connect I2C3 pins to AF4
00504   *            @arg GPIO_AF_SPI1: Connect SPI1 pins to AF5
00505   *            @arg GPIO_AF_SPI2: Connect SPI2/I2S2 pins to AF5
00506   *            @arg GPIO_AF_SPI3: Connect SPI3/I2S3 pins to AF6
00507   *            @arg GPIO_AF_I2S3ext: Connect I2S3ext pins to AF7
00508   *            @arg GPIO_AF_USART1: Connect USART1 pins to AF7
00509   *            @arg GPIO_AF_USART2: Connect USART2 pins to AF7
00510   *            @arg GPIO_AF_USART3: Connect USART3 pins to AF7
00511   *            @arg GPIO_AF_UART4: Connect UART4 pins to AF8
00512   *            @arg GPIO_AF_UART5: Connect UART5 pins to AF8
00513   *            @arg GPIO_AF_USART6: Connect USART6 pins to AF8
00514   *            @arg GPIO_AF_CAN1: Connect CAN1 pins to AF9
00515   *            @arg GPIO_AF_CAN2: Connect CAN2 pins to AF9
00516   *            @arg GPIO_AF_TIM12: Connect TIM12 pins to AF9
00517   *            @arg GPIO_AF_TIM13: Connect TIM13 pins to AF9
00518   *            @arg GPIO_AF_TIM14: Connect TIM14 pins to AF9
00519   *            @arg GPIO_AF_OTG_FS: Connect OTG_FS pins to AF10
00520   *            @arg GPIO_AF_OTG_HS: Connect OTG_HS pins to AF10
00521   *            @arg GPIO_AF_ETH: Connect ETHERNET pins to AF11
00522   *            @arg GPIO_AF_FSMC: Connect FSMC pins to AF12
00523   *            @arg GPIO_AF_OTG_HS_FS: Connect OTG HS (configured in FS) pins to AF12
00524   *            @arg GPIO_AF_SDIO: Connect SDIO pins to AF12
00525   *            @arg GPIO_AF_DCMI: Connect DCMI pins to AF13
00526   *            @arg GPIO_AF_EVENTOUT: Connect EVENTOUT pins to AF15
00527   * @retval None
00528   */
00529 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
00530 {
00531   uint32_t temp = 0x00;
00532   uint32_t temp_2 = 0x00;
00533   
00534   /* Check the parameters */
00535   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00536   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
00537   assert_param(IS_GPIO_AF(GPIO_AF));
00538   
00539   temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
00540   GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
00541   temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
00542   GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
00543 }
00544 
00545 /**
00546   * @}
00547   */ 
00548 
00549 /**
00550   * @}
00551   */
00552 
00553 /**
00554   * @}
00555   */ 
00556 
00557 /**
00558   * @}
00559   */ 
00560 
00561 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
00562