Merge pull request #93 from zyp/master
[fw/stlink] / example / libs_stm / src / stm32l1xx / stm32l1xx_gpio.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l1xx_gpio.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0\r
6   * @date    31-December-2010\r
7   * @brief   This file provides firmware functions to manage the following \r
8   *          functionalities of the GPIO peripheral:           \r
9   *           - Initialization and Configuration\r
10   *           - GPIO Read and Write\r
11   *           - GPIO Alternate functions configuration\r
12   * \r
13   *  @verbatim\r
14   *\r
15   *          ===================================================================\r
16   *                                 How to use this driver\r
17   *          ===================================================================       \r
18   *           1. Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd()\r
19   *             \r
20   *           2. Configure the GPIO pin(s) using GPIO_Init()\r
21   *              Four possible configuration are available for each pin:\r
22   *                - Input: Floating, Pull-up, Pull-down.\r
23   *                - Output: Push-Pull (Pull-up, Pull-down or no Pull)\r
24   *                          Open Drain (Pull-up, Pull-down or no Pull).\r
25   *                  In output mode, the speed is configurable: Very Low, Low,\r
26   *                  Medium or High.\r
27   *                - Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull)\r
28   *                                      Open Drain (Pull-up, Pull-down or no Pull).\r
29   *                - Analog: required mode when a pin is to be used as ADC channel,\r
30   *                          DAC output or comparator input.\r
31   * \r
32   *          3- Peripherals alternate function:\r
33   *              - For ADC, DAC and comparators, configure the desired pin in \r
34   *                analog mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN\r
35   *              - For other peripherals (TIM, USART...):\r
36   *                 - Connect the pin to the desired peripherals' Alternate \r
37   *                   Function (AF) using GPIO_PinAFConfig() function\r
38   *                 - Configure the desired pin in alternate function mode using\r
39   *                   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF\r
40   *                 - Select the type, pull-up/pull-down and output speed via \r
41   *                   GPIO_PuPd, GPIO_OType and GPIO_Speed members\r
42   *                 - Call GPIO_Init() function\r
43   *        \r
44   *          4. To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()\r
45   *          \r
46   *          5. To set/reset the level of a pin configured in output mode use\r
47   *             GPIO_SetBits()/GPIO_ResetBits()\r
48   *               \r
49   *          6. During and just after reset, the alternate functions are not \r
50   *             active and the GPIO pins are configured in input floating mode\r
51   *             (except JTAG pins).\r
52   *\r
53   *          7. The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as \r
54   *             general-purpose (PC14 and PC15, respectively) when the LSE\r
55   *             oscillator is off. The LSE has priority over the GPIO function.\r
56   *\r
57   *          8. The HSE oscillator pins OSC_IN/OSC_OUT can be used as \r
58   *             general-purpose PH0 and PH1, respectively, when the HSE \r
59   *             oscillator is off. The HSE has priority over the GPIO function.\r
60   *             \r
61   *  @endverbatim        \r
62   *\r
63   ******************************************************************************\r
64   * @attention\r
65   *\r
66   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
67   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
68   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
69   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
70   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
71   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
72   *\r
73   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
74   ******************************************************************************  \r
75   */ \r
76 \r
77 /* Includes ------------------------------------------------------------------*/\r
78 #include "stm32l1xx_gpio.h"\r
79 #include "stm32l1xx_rcc.h"\r
80 \r
81 /** @addtogroup STM32L1xx_StdPeriph_Driver\r
82   * @{\r
83   */\r
84 \r
85 /** @defgroup GPIO \r
86   * @brief GPIO driver modules\r
87   * @{\r
88   */\r
89 \r
90 /* Private typedef -----------------------------------------------------------*/\r
91 /* Private define ------------------------------------------------------------*/\r
92 /* Private macro -------------------------------------------------------------*/\r
93 /* Private variables ---------------------------------------------------------*/\r
94 /* Private function prototypes -----------------------------------------------*/\r
95 /* Private functions ---------------------------------------------------------*/\r
96 \r
97 /** @defgroup GPIO_Private_Functions\r
98   * @{\r
99   */\r
100 \r
101 /** @defgroup GPIO_Group1 Initialization and Configuration\r
102  *  @brief   Initialization and Configuration\r
103  *\r
104 @verbatim   \r
105  ===============================================================================\r
106                         Initialization and Configuration\r
107  ===============================================================================  \r
108 \r
109 @endverbatim\r
110   * @{\r
111   */\r
112 \r
113 /**\r
114   * @brief  Deinitializes the GPIOx peripheral registers to their default reset \r
115   *         values.\r
116   *         By default, The GPIO pins are configured in input floating mode\r
117   *         (except JTAG pins).\r
118   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
119   * @retval None\r
120   */\r
121 void GPIO_DeInit(GPIO_TypeDef* GPIOx)\r
122 {\r
123   /* Check the parameters */\r
124   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
125 \r
126   if(GPIOx == GPIOA)\r
127   {\r
128     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);\r
129     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);  \r
130   }\r
131   else if(GPIOx == GPIOB)\r
132   {\r
133     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);\r
134     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);\r
135   }\r
136   else if(GPIOx == GPIOC)\r
137   {\r
138     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);\r
139     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);\r
140   }\r
141   else if(GPIOx == GPIOD)\r
142   {\r
143     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);\r
144     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);\r
145   }\r
146   else if(GPIOx == GPIOE)\r
147   {\r
148       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);\r
149       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);\r
150   }\r
151   else\r
152   {\r
153     if(GPIOx == GPIOH)\r
154     {\r
155       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, ENABLE);\r
156       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, DISABLE);\r
157     }\r
158   }\r
159 }\r
160 \r
161 /**\r
162   * @brief  Initializes the GPIOx peripheral according to the specified \r
163   *         parameters in the GPIO_InitStruct.\r
164   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
165   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that \r
166   *         contains the configuration information for the specified GPIO\r
167   *         peripheral.\r
168   *         GPIO_Pin: selects the pin to be configured: GPIO_Pin_0 -> GPIO_Pin_15\r
169   *         GPIO_Mode: selects the mode of the pin: \r
170   *                      - Input mode: GPIO_Mode_IN\r
171   *                      - Output mode: GPIO_Mode_OUT\r
172   *                      - Alternate Function mode: GPIO_Mode_AF\r
173   *                      - Analog mode: GPIO_Mode_AN\r
174   *         GPIO_Speed: selects the speed of the pin if configured in Output:\r
175   *                      - Very Low: GPIO_Speed_400KHz\r
176   *                      - Low: GPIO_Speed_2MHz\r
177   *                      - Medium: GPIO_Speed_10MHz\r
178   *                      - High: GPIO_Speed_40MHz\r
179   *         GPIO_OType: selects the Output type (if the selected mode is output):\r
180   *                      - Push-pull: GPIO_OType_PP\r
181   *                      - Open Drain: GPIO_OType_OD\r
182   *         GPIO_PuPd: configures the Pull-up/Pull-down resistor on the pin:\r
183   *                      - pull-up: GPIO_PuPd_UP\r
184   *                      - pull-down: GPIO_PuPd_DOWN\r
185   *                      - Neither pull-up nor Pull-down: GPIO_PuPd_NOPULL\r
186   * @retval None\r
187   */\r
188 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)\r
189 {\r
190   uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;\r
191   \r
192   /* Check the parameters */\r
193   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
194   assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));\r
195   assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));\r
196   assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));\r
197 \r
198   /* -------------------------Configure the port pins---------------- */\r
199   /*-- GPIO Mode Configuration --*/\r
200   for (pinpos = 0x00; pinpos < 0x10; pinpos++)\r
201   {\r
202     pos = ((uint32_t)0x01) << pinpos;\r
203 \r
204     /* Get the port pins position */\r
205     currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;\r
206 \r
207     if (currentpin == pos)\r
208     {\r
209       GPIOx->MODER  &= ~(GPIO_MODER_MODER0 << (pinpos * 2));\r
210 \r
211       GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));\r
212 \r
213       if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))\r
214       {\r
215         /* Check Speed mode parameters */\r
216         assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));\r
217 \r
218         /* Speed mode configuration */\r
219         GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));\r
220         GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));\r
221 \r
222         /*Check Output mode parameters */\r
223         assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));\r
224 \r
225         /* Output mode configuration */\r
226         GPIOx->OTYPER  &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;\r
227         GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));\r
228       }\r
229 \r
230       /* Pull-up Pull down resistor configuration */\r
231       GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));\r
232       GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));\r
233     }\r
234   }\r
235 }\r
236 \r
237 /**\r
238   * @brief  Fills each GPIO_InitStruct member with its default value.\r
239   * @param  GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will \r
240   *         be initialized.\r
241   * @retval None\r
242   */\r
243 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)\r
244 {\r
245   /* Reset GPIO init structure parameters values */\r
246   GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;\r
247   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;\r
248   GPIO_InitStruct->GPIO_Speed = GPIO_Speed_400KHz;\r
249   GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;\r
250   GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;\r
251 }\r
252 \r
253 /**\r
254   * @brief  Locks GPIO Pins configuration registers.\r
255   *         The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,\r
256   *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.\r
257   *         The configuration of the locked GPIO pins can no longer be modified\r
258   *         until the next reset.\r
259   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
260   * @param  GPIO_Pin: specifies the port bit to be written.\r
261   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).\r
262   * @retval None\r
263   */\r
264 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
265 {\r
266   uint32_t tmp = 0x00010000;\r
267   \r
268   /* Check the parameters */\r
269   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
270   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
271   \r
272   tmp |= GPIO_Pin;\r
273   /* Set LCKK bit */\r
274   GPIOx->LCKR = tmp;\r
275   /* Reset LCKK bit */\r
276   GPIOx->LCKR =  GPIO_Pin;\r
277   /* Set LCKK bit */\r
278   GPIOx->LCKR = tmp;\r
279   /* Read LCKK bit*/\r
280   tmp = GPIOx->LCKR;\r
281   /* Read LCKK bit*/\r
282   tmp = GPIOx->LCKR;\r
283 }\r
284 \r
285 /**\r
286   * @}\r
287   */\r
288 \r
289 /** @defgroup GPIO_Group2 GPIO Read and Write\r
290  *  @brief   GPIO Read and Write\r
291  *\r
292 @verbatim   \r
293  ===============================================================================\r
294                               GPIO Read and Write\r
295  ===============================================================================  \r
296 \r
297 @endverbatim\r
298   * @{\r
299   */\r
300 \r
301 /**\r
302   * @brief  Reads the specified input port pin.\r
303   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
304   * @param  GPIO_Pin: specifies the port bit to read.\r
305   *   This parameter can be GPIO_Pin_x where x can be (0..15).\r
306   * @retval The input port pin value.\r
307   */\r
308 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
309 {\r
310   uint8_t bitstatus = 0x00;\r
311   \r
312   /* Check the parameters */\r
313   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
314   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));\r
315 \r
316   if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)\r
317   {\r
318     bitstatus = (uint8_t)Bit_SET;\r
319   }\r
320   else\r
321   {\r
322     bitstatus = (uint8_t)Bit_RESET;\r
323   }\r
324   return bitstatus;\r
325 }\r
326 \r
327 /**\r
328   * @brief  Reads the specified GPIO input data port.\r
329   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
330   * @retval GPIO input data port value.\r
331   */\r
332 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)\r
333 {\r
334   /* Check the parameters */\r
335   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
336   \r
337   return ((uint16_t)GPIOx->IDR);\r
338 }\r
339 \r
340 /**\r
341   * @brief  Reads the specified output data port bit.\r
342   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
343   * @param  GPIO_Pin: Specifies the port bit to read.\r
344   *   This parameter can be GPIO_Pin_x where x can be (0..15).\r
345   * @retval The output port pin value.\r
346   */\r
347 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
348 {\r
349   uint8_t bitstatus = 0x00;\r
350 \r
351   /* Check the parameters */\r
352   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
353   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));\r
354   \r
355   if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)\r
356   {\r
357     bitstatus = (uint8_t)Bit_SET;\r
358   }\r
359   else\r
360   {\r
361     bitstatus = (uint8_t)Bit_RESET;\r
362   }\r
363   return bitstatus;\r
364 }\r
365 \r
366 /**\r
367   * @brief  Reads the specified GPIO output data port.\r
368   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
369   * @retval GPIO output data port value.\r
370   */\r
371 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)\r
372 {\r
373   /* Check the parameters */\r
374   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
375   \r
376   return ((uint16_t)GPIOx->ODR);\r
377 }\r
378 \r
379 /**\r
380   * @brief  Sets the selected data port bits.\r
381   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
382   * @param  GPIO_Pin: specifies the port bits to be written.\r
383   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).\r
384   * @note  This functions uses GPIOx_BSRR register to allow atomic read/modify \r
385   *        accesses. In this way, there is no risk of an IRQ occurring between\r
386   *        the read and the modify access.\r
387   * @retval None\r
388   */\r
389 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
390 {\r
391   /* Check the parameters */\r
392   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
393   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
394   \r
395   GPIOx->BSRRL = GPIO_Pin;\r
396 }\r
397 \r
398 /**\r
399   * @brief  Clears the selected data port bits.\r
400   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
401   * @param  GPIO_Pin: specifies the port bits to be written.\r
402   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).\r
403   * @note  This functions uses GPIOx_BSRR register to allow atomic read/modify \r
404   *        accesses. In this way, there is no risk of an IRQ occurring between\r
405   *        the read and the modify access.\r
406   * @retval None\r
407   */\r
408 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)\r
409 {\r
410   /* Check the parameters */\r
411   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
412   assert_param(IS_GPIO_PIN(GPIO_Pin));\r
413   \r
414   GPIOx->BSRRH = GPIO_Pin;\r
415 }\r
416 \r
417 /**\r
418   * @brief  Sets or clears the selected data port bit.\r
419   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
420   * @param  GPIO_Pin: specifies the port bit to be written.\r
421   *   This parameter can be one of GPIO_Pin_x where x can be (0..15).\r
422   * @param  BitVal: specifies the value to be written to the selected bit.\r
423   *   This parameter can be one of the BitAction enum values:\r
424   *     @arg Bit_RESET: to clear the port pin\r
425   *     @arg Bit_SET: to set the port pin\r
426   * @retval None\r
427   */\r
428 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)\r
429 {\r
430   /* Check the parameters */\r
431   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
432   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));\r
433   assert_param(IS_GPIO_BIT_ACTION(BitVal));\r
434   \r
435   if (BitVal != Bit_RESET)\r
436   {\r
437     GPIOx->BSRRL = GPIO_Pin;\r
438   }\r
439   else\r
440   {\r
441     GPIOx->BSRRH = GPIO_Pin ;\r
442   }\r
443 }\r
444 \r
445 /**\r
446   * @brief  Writes data to the specified GPIO data port.\r
447   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
448   * @param  PortVal: specifies the value to be written to the port output data \r
449   *                  register.\r
450   * @retval None\r
451   */\r
452 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)\r
453 {\r
454   /* Check the parameters */\r
455   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
456   \r
457   GPIOx->ODR = PortVal;\r
458 }\r
459 \r
460 /**\r
461   * @}\r
462   */\r
463 \r
464 /** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions\r
465  *  @brief   GPIO Alternate functions configuration functions\r
466  *\r
467 @verbatim   \r
468  ===============================================================================\r
469                GPIO Alternate functions configuration functions\r
470  ===============================================================================  \r
471 \r
472 @endverbatim\r
473   * @{\r
474   */\r
475 \r
476 /**\r
477   * @brief  Changes the mapping of the specified pin.\r
478   * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.\r
479   * @param  GPIO_PinSource: specifies the pin for the Alternate function.\r
480   *   This parameter can be GPIO_PinSourcex where x can be (0..15).\r
481   * @param  GPIO_AFSelection: selects the pin to used as Alternat function.\r
482   *   This parameter can be one of the following values:\r
483   *     @arg GPIO_AF_RTC_50Hz: RTC 50/60 Hz synchronization\r
484   *     @arg GPIO_AF_MCO: Microcontroller clock output\r
485   *     @arg GPIO_AF_RTC_AF1: Time stamp, Tamper, Alarm A out, Alarm B out,\r
486   *                           512 Hz clock output (with an LSE oscillator of 32.768 kHz)\r
487   *     @arg GPIO_AF_WKUP: wakeup\r
488   *     @arg GPIO_AF_SWJ: SWJ (SW and JTAG)\r
489   *     @arg GPIO_AF_TRACE\r
490   *     @arg GPIO_AF_TIM2\r
491   *     @arg GPIO_AF_TIM3\r
492   *     @arg GPIO_AF_TIM4\r
493   *     @arg GPIO_AF_TIM9\r
494   *     @arg GPIO_AF_TIM10\r
495   *     @arg GPIO_AF_TIM11\r
496   *     @arg GPIO_AF_I2C1\r
497   *     @arg GPIO_AF_I2C2\r
498   *     @arg GPIO_AF_SPI1\r
499   *     @arg GPIO_AF_SPI2\r
500   *     @arg GPIO_AF_USART1\r
501   *     @arg GPIO_AF_USART2\r
502   *     @arg GPIO_AF_USART3\r
503   *     @arg GPIO_AF_USB\r
504   *     @arg GPIO_AF_LCD\r
505   *     @arg GPIO_AF_RI\r
506   *     @arg GPIO_AF_EVENTOUT: Cortex-M3 EVENTOUT signal\r
507   * @note: The pin should already been configured in Alternate Function mode(AF)\r
508   *        using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF\r
509   * @note: Please refer to the Alternate function mapping table in the device \r
510   *        datasheet for the detailed mapping of the system and peripherals\92\r
511   *        alternate function I/O pins.  \r
512   * @note: EVENTOUT is not mapped on PH0, PH1 and PH2.  \r
513   * @retval None\r
514   */\r
515 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)\r
516 {\r
517   uint32_t temp = 0x00;\r
518   uint32_t temp_2 = 0x00;\r
519   \r
520   /* Check the parameters */\r
521   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));\r
522   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));\r
523   assert_param(IS_GPIO_AF(GPIO_AF));\r
524   \r
525   temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;\r
526   GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;\r
527   temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;\r
528   GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;\r
529 }\r
530 \r
531 /**\r
532   * @}\r
533   */\r
534 \r
535 /**\r
536   * @}\r
537   */\r
538 \r
539 /**\r
540   * @}\r
541   */\r
542 \r
543 /**\r
544   * @}\r
545   */\r
546 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r