Martin Johnson / STM32F3-Discovery

Dependents:   Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f30x_gpio.c Source File

stm32f30x_gpio.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f30x_gpio.c
00004   * @author  MCD Application Team
00005   * @version V1.2.3
00006   * @date    10-July-2015
00007   * @brief   This file provides firmware functions to manage the following 
00008   *          functionalities of the GPIO peripheral:
00009   *           + Initialization and Configuration functions
00010   *           + GPIO Read and Write functions
00011   *           + GPIO Alternate functions configuration functions
00012   *
00013   *  @verbatim
00014 
00015 
00016  ===============================================================================
00017                       ##### How to use this driver #####
00018  ===============================================================================
00019     [..]
00020     (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd()
00021     (#) 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: Low, Medium, Fast or High.
00027         (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull), 
00028                                  Open Drain (Pull-up, Pull-down or no Pull).
00029         (++) Analog: required mode when a pin is to be used as ADC channel,
00030              DAC output or comparator input.
00031     (#) Peripherals alternate function:
00032         (++) For ADC, DAC and comparators, configure the desired pin in 
00033              analog mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN
00034         (++) For other peripherals (TIM, USART...):
00035              (+++) Connect the pin to the desired peripherals' Alternate 
00036                    Function (AF) using GPIO_PinAFConfig() function.
00037              (+++) Configure the desired pin in alternate function mode using
00038                    GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
00039              (+++) Select the type, pull-up/pull-down and output speed via 
00040                    GPIO_PuPd, GPIO_OType and GPIO_Speed members.
00041              (+++) Call GPIO_Init() function.
00042     (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()
00043     (#) To set/reset the level of a pin configured in output mode use
00044         GPIO_SetBits()/GPIO_ResetBits()
00045     (#) During and just after reset, the alternate functions are not active 
00046         and the GPIO pins are configured in input floating mode (except JTAG pins).
00047     (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as 
00048         general-purpose (PC14 and PC15, respectively) when the LSE
00049         oscillator is off. The LSE has priority over the GPIO function.
00050     (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as general-purpose 
00051         (PF0 and PF1 respectively) when the HSE oscillator is off. The HSE has 
00052         the priority over the GPIO function.  
00053 
00054   @endverbatim
00055 
00056   ******************************************************************************
00057   * @attention
00058   *
00059   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
00060   *
00061   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00062   * You may not use this file except in compliance with the License.
00063   * You may obtain a copy of the License at:
00064   *
00065   *        http://www.st.com/software_license_agreement_liberty_v2
00066   *
00067   * Unless required by applicable law or agreed to in writing, software 
00068   * distributed under the License is distributed on an "AS IS" BASIS, 
00069   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00070   * See the License for the specific language governing permissions and
00071   * limitations under the License.
00072   *
00073   ******************************************************************************
00074   */
00075 
00076 /* Includes ------------------------------------------------------------------*/
00077 #include "stm32f30x_gpio.h"
00078 #include "stm32f30x_rcc.h"
00079 
00080 /** @addtogroup STM32F30x_StdPeriph_Driver
00081   * @{
00082   */
00083 
00084 /** @defgroup GPIO 
00085   * @brief GPIO driver modules
00086   * @{
00087   */
00088 
00089 
00090 /* Private typedef -----------------------------------------------------------*/
00091 /* Private define ------------------------------------------------------------*/
00092 
00093 
00094 /* Private macro -------------------------------------------------------------*/
00095 /* Private variables ---------------------------------------------------------*/
00096 /* Private function prototypes -----------------------------------------------*/
00097 /* Private functions ---------------------------------------------------------*/
00098 
00099 /** @defgroup GPIO_Private_Functions 
00100   * @{
00101   */
00102 
00103 /** @defgroup GPIO_Group1 Initialization and Configuration
00104  *  @brief   Initialization and Configuration
00105  *
00106 @verbatim
00107  ===============================================================================
00108             ##### Initialization and Configuration #####
00109  ===============================================================================
00110 
00111 @endverbatim
00112   * @{
00113   */
00114   
00115 /**
00116   * @brief  Deinitializes the GPIOx peripheral registers to their default reset 
00117   *         values.
00118   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
00119   * @retval None
00120   */
00121 void GPIO_DeInit(GPIO_TypeDef* GPIOx)
00122 {
00123   /* Check the parameters */
00124   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00125 
00126   if(GPIOx == GPIOA)
00127   {
00128     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
00129     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
00130   }
00131   else if(GPIOx == GPIOB)
00132   {
00133     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);
00134     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
00135   }
00136   else if(GPIOx == GPIOC)
00137   {
00138     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);
00139     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
00140   }
00141   else if(GPIOx == GPIOD)
00142   {
00143     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);
00144     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);
00145   }
00146   else if(GPIOx == GPIOE)
00147   {
00148     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);
00149     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);
00150   }
00151   else if(GPIOx == GPIOF)
00152   {
00153     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE);
00154     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE);
00155   }
00156   else if(GPIOx == GPIOG)
00157   {
00158     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOG, ENABLE);
00159     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOG, DISABLE);
00160   }
00161   else
00162   {
00163     if(GPIOx == GPIOH)
00164     {
00165       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, ENABLE);
00166       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, DISABLE);
00167     }
00168   }
00169 }
00170 
00171 /**
00172   * @brief  Initializes the GPIOx peripheral according to the specified 
00173   *         parameters in the GPIO_InitStruct.
00174   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00175   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that 
00176   *         contains the configuration information for the specified GPIO
00177   *         peripheral.
00178   * @note   GPIO_Pin: selects the pin to be configured:
00179   *         GPIO_Pin_0->GPIO_Pin_15 for GPIOA, GPIOB, GPIOC, GPIOD and GPIOE;
00180   *         GPIO_Pin_0->GPIO_Pin_2, GPIO_Pin_4, GPIO_Pin_6, GPIO_Pin_9 
00181   *                       and GPIO_Pin_10 for GPIOF.
00182   * @retval None
00183   */
00184 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
00185 { 
00186   uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
00187   uint32_t tmpreg = 0x00;
00188 
00189   /* Check the parameters */
00190   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00191   assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
00192   assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
00193   assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
00194 
00195   /*-------------------------- Configure the port pins -----------------------*/
00196   /*-- GPIO Mode Configuration --*/
00197   for (pinpos = 0x00; pinpos < 0x10; pinpos++)
00198   {
00199     pos = ((uint32_t)0x01) << pinpos;
00200 
00201     /* Get the port pins position */
00202     currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
00203 
00204     if (currentpin == pos)
00205     {
00206       if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
00207       {
00208         /* Check Speed mode parameters */
00209         assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
00210 
00211         /* Speed mode configuration */
00212         GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
00213         GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
00214 
00215         /* Check Output mode parameters */
00216         assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
00217 
00218         /* Output mode configuration */
00219         GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos));
00220         GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
00221       }
00222       
00223       GPIOx->MODER  &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
00224 
00225       GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
00226 
00227       /* Use temporary variable to update PUPDR register configuration, to avoid 
00228          unexpected transition in the GPIO pin configuration. */
00229       tmpreg = GPIOx->PUPDR;
00230       tmpreg &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
00231       tmpreg |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
00232       GPIOx->PUPDR = tmpreg;
00233     }
00234   }
00235 }
00236 
00237 /**
00238   * @brief  Fills each GPIO_InitStruct member with its default value.
00239   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure which will 
00240   *         be initialized.
00241   * @retval None
00242   */
00243 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
00244 {
00245   /* Reset GPIO init structure parameters values */
00246   GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
00247   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
00248   GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
00249   GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
00250   GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
00251 }
00252 
00253 /**
00254   * @brief  Locks GPIO Pins configuration registers.
00255   *         The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
00256   *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
00257   * @note   The configuration of the locked GPIO pins can no longer be modified
00258   *         until the next reset.
00259   * @param  GPIOx: where x can be (A or B or D) to select the GPIO peripheral.
00260   * @param  GPIO_Pin: specifies the port bit to be written.
00261   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
00262   * @retval None
00263   */
00264 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00265 {
00266   uint32_t tmp = 0x00010000;
00267   
00268   /* Check the parameters */
00269   assert_param(IS_GPIO_LIST_PERIPH(GPIOx));
00270   assert_param(IS_GPIO_PIN(GPIO_Pin));
00271   
00272   tmp |= GPIO_Pin;
00273   /* Set LCKK bit */
00274   GPIOx->LCKR = tmp;
00275   /* Reset LCKK bit */
00276   GPIOx->LCKR =  GPIO_Pin;
00277   /* Set LCKK bit */
00278   GPIOx->LCKR = tmp;
00279   /* Read LCKK bit */
00280   tmp = GPIOx->LCKR;
00281   /* Read LCKK bit */
00282   tmp = GPIOx->LCKR;
00283 }
00284 
00285 /**
00286   * @}
00287   */
00288   
00289 /** @defgroup GPIO_Group2 GPIO Read and Write
00290  *  @brief    GPIO Read and Write
00291  *
00292 @verbatim
00293  ===============================================================================
00294                   ##### GPIO Read and Write #####
00295  ===============================================================================  
00296 
00297 @endverbatim
00298   * @{
00299   */   
00300 
00301 /**
00302   * @brief  Reads the specified input port pin.
00303   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00304   * @param  GPIO_Pin: specifies the port bit to read.
00305   * @note   This parameter can be GPIO_Pin_x where x can be :
00306   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
00307   *         (0..2, 4, 6, 9..10) for GPIOF.
00308   * @retval The input port pin value.
00309   */
00310 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00311 {
00312   uint8_t bitstatus = 0x00;
00313   
00314   /* Check the parameters */
00315   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00316   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
00317 
00318   if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
00319   {
00320     bitstatus = (uint8_t)Bit_SET;
00321   }
00322   else
00323   {
00324     bitstatus = (uint8_t)Bit_RESET;
00325   }
00326   return bitstatus;
00327 }
00328 
00329 /**
00330   * @brief  Reads the specified input port pin.
00331   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00332   * @retval The input port pin value.
00333   */
00334 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
00335 {
00336   /* Check the parameters */
00337   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00338 
00339   return ((uint16_t)GPIOx->IDR);
00340 }
00341 
00342 /**
00343   * @brief  Reads the specified output data port bit.
00344   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00345   * @param  GPIO_Pin: Specifies the port bit to read.
00346   * @note   This parameter can be GPIO_Pin_x where x can be :
00347   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
00348   *         (0..2, 4, 6, 9..10) for GPIOF.
00349   * @retval The output port pin value.
00350   */
00351 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00352 {
00353   uint8_t bitstatus = 0x00;
00354 
00355   /* Check the parameters */
00356   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00357   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
00358   
00359   if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
00360   {
00361     bitstatus = (uint8_t)Bit_SET;
00362   }
00363   else
00364   {
00365     bitstatus = (uint8_t)Bit_RESET;
00366   }
00367   return bitstatus;
00368 }
00369 
00370 /**
00371   * @brief  Reads the specified GPIO output data port.
00372   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00373   * @retval GPIO output data port value.
00374   */
00375 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
00376 {
00377   /* Check the parameters */
00378   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00379   
00380   return ((uint16_t)GPIOx->ODR);
00381 }
00382 
00383 /**
00384   * @brief  Sets the selected data port bits.
00385   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00386   * @param  GPIO_Pin: specifies the port bits to be written.
00387   * @note   This parameter can be GPIO_Pin_x where x can be :
00388   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
00389   *         (0..2, 4, 6, 9..10) for GPIOF.
00390   * @retval None
00391   */
00392 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00393 {
00394   /* Check the parameters */
00395   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00396   assert_param(IS_GPIO_PIN(GPIO_Pin));
00397   
00398   GPIOx->BSRR = GPIO_Pin;
00399 }
00400 
00401 /**
00402   * @brief  Clears the selected data port bits.
00403   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00404   * @param  GPIO_Pin: specifies the port bits to be written.
00405   * @note   This parameter can be GPIO_Pin_x where x can be :
00406   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
00407   *         (0..2, 4, 6, 9..10) for GPIOF.
00408   * @retval None
00409   */
00410 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
00411 {
00412   /* Check the parameters */
00413   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00414   assert_param(IS_GPIO_PIN(GPIO_Pin));
00415   
00416   GPIOx->BRR = GPIO_Pin;
00417 }
00418 
00419 /**
00420   * @brief  Sets or clears the selected data port bit.
00421   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00422   * @param  GPIO_Pin: specifies the port bit to be written.
00423   * @note   This parameter can be GPIO_Pin_x where x can be :
00424   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
00425   *         (0..2, 4, 6, 9..10) for GPIOF.
00426   * @param  BitVal: specifies the value to be written to the selected bit.
00427   *   This parameter can be one of the BitAction enumeration values:
00428   *     @arg Bit_RESET: to clear the port pin
00429   *     @arg Bit_SET: to set the port pin
00430   * @retval None
00431   */
00432 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
00433 {
00434   /* Check the parameters */
00435   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00436   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
00437   assert_param(IS_GPIO_BIT_ACTION(BitVal));
00438   
00439   if (BitVal != Bit_RESET)
00440   {
00441     GPIOx->BSRR = GPIO_Pin;
00442   }
00443   else
00444   {
00445     GPIOx->BRR = GPIO_Pin ;
00446   }
00447 }
00448 
00449 /**
00450   * @brief  Writes data to the specified GPIO data port.
00451   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) to select the GPIO peripheral.
00452   * @param  PortVal: specifies the value to be written to the port output data 
00453   *                  register.
00454   * @retval None
00455   */
00456 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
00457 {
00458   /* Check the parameters */
00459   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00460   
00461   GPIOx->ODR = PortVal;
00462 }
00463 
00464 /**
00465   * @}
00466   */
00467 
00468 /** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions
00469  *  @brief   GPIO Alternate functions configuration functions
00470  *
00471 @verbatim
00472  ===============================================================================
00473           ##### GPIO Alternate functions configuration functions #####
00474  ===============================================================================
00475 
00476 @endverbatim
00477   * @{
00478   */
00479 
00480 /**
00481   * @brief  Writes data to the specified GPIO data port.
00482   * @param  GPIOx: where x can be (A, B, C, D, E, F, G or H) 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_AF: selects the pin to be used as Alternate function.  
00486   *   This parameter can be one of the following value:
00487   *     @arg GPIO_AF_0:  JTCK-SWCLK, JTDI, JTDO/TRACESW0, JTMS-SWDAT, MCO, NJTRST, 
00488   *                      TRACED, TRACECK.
00489   *     @arg GPIO_AF_1:  OUT, TIM2, TIM15, TIM16, TIM17.
00490   *     @arg GPIO_AF_2:  COMP1_OUT, TIM1, TIM2, TIM3, TIM4, TIM8, TIM15, TIM16.
00491   *     @arg GPIO_AF_3:  COMP7_OUT, TIM8, TIM15, Touch, HRTIM.
00492   *     @arg GPIO_AF_4:  I2C1, I2C2, TIM1, TIM8, TIM16, TIM17.
00493   *     @arg GPIO_AF_5:  IR_OUT, I2S2, I2S3, SPI1, SPI2, TIM8, USART4, USART5
00494   *     @arg GPIO_AF_6:  IR_OUT, I2S2, I2S3, SPI2, SPI3, TIM1, TIM8
00495   *     @arg GPIO_AF_7:  AOP2_OUT, CAN, COMP3_OUT, COMP5_OUT, COMP6_OUT, USART1, 
00496   *                      USART2, USART3.
00497   *     @arg GPIO_AF_8:  COMP1_OUT, COMP2_OUT, COMP3_OUT, COMP4_OUT, COMP5_OUT, 
00498   *                      COMP6_OUT.
00499   *     @arg GPIO_AF_9:  AOP4_OUT, CAN, TIM1, TIM8, TIM15.
00500   *     @arg GPIO_AF_10: AOP1_OUT, AOP3_OUT, TIM2, TIM3, TIM4, TIM8, TIM17. 
00501   *     @arg GPIO_AF_11: TIM1, TIM8.
00502   *     @arg GPIO_AF_12: TIM1, HRTIM.
00503   *     @arg GPIO_AF_13: HRTIM, AOP2_OUT.
00504   *     @arg GPIO_AF_14: USBDM, USBDP.
00505   *     @arg GPIO_AF_15: OUT.             
00506   * @note  The pin should already been configured in Alternate Function mode(AF)
00507   *        using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
00508   * @note  Refer to the Alternate function mapping table in the device datasheet 
00509   *        for the detailed mapping of the system and peripherals alternate 
00510   *        function I/O pins.
00511   * @retval None
00512   */
00513 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
00514 {
00515   uint32_t temp = 0x00;
00516   uint32_t temp_2 = 0x00;
00517   
00518   /* Check the parameters */
00519   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
00520   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
00521   assert_param(IS_GPIO_AF(GPIO_AF));
00522   
00523   temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
00524   GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
00525   temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
00526   GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
00527 }
00528 
00529 /**
00530   * @}
00531   */
00532   
00533 /**
00534   * @}
00535   */
00536 
00537 /**
00538   * @}
00539   */
00540 
00541 /**
00542   * @}
00543   */
00544 
00545 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/