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