mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Sep 30 17:00:09 2015 +0100
Revision:
636:a11c0372f0ba
Parent:
631:825f75ca301e
Synchronized with git revision d29c98dae61be0946ddf3a3c641c7726056f9452

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

Added support for SAMW25

Who changed what in which revision?

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