]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_gpio.c
Merge commit '28203e909e83b1ac6becb45a3eadae23b190df32' into master-core-pull
[max/tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3XX / stm32f30x_gpio.c
1 /**
2   ******************************************************************************
3   * @file    stm32f30x_gpio.c
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    27-February-2014
7   * @brief   This file provides firmware functions to manage the following 
8   *          functionalities of the GPIO peripheral:
9   *           + Initialization and Configuration functions
10   *           + GPIO Read and Write functions
11   *           + GPIO Alternate functions configuration functions
12   *
13   *  @verbatim
14
15
16  ===============================================================================
17                       ##### How to use this driver #####
18  ===============================================================================
19     [..]
20     (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd()
21     (#) Configure the GPIO pin(s) using GPIO_Init()
22         Four possible configuration are available for each pin:
23         (++) Input: Floating, Pull-up, Pull-down.
24         (++) Output: Push-Pull (Pull-up, Pull-down or no Pull),
25                      Open Drain (Pull-up, Pull-down or no Pull).
26              In output mode, the speed is configurable: Low, Medium, Fast or High.
27         (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull), 
28                                  Open Drain (Pull-up, Pull-down or no Pull).
29         (++) Analog: required mode when a pin is to be used as ADC channel,
30              DAC output or comparator input.
31     (#) Peripherals alternate function:
32         (++) For ADC, DAC and comparators, configure the desired pin in 
33              analog mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN
34         (++) For other peripherals (TIM, USART...):
35              (+++) Connect the pin to the desired peripherals' Alternate 
36                    Function (AF) using GPIO_PinAFConfig() function.
37              (+++) Configure the desired pin in alternate function mode using
38                    GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
39              (+++) Select the type, pull-up/pull-down and output speed via 
40                    GPIO_PuPd, GPIO_OType and GPIO_Speed members.
41              (+++) Call GPIO_Init() function.
42     (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()
43     (#) To set/reset the level of a pin configured in output mode use
44         GPIO_SetBits()/GPIO_ResetBits()
45     (#) During and just after reset, the alternate functions are not active 
46         and the GPIO pins are configured in input floating mode (except JTAG pins).
47     (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as 
48         general-purpose (PC14 and PC15, respectively) when the LSE
49         oscillator is off. The LSE has priority over the GPIO function.
50     (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as general-purpose 
51         (PF0 and PF1 respectively) when the HSE oscillator is off. The HSE has 
52         the priority over the GPIO function.  
53
54   @endverbatim
55
56   ******************************************************************************
57   * @attention
58   *
59   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
60   *
61   * Redistribution and use in source and binary forms, with or without modification,
62   * are permitted provided that the following conditions are met:
63   *   1. Redistributions of source code must retain the above copyright notice,
64   *      this list of conditions and the following disclaimer.
65   *   2. Redistributions in binary form must reproduce the above copyright notice,
66   *      this list of conditions and the following disclaimer in the documentation
67   *      and/or other materials provided with the distribution.
68   *   3. Neither the name of STMicroelectronics nor the names of its contributors
69   *      may be used to endorse or promote products derived from this software
70   *      without specific prior written permission.
71   *
72   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
73   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
75   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
76   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
77   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
78   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
79   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
80   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
81   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82   *
83   ******************************************************************************
84   */
85
86 /* Includes ------------------------------------------------------------------*/
87 #include "stm32f30x_gpio.h"
88 #include "stm32f30x_rcc.h"
89
90 /** @addtogroup STM32F30x_StdPeriph_Driver
91   * @{
92   */
93
94 /** @defgroup GPIO 
95   * @brief GPIO driver modules
96   * @{
97   */
98
99
100 /* Private typedef -----------------------------------------------------------*/
101 /* Private define ------------------------------------------------------------*/
102
103
104 /* Private macro -------------------------------------------------------------*/
105 /* Private variables ---------------------------------------------------------*/
106 /* Private function prototypes -----------------------------------------------*/
107 /* Private functions ---------------------------------------------------------*/
108
109 /** @defgroup GPIO_Private_Functions 
110   * @{
111   */
112
113 /** @defgroup GPIO_Group1 Initialization and Configuration
114  *  @brief   Initialization and Configuration
115  *
116 @verbatim
117  ===============================================================================
118             ##### Initialization and Configuration #####
119  ===============================================================================
120
121 @endverbatim
122   * @{
123   */
124   
125 /**
126   * @brief  Deinitializes the GPIOx peripheral registers to their default reset 
127   *         values.
128   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
129   * @retval None
130   */
131 void GPIO_DeInit(GPIO_TypeDef* GPIOx)
132 {
133   /* Check the parameters */
134   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
135
136   if(GPIOx == GPIOA)
137   {
138     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
139     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
140   }
141   else if(GPIOx == GPIOB)
142   {
143     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);
144     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
145   }
146   else if(GPIOx == GPIOC)
147   {
148     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);
149     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
150   }
151   else if(GPIOx == GPIOD)
152   {
153     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);
154     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);
155   }
156   else if(GPIOx == GPIOE)
157   {
158     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);
159     RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);
160   }
161   else
162   {
163     if(GPIOx == GPIOF)
164     {
165       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE);
166       RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE);
167     }
168   }
169 }
170
171 /**
172   * @brief  Initializes the GPIOx peripheral according to the specified 
173   *         parameters in the GPIO_InitStruct.
174   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
175   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that 
176   *         contains the configuration information for the specified GPIO
177   *         peripheral.
178   * @note   GPIO_Pin: selects the pin to be configured:
179   *         GPIO_Pin_0->GPIO_Pin_15 for GPIOA, GPIOB, GPIOC, GPIOD and GPIOE;
180   *         GPIO_Pin_0->GPIO_Pin_2, GPIO_Pin_4, GPIO_Pin_6, GPIO_Pin_9 
181   *                       and GPIO_Pin_10 for GPIOF.
182   * @retval None
183   */
184 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
185
186   uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
187   uint32_t tmpreg = 0x00;
188
189   /* Check the parameters */
190   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
191   assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
192   assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
193   assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
194
195   /*-------------------------- Configure the port pins -----------------------*/
196   /*-- GPIO Mode Configuration --*/
197   for (pinpos = 0x00; pinpos < 0x10; pinpos++)
198   {
199     pos = ((uint32_t)0x01) << pinpos;
200
201     /* Get the port pins position */
202     currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
203
204     if (currentpin == pos)
205     {
206       if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
207       {
208         /* Check Speed mode parameters */
209         assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
210
211         /* Speed mode configuration */
212         GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
213         GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
214
215         /* Check Output mode parameters */
216         assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
217
218         /* Output mode configuration */
219         GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos));
220         GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
221       }
222       
223       GPIOx->MODER  &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
224
225       GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
226
227       /* Use temporary variable to update PUPDR register configuration, to avoid 
228          unexpected transition in the GPIO pin configuration. */
229       tmpreg = GPIOx->PUPDR;
230       tmpreg &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
231       tmpreg |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
232       GPIOx->PUPDR = tmpreg;
233     }
234   }
235 }
236
237 /**
238   * @brief  Fills each GPIO_InitStruct member with its default value.
239   * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure which will 
240   *         be initialized.
241   * @retval None
242   */
243 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
244 {
245   /* Reset GPIO init structure parameters values */
246   GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
247   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
248   GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
249   GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
250   GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
251 }
252
253 /**
254   * @brief  Locks GPIO Pins configuration registers.
255   *         The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
256   *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
257   * @note   The configuration of the locked GPIO pins can no longer be modified
258   *         until the next reset.
259   * @param  GPIOx: where x can be (A or B or D) to select the GPIO peripheral.
260   * @param  GPIO_Pin: specifies the port bit to be written.
261   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
262   * @retval None
263   */
264 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
265 {
266   uint32_t tmp = 0x00010000;
267   
268   /* Check the parameters */
269   assert_param(IS_GPIO_LIST_PERIPH(GPIOx));
270   assert_param(IS_GPIO_PIN(GPIO_Pin));
271   
272   tmp |= GPIO_Pin;
273   /* Set LCKK bit */
274   GPIOx->LCKR = tmp;
275   /* Reset LCKK bit */
276   GPIOx->LCKR =  GPIO_Pin;
277   /* Set LCKK bit */
278   GPIOx->LCKR = tmp;
279   /* Read LCKK bit */
280   tmp = GPIOx->LCKR;
281   /* Read LCKK bit */
282   tmp = GPIOx->LCKR;
283 }
284
285 /**
286   * @}
287   */
288   
289 /** @defgroup GPIO_Group2 GPIO Read and Write
290  *  @brief    GPIO Read and Write
291  *
292 @verbatim
293  ===============================================================================
294                   ##### GPIO Read and Write #####
295  ===============================================================================  
296
297 @endverbatim
298   * @{
299   */   
300
301 /**
302   * @brief  Reads the specified input port pin.
303   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
304   * @param  GPIO_Pin: specifies the port bit to read.
305   * @note   This parameter can be GPIO_Pin_x where x can be :
306   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
307   *         (0..2, 4, 6, 9..10) for GPIOF.
308   * @retval The input port pin value.
309   */
310 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
311 {
312   uint8_t bitstatus = 0x00;
313   
314   /* Check the parameters */
315   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
316   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
317
318   if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
319   {
320     bitstatus = (uint8_t)Bit_SET;
321   }
322   else
323   {
324     bitstatus = (uint8_t)Bit_RESET;
325   }
326   return bitstatus;
327 }
328
329 /**
330   * @brief  Reads the specified input port pin.
331   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
332   * @retval The input port pin value.
333   */
334 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
335 {
336   /* Check the parameters */
337   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
338
339   return ((uint16_t)GPIOx->IDR);
340 }
341
342 /**
343   * @brief  Reads the specified output data port bit.
344   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
345   * @param  GPIO_Pin: Specifies the port bit to read.
346   * @note   This parameter can be GPIO_Pin_x where x can be :
347   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
348   *         (0..2, 4, 6, 9..10) for GPIOF.
349   * @retval The output port pin value.
350   */
351 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
352 {
353   uint8_t bitstatus = 0x00;
354
355   /* Check the parameters */
356   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
357   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
358   
359   if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
360   {
361     bitstatus = (uint8_t)Bit_SET;
362   }
363   else
364   {
365     bitstatus = (uint8_t)Bit_RESET;
366   }
367   return bitstatus;
368 }
369
370 /**
371   * @brief  Reads the specified GPIO output data port.
372   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
373   * @retval GPIO output data port value.
374   */
375 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
376 {
377   /* Check the parameters */
378   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
379   
380   return ((uint16_t)GPIOx->ODR);
381 }
382
383 /**
384   * @brief  Sets the selected data port bits.
385   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
386   * @param  GPIO_Pin: specifies the port bits to be written.
387   * @note   This parameter can be GPIO_Pin_x where x can be :
388   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
389   *         (0..2, 4, 6, 9..10) for GPIOF.
390   * @retval None
391   */
392 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
393 {
394   /* Check the parameters */
395   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
396   assert_param(IS_GPIO_PIN(GPIO_Pin));
397   
398   GPIOx->BSRR = GPIO_Pin;
399 }
400
401 /**
402   * @brief  Clears the selected data port bits.
403   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
404   * @param  GPIO_Pin: specifies the port bits to be written.
405   * @note   This parameter can be GPIO_Pin_x where x can be :
406   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
407   *         (0..2, 4, 6, 9..10) for GPIOF.
408   * @retval None
409   */
410 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
411 {
412   /* Check the parameters */
413   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
414   assert_param(IS_GPIO_PIN(GPIO_Pin));
415   
416   GPIOx->BRR = GPIO_Pin;
417 }
418
419 /**
420   * @brief  Sets or clears the selected data port bit.
421   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
422   * @param  GPIO_Pin: specifies the port bit to be written.
423   * @note   This parameter can be GPIO_Pin_x where x can be :
424   *         (0..15) for GPIOA, GPIOB, GPIOC, GPIOD or GPIOE;
425   *         (0..2, 4, 6, 9..10) for GPIOF.
426   * @param  BitVal: specifies the value to be written to the selected bit.
427   *   This parameter can be one of the BitAction enumeration values:
428   *     @arg Bit_RESET: to clear the port pin
429   *     @arg Bit_SET: to set the port pin
430   * @retval None
431   */
432 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
433 {
434   /* Check the parameters */
435   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
436   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
437   assert_param(IS_GPIO_BIT_ACTION(BitVal));
438   
439   if (BitVal != Bit_RESET)
440   {
441     GPIOx->BSRR = GPIO_Pin;
442   }
443   else
444   {
445     GPIOx->BRR = GPIO_Pin ;
446   }
447 }
448
449 /**
450   * @brief  Writes data to the specified GPIO data port.
451   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
452   * @param  PortVal: specifies the value to be written to the port output data 
453   *                  register.
454   * @retval None
455   */
456 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
457 {
458   /* Check the parameters */
459   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
460   
461   GPIOx->ODR = PortVal;
462 }
463
464 /**
465   * @}
466   */
467
468 /** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions
469  *  @brief   GPIO Alternate functions configuration functions
470  *
471 @verbatim
472  ===============================================================================
473           ##### GPIO Alternate functions configuration functions #####
474  ===============================================================================
475
476 @endverbatim
477   * @{
478   */
479
480 /**
481   * @brief  Writes data to the specified GPIO data port.
482   * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
483   * @param  GPIO_PinSource: specifies the pin for the Alternate function.
484   *   This parameter can be GPIO_PinSourcex where x can be (0..15).
485   * @param  GPIO_AF: selects the pin to be used as Alternate function.  
486   *   This parameter can be one of the following value:
487   *     @arg GPIO_AF_0:  JTCK-SWCLK, JTDI, JTDO/TRACESW0, JTMS-SWDAT, MCO, NJTRST, 
488   *                      TRACED, TRACECK.
489   *     @arg GPIO_AF_1:  OUT, TIM2, TIM15, TIM16, TIM17.
490   *     @arg GPIO_AF_2:  COMP1_OUT, TIM1, TIM2, TIM3, TIM4, TIM8, TIM15, TIM16.
491   *     @arg GPIO_AF_3:  COMP7_OUT, TIM8, TIM15, Touch, HRTIM.
492   *     @arg GPIO_AF_4:  I2C1, I2C2, TIM1, TIM8, TIM16, TIM17.
493   *     @arg GPIO_AF_5:  IR_OUT, I2S2, I2S3, SPI1, SPI2, TIM8, USART4, USART5
494   *     @arg GPIO_AF_6:  IR_OUT, I2S2, I2S3, SPI2, SPI3, TIM1, TIM8
495   *     @arg GPIO_AF_7:  AOP2_OUT, CAN, COMP3_OUT, COMP5_OUT, COMP6_OUT, USART1, 
496   *                      USART2, USART3.
497   *     @arg GPIO_AF_8:  COMP1_OUT, COMP2_OUT, COMP3_OUT, COMP4_OUT, COMP5_OUT, 
498   *                      COMP6_OUT.
499   *     @arg GPIO_AF_9:  AOP4_OUT, CAN, TIM1, TIM8, TIM15.
500   *     @arg GPIO_AF_10: AOP1_OUT, AOP3_OUT, TIM2, TIM3, TIM4, TIM8, TIM17. 
501   *     @arg GPIO_AF_11: TIM1, TIM8.
502   *     @arg GPIO_AF_12: TIM1, HRTIM.
503   *     @arg GPIO_AF_13: HRTIM, AOP2_OUT.
504   *     @arg GPIO_AF_14: USBDM, USBDP.
505   *     @arg GPIO_AF_15: OUT.             
506   * @note  The pin should already been configured in Alternate Function mode(AF)
507   *        using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
508   * @note  Refer to the Alternate function mapping table in the device datasheet 
509   *        for the detailed mapping of the system and peripherals alternate 
510   *        function I/O pins.
511   * @retval None
512   */
513 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
514 {
515   uint32_t temp = 0x00;
516   uint32_t temp_2 = 0x00;
517   
518   /* Check the parameters */
519   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
520   assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
521   assert_param(IS_GPIO_AF(GPIO_AF));
522   
523   temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
524   GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
525   temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
526   GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
527 }
528
529 /**
530   * @}
531   */
532   
533 /**
534   * @}
535   */
536
537 /**
538   * @}
539   */
540
541 /**
542   * @}
543   */
544
545 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/