mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

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