mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_gpio.c@106:ced8cbb51063, 2014-02-26 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Feb 26 09:45:12 2014 +0000
- Revision:
- 106:ced8cbb51063
- Parent:
- 80:66393a7b209d
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd
Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/
[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 76:aeb1df146756 | 1 | /** |
mbed_official | 76:aeb1df146756 | 2 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 3 | * @file stm32l1xx_gpio.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 80:66393a7b209d | 5 | * @version V1.3.0 |
mbed_official | 80:66393a7b209d | 6 | * @date 31-January-2014 |
mbed_official | 76:aeb1df146756 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 76:aeb1df146756 | 8 | * functionalities of the GPIO peripheral: |
mbed_official | 76:aeb1df146756 | 9 | * + Initialization and Configuration |
mbed_official | 76:aeb1df146756 | 10 | * + GPIO Read and Write |
mbed_official | 76:aeb1df146756 | 11 | * + GPIO Alternate functions configuration |
mbed_official | 76:aeb1df146756 | 12 | * |
mbed_official | 76:aeb1df146756 | 13 | * @verbatim |
mbed_official | 76:aeb1df146756 | 14 | =========================================================================== |
mbed_official | 76:aeb1df146756 | 15 | ##### How to use this driver ##### |
mbed_official | 76:aeb1df146756 | 16 | =========================================================================== |
mbed_official | 76:aeb1df146756 | 17 | [..] |
mbed_official | 76:aeb1df146756 | 18 | (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd() |
mbed_official | 76:aeb1df146756 | 19 | (#) Configure the GPIO pin(s) using GPIO_Init() |
mbed_official | 76:aeb1df146756 | 20 | Four possible configuration are available for each pin: |
mbed_official | 76:aeb1df146756 | 21 | (++) Input: Floating, Pull-up, Pull-down. |
mbed_official | 76:aeb1df146756 | 22 | (++) Output: Push-Pull (Pull-up, Pull-down or no Pull) |
mbed_official | 76:aeb1df146756 | 23 | Open Drain (Pull-up, Pull-down or no Pull). |
mbed_official | 76:aeb1df146756 | 24 | In output mode, the speed is configurable: Very Low, Low, |
mbed_official | 76:aeb1df146756 | 25 | Medium or High. |
mbed_official | 76:aeb1df146756 | 26 | (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull) |
mbed_official | 76:aeb1df146756 | 27 | Open Drain (Pull-up, Pull-down or no Pull). |
mbed_official | 76:aeb1df146756 | 28 | (++) Analog: required mode when a pin is to be used as ADC channel, |
mbed_official | 76:aeb1df146756 | 29 | DAC output or comparator input. |
mbed_official | 76:aeb1df146756 | 30 | (#) Peripherals alternate function: |
mbed_official | 76:aeb1df146756 | 31 | (++) For ADC, DAC and comparators, configure the desired pin in |
mbed_official | 76:aeb1df146756 | 32 | analog mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN |
mbed_official | 76:aeb1df146756 | 33 | (++) For other peripherals (TIM, USART...): |
mbed_official | 76:aeb1df146756 | 34 | (+++) Connect the pin to the desired peripherals' Alternate |
mbed_official | 76:aeb1df146756 | 35 | Function (AF) using GPIO_PinAFConfig() function. |
mbed_official | 76:aeb1df146756 | 36 | (+++) Configure the desired pin in alternate function mode using |
mbed_official | 76:aeb1df146756 | 37 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 76:aeb1df146756 | 38 | (+++) Select the type, pull-up/pull-down and output speed via |
mbed_official | 76:aeb1df146756 | 39 | GPIO_PuPd, GPIO_OType and GPIO_Speed members. |
mbed_official | 76:aeb1df146756 | 40 | (+++) Call GPIO_Init() function. |
mbed_official | 76:aeb1df146756 | 41 | (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit() |
mbed_official | 76:aeb1df146756 | 42 | (#) To set/reset the level of a pin configured in output mode use |
mbed_official | 76:aeb1df146756 | 43 | GPIO_SetBits()/GPIO_ResetBits() |
mbed_official | 76:aeb1df146756 | 44 | (#) During and just after reset, the alternate functions are not |
mbed_official | 76:aeb1df146756 | 45 | active and the GPIO pins are configured in input floating mode |
mbed_official | 76:aeb1df146756 | 46 | (except JTAG pins). |
mbed_official | 76:aeb1df146756 | 47 | (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as |
mbed_official | 76:aeb1df146756 | 48 | general-purpose (PC14 and PC15, respectively) when the LSE |
mbed_official | 76:aeb1df146756 | 49 | oscillator is off. The LSE has priority over the GPIO function. |
mbed_official | 76:aeb1df146756 | 50 | (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as |
mbed_official | 76:aeb1df146756 | 51 | general-purpose PH0 and PH1, respectively, when the HSE |
mbed_official | 76:aeb1df146756 | 52 | oscillator is off. The HSE has priority over the GPIO function. |
mbed_official | 76:aeb1df146756 | 53 | @endverbatim |
mbed_official | 76:aeb1df146756 | 54 | * |
mbed_official | 76:aeb1df146756 | 55 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 56 | * @attention |
mbed_official | 76:aeb1df146756 | 57 | * |
mbed_official | 106:ced8cbb51063 | 58 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 59 | * |
mbed_official | 106:ced8cbb51063 | 60 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 106:ced8cbb51063 | 61 | * are permitted provided that the following conditions are met: |
mbed_official | 106:ced8cbb51063 | 62 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 63 | * this list of conditions and the following disclaimer. |
mbed_official | 106:ced8cbb51063 | 64 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 65 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 106:ced8cbb51063 | 66 | * and/or other materials provided with the distribution. |
mbed_official | 106:ced8cbb51063 | 67 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 106:ced8cbb51063 | 68 | * may be used to endorse or promote products derived from this software |
mbed_official | 106:ced8cbb51063 | 69 | * without specific prior written permission. |
mbed_official | 76:aeb1df146756 | 70 | * |
mbed_official | 106:ced8cbb51063 | 71 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 106:ced8cbb51063 | 72 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 106:ced8cbb51063 | 73 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 106:ced8cbb51063 | 74 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 106:ced8cbb51063 | 75 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 106:ced8cbb51063 | 76 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 106:ced8cbb51063 | 77 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 106:ced8cbb51063 | 78 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 106:ced8cbb51063 | 79 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 106:ced8cbb51063 | 80 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 76:aeb1df146756 | 81 | * |
mbed_official | 76:aeb1df146756 | 82 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 83 | */ |
mbed_official | 76:aeb1df146756 | 84 | |
mbed_official | 76:aeb1df146756 | 85 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 86 | #include "stm32l1xx_gpio.h" |
mbed_official | 76:aeb1df146756 | 87 | #include "stm32l1xx_rcc.h" |
mbed_official | 76:aeb1df146756 | 88 | |
mbed_official | 76:aeb1df146756 | 89 | /** @addtogroup STM32L1xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 90 | * @{ |
mbed_official | 76:aeb1df146756 | 91 | */ |
mbed_official | 76:aeb1df146756 | 92 | |
mbed_official | 76:aeb1df146756 | 93 | /** @defgroup GPIO |
mbed_official | 76:aeb1df146756 | 94 | * @brief GPIO driver modules |
mbed_official | 76:aeb1df146756 | 95 | * @{ |
mbed_official | 76:aeb1df146756 | 96 | */ |
mbed_official | 76:aeb1df146756 | 97 | |
mbed_official | 76:aeb1df146756 | 98 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 99 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 100 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 101 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 102 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 103 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 104 | |
mbed_official | 76:aeb1df146756 | 105 | /** @defgroup GPIO_Private_Functions |
mbed_official | 76:aeb1df146756 | 106 | * @{ |
mbed_official | 76:aeb1df146756 | 107 | */ |
mbed_official | 76:aeb1df146756 | 108 | |
mbed_official | 76:aeb1df146756 | 109 | /** @defgroup GPIO_Group1 Initialization and Configuration |
mbed_official | 76:aeb1df146756 | 110 | * @brief Initialization and Configuration |
mbed_official | 76:aeb1df146756 | 111 | * |
mbed_official | 76:aeb1df146756 | 112 | @verbatim |
mbed_official | 76:aeb1df146756 | 113 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 114 | ##### Initialization and Configuration ##### |
mbed_official | 76:aeb1df146756 | 115 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 116 | |
mbed_official | 76:aeb1df146756 | 117 | @endverbatim |
mbed_official | 76:aeb1df146756 | 118 | * @{ |
mbed_official | 76:aeb1df146756 | 119 | */ |
mbed_official | 76:aeb1df146756 | 120 | |
mbed_official | 76:aeb1df146756 | 121 | /** |
mbed_official | 76:aeb1df146756 | 122 | * @brief Deinitializes the GPIOx peripheral registers to their default reset |
mbed_official | 76:aeb1df146756 | 123 | * values. |
mbed_official | 76:aeb1df146756 | 124 | * By default, The GPIO pins are configured in input floating mode |
mbed_official | 76:aeb1df146756 | 125 | * (except JTAG pins). |
mbed_official | 76:aeb1df146756 | 126 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 127 | * @retval None |
mbed_official | 76:aeb1df146756 | 128 | */ |
mbed_official | 76:aeb1df146756 | 129 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) |
mbed_official | 76:aeb1df146756 | 130 | { |
mbed_official | 76:aeb1df146756 | 131 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 132 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 133 | |
mbed_official | 76:aeb1df146756 | 134 | if(GPIOx == GPIOA) |
mbed_official | 76:aeb1df146756 | 135 | { |
mbed_official | 76:aeb1df146756 | 136 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE); |
mbed_official | 76:aeb1df146756 | 137 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE); |
mbed_official | 76:aeb1df146756 | 138 | } |
mbed_official | 76:aeb1df146756 | 139 | else if(GPIOx == GPIOB) |
mbed_official | 76:aeb1df146756 | 140 | { |
mbed_official | 76:aeb1df146756 | 141 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE); |
mbed_official | 76:aeb1df146756 | 142 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE); |
mbed_official | 76:aeb1df146756 | 143 | } |
mbed_official | 76:aeb1df146756 | 144 | else if(GPIOx == GPIOC) |
mbed_official | 76:aeb1df146756 | 145 | { |
mbed_official | 76:aeb1df146756 | 146 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE); |
mbed_official | 76:aeb1df146756 | 147 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE); |
mbed_official | 76:aeb1df146756 | 148 | } |
mbed_official | 76:aeb1df146756 | 149 | else if(GPIOx == GPIOD) |
mbed_official | 76:aeb1df146756 | 150 | { |
mbed_official | 76:aeb1df146756 | 151 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE); |
mbed_official | 76:aeb1df146756 | 152 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE); |
mbed_official | 76:aeb1df146756 | 153 | } |
mbed_official | 76:aeb1df146756 | 154 | else if(GPIOx == GPIOE) |
mbed_official | 76:aeb1df146756 | 155 | { |
mbed_official | 76:aeb1df146756 | 156 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE); |
mbed_official | 76:aeb1df146756 | 157 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE); |
mbed_official | 76:aeb1df146756 | 158 | } |
mbed_official | 76:aeb1df146756 | 159 | else if(GPIOx == GPIOF) |
mbed_official | 76:aeb1df146756 | 160 | { |
mbed_official | 76:aeb1df146756 | 161 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE); |
mbed_official | 76:aeb1df146756 | 162 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE); |
mbed_official | 76:aeb1df146756 | 163 | } |
mbed_official | 76:aeb1df146756 | 164 | else if(GPIOx == GPIOG) |
mbed_official | 76:aeb1df146756 | 165 | { |
mbed_official | 76:aeb1df146756 | 166 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOG, ENABLE); |
mbed_official | 76:aeb1df146756 | 167 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOG, DISABLE); |
mbed_official | 76:aeb1df146756 | 168 | } |
mbed_official | 76:aeb1df146756 | 169 | else |
mbed_official | 76:aeb1df146756 | 170 | { |
mbed_official | 76:aeb1df146756 | 171 | if(GPIOx == GPIOH) |
mbed_official | 76:aeb1df146756 | 172 | { |
mbed_official | 76:aeb1df146756 | 173 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, ENABLE); |
mbed_official | 76:aeb1df146756 | 174 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOH, DISABLE); |
mbed_official | 76:aeb1df146756 | 175 | } |
mbed_official | 76:aeb1df146756 | 176 | } |
mbed_official | 76:aeb1df146756 | 177 | } |
mbed_official | 76:aeb1df146756 | 178 | |
mbed_official | 76:aeb1df146756 | 179 | /** |
mbed_official | 76:aeb1df146756 | 180 | * @brief Initializes the GPIOx peripheral according to the specified |
mbed_official | 76:aeb1df146756 | 181 | * parameters in the GPIO_InitStruct. |
mbed_official | 76:aeb1df146756 | 182 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 183 | * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that |
mbed_official | 76:aeb1df146756 | 184 | * contains the configuration information for the specified GPIO |
mbed_official | 76:aeb1df146756 | 185 | * peripheral. |
mbed_official | 76:aeb1df146756 | 186 | |
mbed_official | 76:aeb1df146756 | 187 | * @retval None |
mbed_official | 76:aeb1df146756 | 188 | */ |
mbed_official | 76:aeb1df146756 | 189 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 76:aeb1df146756 | 190 | { |
mbed_official | 76:aeb1df146756 | 191 | uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00; |
mbed_official | 80:66393a7b209d | 192 | uint32_t tmpreg = 0x00; |
mbed_official | 76:aeb1df146756 | 193 | |
mbed_official | 76:aeb1df146756 | 194 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 195 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 196 | assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 197 | assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode)); |
mbed_official | 76:aeb1df146756 | 198 | assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd)); |
mbed_official | 76:aeb1df146756 | 199 | |
mbed_official | 76:aeb1df146756 | 200 | /* -------------------------Configure the port pins---------------- */ |
mbed_official | 76:aeb1df146756 | 201 | /*-- GPIO Mode Configuration --*/ |
mbed_official | 76:aeb1df146756 | 202 | for (pinpos = 0x00; pinpos < 0x10; pinpos++) |
mbed_official | 76:aeb1df146756 | 203 | { |
mbed_official | 76:aeb1df146756 | 204 | pos = ((uint32_t)0x01) << pinpos; |
mbed_official | 76:aeb1df146756 | 205 | |
mbed_official | 76:aeb1df146756 | 206 | /* Get the port pins position */ |
mbed_official | 76:aeb1df146756 | 207 | currentpin = (GPIO_InitStruct->GPIO_Pin) & pos; |
mbed_official | 76:aeb1df146756 | 208 | |
mbed_official | 76:aeb1df146756 | 209 | if (currentpin == pos) |
mbed_official | 76:aeb1df146756 | 210 | { |
mbed_official | 80:66393a7b209d | 211 | /* Use temporary variable to update MODER register configuration, to avoid |
mbed_official | 80:66393a7b209d | 212 | unexpected transition in the GPIO pin configuration. */ |
mbed_official | 80:66393a7b209d | 213 | tmpreg = GPIOx->MODER; |
mbed_official | 80:66393a7b209d | 214 | tmpreg &= ~(GPIO_MODER_MODER0 << (pinpos * 2)); |
mbed_official | 80:66393a7b209d | 215 | tmpreg |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2)); |
mbed_official | 80:66393a7b209d | 216 | GPIOx->MODER = tmpreg; |
mbed_official | 76:aeb1df146756 | 217 | |
mbed_official | 76:aeb1df146756 | 218 | if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF)) |
mbed_official | 76:aeb1df146756 | 219 | { |
mbed_official | 76:aeb1df146756 | 220 | /* Check Speed mode parameters */ |
mbed_official | 76:aeb1df146756 | 221 | assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed)); |
mbed_official | 76:aeb1df146756 | 222 | |
mbed_official | 80:66393a7b209d | 223 | /* Use temporary variable to update OSPEEDR register configuration, to avoid |
mbed_official | 80:66393a7b209d | 224 | unexpected transition in the GPIO pin configuration. */ |
mbed_official | 80:66393a7b209d | 225 | tmpreg = GPIOx->OSPEEDR; |
mbed_official | 80:66393a7b209d | 226 | tmpreg &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2)); |
mbed_official | 80:66393a7b209d | 227 | tmpreg |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2)); |
mbed_official | 80:66393a7b209d | 228 | GPIOx->OSPEEDR = tmpreg; |
mbed_official | 76:aeb1df146756 | 229 | |
mbed_official | 76:aeb1df146756 | 230 | /*Check Output mode parameters */ |
mbed_official | 76:aeb1df146756 | 231 | assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType)); |
mbed_official | 76:aeb1df146756 | 232 | |
mbed_official | 80:66393a7b209d | 233 | /* Use temporary variable to update OTYPER register configuration, to avoid |
mbed_official | 80:66393a7b209d | 234 | unexpected transition in the GPIO pin configuration. */ |
mbed_official | 80:66393a7b209d | 235 | tmpreg = GPIOx->OTYPER; |
mbed_official | 80:66393a7b209d | 236 | tmpreg &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)); |
mbed_official | 80:66393a7b209d | 237 | tmpreg |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos)); |
mbed_official | 80:66393a7b209d | 238 | GPIOx->OTYPER = tmpreg; |
mbed_official | 76:aeb1df146756 | 239 | } |
mbed_official | 76:aeb1df146756 | 240 | |
mbed_official | 80:66393a7b209d | 241 | /* Use temporary variable to update PUPDR register configuration, to avoid |
mbed_official | 80:66393a7b209d | 242 | unexpected transition in the GPIO pin configuration. */ |
mbed_official | 80:66393a7b209d | 243 | tmpreg = GPIOx->PUPDR; |
mbed_official | 80:66393a7b209d | 244 | tmpreg &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2)); |
mbed_official | 80:66393a7b209d | 245 | tmpreg |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2)); |
mbed_official | 80:66393a7b209d | 246 | GPIOx->PUPDR = tmpreg; |
mbed_official | 76:aeb1df146756 | 247 | } |
mbed_official | 76:aeb1df146756 | 248 | } |
mbed_official | 76:aeb1df146756 | 249 | } |
mbed_official | 76:aeb1df146756 | 250 | |
mbed_official | 76:aeb1df146756 | 251 | /** |
mbed_official | 76:aeb1df146756 | 252 | * @brief Fills each GPIO_InitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 253 | * @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will |
mbed_official | 76:aeb1df146756 | 254 | * be initialized. |
mbed_official | 76:aeb1df146756 | 255 | * @retval None |
mbed_official | 76:aeb1df146756 | 256 | */ |
mbed_official | 76:aeb1df146756 | 257 | void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 76:aeb1df146756 | 258 | { |
mbed_official | 76:aeb1df146756 | 259 | /* Reset GPIO init structure parameters values */ |
mbed_official | 76:aeb1df146756 | 260 | GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; |
mbed_official | 76:aeb1df146756 | 261 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN; |
mbed_official | 76:aeb1df146756 | 262 | GPIO_InitStruct->GPIO_Speed = GPIO_Speed_400KHz; |
mbed_official | 76:aeb1df146756 | 263 | GPIO_InitStruct->GPIO_OType = GPIO_OType_PP; |
mbed_official | 76:aeb1df146756 | 264 | GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL; |
mbed_official | 76:aeb1df146756 | 265 | } |
mbed_official | 76:aeb1df146756 | 266 | |
mbed_official | 76:aeb1df146756 | 267 | /** |
mbed_official | 76:aeb1df146756 | 268 | * @brief Locks GPIO Pins configuration registers. |
mbed_official | 76:aeb1df146756 | 269 | * The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, |
mbed_official | 76:aeb1df146756 | 270 | * GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH. |
mbed_official | 76:aeb1df146756 | 271 | * The configuration of the locked GPIO pins can no longer be modified |
mbed_official | 76:aeb1df146756 | 272 | * until the next reset. |
mbed_official | 76:aeb1df146756 | 273 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 274 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 76:aeb1df146756 | 275 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 276 | * @retval None |
mbed_official | 76:aeb1df146756 | 277 | */ |
mbed_official | 76:aeb1df146756 | 278 | void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 279 | { |
mbed_official | 76:aeb1df146756 | 280 | __IO uint32_t tmp = 0x00010000; |
mbed_official | 76:aeb1df146756 | 281 | |
mbed_official | 76:aeb1df146756 | 282 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 283 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 284 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 285 | |
mbed_official | 76:aeb1df146756 | 286 | tmp |= GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 287 | /* Set LCKK bit */ |
mbed_official | 76:aeb1df146756 | 288 | GPIOx->LCKR = tmp; |
mbed_official | 76:aeb1df146756 | 289 | /* Reset LCKK bit */ |
mbed_official | 76:aeb1df146756 | 290 | GPIOx->LCKR = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 291 | /* Set LCKK bit */ |
mbed_official | 76:aeb1df146756 | 292 | GPIOx->LCKR = tmp; |
mbed_official | 76:aeb1df146756 | 293 | /* Read LCKK bit*/ |
mbed_official | 76:aeb1df146756 | 294 | tmp = GPIOx->LCKR; |
mbed_official | 76:aeb1df146756 | 295 | /* Read LCKK bit*/ |
mbed_official | 76:aeb1df146756 | 296 | tmp = GPIOx->LCKR; |
mbed_official | 76:aeb1df146756 | 297 | } |
mbed_official | 76:aeb1df146756 | 298 | |
mbed_official | 76:aeb1df146756 | 299 | /** |
mbed_official | 76:aeb1df146756 | 300 | * @} |
mbed_official | 76:aeb1df146756 | 301 | */ |
mbed_official | 76:aeb1df146756 | 302 | |
mbed_official | 76:aeb1df146756 | 303 | /** @defgroup GPIO_Group2 GPIO Read and Write |
mbed_official | 76:aeb1df146756 | 304 | * @brief GPIO Read and Write |
mbed_official | 76:aeb1df146756 | 305 | * |
mbed_official | 76:aeb1df146756 | 306 | @verbatim |
mbed_official | 76:aeb1df146756 | 307 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 308 | ##### GPIO Read and Write ##### |
mbed_official | 76:aeb1df146756 | 309 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 310 | |
mbed_official | 76:aeb1df146756 | 311 | @endverbatim |
mbed_official | 76:aeb1df146756 | 312 | * @{ |
mbed_official | 76:aeb1df146756 | 313 | */ |
mbed_official | 76:aeb1df146756 | 314 | |
mbed_official | 76:aeb1df146756 | 315 | /** |
mbed_official | 76:aeb1df146756 | 316 | * @brief Reads the specified input port pin. |
mbed_official | 76:aeb1df146756 | 317 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 318 | * @param GPIO_Pin: specifies the port bit to read. |
mbed_official | 76:aeb1df146756 | 319 | * This parameter can be GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 320 | * @retval The input port pin value. |
mbed_official | 76:aeb1df146756 | 321 | */ |
mbed_official | 76:aeb1df146756 | 322 | uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 323 | { |
mbed_official | 76:aeb1df146756 | 324 | uint8_t bitstatus = 0x00; |
mbed_official | 76:aeb1df146756 | 325 | |
mbed_official | 76:aeb1df146756 | 326 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 327 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 328 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 329 | |
mbed_official | 76:aeb1df146756 | 330 | if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 76:aeb1df146756 | 331 | { |
mbed_official | 76:aeb1df146756 | 332 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 76:aeb1df146756 | 333 | } |
mbed_official | 76:aeb1df146756 | 334 | else |
mbed_official | 76:aeb1df146756 | 335 | { |
mbed_official | 76:aeb1df146756 | 336 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 76:aeb1df146756 | 337 | } |
mbed_official | 76:aeb1df146756 | 338 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 339 | } |
mbed_official | 76:aeb1df146756 | 340 | |
mbed_official | 76:aeb1df146756 | 341 | /** |
mbed_official | 76:aeb1df146756 | 342 | * @brief Reads the specified GPIO input data port. |
mbed_official | 76:aeb1df146756 | 343 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 344 | * @retval GPIO input data port value. |
mbed_official | 76:aeb1df146756 | 345 | */ |
mbed_official | 76:aeb1df146756 | 346 | uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx) |
mbed_official | 76:aeb1df146756 | 347 | { |
mbed_official | 76:aeb1df146756 | 348 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 349 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 350 | |
mbed_official | 76:aeb1df146756 | 351 | return ((uint16_t)GPIOx->IDR); |
mbed_official | 76:aeb1df146756 | 352 | } |
mbed_official | 76:aeb1df146756 | 353 | |
mbed_official | 76:aeb1df146756 | 354 | /** |
mbed_official | 76:aeb1df146756 | 355 | * @brief Reads the specified output data port bit. |
mbed_official | 76:aeb1df146756 | 356 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 357 | * @param GPIO_Pin: Specifies the port bit to read. |
mbed_official | 76:aeb1df146756 | 358 | * This parameter can be GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 359 | * @retval The output port pin value. |
mbed_official | 76:aeb1df146756 | 360 | */ |
mbed_official | 76:aeb1df146756 | 361 | uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 362 | { |
mbed_official | 76:aeb1df146756 | 363 | uint8_t bitstatus = 0x00; |
mbed_official | 76:aeb1df146756 | 364 | |
mbed_official | 76:aeb1df146756 | 365 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 366 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 367 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 368 | |
mbed_official | 76:aeb1df146756 | 369 | if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 76:aeb1df146756 | 370 | { |
mbed_official | 76:aeb1df146756 | 371 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 76:aeb1df146756 | 372 | } |
mbed_official | 76:aeb1df146756 | 373 | else |
mbed_official | 76:aeb1df146756 | 374 | { |
mbed_official | 76:aeb1df146756 | 375 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 76:aeb1df146756 | 376 | } |
mbed_official | 76:aeb1df146756 | 377 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 378 | } |
mbed_official | 76:aeb1df146756 | 379 | |
mbed_official | 76:aeb1df146756 | 380 | /** |
mbed_official | 76:aeb1df146756 | 381 | * @brief Reads the specified GPIO output data port. |
mbed_official | 76:aeb1df146756 | 382 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 383 | * @retval GPIO output data port value. |
mbed_official | 76:aeb1df146756 | 384 | */ |
mbed_official | 76:aeb1df146756 | 385 | uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx) |
mbed_official | 76:aeb1df146756 | 386 | { |
mbed_official | 76:aeb1df146756 | 387 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 388 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 389 | |
mbed_official | 76:aeb1df146756 | 390 | return ((uint16_t)GPIOx->ODR); |
mbed_official | 76:aeb1df146756 | 391 | } |
mbed_official | 76:aeb1df146756 | 392 | |
mbed_official | 76:aeb1df146756 | 393 | /** |
mbed_official | 76:aeb1df146756 | 394 | * @brief Sets the selected data port bits. |
mbed_official | 76:aeb1df146756 | 395 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 396 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 76:aeb1df146756 | 397 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 398 | * @note This functions uses GPIOx_BSRR register to allow atomic read/modify |
mbed_official | 76:aeb1df146756 | 399 | * accesses. In this way, there is no risk of an IRQ occurring between |
mbed_official | 76:aeb1df146756 | 400 | * the read and the modify access. |
mbed_official | 76:aeb1df146756 | 401 | * @retval None |
mbed_official | 76:aeb1df146756 | 402 | */ |
mbed_official | 76:aeb1df146756 | 403 | void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 404 | { |
mbed_official | 76:aeb1df146756 | 405 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 406 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 407 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 408 | |
mbed_official | 76:aeb1df146756 | 409 | GPIOx->BSRRL = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 410 | } |
mbed_official | 76:aeb1df146756 | 411 | |
mbed_official | 76:aeb1df146756 | 412 | /** |
mbed_official | 76:aeb1df146756 | 413 | * @brief Clears the selected data port bits. |
mbed_official | 76:aeb1df146756 | 414 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 415 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 76:aeb1df146756 | 416 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 417 | * @note This functions uses GPIOx_BSRR register to allow atomic read/modify |
mbed_official | 76:aeb1df146756 | 418 | * accesses. In this way, there is no risk of an IRQ occurring between |
mbed_official | 76:aeb1df146756 | 419 | * the read and the modify access. |
mbed_official | 76:aeb1df146756 | 420 | * @retval None |
mbed_official | 76:aeb1df146756 | 421 | */ |
mbed_official | 76:aeb1df146756 | 422 | void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 423 | { |
mbed_official | 76:aeb1df146756 | 424 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 425 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 426 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 427 | |
mbed_official | 76:aeb1df146756 | 428 | GPIOx->BSRRH = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 429 | } |
mbed_official | 76:aeb1df146756 | 430 | |
mbed_official | 76:aeb1df146756 | 431 | /** |
mbed_official | 76:aeb1df146756 | 432 | * @brief Sets or clears the selected data port bit. |
mbed_official | 76:aeb1df146756 | 433 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 434 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 76:aeb1df146756 | 435 | * This parameter can be one of GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 436 | * @param BitVal: specifies the value to be written to the selected bit. |
mbed_official | 76:aeb1df146756 | 437 | * This parameter can be one of the BitAction enum values: |
mbed_official | 76:aeb1df146756 | 438 | * @arg Bit_RESET: to clear the port pin |
mbed_official | 76:aeb1df146756 | 439 | * @arg Bit_SET: to set the port pin |
mbed_official | 76:aeb1df146756 | 440 | * @retval None |
mbed_official | 76:aeb1df146756 | 441 | */ |
mbed_official | 76:aeb1df146756 | 442 | void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal) |
mbed_official | 76:aeb1df146756 | 443 | { |
mbed_official | 76:aeb1df146756 | 444 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 445 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 446 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 447 | assert_param(IS_GPIO_BIT_ACTION(BitVal)); |
mbed_official | 76:aeb1df146756 | 448 | |
mbed_official | 76:aeb1df146756 | 449 | if (BitVal != Bit_RESET) |
mbed_official | 76:aeb1df146756 | 450 | { |
mbed_official | 76:aeb1df146756 | 451 | GPIOx->BSRRL = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 452 | } |
mbed_official | 76:aeb1df146756 | 453 | else |
mbed_official | 76:aeb1df146756 | 454 | { |
mbed_official | 76:aeb1df146756 | 455 | GPIOx->BSRRH = GPIO_Pin ; |
mbed_official | 76:aeb1df146756 | 456 | } |
mbed_official | 76:aeb1df146756 | 457 | } |
mbed_official | 76:aeb1df146756 | 458 | |
mbed_official | 76:aeb1df146756 | 459 | /** |
mbed_official | 76:aeb1df146756 | 460 | * @brief Writes data to the specified GPIO data port. |
mbed_official | 76:aeb1df146756 | 461 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 462 | * @param PortVal: specifies the value to be written to the port output data |
mbed_official | 76:aeb1df146756 | 463 | * register. |
mbed_official | 76:aeb1df146756 | 464 | * @retval None |
mbed_official | 76:aeb1df146756 | 465 | */ |
mbed_official | 76:aeb1df146756 | 466 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal) |
mbed_official | 76:aeb1df146756 | 467 | { |
mbed_official | 76:aeb1df146756 | 468 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 469 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 470 | |
mbed_official | 76:aeb1df146756 | 471 | GPIOx->ODR = PortVal; |
mbed_official | 76:aeb1df146756 | 472 | } |
mbed_official | 76:aeb1df146756 | 473 | |
mbed_official | 76:aeb1df146756 | 474 | /** |
mbed_official | 76:aeb1df146756 | 475 | * @brief Toggles the specified GPIO pins.. |
mbed_official | 76:aeb1df146756 | 476 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 477 | * @param GPIO_Pin: Specifies the pins to be toggled. |
mbed_official | 76:aeb1df146756 | 478 | * @retval None |
mbed_official | 76:aeb1df146756 | 479 | */ |
mbed_official | 76:aeb1df146756 | 480 | void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 481 | { |
mbed_official | 76:aeb1df146756 | 482 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 483 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 484 | |
mbed_official | 76:aeb1df146756 | 485 | GPIOx->ODR ^= GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 486 | } |
mbed_official | 76:aeb1df146756 | 487 | |
mbed_official | 76:aeb1df146756 | 488 | /** |
mbed_official | 76:aeb1df146756 | 489 | * @} |
mbed_official | 76:aeb1df146756 | 490 | */ |
mbed_official | 76:aeb1df146756 | 491 | |
mbed_official | 76:aeb1df146756 | 492 | /** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions |
mbed_official | 76:aeb1df146756 | 493 | * @brief GPIO Alternate functions configuration functions |
mbed_official | 76:aeb1df146756 | 494 | * |
mbed_official | 76:aeb1df146756 | 495 | @verbatim |
mbed_official | 76:aeb1df146756 | 496 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 497 | ##### GPIO Alternate functions configuration functions ##### |
mbed_official | 76:aeb1df146756 | 498 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 499 | |
mbed_official | 76:aeb1df146756 | 500 | @endverbatim |
mbed_official | 76:aeb1df146756 | 501 | * @{ |
mbed_official | 76:aeb1df146756 | 502 | */ |
mbed_official | 76:aeb1df146756 | 503 | |
mbed_official | 76:aeb1df146756 | 504 | /** |
mbed_official | 76:aeb1df146756 | 505 | * @brief Changes the mapping of the specified pin. |
mbed_official | 76:aeb1df146756 | 506 | * @param GPIOx: where x can be (A..H) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 507 | * @param GPIO_PinSource: specifies the pin for the Alternate function. |
mbed_official | 76:aeb1df146756 | 508 | * This parameter can be GPIO_PinSourcex where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 509 | * @param GPIO_AFSelection: selects the pin to used as Alternat function. |
mbed_official | 76:aeb1df146756 | 510 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 511 | * @arg GPIO_AF_RTC_50Hz: RTC 50/60 Hz synchronization |
mbed_official | 76:aeb1df146756 | 512 | * @arg GPIO_AF_MCO: Microcontroller clock output |
mbed_official | 76:aeb1df146756 | 513 | * @arg GPIO_AF_RTC_AF1: Time stamp, Tamper, Alarm A out, Alarm B out, |
mbed_official | 76:aeb1df146756 | 514 | * 512 Hz clock output (with an LSE oscillator of 32.768 kHz) |
mbed_official | 76:aeb1df146756 | 515 | * @arg GPIO_AF_WKUP: wakeup |
mbed_official | 76:aeb1df146756 | 516 | * @arg GPIO_AF_SWJ: SWJ (SW and JTAG) |
mbed_official | 76:aeb1df146756 | 517 | * @arg GPIO_AF_TRACE: Connect TRACE pins to AF0 (default after reset) |
mbed_official | 76:aeb1df146756 | 518 | * @arg GPIO_AF_TIM2c: Connect TIM2 pins to AF1 |
mbed_official | 76:aeb1df146756 | 519 | * @arg GPIO_AF_TIM3: Connect TIM3 pins to AF2 |
mbed_official | 76:aeb1df146756 | 520 | * @arg GPIO_AF_TIM4: Connect TIM4 pins to AF2 |
mbed_official | 76:aeb1df146756 | 521 | * @arg GPIO_AF_TIM5: Connect TIM5 pins to AF2 |
mbed_official | 76:aeb1df146756 | 522 | * @arg GPIO_AF_TIM9: Connect TIM9 pins to AF3 |
mbed_official | 76:aeb1df146756 | 523 | * @arg GPIO_AF_TIM10: Connect TIM10 pins to AF3 |
mbed_official | 76:aeb1df146756 | 524 | * @arg GPIO_AF_TIM11: Connect TIM11 pins to AF3 |
mbed_official | 76:aeb1df146756 | 525 | * @arg GPIO_AF_I2C1: Connect I2C1 pins to AF4 |
mbed_official | 76:aeb1df146756 | 526 | * @arg GPIO_AF_I2C2: Connect I2C2 pins to AF4 |
mbed_official | 76:aeb1df146756 | 527 | * @arg GPIO_AF_SPI1: Connect SPI1 pins to AF5 |
mbed_official | 76:aeb1df146756 | 528 | * @arg GPIO_AF_SPI2: Connect SPI2/I2S2 pins to AF5 |
mbed_official | 76:aeb1df146756 | 529 | * @arg GPIO_AF_SPI3: Connect SPI3/I2S3 pins to AF6 |
mbed_official | 76:aeb1df146756 | 530 | * @arg GPIO_AF_USART1: Connect USART1 pins to AF7 |
mbed_official | 76:aeb1df146756 | 531 | * @arg GPIO_AF_USART2: Connect USART2 pins to AF7 |
mbed_official | 76:aeb1df146756 | 532 | * @arg GPIO_AF_USART3: Connect USART3 pins to AF7 |
mbed_official | 76:aeb1df146756 | 533 | * @arg GPIO_AF_UART4: Connect UART4 pins to AF8 |
mbed_official | 76:aeb1df146756 | 534 | * @arg GPIO_AF_UART5: Connect UART5 pins to AF8 |
mbed_official | 76:aeb1df146756 | 535 | * @arg GPIO_AF_USB: Connect USB pins to AF10 |
mbed_official | 76:aeb1df146756 | 536 | * @arg GPIO_AF_LCD: Connect LCD pins to AF11 |
mbed_official | 76:aeb1df146756 | 537 | * @arg GPIO_AF_FSMC: Connect FSMC pins to AF12 |
mbed_official | 76:aeb1df146756 | 538 | * @arg GPIO_AF_SDIO: Connect SDIO pins to AF12 |
mbed_official | 76:aeb1df146756 | 539 | * @arg GPIO_AF_RI: Connect RI pins to AF14 |
mbed_official | 76:aeb1df146756 | 540 | * @arg GPIO_AF_EVENTOUT: Cortex-M3 EVENTOUT signal |
mbed_official | 76:aeb1df146756 | 541 | * @note The pin should already been configured in Alternate Function mode(AF) |
mbed_official | 76:aeb1df146756 | 542 | * using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 76:aeb1df146756 | 543 | * @note Please refer to the Alternate function mapping table in the device |
mbed_official | 76:aeb1df146756 | 544 | * datasheet for the detailed mapping of the system and peripherals' |
mbed_official | 76:aeb1df146756 | 545 | * alternate function I/O pins. |
mbed_official | 76:aeb1df146756 | 546 | * @note EVENTOUT is not mapped on PH0, PH1 and PH2. |
mbed_official | 76:aeb1df146756 | 547 | * @retval None |
mbed_official | 76:aeb1df146756 | 548 | */ |
mbed_official | 76:aeb1df146756 | 549 | void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF) |
mbed_official | 76:aeb1df146756 | 550 | { |
mbed_official | 76:aeb1df146756 | 551 | uint32_t temp = 0x00; |
mbed_official | 76:aeb1df146756 | 552 | uint32_t temp_2 = 0x00; |
mbed_official | 76:aeb1df146756 | 553 | |
mbed_official | 76:aeb1df146756 | 554 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 555 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 556 | assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource)); |
mbed_official | 76:aeb1df146756 | 557 | assert_param(IS_GPIO_AF(GPIO_AF)); |
mbed_official | 76:aeb1df146756 | 558 | |
mbed_official | 76:aeb1df146756 | 559 | temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ; |
mbed_official | 76:aeb1df146756 | 560 | GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)) ; |
mbed_official | 76:aeb1df146756 | 561 | temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp; |
mbed_official | 76:aeb1df146756 | 562 | GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2; |
mbed_official | 76:aeb1df146756 | 563 | } |
mbed_official | 76:aeb1df146756 | 564 | |
mbed_official | 76:aeb1df146756 | 565 | /** |
mbed_official | 76:aeb1df146756 | 566 | * @} |
mbed_official | 76:aeb1df146756 | 567 | */ |
mbed_official | 76:aeb1df146756 | 568 | |
mbed_official | 76:aeb1df146756 | 569 | /** |
mbed_official | 76:aeb1df146756 | 570 | * @} |
mbed_official | 76:aeb1df146756 | 571 | */ |
mbed_official | 76:aeb1df146756 | 572 | |
mbed_official | 76:aeb1df146756 | 573 | /** |
mbed_official | 76:aeb1df146756 | 574 | * @} |
mbed_official | 76:aeb1df146756 | 575 | */ |
mbed_official | 76:aeb1df146756 | 576 | |
mbed_official | 76:aeb1df146756 | 577 | /** |
mbed_official | 76:aeb1df146756 | 578 | * @} |
mbed_official | 76:aeb1df146756 | 579 | */ |
mbed_official | 76:aeb1df146756 | 580 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |