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:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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