mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F030R8/stm32f0xx_gpio.c@76:aeb1df146756, 2014-01-27 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jan 27 14:30:07 2014 +0000
- Revision:
- 76:aeb1df146756
- Child:
- 106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd
Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/
Add NUCLEO_L152RE
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 stm32f0xx_gpio.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 76:aeb1df146756 | 5 | * @version V1.3.0 |
mbed_official | 76:aeb1df146756 | 6 | * @date 16-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 functions |
mbed_official | 76:aeb1df146756 | 10 | * + GPIO Read and Write functions |
mbed_official | 76:aeb1df146756 | 11 | * + GPIO Alternate functions configuration functions |
mbed_official | 76:aeb1df146756 | 12 | * |
mbed_official | 76:aeb1df146756 | 13 | * @verbatim |
mbed_official | 76:aeb1df146756 | 14 | * |
mbed_official | 76:aeb1df146756 | 15 | * |
mbed_official | 76:aeb1df146756 | 16 | =========================================================================== |
mbed_official | 76:aeb1df146756 | 17 | ##### How to use this driver ##### |
mbed_official | 76:aeb1df146756 | 18 | =========================================================================== |
mbed_official | 76:aeb1df146756 | 19 | [..] |
mbed_official | 76:aeb1df146756 | 20 | (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd() |
mbed_official | 76:aeb1df146756 | 21 | (#) Configure the GPIO pin(s) using GPIO_Init() |
mbed_official | 76:aeb1df146756 | 22 | Four possible configuration are available for each pin: |
mbed_official | 76:aeb1df146756 | 23 | (++) Input: Floating, Pull-up, Pull-down. |
mbed_official | 76:aeb1df146756 | 24 | (++) Output: Push-Pull (Pull-up, Pull-down or no Pull) |
mbed_official | 76:aeb1df146756 | 25 | Open Drain (Pull-up, Pull-down or no Pull). |
mbed_official | 76:aeb1df146756 | 26 | In output mode, the speed is configurable: Low, Medium, Fast or High. |
mbed_official | 76:aeb1df146756 | 27 | (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull) |
mbed_official | 76:aeb1df146756 | 28 | Open Drain (Pull-up, Pull-down or no Pull). |
mbed_official | 76:aeb1df146756 | 29 | (++) Analog: required mode when a pin is to be used as ADC channel, |
mbed_official | 76:aeb1df146756 | 30 | DAC output or comparator input. |
mbed_official | 76:aeb1df146756 | 31 | (#) Peripherals alternate function: |
mbed_official | 76:aeb1df146756 | 32 | (++) For ADC, DAC and comparators, configure the desired pin in analog |
mbed_official | 76:aeb1df146756 | 33 | mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN |
mbed_official | 76:aeb1df146756 | 34 | (++) For other peripherals (TIM, USART...): |
mbed_official | 76:aeb1df146756 | 35 | (+++) Connect the pin to the desired peripherals' Alternate |
mbed_official | 76:aeb1df146756 | 36 | Function (AF) using GPIO_PinAFConfig() function. For PortC, |
mbed_official | 76:aeb1df146756 | 37 | PortD and PortF, no configuration is needed. |
mbed_official | 76:aeb1df146756 | 38 | (+++) Configure the desired pin in alternate function mode using |
mbed_official | 76:aeb1df146756 | 39 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 76:aeb1df146756 | 40 | (+++) Select the type, pull-up/pull-down and output speed via |
mbed_official | 76:aeb1df146756 | 41 | GPIO_PuPd, GPIO_OType and GPIO_Speed members |
mbed_official | 76:aeb1df146756 | 42 | (+++) Call GPIO_Init() function |
mbed_official | 76:aeb1df146756 | 43 | (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit() |
mbed_official | 76:aeb1df146756 | 44 | (#) To set/reset the level of a pin configured in output mode use |
mbed_official | 76:aeb1df146756 | 45 | GPIO_SetBits()/GPIO_ResetBits() |
mbed_official | 76:aeb1df146756 | 46 | (#) During and just after reset, the alternate functions are not active and |
mbed_official | 76:aeb1df146756 | 47 | the GPIO pins are configured in input floating mode (except JTAG pins). |
mbed_official | 76:aeb1df146756 | 48 | (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as |
mbed_official | 76:aeb1df146756 | 49 | general-purpose (PC14 and PC15, respectively) when the LSE oscillator |
mbed_official | 76:aeb1df146756 | 50 | is off. The LSE has priority over the GPIO function. |
mbed_official | 76:aeb1df146756 | 51 | (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as general-purpose |
mbed_official | 76:aeb1df146756 | 52 | PD0 and PD1, respectively, when the HSE oscillator is off. The HSE has |
mbed_official | 76:aeb1df146756 | 53 | priority over the GPIO function. |
mbed_official | 76:aeb1df146756 | 54 | @endverbatim |
mbed_official | 76:aeb1df146756 | 55 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 56 | * @attention |
mbed_official | 76:aeb1df146756 | 57 | * |
mbed_official | 76:aeb1df146756 | 58 | * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 59 | * |
mbed_official | 76:aeb1df146756 | 60 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
mbed_official | 76:aeb1df146756 | 61 | * You may not use this file except in compliance with the License. |
mbed_official | 76:aeb1df146756 | 62 | * You may obtain a copy of the License at: |
mbed_official | 76:aeb1df146756 | 63 | * |
mbed_official | 76:aeb1df146756 | 64 | * http://www.st.com/software_license_agreement_liberty_v2 |
mbed_official | 76:aeb1df146756 | 65 | * |
mbed_official | 76:aeb1df146756 | 66 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 76:aeb1df146756 | 67 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 76:aeb1df146756 | 68 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 76:aeb1df146756 | 69 | * See the License for the specific language governing permissions and |
mbed_official | 76:aeb1df146756 | 70 | * limitations under the License. |
mbed_official | 76:aeb1df146756 | 71 | * |
mbed_official | 76:aeb1df146756 | 72 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 73 | */ |
mbed_official | 76:aeb1df146756 | 74 | |
mbed_official | 76:aeb1df146756 | 75 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 76 | #include "stm32f0xx_gpio.h" |
mbed_official | 76:aeb1df146756 | 77 | #include "stm32f0xx_rcc.h" |
mbed_official | 76:aeb1df146756 | 78 | |
mbed_official | 76:aeb1df146756 | 79 | /** @addtogroup STM32F0xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 80 | * @{ |
mbed_official | 76:aeb1df146756 | 81 | */ |
mbed_official | 76:aeb1df146756 | 82 | |
mbed_official | 76:aeb1df146756 | 83 | /** @defgroup GPIO |
mbed_official | 76:aeb1df146756 | 84 | * @brief GPIO driver modules |
mbed_official | 76:aeb1df146756 | 85 | * @{ |
mbed_official | 76:aeb1df146756 | 86 | */ |
mbed_official | 76:aeb1df146756 | 87 | |
mbed_official | 76:aeb1df146756 | 88 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 89 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 90 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 91 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 92 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 93 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 94 | |
mbed_official | 76:aeb1df146756 | 95 | /** @defgroup GPIO_Private_Functions |
mbed_official | 76:aeb1df146756 | 96 | * @{ |
mbed_official | 76:aeb1df146756 | 97 | */ |
mbed_official | 76:aeb1df146756 | 98 | |
mbed_official | 76:aeb1df146756 | 99 | /** @defgroup GPIO_Group1 Initialization and Configuration |
mbed_official | 76:aeb1df146756 | 100 | * @brief Initialization and Configuration |
mbed_official | 76:aeb1df146756 | 101 | * |
mbed_official | 76:aeb1df146756 | 102 | @verbatim |
mbed_official | 76:aeb1df146756 | 103 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 104 | ##### Initialization and Configuration ##### |
mbed_official | 76:aeb1df146756 | 105 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 106 | |
mbed_official | 76:aeb1df146756 | 107 | @endverbatim |
mbed_official | 76:aeb1df146756 | 108 | * @{ |
mbed_official | 76:aeb1df146756 | 109 | */ |
mbed_official | 76:aeb1df146756 | 110 | |
mbed_official | 76:aeb1df146756 | 111 | /** |
mbed_official | 76:aeb1df146756 | 112 | * @brief Deinitializes the GPIOx peripheral registers to their default reset |
mbed_official | 76:aeb1df146756 | 113 | * values. |
mbed_official | 76:aeb1df146756 | 114 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 115 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 116 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 117 | * @retval None |
mbed_official | 76:aeb1df146756 | 118 | */ |
mbed_official | 76:aeb1df146756 | 119 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) |
mbed_official | 76:aeb1df146756 | 120 | { |
mbed_official | 76:aeb1df146756 | 121 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 122 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 123 | |
mbed_official | 76:aeb1df146756 | 124 | if(GPIOx == GPIOA) |
mbed_official | 76:aeb1df146756 | 125 | { |
mbed_official | 76:aeb1df146756 | 126 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE); |
mbed_official | 76:aeb1df146756 | 127 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE); |
mbed_official | 76:aeb1df146756 | 128 | } |
mbed_official | 76:aeb1df146756 | 129 | else if(GPIOx == GPIOB) |
mbed_official | 76:aeb1df146756 | 130 | { |
mbed_official | 76:aeb1df146756 | 131 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE); |
mbed_official | 76:aeb1df146756 | 132 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE); |
mbed_official | 76:aeb1df146756 | 133 | } |
mbed_official | 76:aeb1df146756 | 134 | else if(GPIOx == GPIOC) |
mbed_official | 76:aeb1df146756 | 135 | { |
mbed_official | 76:aeb1df146756 | 136 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE); |
mbed_official | 76:aeb1df146756 | 137 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE); |
mbed_official | 76:aeb1df146756 | 138 | } |
mbed_official | 76:aeb1df146756 | 139 | else if(GPIOx == GPIOD) |
mbed_official | 76:aeb1df146756 | 140 | { |
mbed_official | 76:aeb1df146756 | 141 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE); |
mbed_official | 76:aeb1df146756 | 142 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE); |
mbed_official | 76:aeb1df146756 | 143 | } |
mbed_official | 76:aeb1df146756 | 144 | else if(GPIOx == GPIOE) |
mbed_official | 76:aeb1df146756 | 145 | { |
mbed_official | 76:aeb1df146756 | 146 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE); |
mbed_official | 76:aeb1df146756 | 147 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE); |
mbed_official | 76:aeb1df146756 | 148 | } |
mbed_official | 76:aeb1df146756 | 149 | else |
mbed_official | 76:aeb1df146756 | 150 | { |
mbed_official | 76:aeb1df146756 | 151 | if(GPIOx == GPIOF) |
mbed_official | 76:aeb1df146756 | 152 | { |
mbed_official | 76:aeb1df146756 | 153 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE); |
mbed_official | 76:aeb1df146756 | 154 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE); |
mbed_official | 76:aeb1df146756 | 155 | } |
mbed_official | 76:aeb1df146756 | 156 | } |
mbed_official | 76:aeb1df146756 | 157 | } |
mbed_official | 76:aeb1df146756 | 158 | |
mbed_official | 76:aeb1df146756 | 159 | /** |
mbed_official | 76:aeb1df146756 | 160 | * @brief Initializes the GPIOx peripheral according to the specified |
mbed_official | 76:aeb1df146756 | 161 | * parameters in the GPIO_InitStruct. |
mbed_official | 76:aeb1df146756 | 162 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 163 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 164 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 165 | * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that contains |
mbed_official | 76:aeb1df146756 | 166 | * the configuration information for the specified GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 167 | * @retval None |
mbed_official | 76:aeb1df146756 | 168 | */ |
mbed_official | 76:aeb1df146756 | 169 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 76:aeb1df146756 | 170 | { |
mbed_official | 76:aeb1df146756 | 171 | uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00; |
mbed_official | 76:aeb1df146756 | 172 | |
mbed_official | 76:aeb1df146756 | 173 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 174 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 175 | assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 176 | assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode)); |
mbed_official | 76:aeb1df146756 | 177 | assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd)); |
mbed_official | 76:aeb1df146756 | 178 | |
mbed_official | 76:aeb1df146756 | 179 | /*-------------------------- Configure the port pins -----------------------*/ |
mbed_official | 76:aeb1df146756 | 180 | /*-- GPIO Mode Configuration --*/ |
mbed_official | 76:aeb1df146756 | 181 | for (pinpos = 0x00; pinpos < 0x10; pinpos++) |
mbed_official | 76:aeb1df146756 | 182 | { |
mbed_official | 76:aeb1df146756 | 183 | pos = ((uint32_t)0x01) << pinpos; |
mbed_official | 76:aeb1df146756 | 184 | |
mbed_official | 76:aeb1df146756 | 185 | /* Get the port pins position */ |
mbed_official | 76:aeb1df146756 | 186 | currentpin = (GPIO_InitStruct->GPIO_Pin) & pos; |
mbed_official | 76:aeb1df146756 | 187 | |
mbed_official | 76:aeb1df146756 | 188 | if (currentpin == pos) |
mbed_official | 76:aeb1df146756 | 189 | { |
mbed_official | 76:aeb1df146756 | 190 | if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF)) |
mbed_official | 76:aeb1df146756 | 191 | { |
mbed_official | 76:aeb1df146756 | 192 | /* Check Speed mode parameters */ |
mbed_official | 76:aeb1df146756 | 193 | assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed)); |
mbed_official | 76:aeb1df146756 | 194 | |
mbed_official | 76:aeb1df146756 | 195 | /* Speed mode configuration */ |
mbed_official | 76:aeb1df146756 | 196 | GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2)); |
mbed_official | 76:aeb1df146756 | 197 | GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2)); |
mbed_official | 76:aeb1df146756 | 198 | |
mbed_official | 76:aeb1df146756 | 199 | /* Check Output mode parameters */ |
mbed_official | 76:aeb1df146756 | 200 | assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType)); |
mbed_official | 76:aeb1df146756 | 201 | |
mbed_official | 76:aeb1df146756 | 202 | /* Output mode configuration */ |
mbed_official | 76:aeb1df146756 | 203 | GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)); |
mbed_official | 76:aeb1df146756 | 204 | GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos)); |
mbed_official | 76:aeb1df146756 | 205 | } |
mbed_official | 76:aeb1df146756 | 206 | |
mbed_official | 76:aeb1df146756 | 207 | GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (pinpos * 2)); |
mbed_official | 76:aeb1df146756 | 208 | |
mbed_official | 76:aeb1df146756 | 209 | GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2)); |
mbed_official | 76:aeb1df146756 | 210 | |
mbed_official | 76:aeb1df146756 | 211 | /* Pull-up Pull down resistor configuration */ |
mbed_official | 76:aeb1df146756 | 212 | GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2)); |
mbed_official | 76:aeb1df146756 | 213 | GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2)); |
mbed_official | 76:aeb1df146756 | 214 | } |
mbed_official | 76:aeb1df146756 | 215 | } |
mbed_official | 76:aeb1df146756 | 216 | } |
mbed_official | 76:aeb1df146756 | 217 | |
mbed_official | 76:aeb1df146756 | 218 | /** |
mbed_official | 76:aeb1df146756 | 219 | * @brief Fills each GPIO_InitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 220 | * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure which will |
mbed_official | 76:aeb1df146756 | 221 | * be initialized. |
mbed_official | 76:aeb1df146756 | 222 | * @retval None |
mbed_official | 76:aeb1df146756 | 223 | */ |
mbed_official | 76:aeb1df146756 | 224 | void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct) |
mbed_official | 76:aeb1df146756 | 225 | { |
mbed_official | 76:aeb1df146756 | 226 | /* Reset GPIO init structure parameters values */ |
mbed_official | 76:aeb1df146756 | 227 | GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; |
mbed_official | 76:aeb1df146756 | 228 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN; |
mbed_official | 76:aeb1df146756 | 229 | GPIO_InitStruct->GPIO_Speed = GPIO_Speed_Level_2; |
mbed_official | 76:aeb1df146756 | 230 | GPIO_InitStruct->GPIO_OType = GPIO_OType_PP; |
mbed_official | 76:aeb1df146756 | 231 | GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL; |
mbed_official | 76:aeb1df146756 | 232 | } |
mbed_official | 76:aeb1df146756 | 233 | |
mbed_official | 76:aeb1df146756 | 234 | /** |
mbed_official | 76:aeb1df146756 | 235 | * @brief Locks GPIO Pins configuration registers. |
mbed_official | 76:aeb1df146756 | 236 | * @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, |
mbed_official | 76:aeb1df146756 | 237 | * GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH. |
mbed_official | 76:aeb1df146756 | 238 | * @note The configuration of the locked GPIO pins can no longer be modified |
mbed_official | 76:aeb1df146756 | 239 | * until the next device reset. |
mbed_official | 76:aeb1df146756 | 240 | * @param GPIOx: where x can be (A or B) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 241 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 76:aeb1df146756 | 242 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
mbed_official | 76:aeb1df146756 | 243 | * @retval None |
mbed_official | 76:aeb1df146756 | 244 | */ |
mbed_official | 76:aeb1df146756 | 245 | void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 246 | { |
mbed_official | 76:aeb1df146756 | 247 | __IO uint32_t tmp = 0x00010000; |
mbed_official | 76:aeb1df146756 | 248 | |
mbed_official | 76:aeb1df146756 | 249 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 250 | assert_param(IS_GPIO_LIST_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 251 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 252 | |
mbed_official | 76:aeb1df146756 | 253 | tmp |= GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 254 | /* Set LCKK bit */ |
mbed_official | 76:aeb1df146756 | 255 | GPIOx->LCKR = tmp; |
mbed_official | 76:aeb1df146756 | 256 | /* Reset LCKK bit */ |
mbed_official | 76:aeb1df146756 | 257 | GPIOx->LCKR = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 258 | /* Set LCKK bit */ |
mbed_official | 76:aeb1df146756 | 259 | GPIOx->LCKR = tmp; |
mbed_official | 76:aeb1df146756 | 260 | /* Read LCKK bit */ |
mbed_official | 76:aeb1df146756 | 261 | tmp = GPIOx->LCKR; |
mbed_official | 76:aeb1df146756 | 262 | /* Read LCKK bit */ |
mbed_official | 76:aeb1df146756 | 263 | tmp = GPIOx->LCKR; |
mbed_official | 76:aeb1df146756 | 264 | } |
mbed_official | 76:aeb1df146756 | 265 | |
mbed_official | 76:aeb1df146756 | 266 | /** |
mbed_official | 76:aeb1df146756 | 267 | * @} |
mbed_official | 76:aeb1df146756 | 268 | */ |
mbed_official | 76:aeb1df146756 | 269 | |
mbed_official | 76:aeb1df146756 | 270 | /** @defgroup GPIO_Group2 GPIO Read and Write |
mbed_official | 76:aeb1df146756 | 271 | * @brief GPIO Read and Write |
mbed_official | 76:aeb1df146756 | 272 | * |
mbed_official | 76:aeb1df146756 | 273 | @verbatim |
mbed_official | 76:aeb1df146756 | 274 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 275 | ##### GPIO Read and Write ##### |
mbed_official | 76:aeb1df146756 | 276 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 277 | |
mbed_official | 76:aeb1df146756 | 278 | @endverbatim |
mbed_official | 76:aeb1df146756 | 279 | * @{ |
mbed_official | 76:aeb1df146756 | 280 | */ |
mbed_official | 76:aeb1df146756 | 281 | |
mbed_official | 76:aeb1df146756 | 282 | /** |
mbed_official | 76:aeb1df146756 | 283 | * @brief Reads the specified input port pin. |
mbed_official | 76:aeb1df146756 | 284 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 285 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 286 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 287 | * @param GPIO_Pin: specifies the port bit to read. |
mbed_official | 76:aeb1df146756 | 288 | * @note This parameter can be GPIO_Pin_x where x can be: |
mbed_official | 76:aeb1df146756 | 289 | * For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF. |
mbed_official | 76:aeb1df146756 | 290 | * For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF. |
mbed_official | 76:aeb1df146756 | 291 | * For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. |
mbed_official | 76:aeb1df146756 | 292 | * @retval The input port pin value. |
mbed_official | 76:aeb1df146756 | 293 | */ |
mbed_official | 76:aeb1df146756 | 294 | uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 295 | { |
mbed_official | 76:aeb1df146756 | 296 | uint8_t bitstatus = 0x00; |
mbed_official | 76:aeb1df146756 | 297 | |
mbed_official | 76:aeb1df146756 | 298 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 299 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 300 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 301 | |
mbed_official | 76:aeb1df146756 | 302 | if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 76:aeb1df146756 | 303 | { |
mbed_official | 76:aeb1df146756 | 304 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 76:aeb1df146756 | 305 | } |
mbed_official | 76:aeb1df146756 | 306 | else |
mbed_official | 76:aeb1df146756 | 307 | { |
mbed_official | 76:aeb1df146756 | 308 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 76:aeb1df146756 | 309 | } |
mbed_official | 76:aeb1df146756 | 310 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 311 | } |
mbed_official | 76:aeb1df146756 | 312 | |
mbed_official | 76:aeb1df146756 | 313 | /** |
mbed_official | 76:aeb1df146756 | 314 | * @brief Reads the specified input port pin. |
mbed_official | 76:aeb1df146756 | 315 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 316 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 317 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 318 | * @retval The input port pin value. |
mbed_official | 76:aeb1df146756 | 319 | */ |
mbed_official | 76:aeb1df146756 | 320 | uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx) |
mbed_official | 76:aeb1df146756 | 321 | { |
mbed_official | 76:aeb1df146756 | 322 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 323 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 324 | |
mbed_official | 76:aeb1df146756 | 325 | return ((uint16_t)GPIOx->IDR); |
mbed_official | 76:aeb1df146756 | 326 | } |
mbed_official | 76:aeb1df146756 | 327 | |
mbed_official | 76:aeb1df146756 | 328 | /** |
mbed_official | 76:aeb1df146756 | 329 | * @brief Reads the specified output data port bit. |
mbed_official | 76:aeb1df146756 | 330 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 331 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 332 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 333 | * @param GPIO_Pin: Specifies the port bit to read. |
mbed_official | 76:aeb1df146756 | 334 | * @note This parameter can be GPIO_Pin_x where x can be: |
mbed_official | 76:aeb1df146756 | 335 | * For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF. |
mbed_official | 76:aeb1df146756 | 336 | * For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF. |
mbed_official | 76:aeb1df146756 | 337 | * For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. |
mbed_official | 76:aeb1df146756 | 338 | * @retval The output port pin value. |
mbed_official | 76:aeb1df146756 | 339 | */ |
mbed_official | 76:aeb1df146756 | 340 | uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 341 | { |
mbed_official | 76:aeb1df146756 | 342 | uint8_t bitstatus = 0x00; |
mbed_official | 76:aeb1df146756 | 343 | |
mbed_official | 76:aeb1df146756 | 344 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 345 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 346 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 347 | |
mbed_official | 76:aeb1df146756 | 348 | if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET) |
mbed_official | 76:aeb1df146756 | 349 | { |
mbed_official | 76:aeb1df146756 | 350 | bitstatus = (uint8_t)Bit_SET; |
mbed_official | 76:aeb1df146756 | 351 | } |
mbed_official | 76:aeb1df146756 | 352 | else |
mbed_official | 76:aeb1df146756 | 353 | { |
mbed_official | 76:aeb1df146756 | 354 | bitstatus = (uint8_t)Bit_RESET; |
mbed_official | 76:aeb1df146756 | 355 | } |
mbed_official | 76:aeb1df146756 | 356 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 357 | } |
mbed_official | 76:aeb1df146756 | 358 | |
mbed_official | 76:aeb1df146756 | 359 | /** |
mbed_official | 76:aeb1df146756 | 360 | * @brief Reads the specified GPIO output data port. |
mbed_official | 76:aeb1df146756 | 361 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 362 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 363 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 364 | * @retval GPIO output data port value. |
mbed_official | 76:aeb1df146756 | 365 | */ |
mbed_official | 76:aeb1df146756 | 366 | uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx) |
mbed_official | 76:aeb1df146756 | 367 | { |
mbed_official | 76:aeb1df146756 | 368 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 369 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 370 | |
mbed_official | 76:aeb1df146756 | 371 | return ((uint16_t)GPIOx->ODR); |
mbed_official | 76:aeb1df146756 | 372 | } |
mbed_official | 76:aeb1df146756 | 373 | |
mbed_official | 76:aeb1df146756 | 374 | /** |
mbed_official | 76:aeb1df146756 | 375 | * @brief Sets the selected data port bits. |
mbed_official | 76:aeb1df146756 | 376 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 377 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 378 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 379 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 76:aeb1df146756 | 380 | * @note This parameter can be GPIO_Pin_x where x can be: |
mbed_official | 76:aeb1df146756 | 381 | * For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF. |
mbed_official | 76:aeb1df146756 | 382 | * For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF. |
mbed_official | 76:aeb1df146756 | 383 | * For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. |
mbed_official | 76:aeb1df146756 | 384 | * @retval None |
mbed_official | 76:aeb1df146756 | 385 | */ |
mbed_official | 76:aeb1df146756 | 386 | void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 387 | { |
mbed_official | 76:aeb1df146756 | 388 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 389 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 390 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 391 | |
mbed_official | 76:aeb1df146756 | 392 | GPIOx->BSRR = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 393 | } |
mbed_official | 76:aeb1df146756 | 394 | |
mbed_official | 76:aeb1df146756 | 395 | /** |
mbed_official | 76:aeb1df146756 | 396 | * @brief Clears the selected data port bits. |
mbed_official | 76:aeb1df146756 | 397 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 398 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 399 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 400 | * @param GPIO_Pin: specifies the port bits to be written. |
mbed_official | 76:aeb1df146756 | 401 | * @note This parameter can be GPIO_Pin_x where x can be: |
mbed_official | 76:aeb1df146756 | 402 | * For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF. |
mbed_official | 76:aeb1df146756 | 403 | * For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF. |
mbed_official | 76:aeb1df146756 | 404 | * For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. |
mbed_official | 76:aeb1df146756 | 405 | * @retval None |
mbed_official | 76:aeb1df146756 | 406 | */ |
mbed_official | 76:aeb1df146756 | 407 | void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 76:aeb1df146756 | 408 | { |
mbed_official | 76:aeb1df146756 | 409 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 410 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 411 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 412 | |
mbed_official | 76:aeb1df146756 | 413 | GPIOx->BRR = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 414 | } |
mbed_official | 76:aeb1df146756 | 415 | |
mbed_official | 76:aeb1df146756 | 416 | /** |
mbed_official | 76:aeb1df146756 | 417 | * @brief Sets or clears the selected data port bit. |
mbed_official | 76:aeb1df146756 | 418 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 419 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 420 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 421 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 76:aeb1df146756 | 422 | * @param BitVal: specifies the value to be written to the selected bit. |
mbed_official | 76:aeb1df146756 | 423 | * This parameter can be one of the BitAction enumeration values: |
mbed_official | 76:aeb1df146756 | 424 | * @arg Bit_RESET: to clear the port pin |
mbed_official | 76:aeb1df146756 | 425 | * @arg Bit_SET: to set the port pin |
mbed_official | 76:aeb1df146756 | 426 | * @note This parameter can be GPIO_Pin_x where x can be: |
mbed_official | 76:aeb1df146756 | 427 | * For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF. |
mbed_official | 76:aeb1df146756 | 428 | * For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF. |
mbed_official | 76:aeb1df146756 | 429 | * For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. |
mbed_official | 76:aeb1df146756 | 430 | * @retval None |
mbed_official | 76:aeb1df146756 | 431 | */ |
mbed_official | 76:aeb1df146756 | 432 | void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal) |
mbed_official | 76:aeb1df146756 | 433 | { |
mbed_official | 76:aeb1df146756 | 434 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 435 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 436 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 76:aeb1df146756 | 437 | assert_param(IS_GPIO_BIT_ACTION(BitVal)); |
mbed_official | 76:aeb1df146756 | 438 | |
mbed_official | 76:aeb1df146756 | 439 | if (BitVal != Bit_RESET) |
mbed_official | 76:aeb1df146756 | 440 | { |
mbed_official | 76:aeb1df146756 | 441 | GPIOx->BSRR = GPIO_Pin; |
mbed_official | 76:aeb1df146756 | 442 | } |
mbed_official | 76:aeb1df146756 | 443 | else |
mbed_official | 76:aeb1df146756 | 444 | { |
mbed_official | 76:aeb1df146756 | 445 | GPIOx->BRR = GPIO_Pin ; |
mbed_official | 76:aeb1df146756 | 446 | } |
mbed_official | 76:aeb1df146756 | 447 | } |
mbed_official | 76:aeb1df146756 | 448 | |
mbed_official | 76:aeb1df146756 | 449 | /** |
mbed_official | 76:aeb1df146756 | 450 | * @brief Writes data to the specified GPIO data port. |
mbed_official | 76:aeb1df146756 | 451 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 452 | * @note GPIOE is available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 453 | * @note GPIOD is not available for STM32F031. |
mbed_official | 76:aeb1df146756 | 454 | * @param PortVal: specifies the value to be written to the port output data register. |
mbed_official | 76:aeb1df146756 | 455 | * @retval None |
mbed_official | 76:aeb1df146756 | 456 | */ |
mbed_official | 76:aeb1df146756 | 457 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal) |
mbed_official | 76:aeb1df146756 | 458 | { |
mbed_official | 76:aeb1df146756 | 459 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 460 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 461 | |
mbed_official | 76:aeb1df146756 | 462 | GPIOx->ODR = PortVal; |
mbed_official | 76:aeb1df146756 | 463 | } |
mbed_official | 76:aeb1df146756 | 464 | |
mbed_official | 76:aeb1df146756 | 465 | /** |
mbed_official | 76:aeb1df146756 | 466 | * @} |
mbed_official | 76:aeb1df146756 | 467 | */ |
mbed_official | 76:aeb1df146756 | 468 | |
mbed_official | 76:aeb1df146756 | 469 | /** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions |
mbed_official | 76:aeb1df146756 | 470 | * @brief GPIO Alternate functions configuration functions |
mbed_official | 76:aeb1df146756 | 471 | * |
mbed_official | 76:aeb1df146756 | 472 | @verbatim |
mbed_official | 76:aeb1df146756 | 473 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 474 | ##### GPIO Alternate functions configuration functions ##### |
mbed_official | 76:aeb1df146756 | 475 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 476 | |
mbed_official | 76:aeb1df146756 | 477 | @endverbatim |
mbed_official | 76:aeb1df146756 | 478 | * @{ |
mbed_official | 76:aeb1df146756 | 479 | */ |
mbed_official | 76:aeb1df146756 | 480 | |
mbed_official | 76:aeb1df146756 | 481 | /** |
mbed_official | 76:aeb1df146756 | 482 | * @brief Writes data to the specified GPIO data port. |
mbed_official | 76:aeb1df146756 | 483 | * @param GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral. |
mbed_official | 76:aeb1df146756 | 484 | * @note GPIOC, GPIOD, GPIOE and GPIOF are available only for STM32F072. |
mbed_official | 76:aeb1df146756 | 485 | * @param GPIO_PinSource: specifies the pin for the Alternate function. |
mbed_official | 76:aeb1df146756 | 486 | * This parameter can be GPIO_PinSourcex where x can be (0..15) for GPIOA, GPIOB, GPIOD, GPIOE |
mbed_official | 76:aeb1df146756 | 487 | * and (0..12) for GPIOC and (0, 2..5, 9..10) for GPIOF. |
mbed_official | 76:aeb1df146756 | 488 | * @param GPIO_AF: selects the pin to used as Alternate function. |
mbed_official | 76:aeb1df146756 | 489 | * This parameter can be one of the following value: |
mbed_official | 76:aeb1df146756 | 490 | * @arg GPIO_AF_0: WKUP, EVENTOUT, TIM15, SPI1, TIM17, MCO, SWDAT, SWCLK, |
mbed_official | 76:aeb1df146756 | 491 | * TIM14, BOOT, USART1, CEC, IR_OUT, SPI2, TIM3, USART4, |
mbed_official | 76:aeb1df146756 | 492 | * CAN, USART2, CRS, TIM16, TIM1, TS |
mbed_official | 76:aeb1df146756 | 493 | * @arg GPIO_AF_1: USART2, CEC, TIM3, USART1, USART2, EVENTOUT, I2C1, |
mbed_official | 76:aeb1df146756 | 494 | * I2C2, TIM15, SPI2, USART3, TS, SPI1 |
mbed_official | 76:aeb1df146756 | 495 | * @arg GPIO_AF_2: TIM2, TIM1, EVENTOUT, TIM16, TIM17, USB |
mbed_official | 76:aeb1df146756 | 496 | * @arg GPIO_AF_3: TS, I2C1, TIM15, EVENTOUT |
mbed_official | 76:aeb1df146756 | 497 | * @arg GPIO_AF_4: TIM14, USART4, USART3, CRS, CAN |
mbed_official | 76:aeb1df146756 | 498 | * @arg GPIO_AF_5: TIM16, TIM17, TIM15, SPI2, I2C2 |
mbed_official | 76:aeb1df146756 | 499 | * @arg GPIO_AF_6: EVENTOUT |
mbed_official | 76:aeb1df146756 | 500 | * @arg GPIO_AF_7: COMP1 OUT, COMP2 OUT |
mbed_official | 76:aeb1df146756 | 501 | * @note The pin should already been configured in Alternate Function mode(AF) |
mbed_official | 76:aeb1df146756 | 502 | * using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 76:aeb1df146756 | 503 | * @note Refer to the Alternate function mapping table in the device datasheet |
mbed_official | 76:aeb1df146756 | 504 | * for the detailed mapping of the system and peripherals'alternate |
mbed_official | 76:aeb1df146756 | 505 | * function I/O pins. |
mbed_official | 76:aeb1df146756 | 506 | * @retval None |
mbed_official | 76:aeb1df146756 | 507 | */ |
mbed_official | 76:aeb1df146756 | 508 | void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF) |
mbed_official | 76:aeb1df146756 | 509 | { |
mbed_official | 76:aeb1df146756 | 510 | uint32_t temp = 0x00; |
mbed_official | 76:aeb1df146756 | 511 | uint32_t temp_2 = 0x00; |
mbed_official | 76:aeb1df146756 | 512 | |
mbed_official | 76:aeb1df146756 | 513 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 514 | assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); |
mbed_official | 76:aeb1df146756 | 515 | assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource)); |
mbed_official | 76:aeb1df146756 | 516 | assert_param(IS_GPIO_AF(GPIO_AF)); |
mbed_official | 76:aeb1df146756 | 517 | |
mbed_official | 76:aeb1df146756 | 518 | temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)); |
mbed_official | 76:aeb1df146756 | 519 | GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4)); |
mbed_official | 76:aeb1df146756 | 520 | temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp; |
mbed_official | 76:aeb1df146756 | 521 | GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2; |
mbed_official | 76:aeb1df146756 | 522 | } |
mbed_official | 76:aeb1df146756 | 523 | |
mbed_official | 76:aeb1df146756 | 524 | /** |
mbed_official | 76:aeb1df146756 | 525 | * @} |
mbed_official | 76:aeb1df146756 | 526 | */ |
mbed_official | 76:aeb1df146756 | 527 | |
mbed_official | 76:aeb1df146756 | 528 | /** |
mbed_official | 76:aeb1df146756 | 529 | * @} |
mbed_official | 76:aeb1df146756 | 530 | */ |
mbed_official | 76:aeb1df146756 | 531 | |
mbed_official | 76:aeb1df146756 | 532 | /** |
mbed_official | 76:aeb1df146756 | 533 | * @} |
mbed_official | 76:aeb1df146756 | 534 | */ |
mbed_official | 76:aeb1df146756 | 535 | |
mbed_official | 76:aeb1df146756 | 536 | /** |
mbed_official | 76:aeb1df146756 | 537 | * @} |
mbed_official | 76:aeb1df146756 | 538 | */ |
mbed_official | 76:aeb1df146756 | 539 | |
mbed_official | 76:aeb1df146756 | 540 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |