mbed library sources, include can_api for nucleo-f091rc

Dependents:   CanNucleoF0_example

Fork of mbed-src by mbed official

Committer:
ptpaterson
Date:
Thu Jan 07 05:49:05 2016 +0000
Revision:
645:13c87cbecd54
Parent:
610:813dcc80987e
corrected freeze on CAN_RECEIVE_IT

Who changed what in which revision?

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