stm32l1xx_hal_gpio.c 21 KB

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