Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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