stm32f1xx_hal_gpio.c 22 KB

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