stm32l5xx_hal_exti.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /**
  2. ******************************************************************************
  3. * @file stm32l5xx_hal_exti.c
  4. * @author MCD Application Team
  5. * @brief EXTI HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Extended Interrupts and event controller
  8. * (EXTI) peripheral:
  9. * + Initialization and de-initialization functions
  10. * + IO operation functions
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * Copyright (c) 2019 STMicroelectronics.
  16. * All rights reserved.
  17. *
  18. * This software is licensed under terms that can be found in the LICENSE file
  19. * in the root directory of this software component.
  20. * If no LICENSE file comes with this software, it is provided AS-IS.
  21. *
  22. ******************************************************************************
  23. @verbatim
  24. ==============================================================================
  25. ##### EXTI Peripheral features #####
  26. ==============================================================================
  27. [..]
  28. (+) Each Exti line can be configured within this driver.
  29. (+) Exti line can be configured in 3 different modes
  30. (++) Interrupt
  31. (++) Event
  32. (++) Both of them
  33. (+) Configurable Exti lines can be configured with 3 different triggers
  34. (++) Rising
  35. (++) Falling
  36. (++) Both of them
  37. (+) When set in interrupt mode, configurable Exti lines have two different
  38. interrupt pending registers which allow to distinguish which transition
  39. occurs:
  40. (++) Rising edge pending interrupt
  41. (++) Falling
  42. (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
  43. be selected through multiplexer.
  44. ##### How to use this driver #####
  45. ==============================================================================
  46. [..]
  47. (#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
  48. (++) Choose the interrupt line number by setting "Line" member from
  49. EXTI_ConfigTypeDef structure.
  50. (++) Configure the interrupt and/or event mode using "Mode" member from
  51. EXTI_ConfigTypeDef structure.
  52. (++) For configurable lines, configure rising and/or falling trigger
  53. "Trigger" member from EXTI_ConfigTypeDef structure.
  54. (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
  55. member from GPIO_InitTypeDef structure.
  56. (#) Get current Exti configuration of a dedicated line using
  57. HAL_EXTI_GetConfigLine().
  58. (++) Provide exiting handle as parameter.
  59. (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
  60. (#) Clear Exti configuration of a dedicated line using HAL_EXTI_GetConfigLine().
  61. (++) Provide exiting handle as parameter.
  62. (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
  63. (++) Provide exiting handle as first parameter.
  64. (++) Provide which callback will be registered using one value from
  65. EXTI_CallbackIDTypeDef.
  66. (++) Provide callback function pointer.
  67. (#) Get interrupt pending bit using HAL_EXTI_GetPending().
  68. (#) Clear interrupt pending bit using HAL_EXTI_GetPending().
  69. (#) Generate software interrupt using HAL_EXTI_GenerateSWI().
  70. @endverbatim
  71. */
  72. /* Includes ------------------------------------------------------------------*/
  73. #include "stm32l5xx_hal.h"
  74. /** @addtogroup STM32L5xx_HAL_Driver
  75. * @{
  76. */
  77. /** @addtogroup EXTI
  78. * @{
  79. */
  80. #ifdef HAL_EXTI_MODULE_ENABLED
  81. /* Private typedef -----------------------------------------------------------*/
  82. /* Private defines ------------------------------------------------------------*/
  83. /** @defgroup EXTI_Private_Constants EXTI Private Constants
  84. * @{
  85. */
  86. #define EXTI_MODE_OFFSET 0x04U /* byte offset between IMR/EMR registers */
  87. #define EXTI_CONFIG_OFFSET 0x08U /* byte offset between Rising/Falling configuration registers */
  88. #define EXTI_PRIVCFGR_OFFSET 0x04U /* byte offset between PRIVCFGR1/PRIVCFGR2 registers */
  89. #define EXTI_SECCFGR_OFFSET 0x04U /* byte offset between SECCFGR1/SECCFGR2 registers */
  90. /**
  91. * @}
  92. */
  93. /* Private macros ------------------------------------------------------------*/
  94. /* Private variables ---------------------------------------------------------*/
  95. /* Private function prototypes -----------------------------------------------*/
  96. /* Exported functions --------------------------------------------------------*/
  97. /** @addtogroup EXTI_Exported_Functions
  98. * @{
  99. */
  100. /** @addtogroup EXTI_Exported_Functions_Group1
  101. * @brief Configuration functions
  102. *
  103. @verbatim
  104. ===============================================================================
  105. ##### Configuration functions #####
  106. ===============================================================================
  107. @endverbatim
  108. * @{
  109. */
  110. /**
  111. * @brief Set configuration of a dedicated Exti line.
  112. * @param hexti Exti handle.
  113. * @param pExtiConfig Pointer on EXTI configuration to be set.
  114. * @retval HAL Status.
  115. */
  116. HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
  117. {
  118. __IO uint32_t *regaddr;
  119. uint32_t regval;
  120. uint32_t linepos;
  121. uint32_t maskline;
  122. uint32_t offset;
  123. /* Check null pointer */
  124. if((hexti == NULL) || (pExtiConfig == NULL))
  125. {
  126. return HAL_ERROR;
  127. }
  128. /* Check the parameters */
  129. assert_param(IS_EXTI_LINE(pExtiConfig->Line));
  130. assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
  131. /* Assign line number to handle */
  132. hexti->Line = pExtiConfig->Line;
  133. /* compute line register offset and line mask */
  134. offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  135. linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
  136. maskline = (1UL << linepos);
  137. /* Configure triggers for configurable lines */
  138. if((pExtiConfig->Line & EXTI_CONFIG) != 0U)
  139. {
  140. assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
  141. /* Configure rising trigger */
  142. regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
  143. regval = *regaddr;
  144. /* Mask or set line */
  145. if((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0U)
  146. {
  147. regval |= maskline;
  148. }
  149. else
  150. {
  151. regval &= ~maskline;
  152. }
  153. /* Store rising trigger mode */
  154. *regaddr = regval;
  155. /* Configure falling trigger */
  156. regaddr = (&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
  157. regval = *regaddr;
  158. /* Mask or set line */
  159. if((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0U)
  160. {
  161. regval |= maskline;
  162. }
  163. else
  164. {
  165. regval &= ~maskline;
  166. }
  167. /* Store falling trigger mode */
  168. *regaddr = regval;
  169. /* Configure gpio port selection in case of gpio exti line */
  170. if((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
  171. {
  172. assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));
  173. assert_param(IS_EXTI_GPIO_PIN(linepos));
  174. regval = EXTI->EXTICR[linepos >> 2U];
  175. regval &= ~(0xFFU << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
  176. regval |= (pExtiConfig->GPIOSel << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
  177. EXTI->EXTICR[linepos >> 2U] = regval;
  178. }
  179. }
  180. /* Configure interrupt mode : read current mode */
  181. regaddr = (&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
  182. regval = *regaddr;
  183. /* Mask or set line */
  184. if((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0U)
  185. {
  186. regval |= maskline;
  187. }
  188. else
  189. {
  190. regval &= ~maskline;
  191. }
  192. /* Store interrupt mode */
  193. *regaddr = regval;
  194. /* Configure event mode : read current mode */
  195. regaddr = (&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
  196. regval = *regaddr;
  197. /* Mask or set line */
  198. if((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0U)
  199. {
  200. regval |= maskline;
  201. }
  202. else
  203. {
  204. regval &= ~maskline;
  205. }
  206. /* Store event mode */
  207. *regaddr = regval;
  208. return HAL_OK;
  209. }
  210. /**
  211. * @brief Get configuration of a dedicated Exti line.
  212. * @param hexti Exti handle.
  213. * @param pExtiConfig Pointer on structure to store Exti configuration.
  214. * @retval HAL Status.
  215. */
  216. HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
  217. {
  218. __IO uint32_t *regaddr;
  219. uint32_t regval;
  220. uint32_t linepos;
  221. uint32_t maskline;
  222. uint32_t offset;
  223. /* Check null pointer */
  224. if((hexti == NULL) || (pExtiConfig == NULL))
  225. {
  226. return HAL_ERROR;
  227. }
  228. /* Check the parameter */
  229. assert_param(IS_EXTI_LINE(hexti->Line));
  230. /* Store handle line number to configiguration structure */
  231. pExtiConfig->Line = hexti->Line;
  232. /* compute line register offset and line mask */
  233. offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  234. linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
  235. maskline = (1UL << linepos);
  236. /* 1] Get core mode : interrupt */
  237. regaddr = (&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
  238. regval = *regaddr;
  239. /* Check if selected line is enable */
  240. if((regval & maskline) != 0U)
  241. {
  242. pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
  243. }
  244. else
  245. {
  246. pExtiConfig->Mode = EXTI_MODE_NONE;
  247. }
  248. /* Get event mode */
  249. regaddr = (&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
  250. regval = *regaddr;
  251. /* Check if selected line is enable */
  252. if((regval & maskline) != 0U)
  253. {
  254. pExtiConfig->Mode |= EXTI_MODE_EVENT;
  255. }
  256. /* Get default Trigger and GPIOSel configuration */
  257. pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
  258. pExtiConfig->GPIOSel = 0x00u;
  259. /* 2] Get trigger for configurable lines : rising */
  260. if((pExtiConfig->Line & EXTI_CONFIG) != 0U)
  261. {
  262. regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
  263. regval = *regaddr;
  264. /* Check if configuration of selected line is enable */
  265. if((regval & maskline) != 0U)
  266. {
  267. pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
  268. }
  269. /* Get falling configuration */
  270. regaddr = (&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
  271. regval = *regaddr;
  272. /* Check if configuration of selected line is enable */
  273. if((regval & maskline) != 0U)
  274. {
  275. pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
  276. }
  277. /* Get Gpio port selection for gpio lines */
  278. if((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
  279. {
  280. assert_param(IS_EXTI_GPIO_PIN(linepos));
  281. regval = EXTI->EXTICR[linepos >> 2U];
  282. pExtiConfig->GPIOSel = (regval >> (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03u))) & EXTI_EXTICR1_EXTI0;
  283. }
  284. }
  285. return HAL_OK;
  286. }
  287. /**
  288. * @brief Clear whole configuration of a dedicated Exti line.
  289. * @param hexti Exti handle.
  290. * @retval HAL Status.
  291. */
  292. HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti)
  293. {
  294. __IO uint32_t *regaddr;
  295. uint32_t regval;
  296. uint32_t linepos;
  297. uint32_t maskline;
  298. uint32_t offset;
  299. /* Check null pointer */
  300. if(hexti == NULL)
  301. {
  302. return HAL_ERROR;
  303. }
  304. /* Check the parameter */
  305. assert_param(IS_EXTI_LINE(hexti->Line));
  306. /* compute line register offset and line mask */
  307. offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  308. linepos = (hexti->Line & EXTI_PIN_MASK);
  309. maskline = (1UL << linepos);
  310. /* 1] Clear interrupt mode */
  311. regaddr = (&EXTI->IMR1 + (EXTI_MODE_OFFSET * offset));
  312. regval = (*regaddr & ~maskline);
  313. *regaddr = regval;
  314. /* 2] Clear event mode */
  315. regaddr = (&EXTI->EMR1 + (EXTI_MODE_OFFSET * offset));
  316. regval = (*regaddr & ~maskline);
  317. *regaddr = regval;
  318. /* 3] Clear triggers in case of configurable lines */
  319. if((hexti->Line & EXTI_CONFIG) != 0U)
  320. {
  321. regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset));
  322. regval = (*regaddr & ~maskline);
  323. *regaddr = regval;
  324. regaddr = (&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset));
  325. regval = (*regaddr & ~maskline);
  326. *regaddr = regval;
  327. /* Get Gpio port selection for gpio lines */
  328. if((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
  329. {
  330. assert_param(IS_EXTI_GPIO_PIN(linepos));
  331. regval = EXTI->EXTICR[linepos >> 2U];
  332. regval &= ~(0xFFU << (EXTI_EXTICR1_EXTI1_Pos * (linepos & 0x03U)));
  333. EXTI->EXTICR[linepos >> 2U] = regval;
  334. }
  335. }
  336. return HAL_OK;
  337. }
  338. /**
  339. * @brief Register callback for a dedicaated Exti line.
  340. * @param hexti Exti handle.
  341. * @param CallbackID User callback identifier.
  342. * This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values.
  343. * @param pPendingCbfn function pointer to be stored as callback.
  344. * @retval HAL Status.
  345. */
  346. HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void))
  347. {
  348. HAL_StatusTypeDef status = HAL_OK;
  349. switch (CallbackID)
  350. {
  351. case HAL_EXTI_COMMON_CB_ID:
  352. hexti->RisingCallback = pPendingCbfn;
  353. hexti->FallingCallback = pPendingCbfn;
  354. break;
  355. case HAL_EXTI_RISING_CB_ID:
  356. hexti->RisingCallback = pPendingCbfn;
  357. break;
  358. case HAL_EXTI_FALLING_CB_ID:
  359. hexti->FallingCallback = pPendingCbfn;
  360. break;
  361. default:
  362. status = HAL_ERROR;
  363. break;
  364. }
  365. return status;
  366. }
  367. /**
  368. * @brief Store line number as handle private field.
  369. * @param hexti Exti handle.
  370. * @param ExtiLine Exti line number.
  371. * This parameter can be from 0 to @ref EXTI_LINE_NB.
  372. * @retval HAL Status.
  373. */
  374. HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
  375. {
  376. /* Check null pointer */
  377. if(hexti == NULL)
  378. {
  379. return HAL_ERROR;
  380. }
  381. /* Check parameters */
  382. assert_param(IS_EXTI_LINE(ExtiLine));
  383. /* Store line number as handle private field */
  384. hexti->Line = ExtiLine;
  385. return HAL_OK;
  386. }
  387. /**
  388. * @}
  389. */
  390. /** @addtogroup EXTI_Exported_Functions_Group2
  391. * @brief EXTI IO functions.
  392. *
  393. @verbatim
  394. ===============================================================================
  395. ##### IO operation functions #####
  396. ===============================================================================
  397. @endverbatim
  398. * @{
  399. */
  400. /**
  401. * @brief Handle EXTI interrupt request.
  402. * @param hexti Exti handle.
  403. * @retval none.
  404. */
  405. void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti)
  406. {
  407. __IO uint32_t *regaddr;
  408. uint32_t regval;
  409. uint32_t maskline;
  410. uint32_t offset;
  411. /* Compute line register offset and line mask */
  412. offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  413. maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
  414. /* Get rising edge pending bit */
  415. regaddr = (&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
  416. regval = (*regaddr & maskline);
  417. if(regval != 0U)
  418. {
  419. /* Clear pending bit */
  420. *regaddr = maskline;
  421. /* Call rising callback */
  422. if(hexti->RisingCallback != NULL)
  423. {
  424. hexti->RisingCallback();
  425. }
  426. }
  427. /* Get falling edge pending bit */
  428. regaddr = (&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
  429. regval = (*regaddr & maskline);
  430. if(regval != 0U)
  431. {
  432. /* Clear pending bit */
  433. *regaddr = maskline;
  434. /* Call rising callback */
  435. if(hexti->FallingCallback != NULL)
  436. {
  437. hexti->FallingCallback();
  438. }
  439. }
  440. }
  441. /**
  442. * @brief Get interrupt pending bit of a dedicated line.
  443. * @param hexti Exti handle.
  444. * @param Edge Specify which pending edge as to be checked.
  445. * This parameter can be one of the following values:
  446. * @arg @ref EXTI_TRIGGER_RISING
  447. * @arg @ref EXTI_TRIGGER_FALLING
  448. * @retval 1 if interrupt is pending else 0.
  449. */
  450. uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
  451. {
  452. __IO uint32_t *regaddr;
  453. uint32_t regval;
  454. uint32_t linepos;
  455. uint32_t maskline;
  456. uint32_t offset;
  457. /* Check the parameters */
  458. assert_param(IS_EXTI_LINE(hexti->Line));
  459. assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
  460. assert_param(IS_EXTI_PENDING_EDGE(Edge));
  461. /* compute line register offset and line mask */
  462. offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  463. linepos = (hexti->Line & EXTI_PIN_MASK);
  464. maskline = (1UL << linepos);
  465. if(Edge != EXTI_TRIGGER_RISING)
  466. {
  467. /* Get falling edge pending bit */
  468. regaddr = (&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
  469. }
  470. else
  471. {
  472. /* Get rising edge pending bit */
  473. regaddr = (&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
  474. }
  475. /* return 1 if bit is set else 0 */
  476. regval = ((*regaddr & maskline) >> linepos);
  477. return regval;
  478. }
  479. /**
  480. * @brief Clear interrupt pending bit of a dedicated line.
  481. * @param hexti Exti handle.
  482. * @param Edge Specify which pending edge as to be clear.
  483. * This parameter can be one of the following values:
  484. * @arg @ref EXTI_TRIGGER_RISING
  485. * @arg @ref EXTI_TRIGGER_FALLING
  486. * @retval None.
  487. */
  488. void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
  489. {
  490. __IO uint32_t *regaddr;
  491. uint32_t maskline;
  492. uint32_t offset;
  493. /* Check the parameters */
  494. assert_param(IS_EXTI_LINE(hexti->Line));
  495. assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
  496. assert_param(IS_EXTI_PENDING_EDGE(Edge));
  497. /* compute line register offset and line mask */
  498. offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  499. maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
  500. if(Edge != EXTI_TRIGGER_RISING)
  501. {
  502. /* Get falling edge pending register address */
  503. regaddr = (&EXTI->FPR1 + (EXTI_CONFIG_OFFSET * offset));
  504. }
  505. else
  506. {
  507. /* Get falling edge pending register address */
  508. regaddr = (&EXTI->RPR1 + (EXTI_CONFIG_OFFSET * offset));
  509. }
  510. /* Clear Pending bit */
  511. *regaddr = maskline;
  512. }
  513. /**
  514. * @brief Generate a software interrupt for a dedicated line.
  515. * @param hexti Exti handle.
  516. * @retval None.
  517. */
  518. void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti)
  519. {
  520. __IO uint32_t *regaddr;
  521. uint32_t maskline;
  522. uint32_t offset;
  523. /* Check the parameters */
  524. assert_param(IS_EXTI_LINE(hexti->Line));
  525. assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
  526. /* compute line register offset and line mask */
  527. offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  528. maskline = (1UL << (hexti->Line & EXTI_PIN_MASK));
  529. regaddr = (&EXTI->SWIER1 + (EXTI_CONFIG_OFFSET * offset));
  530. *regaddr = maskline;
  531. }
  532. /**
  533. * @}
  534. */
  535. /** @defgroup EXTI_Exported_Functions_Group3 EXTI line attributes management functions
  536. * @brief EXTI attributes management functions.
  537. *
  538. @verbatim
  539. ===============================================================================
  540. ##### EXTI attributes functions #####
  541. ===============================================================================
  542. @endverbatim
  543. * @{
  544. */
  545. /**
  546. * @brief Configure the EXTI line attribute(s).
  547. * @note Available attributes are to secure EXTI line and set EXT line as privileged.
  548. * Default state is not secure and unprivileged access allowed.
  549. * @note Secure and non-secure attributes can only be set from the secure
  550. * state when the system implements the security (TZEN=1).
  551. * @note Security and privilege attributes can be set independently.
  552. * @param ExtiLine Exti line number.
  553. * This parameter can be from 0 to @ref EXTI_LINE_NB.
  554. * @param LineAttributes can be one or a combination of the following values:
  555. * @arg @ref EXTI_LINE_PRIV Privileged-only access
  556. * @arg @ref EXTI_LINE_NPRIV Privileged/Non-privileged access
  557. * @arg @ref EXTI_LINE_SEC Secure-only access
  558. * @arg @ref EXTI_LINE_NSEC Secure/Non-secure access
  559. * @retval None
  560. */
  561. void HAL_EXTI_ConfigLineAttributes(uint32_t ExtiLine, uint32_t LineAttributes)
  562. {
  563. __IO uint32_t *regaddr;
  564. uint32_t regval;
  565. uint32_t linepos;
  566. uint32_t maskline;
  567. uint32_t offset;
  568. /* Check the parameters */
  569. assert_param(IS_EXTI_LINE(ExtiLine));
  570. assert_param(IS_EXTI_LINE_ATTRIBUTES(LineAttributes));
  571. /* compute line register offset and line mask */
  572. offset = ((ExtiLine & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  573. linepos = (ExtiLine & EXTI_PIN_MASK);
  574. maskline = (1UL << linepos);
  575. /* Configure privilege or non-privilege attributes */
  576. regaddr = (&EXTI->PRIVCFGR1 + (EXTI_PRIVCFGR_OFFSET * offset));
  577. regval = *regaddr;
  578. /* Mask or set line */
  579. if((LineAttributes & EXTI_LINE_PRIV) == EXTI_LINE_PRIV)
  580. {
  581. regval |= maskline;
  582. }
  583. else if((LineAttributes & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)
  584. {
  585. regval &= ~maskline;
  586. }
  587. else
  588. {
  589. /* do nothing */
  590. }
  591. /* Store privilege or non-privilege attribute */
  592. *regaddr = regval;
  593. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  594. /* Configure secure or non-secure attributes */
  595. regaddr = (&EXTI->SECCFGR1 + (EXTI_SECCFGR_OFFSET * offset));
  596. regval = *regaddr;
  597. /* Mask or set line */
  598. if((LineAttributes & EXTI_LINE_SEC) == EXTI_LINE_SEC)
  599. {
  600. regval |= maskline;
  601. }
  602. else if((LineAttributes & EXTI_LINE_NSEC) == EXTI_LINE_NSEC)
  603. {
  604. regval &= ~maskline;
  605. }
  606. else
  607. {
  608. /* do nothing */
  609. }
  610. /* Store secure or non-secure attribute */
  611. *regaddr = regval;
  612. #endif /* __ARM_FEATURE_CMSE */
  613. }
  614. /**
  615. * @brief Get the EXTI line attribute(s).
  616. * @note Secure and non-secure attributes are only available from secure state
  617. * when the system implements the security (TZEN=1)
  618. * @param ExtiLine Exti line number.
  619. * This parameter can be from 0 to @ref EXTI_LINE_NB.
  620. * @param pLineAttributes: pointer to return line attributes.
  621. * @retval HAL Status.
  622. */
  623. HAL_StatusTypeDef HAL_EXTI_GetConfigLineAttributes(uint32_t ExtiLine, uint32_t *pLineAttributes)
  624. {
  625. __IO uint32_t *regaddr;
  626. uint32_t linepos;
  627. uint32_t maskline;
  628. uint32_t offset;
  629. uint32_t attributes;
  630. /* Check null pointer */
  631. if(pLineAttributes == NULL)
  632. {
  633. return HAL_ERROR;
  634. }
  635. /* Check the parameters */
  636. assert_param(IS_EXTI_LINE(ExtiLine));
  637. /* Compute line register offset and line mask */
  638. offset = ((ExtiLine & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
  639. linepos = (ExtiLine & EXTI_PIN_MASK);
  640. maskline = (1UL << linepos);
  641. /* Get privilege or non-privilege attribute */
  642. regaddr = (&EXTI->PRIVCFGR1 + (EXTI_PRIVCFGR_OFFSET * offset));
  643. if((*regaddr & maskline) != 0U)
  644. {
  645. attributes = EXTI_LINE_PRIV;
  646. }
  647. else
  648. {
  649. attributes = EXTI_LINE_NPRIV;
  650. }
  651. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  652. /* Get secure or non-secure attribute */
  653. regaddr = (&EXTI->SECCFGR1 + (EXTI_SECCFGR_OFFSET * offset));
  654. if((*regaddr & maskline) != 0U)
  655. {
  656. attributes |= EXTI_LINE_SEC;
  657. }
  658. else
  659. {
  660. attributes |= EXTI_LINE_NSEC;
  661. }
  662. #endif /* __ARM_FEATURE_CMSE */
  663. /* return value */
  664. *pLineAttributes = attributes;
  665. return HAL_OK;
  666. }
  667. /**
  668. * @}
  669. */
  670. /**
  671. * @}
  672. */
  673. #endif /* HAL_EXTI_MODULE_ENABLED */
  674. /**
  675. * @}
  676. */
  677. /**
  678. * @}
  679. */