mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Jan 06 16:15:36 2015 +0000
Revision:
441:d2c15dda23c1
Parent:
392:2b59412bb664
Synchronized with git revision 245a60b29caabb42eabdd19658eeac7c3f68313b

Full URL: https://github.com/mbedmicro/mbed/commit/245a60b29caabb42eabdd19658eeac7c3f68313b/

NUCLEO_F072RB/F091RC - adding target to rtos lib and exporter for coide and gcc_arm

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