mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_gpio.c@106:ced8cbb51063, 2014-02-26 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Feb 26 09:45:12 2014 +0000
- Revision:
- 106:ced8cbb51063
- Parent:
- 87:085cde657901
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 | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal_gpio.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 106:ced8cbb51063 | 5 | * @version V1.0.0 |
mbed_official | 106:ced8cbb51063 | 6 | * @date 18-February-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief GPIO HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 87:085cde657901 | 9 | * functionalities of the General Purpose Input/Output (GPIO) peripheral: |
mbed_official | 87:085cde657901 | 10 | * + Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 11 | * + IO operation functions |
mbed_official | 87:085cde657901 | 12 | * |
mbed_official | 87:085cde657901 | 13 | @verbatim |
mbed_official | 87:085cde657901 | 14 | ============================================================================== |
mbed_official | 87:085cde657901 | 15 | ##### GPIO Peripheral features ##### |
mbed_official | 87:085cde657901 | 16 | ============================================================================== |
mbed_official | 87:085cde657901 | 17 | [..] |
mbed_official | 87:085cde657901 | 18 | (+) Each port bit of the general-purpose I/O (GPIO) ports can be individually |
mbed_official | 87:085cde657901 | 19 | configured by software in several modes: |
mbed_official | 87:085cde657901 | 20 | (++) Input mode |
mbed_official | 87:085cde657901 | 21 | (++) Analog mode |
mbed_official | 87:085cde657901 | 22 | (++) Output mode |
mbed_official | 87:085cde657901 | 23 | (++) Alternate function mode |
mbed_official | 87:085cde657901 | 24 | (++) External interrupt/event lines |
mbed_official | 87:085cde657901 | 25 | |
mbed_official | 87:085cde657901 | 26 | (+) During and just after reset, the alternate functions and external interrupt |
mbed_official | 87:085cde657901 | 27 | lines are not active and the I/O ports are configured in input floating mode. |
mbed_official | 87:085cde657901 | 28 | |
mbed_official | 87:085cde657901 | 29 | (+) All GPIO pins have weak internal pull-up and pull-down resistors, which can be |
mbed_official | 87:085cde657901 | 30 | activated or not. |
mbed_official | 87:085cde657901 | 31 | |
mbed_official | 87:085cde657901 | 32 | (+) In Output or Alternate mode, each IO can be configured on open-drain or push-pull |
mbed_official | 87:085cde657901 | 33 | type and the IO speed can be selected depending on the VDD value. |
mbed_official | 87:085cde657901 | 34 | |
mbed_official | 87:085cde657901 | 35 | (+) The microcontroller IO pins are connected to onboard peripherals/modules through a |
mbed_official | 87:085cde657901 | 36 | multiplexer that allows only one peripheral alternate function (AF) connected |
mbed_official | 87:085cde657901 | 37 | to an IO pin at a time. In this way, there can be no conflict between peripherals |
mbed_official | 87:085cde657901 | 38 | sharing the same IO pin. |
mbed_official | 87:085cde657901 | 39 | |
mbed_official | 87:085cde657901 | 40 | (+) All ports have external interrupt/event capability. To use external interrupt |
mbed_official | 87:085cde657901 | 41 | lines, the port must be configured in input mode. All available GPIO pins are |
mbed_official | 87:085cde657901 | 42 | connected to the 16 external interrupt/event lines from EXTI0 to EXTI15. |
mbed_official | 87:085cde657901 | 43 | |
mbed_official | 87:085cde657901 | 44 | (+) The external interrupt/event controller consists of up to 23 edge detectors |
mbed_official | 87:085cde657901 | 45 | (16 lines are connected to GPIO) for generating event/interrupt requests (each |
mbed_official | 87:085cde657901 | 46 | input line can be independently configured to select the type (interrupt or event) |
mbed_official | 87:085cde657901 | 47 | and the corresponding trigger event (rising or falling or both). Each line can |
mbed_official | 87:085cde657901 | 48 | also be masked independently. |
mbed_official | 87:085cde657901 | 49 | |
mbed_official | 87:085cde657901 | 50 | ##### How to use this driver ##### |
mbed_official | 87:085cde657901 | 51 | ============================================================================== |
mbed_official | 87:085cde657901 | 52 | [..] |
mbed_official | 87:085cde657901 | 53 | (#) Enable the GPIO AHB clock using the following function: __GPIOx_CLK_ENABLE(). |
mbed_official | 87:085cde657901 | 54 | |
mbed_official | 87:085cde657901 | 55 | (#) Configure the GPIO pin(s) using HAL_GPIO_Init(). |
mbed_official | 87:085cde657901 | 56 | (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure |
mbed_official | 87:085cde657901 | 57 | (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef |
mbed_official | 87:085cde657901 | 58 | structure. |
mbed_official | 87:085cde657901 | 59 | (++) In case of Output or alternate function mode selection: the speed is |
mbed_official | 87:085cde657901 | 60 | configured through "Speed" member from GPIO_InitTypeDef structure. |
mbed_official | 87:085cde657901 | 61 | (++) In alternate mode is selection, the alternate function connected to the IO |
mbed_official | 87:085cde657901 | 62 | is configured through "Alternate" member from GPIO_InitTypeDef structure. |
mbed_official | 87:085cde657901 | 63 | (++) Analog mode is required when a pin is to be used as ADC channel |
mbed_official | 87:085cde657901 | 64 | or DAC output. |
mbed_official | 87:085cde657901 | 65 | (++) In case of external interrupt/event selection the "Mode" member from |
mbed_official | 87:085cde657901 | 66 | GPIO_InitTypeDef structure select the type (interrupt or event) and |
mbed_official | 87:085cde657901 | 67 | the corresponding trigger event (rising or falling or both). |
mbed_official | 87:085cde657901 | 68 | |
mbed_official | 87:085cde657901 | 69 | (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority |
mbed_official | 87:085cde657901 | 70 | mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using |
mbed_official | 87:085cde657901 | 71 | HAL_NVIC_EnableIRQ(). |
mbed_official | 87:085cde657901 | 72 | |
mbed_official | 87:085cde657901 | 73 | (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin(). |
mbed_official | 87:085cde657901 | 74 | |
mbed_official | 87:085cde657901 | 75 | (#) To set/reset the level of a pin configured in output mode use |
mbed_official | 87:085cde657901 | 76 | HAL_GPIO_WritePin()/HAL_GPIO_TogglePin(). |
mbed_official | 87:085cde657901 | 77 | |
mbed_official | 87:085cde657901 | 78 | (#) During and just after reset, the alternate functions are not |
mbed_official | 87:085cde657901 | 79 | active and the GPIO pins are configured in input floating mode (except JTAG |
mbed_official | 87:085cde657901 | 80 | pins). |
mbed_official | 87:085cde657901 | 81 | |
mbed_official | 87:085cde657901 | 82 | (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose |
mbed_official | 87:085cde657901 | 83 | (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has |
mbed_official | 87:085cde657901 | 84 | priority over the GPIO function. |
mbed_official | 87:085cde657901 | 85 | |
mbed_official | 87:085cde657901 | 86 | (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as |
mbed_official | 87:085cde657901 | 87 | general purpose PH0 and PH1, respectively, when the HSE oscillator is off. |
mbed_official | 87:085cde657901 | 88 | The HSE has priority over the GPIO function. |
mbed_official | 87:085cde657901 | 89 | |
mbed_official | 87:085cde657901 | 90 | @endverbatim |
mbed_official | 87:085cde657901 | 91 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 92 | * @attention |
mbed_official | 87:085cde657901 | 93 | * |
mbed_official | 87:085cde657901 | 94 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 95 | * |
mbed_official | 87:085cde657901 | 96 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 97 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 98 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 99 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 100 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 101 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 102 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 103 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 104 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 105 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 106 | * |
mbed_official | 87:085cde657901 | 107 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 108 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 109 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 110 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 111 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 112 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 113 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 114 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 115 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 116 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 117 | * |
mbed_official | 87:085cde657901 | 118 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 119 | */ |
mbed_official | 87:085cde657901 | 120 | |
mbed_official | 87:085cde657901 | 121 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 122 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 123 | |
mbed_official | 87:085cde657901 | 124 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 125 | * @{ |
mbed_official | 87:085cde657901 | 126 | */ |
mbed_official | 87:085cde657901 | 127 | |
mbed_official | 87:085cde657901 | 128 | /** @defgroup GPIO |
mbed_official | 87:085cde657901 | 129 | * @brief GPIO HAL module driver |
mbed_official | 87:085cde657901 | 130 | * @{ |
mbed_official | 87:085cde657901 | 131 | */ |
mbed_official | 87:085cde657901 | 132 | |
mbed_official | 87:085cde657901 | 133 | #ifdef HAL_GPIO_MODULE_ENABLED |
mbed_official | 87:085cde657901 | 134 | |
mbed_official | 87:085cde657901 | 135 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 136 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 137 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 138 | #define __HAL_GET_GPIO_SOURCE(__GPIOx__) \ |
mbed_official | 87:085cde657901 | 139 | (((uint32_t)(__GPIOx__) == ((uint32_t)GPIOA_BASE))? (uint32_t)0 :\ |
mbed_official | 87:085cde657901 | 140 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x0400)))? (uint32_t)1 :\ |
mbed_official | 87:085cde657901 | 141 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x0800)))? (uint32_t)2 :\ |
mbed_official | 87:085cde657901 | 142 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x0C00)))? (uint32_t)3 :\ |
mbed_official | 87:085cde657901 | 143 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x1000)))? (uint32_t)4 :\ |
mbed_official | 87:085cde657901 | 144 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x1400)))? (uint32_t)5 :\ |
mbed_official | 87:085cde657901 | 145 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x1800)))? (uint32_t)6 :\ |
mbed_official | 87:085cde657901 | 146 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x1C00)))? (uint32_t)7 :\ |
mbed_official | 87:085cde657901 | 147 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x2000)))? (uint32_t)8 :\ |
mbed_official | 87:085cde657901 | 148 | ((uint32_t)(__GPIOx__) == ((uint32_t)(GPIOA_BASE + 0x2400)))? (uint32_t)9 : (uint32_t)10) |
mbed_official | 87:085cde657901 | 149 | |
mbed_official | 87:085cde657901 | 150 | #define GPIO_MODE ((uint32_t)0x00000003) |
mbed_official | 87:085cde657901 | 151 | #define EXTI_MODE ((uint32_t)0x10000000) |
mbed_official | 87:085cde657901 | 152 | #define GPIO_MODE_IT ((uint32_t)0x00010000) |
mbed_official | 87:085cde657901 | 153 | #define GPIO_MODE_EVT ((uint32_t)0x00020000) |
mbed_official | 87:085cde657901 | 154 | #define RISING_EDGE ((uint32_t)0x00100000) |
mbed_official | 87:085cde657901 | 155 | #define FALLING_EDGE ((uint32_t)0x00200000) |
mbed_official | 87:085cde657901 | 156 | #define GPIO_OUTPUT_TYPE ((uint32_t)0x00000010) |
mbed_official | 87:085cde657901 | 157 | |
mbed_official | 87:085cde657901 | 158 | #define GPIO_NUMBER ((uint32_t)16) |
mbed_official | 87:085cde657901 | 159 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 160 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 161 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 162 | |
mbed_official | 87:085cde657901 | 163 | /** @defgroup GPIO_Private_Functions |
mbed_official | 87:085cde657901 | 164 | * @{ |
mbed_official | 87:085cde657901 | 165 | */ |
mbed_official | 87:085cde657901 | 166 | |
mbed_official | 87:085cde657901 | 167 | /** @defgroup GPIO_Group1 Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 168 | * @brief Initialization and Configuration functions |
mbed_official | 87:085cde657901 | 169 | * |
mbed_official | 87:085cde657901 | 170 | @verbatim |
mbed_official | 87:085cde657901 | 171 | =============================================================================== |
mbed_official | 87:085cde657901 | 172 | ##### Initialization and de-initialization functions ##### |
mbed_official | 87:085cde657901 | 173 | =============================================================================== |
mbed_official | 87:085cde657901 | 174 | |
mbed_official | 87:085cde657901 | 175 | @endverbatim |
mbed_official | 87:085cde657901 | 176 | * @{ |
mbed_official | 87:085cde657901 | 177 | */ |
mbed_official | 87:085cde657901 | 178 | |
mbed_official | 87:085cde657901 | 179 | /** |
mbed_official | 87:085cde657901 | 180 | * @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init. |
mbed_official | 87:085cde657901 | 181 | * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F429X device or |
mbed_official | 87:085cde657901 | 182 | * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. |
mbed_official | 87:085cde657901 | 183 | * @param GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains |
mbed_official | 87:085cde657901 | 184 | * the configuration information for the specified GPIO peripheral. |
mbed_official | 87:085cde657901 | 185 | * @retval None |
mbed_official | 87:085cde657901 | 186 | */ |
mbed_official | 87:085cde657901 | 187 | void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) |
mbed_official | 87:085cde657901 | 188 | { |
mbed_official | 87:085cde657901 | 189 | uint32_t position; |
mbed_official | 87:085cde657901 | 190 | uint32_t ioposition = 0x00; |
mbed_official | 87:085cde657901 | 191 | uint32_t iocurrent = 0x00; |
mbed_official | 87:085cde657901 | 192 | uint32_t temp = 0x00; |
mbed_official | 87:085cde657901 | 193 | |
mbed_official | 87:085cde657901 | 194 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 195 | assert_param(IS_GPIO_PIN(GPIO_Init->Pin)); |
mbed_official | 87:085cde657901 | 196 | assert_param(IS_GPIO_MODE(GPIO_Init->Mode)); |
mbed_official | 87:085cde657901 | 197 | assert_param(IS_GPIO_PULL(GPIO_Init->Pull)); |
mbed_official | 87:085cde657901 | 198 | |
mbed_official | 87:085cde657901 | 199 | /* Configure the port pins */ |
mbed_official | 87:085cde657901 | 200 | for(position = 0; position < GPIO_NUMBER; position++) |
mbed_official | 87:085cde657901 | 201 | { |
mbed_official | 87:085cde657901 | 202 | /* Get the IO position */ |
mbed_official | 87:085cde657901 | 203 | ioposition = ((uint32_t)0x01) << position; |
mbed_official | 87:085cde657901 | 204 | /* Get the current IO position */ |
mbed_official | 87:085cde657901 | 205 | iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition; |
mbed_official | 87:085cde657901 | 206 | |
mbed_official | 87:085cde657901 | 207 | if(iocurrent == ioposition) |
mbed_official | 87:085cde657901 | 208 | { |
mbed_official | 87:085cde657901 | 209 | /*--------------------- GPIO Mode Configuration ------------------------*/ |
mbed_official | 87:085cde657901 | 210 | /* In case of Alternate function mode selection */ |
mbed_official | 87:085cde657901 | 211 | if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) |
mbed_official | 87:085cde657901 | 212 | { |
mbed_official | 87:085cde657901 | 213 | /* Check the Alternate function parameter */ |
mbed_official | 87:085cde657901 | 214 | assert_param(IS_GPIO_AF(GPIO_Init->Alternate)); |
mbed_official | 87:085cde657901 | 215 | /* Configure Alternate function mapped with the current IO */ |
mbed_official | 87:085cde657901 | 216 | temp = ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4)) ; |
mbed_official | 87:085cde657901 | 217 | GPIOx->AFR[position >> 3] &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ; |
mbed_official | 87:085cde657901 | 218 | GPIOx->AFR[position >> 3] |= temp; |
mbed_official | 87:085cde657901 | 219 | } |
mbed_official | 87:085cde657901 | 220 | |
mbed_official | 87:085cde657901 | 221 | /* Configure IO Direction mode (Input, Output, Alternate or Analog) */ |
mbed_official | 87:085cde657901 | 222 | GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2)); |
mbed_official | 87:085cde657901 | 223 | GPIOx->MODER |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2)); |
mbed_official | 87:085cde657901 | 224 | |
mbed_official | 87:085cde657901 | 225 | /* In case of Output or Alternate function mode selection */ |
mbed_official | 87:085cde657901 | 226 | if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) || |
mbed_official | 87:085cde657901 | 227 | (GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) |
mbed_official | 87:085cde657901 | 228 | { |
mbed_official | 87:085cde657901 | 229 | /* Check the Speed parameter */ |
mbed_official | 87:085cde657901 | 230 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
mbed_official | 87:085cde657901 | 231 | /* Configure the IO Speed */ |
mbed_official | 87:085cde657901 | 232 | GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2)); |
mbed_official | 87:085cde657901 | 233 | GPIOx->OSPEEDR |= (GPIO_Init->Speed << (position * 2)); |
mbed_official | 87:085cde657901 | 234 | |
mbed_official | 87:085cde657901 | 235 | /* Configure the IO Output Type */ |
mbed_official | 87:085cde657901 | 236 | GPIOx->OTYPER &= ~(GPIO_OTYPER_OT_0 << position) ; |
mbed_official | 87:085cde657901 | 237 | GPIOx->OTYPER |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position); |
mbed_official | 87:085cde657901 | 238 | } |
mbed_official | 87:085cde657901 | 239 | |
mbed_official | 87:085cde657901 | 240 | /* Activate the Pull-up or Pull down resistor for the current IO */ |
mbed_official | 87:085cde657901 | 241 | GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2)); |
mbed_official | 87:085cde657901 | 242 | GPIOx->PUPDR |= ((GPIO_Init->Pull) << (position * 2)); |
mbed_official | 87:085cde657901 | 243 | |
mbed_official | 87:085cde657901 | 244 | |
mbed_official | 87:085cde657901 | 245 | /*--------------------- EXTI Mode Configuration ------------------------*/ |
mbed_official | 87:085cde657901 | 246 | /* Configure the External Interrupt or event for the current IO */ |
mbed_official | 87:085cde657901 | 247 | if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) |
mbed_official | 87:085cde657901 | 248 | { |
mbed_official | 87:085cde657901 | 249 | /* Enable SYSCFG Clock */ |
mbed_official | 87:085cde657901 | 250 | __SYSCFG_CLK_ENABLE(); |
mbed_official | 87:085cde657901 | 251 | |
mbed_official | 87:085cde657901 | 252 | temp = ((uint32_t)0x0F) << (4 * (position & 0x03)); |
mbed_official | 87:085cde657901 | 253 | SYSCFG->EXTICR[position >> 2] &= ~temp; |
mbed_official | 87:085cde657901 | 254 | SYSCFG->EXTICR[position >> 2] |= ((uint32_t)(__HAL_GET_GPIO_SOURCE(GPIOx)) << (4 * (position & 0x03))); |
mbed_official | 87:085cde657901 | 255 | |
mbed_official | 87:085cde657901 | 256 | /* Clear EXTI line configuration */ |
mbed_official | 87:085cde657901 | 257 | EXTI->IMR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 258 | EXTI->EMR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 259 | |
mbed_official | 87:085cde657901 | 260 | if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) |
mbed_official | 87:085cde657901 | 261 | { |
mbed_official | 87:085cde657901 | 262 | EXTI->IMR |= iocurrent; |
mbed_official | 87:085cde657901 | 263 | } |
mbed_official | 87:085cde657901 | 264 | if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) |
mbed_official | 87:085cde657901 | 265 | { |
mbed_official | 87:085cde657901 | 266 | EXTI->EMR |= iocurrent; |
mbed_official | 87:085cde657901 | 267 | } |
mbed_official | 87:085cde657901 | 268 | |
mbed_official | 87:085cde657901 | 269 | /* Clear Rising Falling edge configuration */ |
mbed_official | 87:085cde657901 | 270 | EXTI->RTSR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 271 | EXTI->FTSR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 272 | |
mbed_official | 87:085cde657901 | 273 | if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) |
mbed_official | 87:085cde657901 | 274 | { |
mbed_official | 87:085cde657901 | 275 | EXTI->RTSR |= iocurrent; |
mbed_official | 87:085cde657901 | 276 | } |
mbed_official | 87:085cde657901 | 277 | if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) |
mbed_official | 87:085cde657901 | 278 | { |
mbed_official | 87:085cde657901 | 279 | EXTI->FTSR |= iocurrent; |
mbed_official | 87:085cde657901 | 280 | } |
mbed_official | 87:085cde657901 | 281 | } |
mbed_official | 87:085cde657901 | 282 | } |
mbed_official | 87:085cde657901 | 283 | } |
mbed_official | 87:085cde657901 | 284 | } |
mbed_official | 87:085cde657901 | 285 | |
mbed_official | 87:085cde657901 | 286 | /** |
mbed_official | 87:085cde657901 | 287 | * @brief De-initializes the GPIOx peripheral registers to their default reset values. |
mbed_official | 87:085cde657901 | 288 | * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F429X device or |
mbed_official | 87:085cde657901 | 289 | * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. |
mbed_official | 87:085cde657901 | 290 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 87:085cde657901 | 291 | * This parameter can be one of GPIO_PIN_x where x can be (0..15). |
mbed_official | 87:085cde657901 | 292 | * @retval None |
mbed_official | 87:085cde657901 | 293 | */ |
mbed_official | 87:085cde657901 | 294 | void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) |
mbed_official | 87:085cde657901 | 295 | { |
mbed_official | 87:085cde657901 | 296 | uint32_t position; |
mbed_official | 87:085cde657901 | 297 | uint32_t ioposition = 0x00; |
mbed_official | 87:085cde657901 | 298 | uint32_t iocurrent = 0x00; |
mbed_official | 87:085cde657901 | 299 | uint32_t tmp = 0x00; |
mbed_official | 87:085cde657901 | 300 | |
mbed_official | 87:085cde657901 | 301 | /* Configure the port pins */ |
mbed_official | 87:085cde657901 | 302 | for(position = 0; position < GPIO_NUMBER; position++) |
mbed_official | 87:085cde657901 | 303 | { |
mbed_official | 87:085cde657901 | 304 | /* Get the IO position */ |
mbed_official | 87:085cde657901 | 305 | ioposition = ((uint32_t)0x01) << position; |
mbed_official | 87:085cde657901 | 306 | /* Get the current IO position */ |
mbed_official | 87:085cde657901 | 307 | iocurrent = (GPIO_Pin) & ioposition; |
mbed_official | 87:085cde657901 | 308 | |
mbed_official | 87:085cde657901 | 309 | if(iocurrent == ioposition) |
mbed_official | 87:085cde657901 | 310 | { |
mbed_official | 87:085cde657901 | 311 | /*------------------------- GPIO Mode Configuration --------------------*/ |
mbed_official | 87:085cde657901 | 312 | /* Configure IO Direction in Input Floting Mode */ |
mbed_official | 87:085cde657901 | 313 | GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2)); |
mbed_official | 87:085cde657901 | 314 | |
mbed_official | 87:085cde657901 | 315 | /* Configure the default Alternate Function in current IO */ |
mbed_official | 87:085cde657901 | 316 | GPIOx->AFR[position >> 3] &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ; |
mbed_official | 87:085cde657901 | 317 | |
mbed_official | 87:085cde657901 | 318 | /* Configure the default value for IO Speed */ |
mbed_official | 87:085cde657901 | 319 | GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2)); |
mbed_official | 87:085cde657901 | 320 | |
mbed_official | 87:085cde657901 | 321 | /* Configure the default value IO Output Type */ |
mbed_official | 87:085cde657901 | 322 | GPIOx->OTYPER &= ~(GPIO_OTYPER_OT_0 << position) ; |
mbed_official | 87:085cde657901 | 323 | |
mbed_official | 87:085cde657901 | 324 | /* Deactivate the Pull-up oand Pull-down resistor for the current IO */ |
mbed_official | 87:085cde657901 | 325 | GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2)); |
mbed_official | 87:085cde657901 | 326 | |
mbed_official | 87:085cde657901 | 327 | |
mbed_official | 87:085cde657901 | 328 | /*------------------------- EXTI Mode Configuration --------------------*/ |
mbed_official | 87:085cde657901 | 329 | /* Configure the External Interrupt or event for the current IO */ |
mbed_official | 87:085cde657901 | 330 | tmp = ((uint32_t)0x0F) << (4 * (position & 0x03)); |
mbed_official | 87:085cde657901 | 331 | SYSCFG->EXTICR[position >> 2] &= ~tmp; |
mbed_official | 87:085cde657901 | 332 | |
mbed_official | 87:085cde657901 | 333 | /* Clear EXTI line configuration */ |
mbed_official | 87:085cde657901 | 334 | EXTI->IMR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 335 | EXTI->EMR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 336 | |
mbed_official | 87:085cde657901 | 337 | /* Clear Rising Falling edge configuration */ |
mbed_official | 87:085cde657901 | 338 | EXTI->RTSR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 339 | EXTI->FTSR &= ~((uint32_t)iocurrent); |
mbed_official | 87:085cde657901 | 340 | } |
mbed_official | 87:085cde657901 | 341 | } |
mbed_official | 87:085cde657901 | 342 | } |
mbed_official | 87:085cde657901 | 343 | |
mbed_official | 87:085cde657901 | 344 | /** |
mbed_official | 87:085cde657901 | 345 | * @} |
mbed_official | 87:085cde657901 | 346 | */ |
mbed_official | 87:085cde657901 | 347 | |
mbed_official | 87:085cde657901 | 348 | /** @defgroup GPIO_Group2 IO operation functions |
mbed_official | 87:085cde657901 | 349 | * @brief GPIO Read and Write |
mbed_official | 87:085cde657901 | 350 | * |
mbed_official | 87:085cde657901 | 351 | @verbatim |
mbed_official | 87:085cde657901 | 352 | =============================================================================== |
mbed_official | 87:085cde657901 | 353 | ##### IO operation functions ##### |
mbed_official | 87:085cde657901 | 354 | =============================================================================== |
mbed_official | 87:085cde657901 | 355 | |
mbed_official | 87:085cde657901 | 356 | @endverbatim |
mbed_official | 87:085cde657901 | 357 | * @{ |
mbed_official | 87:085cde657901 | 358 | */ |
mbed_official | 87:085cde657901 | 359 | |
mbed_official | 87:085cde657901 | 360 | /** |
mbed_official | 87:085cde657901 | 361 | * @brief Reads the specified input port pin. |
mbed_official | 87:085cde657901 | 362 | * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F429X device or |
mbed_official | 87:085cde657901 | 363 | * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. |
mbed_official | 87:085cde657901 | 364 | * @param GPIO_Pin: specifies the port bit to read. |
mbed_official | 87:085cde657901 | 365 | * This parameter can be GPIO_PIN_x where x can be (0..15). |
mbed_official | 87:085cde657901 | 366 | * @retval The input port pin value. |
mbed_official | 87:085cde657901 | 367 | */ |
mbed_official | 87:085cde657901 | 368 | GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 87:085cde657901 | 369 | { |
mbed_official | 87:085cde657901 | 370 | GPIO_PinState bitstatus; |
mbed_official | 87:085cde657901 | 371 | |
mbed_official | 87:085cde657901 | 372 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 373 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 87:085cde657901 | 374 | |
mbed_official | 87:085cde657901 | 375 | if((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET) |
mbed_official | 87:085cde657901 | 376 | { |
mbed_official | 87:085cde657901 | 377 | bitstatus = GPIO_PIN_SET; |
mbed_official | 87:085cde657901 | 378 | } |
mbed_official | 87:085cde657901 | 379 | else |
mbed_official | 87:085cde657901 | 380 | { |
mbed_official | 87:085cde657901 | 381 | bitstatus = GPIO_PIN_RESET; |
mbed_official | 87:085cde657901 | 382 | } |
mbed_official | 87:085cde657901 | 383 | return bitstatus; |
mbed_official | 87:085cde657901 | 384 | } |
mbed_official | 87:085cde657901 | 385 | |
mbed_official | 87:085cde657901 | 386 | /** |
mbed_official | 87:085cde657901 | 387 | * @brief Sets or clears the selected data port bit. |
mbed_official | 87:085cde657901 | 388 | * |
mbed_official | 87:085cde657901 | 389 | * @note This function uses GPIOx_BSRR register to allow atomic read/modify |
mbed_official | 87:085cde657901 | 390 | * accesses. In this way, there is no risk of an IRQ occurring between |
mbed_official | 87:085cde657901 | 391 | * the read and the modify access. |
mbed_official | 87:085cde657901 | 392 | * |
mbed_official | 87:085cde657901 | 393 | * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F429X device or |
mbed_official | 87:085cde657901 | 394 | * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. |
mbed_official | 87:085cde657901 | 395 | * @param GPIO_Pin: specifies the port bit to be written. |
mbed_official | 87:085cde657901 | 396 | * This parameter can be one of GPIO_PIN_x where x can be (0..15). |
mbed_official | 87:085cde657901 | 397 | * @param PinState: specifies the value to be written to the selected bit. |
mbed_official | 87:085cde657901 | 398 | * This parameter can be one of the GPIO_PinState enum values: |
mbed_official | 87:085cde657901 | 399 | * @arg GPIO_BIT_RESET: to clear the port pin |
mbed_official | 87:085cde657901 | 400 | * @arg GPIO_BIT_SET: to set the port pin |
mbed_official | 87:085cde657901 | 401 | * @retval None |
mbed_official | 87:085cde657901 | 402 | */ |
mbed_official | 87:085cde657901 | 403 | void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) |
mbed_official | 87:085cde657901 | 404 | { |
mbed_official | 87:085cde657901 | 405 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 406 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 87:085cde657901 | 407 | assert_param(IS_GPIO_PIN_ACTION(PinState)); |
mbed_official | 87:085cde657901 | 408 | |
mbed_official | 87:085cde657901 | 409 | if(PinState != GPIO_PIN_RESET) |
mbed_official | 87:085cde657901 | 410 | { |
mbed_official | 87:085cde657901 | 411 | GPIOx->BSRRL = GPIO_Pin; |
mbed_official | 87:085cde657901 | 412 | } |
mbed_official | 87:085cde657901 | 413 | else |
mbed_official | 87:085cde657901 | 414 | { |
mbed_official | 87:085cde657901 | 415 | GPIOx->BSRRH = GPIO_Pin ; |
mbed_official | 87:085cde657901 | 416 | } |
mbed_official | 87:085cde657901 | 417 | } |
mbed_official | 87:085cde657901 | 418 | |
mbed_official | 87:085cde657901 | 419 | /** |
mbed_official | 87:085cde657901 | 420 | * @brief Toggles the specified GPIO pins. |
mbed_official | 87:085cde657901 | 421 | * @param GPIOx: Where x can be (A..K) to select the GPIO peripheral for STM32F429X device or |
mbed_official | 87:085cde657901 | 422 | * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. |
mbed_official | 87:085cde657901 | 423 | * @param GPIO_Pin: Specifies the pins to be toggled. |
mbed_official | 87:085cde657901 | 424 | * @retval None |
mbed_official | 87:085cde657901 | 425 | */ |
mbed_official | 87:085cde657901 | 426 | void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) |
mbed_official | 87:085cde657901 | 427 | { |
mbed_official | 87:085cde657901 | 428 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 429 | assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); |
mbed_official | 87:085cde657901 | 430 | |
mbed_official | 87:085cde657901 | 431 | GPIOx->ODR ^= GPIO_Pin; |
mbed_official | 87:085cde657901 | 432 | } |
mbed_official | 87:085cde657901 | 433 | |
mbed_official | 87:085cde657901 | 434 | /** |
mbed_official | 87:085cde657901 | 435 | * @brief This function handles EXTI interrupt request. |
mbed_official | 87:085cde657901 | 436 | * @param GPIO_Pin: Specifies the pins connected EXTI line |
mbed_official | 87:085cde657901 | 437 | * @retval None |
mbed_official | 87:085cde657901 | 438 | */ |
mbed_official | 87:085cde657901 | 439 | void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin) |
mbed_official | 87:085cde657901 | 440 | { |
mbed_official | 87:085cde657901 | 441 | /* EXTI line interrupt detected */ |
mbed_official | 87:085cde657901 | 442 | if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET) |
mbed_official | 87:085cde657901 | 443 | { |
mbed_official | 87:085cde657901 | 444 | __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); |
mbed_official | 87:085cde657901 | 445 | HAL_GPIO_EXTI_Callback(GPIO_Pin); |
mbed_official | 87:085cde657901 | 446 | } |
mbed_official | 87:085cde657901 | 447 | } |
mbed_official | 87:085cde657901 | 448 | |
mbed_official | 87:085cde657901 | 449 | /** |
mbed_official | 87:085cde657901 | 450 | * @brief EXTI line detection callbacks. |
mbed_official | 87:085cde657901 | 451 | * @param GPIO_Pin: Specifies the pins connected EXTI line |
mbed_official | 87:085cde657901 | 452 | * @retval None |
mbed_official | 87:085cde657901 | 453 | */ |
mbed_official | 87:085cde657901 | 454 | __weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
mbed_official | 87:085cde657901 | 455 | { |
mbed_official | 87:085cde657901 | 456 | /* NOTE: This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 457 | the HAL_GPIO_EXTI_Callback could be implemented in the user file |
mbed_official | 87:085cde657901 | 458 | */ |
mbed_official | 87:085cde657901 | 459 | } |
mbed_official | 87:085cde657901 | 460 | |
mbed_official | 87:085cde657901 | 461 | /** |
mbed_official | 87:085cde657901 | 462 | * @} |
mbed_official | 87:085cde657901 | 463 | */ |
mbed_official | 87:085cde657901 | 464 | |
mbed_official | 87:085cde657901 | 465 | |
mbed_official | 87:085cde657901 | 466 | /** |
mbed_official | 87:085cde657901 | 467 | * @} |
mbed_official | 87:085cde657901 | 468 | */ |
mbed_official | 87:085cde657901 | 469 | |
mbed_official | 87:085cde657901 | 470 | #endif /* HAL_GPIO_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 471 | /** |
mbed_official | 87:085cde657901 | 472 | * @} |
mbed_official | 87:085cde657901 | 473 | */ |
mbed_official | 87:085cde657901 | 474 | |
mbed_official | 87:085cde657901 | 475 | /** |
mbed_official | 87:085cde657901 | 476 | * @} |
mbed_official | 87:085cde657901 | 477 | */ |
mbed_official | 87:085cde657901 | 478 | |
mbed_official | 87:085cde657901 | 479 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |