mbed library sources

Fork of mbed-src by mbed official

Committer:
lzbpli
Date:
Thu Jul 07 06:48:59 2016 +0000
Revision:
636:b0d178e9fa10
Parent:
394:83f921546702
l053

Who changed what in which revision?

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