stm32l4xx_hal_gpio.c 21 KB

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