mbed library sources modified for open wear

Dependents:   openwear-lifelogger-example

Fork of mbed-src by mbed official

Committer:
janekm
Date:
Tue Sep 16 22:42:01 2014 +0000
Revision:
310:6188e0254baa
Parent:
237:f3da66175598
N/A

Who changed what in which revision?

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