inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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