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:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
489:119543c9f674
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

Who changed what in which revision?

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