REVONANO - Update SPL to 1.3.0
[librepilot.git] / flight / pios / stm32f4xx / libraries / STM32F4xx_StdPeriph_Driver / src / stm32f4xx_gpio.c
blob6210c4343f2b5180d92f2821d75ba6c93f84c111
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_gpio.c
4 * @author MCD Application Team
5 * @version V1.3.0
6 * @date 08-November-2013
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the GPIO peripheral:
9 * + Initialization and Configuration
10 * + GPIO Read and Write
11 * + GPIO Alternate functions configuration
13 @verbatim
14 ===============================================================================
15 ##### How to use this driver #####
16 ===============================================================================
17 [..]
18 (#) Enable the GPIO AHB clock using the following function
19 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
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). In output mode, the speed
26 is configurable: 2 MHz, 25 MHz, 50 MHz or 100 MHz.
27 (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull) Open
28 Drain (Pull-up, Pull-down or no Pull).
29 (++) Analog: required mode when a pin is to be used as ADC channel or DAC
30 output.
32 (#) Peripherals alternate function:
33 (++) For ADC and DAC, configure the desired pin in analog mode using
34 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN;
35 (+++) For other peripherals (TIM, USART...):
36 (+++) Connect the pin to the desired peripherals' Alternate
37 Function (AF) using GPIO_PinAFConfig() function
38 (+++) Configure the desired pin in alternate function mode using
39 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
40 (+++) Select the type, pull-up/pull-down and output speed via
41 GPIO_PuPd, GPIO_OType and GPIO_Speed members
42 (+++) Call GPIO_Init() function
44 (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()
46 (#) To set/reset the level of a pin configured in output mode use
47 GPIO_SetBits()/GPIO_ResetBits()
49 (#) During and just after reset, the alternate functions are not
50 active and the GPIO pins are configured in input floating mode (except JTAG
51 pins).
53 (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
54 (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
55 priority over the GPIO function.
57 (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
58 general purpose PH0 and PH1, respectively, when the HSE oscillator is off.
59 The HSE has priority over the GPIO function.
61 @endverbatim
63 ******************************************************************************
64 * @attention
66 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
68 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
69 * You may not use this file except in compliance with the License.
70 * You may obtain a copy of the License at:
72 * http://www.st.com/software_license_agreement_liberty_v2
74 * Unless required by applicable law or agreed to in writing, software
75 * distributed under the License is distributed on an "AS IS" BASIS,
76 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77 * See the License for the specific language governing permissions and
78 * limitations under the License.
80 ******************************************************************************
83 /* Includes ------------------------------------------------------------------*/
84 #include "stm32f4xx_gpio.h"
85 #include "stm32f4xx_rcc.h"
87 /** @addtogroup STM32F4xx_StdPeriph_Driver
88 * @{
91 /** @defgroup GPIO
92 * @brief GPIO driver modules
93 * @{
94 */
96 /* Private typedef -----------------------------------------------------------*/
97 /* Private define ------------------------------------------------------------*/
98 /* Private macro -------------------------------------------------------------*/
99 /* Private variables ---------------------------------------------------------*/
100 /* Private function prototypes -----------------------------------------------*/
101 /* Private functions ---------------------------------------------------------*/
103 /** @defgroup GPIO_Private_Functions
104 * @{
107 /** @defgroup GPIO_Group1 Initialization and Configuration
108 * @brief Initialization and Configuration
110 @verbatim
111 ===============================================================================
112 ##### Initialization and Configuration #####
113 ===============================================================================
115 @endverbatim
116 * @{
120 * @brief De-initializes the GPIOx peripheral registers to their default reset values.
121 * @note By default, The GPIO pins are configured in input floating mode (except JTAG pins).
122 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
123 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
124 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
125 * @retval None
127 void GPIO_DeInit(GPIO_TypeDef* GPIOx)
129 /* Check the parameters */
130 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
132 if (GPIOx == GPIOA)
134 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, ENABLE);
135 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA, DISABLE);
137 else if (GPIOx == GPIOB)
139 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOB, ENABLE);
140 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOB, DISABLE);
142 else if (GPIOx == GPIOC)
144 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOC, ENABLE);
145 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOC, DISABLE);
147 else if (GPIOx == GPIOD)
149 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOD, ENABLE);
150 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOD, DISABLE);
152 else if (GPIOx == GPIOE)
154 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE, ENABLE);
155 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE, DISABLE);
157 else if (GPIOx == GPIOF)
159 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOF, ENABLE);
160 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOF, DISABLE);
162 else if (GPIOx == GPIOG)
164 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOG, ENABLE);
165 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOG, DISABLE);
167 else if (GPIOx == GPIOH)
169 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOH, ENABLE);
170 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOH, DISABLE);
173 else if (GPIOx == GPIOI)
175 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOI, ENABLE);
176 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOI, DISABLE);
178 else if (GPIOx == GPIOJ)
180 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOJ, ENABLE);
181 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOJ, DISABLE);
183 else
185 if (GPIOx == GPIOK)
187 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOK, ENABLE);
188 RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOK, DISABLE);
194 * @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
195 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
196 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
197 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
198 * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that contains
199 * the configuration information for the specified GPIO peripheral.
200 * @retval None
202 void GPIO_Init(GPIO_TypeDef* GPIOx, const GPIO_InitTypeDef* GPIO_InitStruct)
204 uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
206 /* Check the parameters */
207 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
208 assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
209 assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
210 assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
212 /* ------------------------- Configure the port pins ---------------- */
213 /*-- GPIO Mode Configuration --*/
214 for (pinpos = 0x00; pinpos < 0x10; pinpos++)
216 pos = ((uint32_t)0x01) << pinpos;
217 /* Get the port pins position */
218 currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
220 if (currentpin == pos)
222 GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
223 GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
225 if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
227 /* Check Speed mode parameters */
228 assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
230 /* Speed mode configuration */
231 GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
232 GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
234 /* Check Output mode parameters */
235 assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
237 /* Output mode configuration*/
238 GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;
239 GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
242 /* Pull-up Pull down resistor configuration*/
243 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
244 GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
250 * @brief Fills each GPIO_InitStruct member with its default value.
251 * @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will be initialized.
252 * @retval None
254 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
256 /* Reset GPIO init structure parameters values */
257 GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
258 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
259 GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
260 GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
261 GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
265 * @brief Locks GPIO Pins configuration registers.
266 * @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
267 * GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
268 * @note The configuration of the locked GPIO pins can no longer be modified
269 * until the next reset.
270 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
271 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
272 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
273 * @param GPIO_Pin: specifies the port bit to be locked.
274 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
275 * @retval None
277 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
279 __IO uint32_t tmp = 0x00010000;
281 /* Check the parameters */
282 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
283 assert_param(IS_GPIO_PIN(GPIO_Pin));
285 tmp |= GPIO_Pin;
286 /* Set LCKK bit */
287 GPIOx->LCKR = tmp;
288 /* Reset LCKK bit */
289 GPIOx->LCKR = GPIO_Pin;
290 /* Set LCKK bit */
291 GPIOx->LCKR = tmp;
292 /* Read LCKK bit*/
293 tmp = GPIOx->LCKR;
294 /* Read LCKK bit*/
295 tmp = GPIOx->LCKR;
299 * @}
302 /** @defgroup GPIO_Group2 GPIO Read and Write
303 * @brief GPIO Read and Write
305 @verbatim
306 ===============================================================================
307 ##### GPIO Read and Write #####
308 ===============================================================================
310 @endverbatim
311 * @{
315 * @brief Reads the specified input port pin.
316 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
317 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
318 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
319 * @param GPIO_Pin: specifies the port bit to read.
320 * This parameter can be GPIO_Pin_x where x can be (0..15).
321 * @retval The input port pin value.
323 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
325 uint8_t bitstatus = 0x00;
327 /* Check the parameters */
328 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
329 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
331 if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
333 bitstatus = (uint8_t)Bit_SET;
335 else
337 bitstatus = (uint8_t)Bit_RESET;
339 return bitstatus;
343 * @brief Reads the specified GPIO input data port.
344 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
345 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
346 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
347 * @retval GPIO input data port value.
349 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
351 /* Check the parameters */
352 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
354 return ((uint16_t)GPIOx->IDR);
358 * @brief Reads the specified output data port bit.
359 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
360 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
361 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
362 * @param GPIO_Pin: specifies the port bit to read.
363 * This parameter can be GPIO_Pin_x where x can be (0..15).
364 * @retval The output port pin value.
366 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
368 uint8_t bitstatus = 0x00;
370 /* Check the parameters */
371 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
372 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
374 if (((GPIOx->ODR) & GPIO_Pin) != (uint32_t)Bit_RESET)
376 bitstatus = (uint8_t)Bit_SET;
378 else
380 bitstatus = (uint8_t)Bit_RESET;
382 return bitstatus;
386 * @brief Reads the specified GPIO output data port.
387 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
388 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
389 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
390 * @retval GPIO output data port value.
392 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
394 /* Check the parameters */
395 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
397 return ((uint16_t)GPIOx->ODR);
401 * @brief Sets the selected data port bits.
402 * @note This functions uses GPIOx_BSRR register to allow atomic read/modify
403 * accesses. In this way, there is no risk of an IRQ occurring between
404 * the read and the modify access.
405 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
406 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
407 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
408 * @param GPIO_Pin: specifies the port bits to be written.
409 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
410 * @retval None
412 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
414 /* Check the parameters */
415 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
416 assert_param(IS_GPIO_PIN(GPIO_Pin));
418 GPIOx->BSRRL = GPIO_Pin;
422 * @brief Clears the selected data port bits.
423 * @note This functions uses GPIOx_BSRR register to allow atomic read/modify
424 * accesses. In this way, there is no risk of an IRQ occurring between
425 * the read and the modify access.
426 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
427 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
428 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
429 * @param GPIO_Pin: specifies the port bits to be written.
430 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
431 * @retval None
433 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
435 /* Check the parameters */
436 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
437 assert_param(IS_GPIO_PIN(GPIO_Pin));
439 GPIOx->BSRRH = GPIO_Pin;
443 * @brief Sets or clears the selected data port bit.
444 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
445 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
446 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
447 * @param GPIO_Pin: specifies the port bit to be written.
448 * This parameter can be one of GPIO_Pin_x where x can be (0..15).
449 * @param BitVal: specifies the value to be written to the selected bit.
450 * This parameter can be one of the BitAction enum values:
451 * @arg Bit_RESET: to clear the port pin
452 * @arg Bit_SET: to set the port pin
453 * @retval None
455 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
457 /* Check the parameters */
458 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
459 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
460 assert_param(IS_GPIO_BIT_ACTION(BitVal));
462 if (BitVal != Bit_RESET)
464 GPIOx->BSRRL = GPIO_Pin;
466 else
468 GPIOx->BSRRH = GPIO_Pin ;
473 * @brief Writes data to the specified GPIO data port.
474 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
475 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
476 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
477 * @param PortVal: specifies the value to be written to the port output data register.
478 * @retval None
480 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
482 /* Check the parameters */
483 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
485 GPIOx->ODR = PortVal;
489 * @brief Toggles the specified GPIO pins..
490 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
491 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
492 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
493 * @param GPIO_Pin: Specifies the pins to be toggled.
494 * @retval None
496 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
498 /* Check the parameters */
499 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
501 GPIOx->ODR ^= GPIO_Pin;
505 * @}
508 /** @defgroup GPIO_Group3 GPIO Alternate functions configuration function
509 * @brief GPIO Alternate functions configuration function
511 @verbatim
512 ===============================================================================
513 ##### GPIO Alternate functions configuration function #####
514 ===============================================================================
516 @endverbatim
517 * @{
521 * @brief Changes the mapping of the specified pin.
522 * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices
523 * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices.
524 * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices.
525 * @param GPIO_PinSource: specifies the pin for the Alternate function.
526 * This parameter can be GPIO_PinSourcex where x can be (0..15).
527 * @param GPIO_AFSelection: selects the pin to used as Alternate function.
528 * This parameter can be one of the following values:
529 * @arg GPIO_AF_RTC_50Hz: Connect RTC_50Hz pin to AF0 (default after reset)
530 * @arg GPIO_AF_MCO: Connect MCO pin (MCO1 and MCO2) to AF0 (default after reset)
531 * @arg GPIO_AF_TAMPER: Connect TAMPER pins (TAMPER_1 and TAMPER_2) to AF0 (default after reset)
532 * @arg GPIO_AF_SWJ: Connect SWJ pins (SWD and JTAG)to AF0 (default after reset)
533 * @arg GPIO_AF_TRACE: Connect TRACE pins to AF0 (default after reset)
534 * @arg GPIO_AF_TIM1: Connect TIM1 pins to AF1
535 * @arg GPIO_AF_TIM2: Connect TIM2 pins to AF1
536 * @arg GPIO_AF_TIM3: Connect TIM3 pins to AF2
537 * @arg GPIO_AF_TIM4: Connect TIM4 pins to AF2
538 * @arg GPIO_AF_TIM5: Connect TIM5 pins to AF2
539 * @arg GPIO_AF_TIM8: Connect TIM8 pins to AF3
540 * @arg GPIO_AF_TIM9: Connect TIM9 pins to AF3
541 * @arg GPIO_AF_TIM10: Connect TIM10 pins to AF3
542 * @arg GPIO_AF_TIM11: Connect TIM11 pins to AF3
543 * @arg GPIO_AF_I2C1: Connect I2C1 pins to AF4
544 * @arg GPIO_AF_I2C2: Connect I2C2 pins to AF4
545 * @arg GPIO_AF_I2C3: Connect I2C3 pins to AF4
546 * @arg GPIO_AF_SPI1: Connect SPI1 pins to AF5
547 * @arg GPIO_AF_SPI2: Connect SPI2/I2S2 pins to AF5
548 * @arg GPIO_AF_SPI4: Connect SPI4 pins to AF5
549 * @arg GPIO_AF_SPI5: Connect SPI5 pins to AF5
550 * @arg GPIO_AF_SPI6: Connect SPI6 pins to AF5
551 * @arg GPIO_AF_SAI1: Connect SAI1 pins to AF6 for STM32F42xxx/43xxx devices.
552 * @arg GPIO_AF_SPI3: Connect SPI3/I2S3 pins to AF6
553 * @arg GPIO_AF_I2S3ext: Connect I2S3ext pins to AF7
554 * @arg GPIO_AF_USART1: Connect USART1 pins to AF7
555 * @arg GPIO_AF_USART2: Connect USART2 pins to AF7
556 * @arg GPIO_AF_USART3: Connect USART3 pins to AF7
557 * @arg GPIO_AF_UART4: Connect UART4 pins to AF8
558 * @arg GPIO_AF_UART5: Connect UART5 pins to AF8
559 * @arg GPIO_AF_USART6: Connect USART6 pins to AF8
560 * @arg GPIO_AF_UART7: Connect UART7 pins to AF8
561 * @arg GPIO_AF_UART8: Connect UART8 pins to AF8
562 * @arg GPIO_AF_CAN1: Connect CAN1 pins to AF9
563 * @arg GPIO_AF_CAN2: Connect CAN2 pins to AF9
564 * @arg GPIO_AF_TIM12: Connect TIM12 pins to AF9
565 * @arg GPIO_AF_TIM13: Connect TIM13 pins to AF9
566 * @arg GPIO_AF_TIM14: Connect TIM14 pins to AF9
567 * @arg GPIO_AF_OTG_FS: Connect OTG_FS pins to AF10
568 * @arg GPIO_AF_OTG_HS: Connect OTG_HS pins to AF10
569 * @arg GPIO_AF_ETH: Connect ETHERNET pins to AF11
570 * @arg GPIO_AF_FSMC: Connect FSMC pins to AF12
571 * @arg GPIO_AF_FMC: Connect FMC pins to AF12 for STM32F42xxx/43xxx devices.
572 * @arg GPIO_AF_OTG_HS_FS: Connect OTG HS (configured in FS) pins to AF12
573 * @arg GPIO_AF_SDIO: Connect SDIO pins to AF12
574 * @arg GPIO_AF_DCMI: Connect DCMI pins to AF13
575 * @arg GPIO_AF_LTDC: Connect LTDC pins to AF14 for STM32F429xx/439xx devices.
576 * @arg GPIO_AF_EVENTOUT: Connect EVENTOUT pins to AF15
577 * @retval None
579 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
581 uint32_t temp = 0x00;
582 uint32_t temp_2 = 0x00;
584 /* Check the parameters */
585 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
586 assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
587 assert_param(IS_GPIO_AF(GPIO_AF));
589 temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
590 GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ;
591 temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
592 GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
596 * @}
600 * @}
604 * @}
608 * @}
611 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/