L4 HAL Drivers

Committer:
EricLew
Date:
Mon Nov 02 19:37:23 2015 +0000
Revision:
0:80ee8f3b695e
Errors are with definitions of LCD and QSPI functions. I believe all .h and .c files are  uploaded, but there may need to be certain functions called.

Who changed what in which revision?

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