mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
532:fe11edbda85c
Child:
613:bc40b8d2aec4
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

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