stm32h5xx_ll_gpio.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. /**
  2. ******************************************************************************
  3. * @file stm32h5xx_ll_gpio.h
  4. * @author MCD Application Team
  5. * @brief Header file of GPIO LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef __STM32H5xx_LL_GPIO_H
  20. #define __STM32H5xx_LL_GPIO_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32h5xx.h"
  26. /** @addtogroup STM32H5xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || \
  30. defined (GPIOG) || defined (GPIOH) || defined (GPIOI)
  31. /** @defgroup GPIO_LL GPIO
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. #if defined(USE_FULL_LL_DRIVER)
  39. /** @defgroup GPIO_LL_Private_Macros GPIO Private Macros
  40. * @{
  41. */
  42. /**
  43. * @}
  44. */
  45. #endif /*USE_FULL_LL_DRIVER*/
  46. /* Exported types ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup GPIO_LL_ES_INIT GPIO Exported Init structures
  49. * @{
  50. */
  51. /**
  52. * @brief LL GPIO Init Structure definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
  57. This parameter can be any value of @ref GPIO_LL_EC_PIN */
  58. uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
  59. This parameter can be a value of @ref GPIO_LL_EC_MODE.
  60. GPIO HW configuration can be modified afterwards using unitary function
  61. @ref LL_GPIO_SetPinMode().*/
  62. uint32_t Speed; /*!< Specifies the speed for the selected pins.
  63. This parameter can be a value of @ref GPIO_LL_EC_SPEED.
  64. GPIO HW configuration can be modified afterwards using unitary function
  65. @ref LL_GPIO_SetPinSpeed().*/
  66. uint32_t OutputType; /*!< Specifies the operating output type for the selected pins.
  67. This parameter can be a value of @ref GPIO_LL_EC_OUTPUT.
  68. GPIO HW configuration can be modified afterwards using unitary function
  69. @ref LL_GPIO_SetPinOutputType().*/
  70. uint32_t Pull; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
  71. This parameter can be a value of @ref GPIO_LL_EC_PULL.
  72. GPIO HW configuration can be modified afterwards using unitary function
  73. @ref LL_GPIO_SetPinPull().*/
  74. uint32_t Alternate; /*!< Specifies the Peripheral to be connected to the selected pins.
  75. This parameter can be a value of @ref GPIO_LL_EC_AF.
  76. GPIO HW configuration can be modified afterwards using unitary function
  77. @ref LL_GPIO_SetAFPin_0_7() and LL_GPIO_SetAFPin_8_15().*/
  78. } LL_GPIO_InitTypeDef;
  79. /**
  80. * @}
  81. */
  82. #endif /* USE_FULL_LL_DRIVER */
  83. /* Exported constants --------------------------------------------------------*/
  84. /** @defgroup GPIO_LL_Exported_Constants GPIO Exported Constants
  85. * @{
  86. */
  87. /** @defgroup GPIO_LL_EC_PIN PIN
  88. * @{
  89. */
  90. #define LL_GPIO_PIN_0 GPIO_BSRR_BS0 /*!< Select pin 0 */
  91. #define LL_GPIO_PIN_1 GPIO_BSRR_BS1 /*!< Select pin 1 */
  92. #define LL_GPIO_PIN_2 GPIO_BSRR_BS2 /*!< Select pin 2 */
  93. #define LL_GPIO_PIN_3 GPIO_BSRR_BS3 /*!< Select pin 3 */
  94. #define LL_GPIO_PIN_4 GPIO_BSRR_BS4 /*!< Select pin 4 */
  95. #define LL_GPIO_PIN_5 GPIO_BSRR_BS5 /*!< Select pin 5 */
  96. #define LL_GPIO_PIN_6 GPIO_BSRR_BS6 /*!< Select pin 6 */
  97. #define LL_GPIO_PIN_7 GPIO_BSRR_BS7 /*!< Select pin 7 */
  98. #define LL_GPIO_PIN_8 GPIO_BSRR_BS8 /*!< Select pin 8 */
  99. #define LL_GPIO_PIN_9 GPIO_BSRR_BS9 /*!< Select pin 9 */
  100. #define LL_GPIO_PIN_10 GPIO_BSRR_BS10 /*!< Select pin 10 */
  101. #define LL_GPIO_PIN_11 GPIO_BSRR_BS11 /*!< Select pin 11 */
  102. #define LL_GPIO_PIN_12 GPIO_BSRR_BS12 /*!< Select pin 12 */
  103. #define LL_GPIO_PIN_13 GPIO_BSRR_BS13 /*!< Select pin 13 */
  104. #define LL_GPIO_PIN_14 GPIO_BSRR_BS14 /*!< Select pin 14 */
  105. #define LL_GPIO_PIN_15 GPIO_BSRR_BS15 /*!< Select pin 15 */
  106. #define LL_GPIO_PIN_ALL (GPIO_BSRR_BS0 | GPIO_BSRR_BS1 | GPIO_BSRR_BS2 | \
  107. GPIO_BSRR_BS3 | GPIO_BSRR_BS4 | GPIO_BSRR_BS5 | \
  108. GPIO_BSRR_BS6 | GPIO_BSRR_BS7 | GPIO_BSRR_BS8 | \
  109. GPIO_BSRR_BS9 | GPIO_BSRR_BS10 | GPIO_BSRR_BS11 | \
  110. GPIO_BSRR_BS12 | GPIO_BSRR_BS13 | GPIO_BSRR_BS14 | \
  111. GPIO_BSRR_BS15) /*!< Select all pins */
  112. /**
  113. * @}
  114. */
  115. /** @defgroup GPIO_LL_EC_MODE Mode
  116. * @{
  117. */
  118. #define LL_GPIO_MODE_INPUT (0x00000000U) /*!< Select input mode */
  119. #define LL_GPIO_MODE_OUTPUT GPIO_MODER_MODE0_0 /*!< Select output mode */
  120. #define LL_GPIO_MODE_ALTERNATE GPIO_MODER_MODE0_1 /*!< Select alternate function mode */
  121. #define LL_GPIO_MODE_ANALOG GPIO_MODER_MODE0 /*!< Select analog mode */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup GPIO_LL_EC_OUTPUT Output Type
  126. * @{
  127. */
  128. #define LL_GPIO_OUTPUT_PUSHPULL (0x00000000U) /*!< Select push-pull as output type */
  129. #define LL_GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT0 /*!< Select open-drain as output type */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup GPIO_LL_EC_SPEED Output Speed
  134. * @{
  135. */
  136. #define LL_GPIO_SPEED_FREQ_LOW (0x00000000U) /*!< Select I/O low output speed */
  137. #define LL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDR_OSPEED0_0 /*!< Select I/O medium output speed */
  138. #define LL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDR_OSPEED0_1 /*!< Select I/O fast output speed */
  139. #define LL_GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDR_OSPEED0 /*!< Select I/O high output speed */
  140. /**
  141. * @}
  142. */
  143. #define LL_GPIO_SPEED_LOW LL_GPIO_SPEED_FREQ_LOW
  144. #define LL_GPIO_SPEED_MEDIUM LL_GPIO_SPEED_FREQ_MEDIUM
  145. #define LL_GPIO_SPEED_FAST LL_GPIO_SPEED_FREQ_HIGH
  146. #define LL_GPIO_SPEED_HIGH LL_GPIO_SPEED_FREQ_VERY_HIGH
  147. /** @defgroup GPIO_LL_EC_PULL Pull Up Pull Down
  148. * @{
  149. */
  150. #define LL_GPIO_PULL_NO (0x00000000U) /*!< Select I/O no pull */
  151. #define LL_GPIO_PULL_UP GPIO_PUPDR_PUPD0_0 /*!< Select I/O pull up */
  152. #define LL_GPIO_PULL_DOWN GPIO_PUPDR_PUPD0_1 /*!< Select I/O pull down */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup GPIO_LL_EC_AF Alternate Function
  157. * @{
  158. */
  159. #define LL_GPIO_AF_0 (0x0000000U) /*!< Select alternate function 0 */
  160. #define LL_GPIO_AF_1 (0x0000001U) /*!< Select alternate function 1 */
  161. #define LL_GPIO_AF_2 (0x0000002U) /*!< Select alternate function 2 */
  162. #define LL_GPIO_AF_3 (0x0000003U) /*!< Select alternate function 3 */
  163. #define LL_GPIO_AF_4 (0x0000004U) /*!< Select alternate function 4 */
  164. #define LL_GPIO_AF_5 (0x0000005U) /*!< Select alternate function 5 */
  165. #define LL_GPIO_AF_6 (0x0000006U) /*!< Select alternate function 6 */
  166. #define LL_GPIO_AF_7 (0x0000007U) /*!< Select alternate function 7 */
  167. #define LL_GPIO_AF_8 (0x0000008U) /*!< Select alternate function 8 */
  168. #define LL_GPIO_AF_9 (0x0000009U) /*!< Select alternate function 9 */
  169. #define LL_GPIO_AF_10 (0x000000AU) /*!< Select alternate function 10 */
  170. #define LL_GPIO_AF_11 (0x000000BU) /*!< Select alternate function 11 */
  171. #define LL_GPIO_AF_12 (0x000000CU) /*!< Select alternate function 12 */
  172. #define LL_GPIO_AF_13 (0x000000DU) /*!< Select alternate function 13 */
  173. #define LL_GPIO_AF_14 (0x000000EU) /*!< Select alternate function 14 */
  174. #define LL_GPIO_AF_15 (0x000000FU) /*!< Select alternate function 15 */
  175. /**
  176. * @}
  177. */
  178. /**
  179. * @}
  180. */
  181. /* Exported macro ------------------------------------------------------------*/
  182. /** @defgroup GPIO_LL_Exported_Macros GPIO Exported Macros
  183. * @{
  184. */
  185. /** @defgroup GPIO_LL_EM_WRITE_READ Common Write and read registers Macros
  186. * @{
  187. */
  188. /**
  189. * @brief Write a value in GPIO register
  190. * @param __INSTANCE__ GPIO Instance
  191. * @param __REG__ Register to be written
  192. * @param __VALUE__ Value to be written in the register
  193. * @retval None
  194. */
  195. #define LL_GPIO_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  196. /**
  197. * @brief Read a value in GPIO register
  198. * @param __INSTANCE__ GPIO Instance
  199. * @param __REG__ Register to be read
  200. * @retval Register value
  201. */
  202. #define LL_GPIO_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  203. /**
  204. * @}
  205. */
  206. /**
  207. * @}
  208. */
  209. /* Exported functions --------------------------------------------------------*/
  210. /** @defgroup GPIO_LL_Exported_Functions GPIO Exported Functions
  211. * @{
  212. */
  213. /** @defgroup GPIO_LL_EF_Port_Configuration Port Configuration
  214. * @{
  215. */
  216. /**
  217. * @brief Configure gpio mode for a dedicated pin on dedicated port.
  218. * @note I/O mode can be Input mode, General purpose output, Alternate function mode or Analog.
  219. * @note Warning: only one pin can be passed as parameter.
  220. * @rmtoll MODER MODEy LL_GPIO_SetPinMode
  221. * @param GPIOx GPIO Port
  222. * @param Pin This parameter can be one of the following values:
  223. * @arg @ref LL_GPIO_PIN_0
  224. * @arg @ref LL_GPIO_PIN_1
  225. * @arg @ref LL_GPIO_PIN_2
  226. * @arg @ref LL_GPIO_PIN_3
  227. * @arg @ref LL_GPIO_PIN_4
  228. * @arg @ref LL_GPIO_PIN_5
  229. * @arg @ref LL_GPIO_PIN_6
  230. * @arg @ref LL_GPIO_PIN_7
  231. * @arg @ref LL_GPIO_PIN_8
  232. * @arg @ref LL_GPIO_PIN_9
  233. * @arg @ref LL_GPIO_PIN_10
  234. * @arg @ref LL_GPIO_PIN_11
  235. * @arg @ref LL_GPIO_PIN_12
  236. * @arg @ref LL_GPIO_PIN_13
  237. * @arg @ref LL_GPIO_PIN_14
  238. * @arg @ref LL_GPIO_PIN_15
  239. * @param Mode This parameter can be one of the following values:
  240. * @arg @ref LL_GPIO_MODE_INPUT
  241. * @arg @ref LL_GPIO_MODE_OUTPUT
  242. * @arg @ref LL_GPIO_MODE_ALTERNATE
  243. * @arg @ref LL_GPIO_MODE_ANALOG
  244. * @retval None
  245. */
  246. __STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode)
  247. {
  248. MODIFY_REG(GPIOx->MODER, (GPIO_MODER_MODE0 << (POSITION_VAL(Pin) * GPIO_MODER_MODE1_Pos)),
  249. (Mode << (POSITION_VAL(Pin) * GPIO_MODER_MODE1_Pos)));
  250. }
  251. /**
  252. * @brief Return gpio mode for a dedicated pin on dedicated port.
  253. * @note I/O mode can be Input mode, General purpose output, Alternate function mode or Analog.
  254. * @note Warning: only one pin can be passed as parameter.
  255. * @rmtoll MODER MODEy LL_GPIO_GetPinMode
  256. * @param GPIOx GPIO Port
  257. * @param Pin This parameter can be one of the following values:
  258. * @arg @ref LL_GPIO_PIN_0
  259. * @arg @ref LL_GPIO_PIN_1
  260. * @arg @ref LL_GPIO_PIN_2
  261. * @arg @ref LL_GPIO_PIN_3
  262. * @arg @ref LL_GPIO_PIN_4
  263. * @arg @ref LL_GPIO_PIN_5
  264. * @arg @ref LL_GPIO_PIN_6
  265. * @arg @ref LL_GPIO_PIN_7
  266. * @arg @ref LL_GPIO_PIN_8
  267. * @arg @ref LL_GPIO_PIN_9
  268. * @arg @ref LL_GPIO_PIN_10
  269. * @arg @ref LL_GPIO_PIN_11
  270. * @arg @ref LL_GPIO_PIN_12
  271. * @arg @ref LL_GPIO_PIN_13
  272. * @arg @ref LL_GPIO_PIN_14
  273. * @arg @ref LL_GPIO_PIN_15
  274. * @retval Returned value can be one of the following values:
  275. * @arg @ref LL_GPIO_MODE_INPUT
  276. * @arg @ref LL_GPIO_MODE_OUTPUT
  277. * @arg @ref LL_GPIO_MODE_ALTERNATE
  278. * @arg @ref LL_GPIO_MODE_ANALOG
  279. */
  280. __STATIC_INLINE uint32_t LL_GPIO_GetPinMode(const GPIO_TypeDef *GPIOx, uint32_t Pin)
  281. {
  282. return (uint32_t)(READ_BIT(GPIOx->MODER, (GPIO_MODER_MODE0 << (POSITION_VAL(Pin) * GPIO_MODER_MODE1_Pos))) >> \
  283. (POSITION_VAL(Pin) * GPIO_MODER_MODE1_Pos));
  284. }
  285. /**
  286. * @brief Configure gpio output type for several pins on dedicated port.
  287. * @note Output type as to be set when gpio pin is in output or
  288. * alternate modes. Possible type are Push-pull or Open-drain.
  289. * @rmtoll OTYPER OTy LL_GPIO_SetPinOutputType
  290. * @param GPIOx GPIO Port
  291. * @param PinMask This parameter can be a combination of the following values:
  292. * @arg @ref LL_GPIO_PIN_0
  293. * @arg @ref LL_GPIO_PIN_1
  294. * @arg @ref LL_GPIO_PIN_2
  295. * @arg @ref LL_GPIO_PIN_3
  296. * @arg @ref LL_GPIO_PIN_4
  297. * @arg @ref LL_GPIO_PIN_5
  298. * @arg @ref LL_GPIO_PIN_6
  299. * @arg @ref LL_GPIO_PIN_7
  300. * @arg @ref LL_GPIO_PIN_8
  301. * @arg @ref LL_GPIO_PIN_9
  302. * @arg @ref LL_GPIO_PIN_10
  303. * @arg @ref LL_GPIO_PIN_11
  304. * @arg @ref LL_GPIO_PIN_12
  305. * @arg @ref LL_GPIO_PIN_13
  306. * @arg @ref LL_GPIO_PIN_14
  307. * @arg @ref LL_GPIO_PIN_15
  308. * @arg @ref LL_GPIO_PIN_ALL
  309. * @param OutputType This parameter can be one of the following values:
  310. * @arg @ref LL_GPIO_OUTPUT_PUSHPULL
  311. * @arg @ref LL_GPIO_OUTPUT_OPENDRAIN
  312. * @retval None
  313. */
  314. __STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType)
  315. {
  316. MODIFY_REG(GPIOx->OTYPER, PinMask, (PinMask * OutputType));
  317. }
  318. /**
  319. * @brief Return gpio output type for several pins on dedicated port.
  320. * @note Output type as to be set when gpio pin is in output or
  321. * alternate modes. Possible type are Push-pull or Open-drain.
  322. * @note Warning: only one pin can be passed as parameter.
  323. * @rmtoll OTYPER OTy LL_GPIO_GetPinOutputType
  324. * @param GPIOx GPIO Port
  325. * @param Pin This parameter can be one of the following values:
  326. * @arg @ref LL_GPIO_PIN_0
  327. * @arg @ref LL_GPIO_PIN_1
  328. * @arg @ref LL_GPIO_PIN_2
  329. * @arg @ref LL_GPIO_PIN_3
  330. * @arg @ref LL_GPIO_PIN_4
  331. * @arg @ref LL_GPIO_PIN_5
  332. * @arg @ref LL_GPIO_PIN_6
  333. * @arg @ref LL_GPIO_PIN_7
  334. * @arg @ref LL_GPIO_PIN_8
  335. * @arg @ref LL_GPIO_PIN_9
  336. * @arg @ref LL_GPIO_PIN_10
  337. * @arg @ref LL_GPIO_PIN_11
  338. * @arg @ref LL_GPIO_PIN_12
  339. * @arg @ref LL_GPIO_PIN_13
  340. * @arg @ref LL_GPIO_PIN_14
  341. * @arg @ref LL_GPIO_PIN_15
  342. * @arg @ref LL_GPIO_PIN_ALL
  343. * @retval Returned value can be one of the following values:
  344. * @arg @ref LL_GPIO_OUTPUT_PUSHPULL
  345. * @arg @ref LL_GPIO_OUTPUT_OPENDRAIN
  346. */
  347. __STATIC_INLINE uint32_t LL_GPIO_GetPinOutputType(const GPIO_TypeDef *GPIOx, uint32_t Pin)
  348. {
  349. return (uint32_t)(READ_BIT(GPIOx->OTYPER, Pin) >> POSITION_VAL(Pin));
  350. }
  351. /**
  352. * @brief Configure gpio speed for a dedicated pin on dedicated port.
  353. * @note I/O speed can be Low, Medium, Fast or High speed.
  354. * @note Warning: only one pin can be passed as parameter.
  355. * @note Refer to datasheet for frequency specifications and the power
  356. * supply and load conditions for each speed.
  357. * @rmtoll OSPEEDR OSPEEDy LL_GPIO_SetPinSpeed
  358. * @param GPIOx GPIO Port
  359. * @param Pin This parameter can be one of the following values:
  360. * @arg @ref LL_GPIO_PIN_0
  361. * @arg @ref LL_GPIO_PIN_1
  362. * @arg @ref LL_GPIO_PIN_2
  363. * @arg @ref LL_GPIO_PIN_3
  364. * @arg @ref LL_GPIO_PIN_4
  365. * @arg @ref LL_GPIO_PIN_5
  366. * @arg @ref LL_GPIO_PIN_6
  367. * @arg @ref LL_GPIO_PIN_7
  368. * @arg @ref LL_GPIO_PIN_8
  369. * @arg @ref LL_GPIO_PIN_9
  370. * @arg @ref LL_GPIO_PIN_10
  371. * @arg @ref LL_GPIO_PIN_11
  372. * @arg @ref LL_GPIO_PIN_12
  373. * @arg @ref LL_GPIO_PIN_13
  374. * @arg @ref LL_GPIO_PIN_14
  375. * @arg @ref LL_GPIO_PIN_15
  376. * @param Speed This parameter can be one of the following values:
  377. * @arg @ref LL_GPIO_SPEED_FREQ_LOW
  378. * @arg @ref LL_GPIO_SPEED_FREQ_MEDIUM
  379. * @arg @ref LL_GPIO_SPEED_FREQ_HIGH
  380. * @arg @ref LL_GPIO_SPEED_FREQ_VERY_HIGH
  381. * @retval None
  382. */
  383. __STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed)
  384. {
  385. MODIFY_REG(GPIOx->OSPEEDR, (GPIO_OSPEEDR_OSPEED0 << (POSITION_VAL(Pin) * GPIO_OSPEEDR_OSPEED1_Pos)),
  386. (Speed << (POSITION_VAL(Pin) * GPIO_OSPEEDR_OSPEED1_Pos)));
  387. }
  388. /**
  389. * @brief Return gpio speed for a dedicated pin on dedicated port.
  390. * @note I/O speed can be Low, Medium, Fast or High speed.
  391. * @note Warning: only one pin can be passed as parameter.
  392. * @note Refer to datasheet for frequency specifications and the power
  393. * supply and load conditions for each speed.
  394. * @rmtoll OSPEEDR OSPEEDy LL_GPIO_GetPinSpeed
  395. * @param GPIOx GPIO Port
  396. * @param Pin This parameter can be one of the following values:
  397. * @arg @ref LL_GPIO_PIN_0
  398. * @arg @ref LL_GPIO_PIN_1
  399. * @arg @ref LL_GPIO_PIN_2
  400. * @arg @ref LL_GPIO_PIN_3
  401. * @arg @ref LL_GPIO_PIN_4
  402. * @arg @ref LL_GPIO_PIN_5
  403. * @arg @ref LL_GPIO_PIN_6
  404. * @arg @ref LL_GPIO_PIN_7
  405. * @arg @ref LL_GPIO_PIN_8
  406. * @arg @ref LL_GPIO_PIN_9
  407. * @arg @ref LL_GPIO_PIN_10
  408. * @arg @ref LL_GPIO_PIN_11
  409. * @arg @ref LL_GPIO_PIN_12
  410. * @arg @ref LL_GPIO_PIN_13
  411. * @arg @ref LL_GPIO_PIN_14
  412. * @arg @ref LL_GPIO_PIN_15
  413. * @retval Returned value can be one of the following values:
  414. * @arg @ref LL_GPIO_SPEED_FREQ_LOW
  415. * @arg @ref LL_GPIO_SPEED_FREQ_MEDIUM
  416. * @arg @ref LL_GPIO_SPEED_FREQ_HIGH
  417. * @arg @ref LL_GPIO_SPEED_FREQ_VERY_HIGH
  418. */
  419. __STATIC_INLINE uint32_t LL_GPIO_GetPinSpeed(const GPIO_TypeDef *GPIOx, uint32_t Pin)
  420. {
  421. return (uint32_t)(READ_BIT(GPIOx->OSPEEDR, (GPIO_OSPEEDR_OSPEED0 << \
  422. (POSITION_VAL(Pin) * GPIO_OSPEEDR_OSPEED1_Pos))) >> \
  423. (POSITION_VAL(Pin) * GPIO_OSPEEDR_OSPEED1_Pos));
  424. }
  425. /**
  426. * @brief Configure gpio pull-up or pull-down for a dedicated pin on a dedicated port.
  427. * @note Warning: only one pin can be passed as parameter.
  428. * @rmtoll PUPDR PUPDy LL_GPIO_SetPinPull
  429. * @param GPIOx GPIO Port
  430. * @param Pin This parameter can be one of the following values:
  431. * @arg @ref LL_GPIO_PIN_0
  432. * @arg @ref LL_GPIO_PIN_1
  433. * @arg @ref LL_GPIO_PIN_2
  434. * @arg @ref LL_GPIO_PIN_3
  435. * @arg @ref LL_GPIO_PIN_4
  436. * @arg @ref LL_GPIO_PIN_5
  437. * @arg @ref LL_GPIO_PIN_6
  438. * @arg @ref LL_GPIO_PIN_7
  439. * @arg @ref LL_GPIO_PIN_8
  440. * @arg @ref LL_GPIO_PIN_9
  441. * @arg @ref LL_GPIO_PIN_10
  442. * @arg @ref LL_GPIO_PIN_11
  443. * @arg @ref LL_GPIO_PIN_12
  444. * @arg @ref LL_GPIO_PIN_13
  445. * @arg @ref LL_GPIO_PIN_14
  446. * @arg @ref LL_GPIO_PIN_15
  447. * @param Pull This parameter can be one of the following values:
  448. * @arg @ref LL_GPIO_PULL_NO
  449. * @arg @ref LL_GPIO_PULL_UP
  450. * @arg @ref LL_GPIO_PULL_DOWN
  451. * @retval None
  452. */
  453. __STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull)
  454. {
  455. MODIFY_REG(GPIOx->PUPDR, (GPIO_PUPDR_PUPD0 << (POSITION_VAL(Pin) * GPIO_PUPDR_PUPD1_Pos)),
  456. (Pull << (POSITION_VAL(Pin) * GPIO_PUPDR_PUPD1_Pos)));
  457. }
  458. /**
  459. * @brief Return gpio pull-up or pull-down for a dedicated pin on a dedicated port
  460. * @note Warning: only one pin can be passed as parameter.
  461. * @rmtoll PUPDR PUPDy LL_GPIO_GetPinPull
  462. * @param GPIOx GPIO Port
  463. * @param Pin This parameter can be one of the following values:
  464. * @arg @ref LL_GPIO_PIN_0
  465. * @arg @ref LL_GPIO_PIN_1
  466. * @arg @ref LL_GPIO_PIN_2
  467. * @arg @ref LL_GPIO_PIN_3
  468. * @arg @ref LL_GPIO_PIN_4
  469. * @arg @ref LL_GPIO_PIN_5
  470. * @arg @ref LL_GPIO_PIN_6
  471. * @arg @ref LL_GPIO_PIN_7
  472. * @arg @ref LL_GPIO_PIN_8
  473. * @arg @ref LL_GPIO_PIN_9
  474. * @arg @ref LL_GPIO_PIN_10
  475. * @arg @ref LL_GPIO_PIN_11
  476. * @arg @ref LL_GPIO_PIN_12
  477. * @arg @ref LL_GPIO_PIN_13
  478. * @arg @ref LL_GPIO_PIN_14
  479. * @arg @ref LL_GPIO_PIN_15
  480. * @retval Returned value can be one of the following values:
  481. * @arg @ref LL_GPIO_PULL_NO
  482. * @arg @ref LL_GPIO_PULL_UP
  483. * @arg @ref LL_GPIO_PULL_DOWN
  484. */
  485. __STATIC_INLINE uint32_t LL_GPIO_GetPinPull(const GPIO_TypeDef *GPIOx, uint32_t Pin)
  486. {
  487. return (uint32_t)(READ_BIT(GPIOx->PUPDR, (GPIO_PUPDR_PUPD0 << (POSITION_VAL(Pin) * GPIO_PUPDR_PUPD1_Pos))) >> \
  488. (POSITION_VAL(Pin) * GPIO_PUPDR_PUPD1_Pos));
  489. }
  490. /**
  491. * @brief Configure gpio alternate function of a dedicated pin from 0 to 7 for a dedicated port.
  492. * @note Possible values are from AF0 to AF15 depending on target.
  493. * @note Warning: only one pin can be passed as parameter.
  494. * @rmtoll AFRL AFSELy LL_GPIO_SetAFPin_0_7
  495. * @param GPIOx GPIO Port
  496. * @param Pin This parameter can be one of the following values:
  497. * @arg @ref LL_GPIO_PIN_0
  498. * @arg @ref LL_GPIO_PIN_1
  499. * @arg @ref LL_GPIO_PIN_2
  500. * @arg @ref LL_GPIO_PIN_3
  501. * @arg @ref LL_GPIO_PIN_4
  502. * @arg @ref LL_GPIO_PIN_5
  503. * @arg @ref LL_GPIO_PIN_6
  504. * @arg @ref LL_GPIO_PIN_7
  505. * @param Alternate This parameter can be one of the following values:
  506. * @arg @ref LL_GPIO_AF_0
  507. * @arg @ref LL_GPIO_AF_1
  508. * @arg @ref LL_GPIO_AF_2
  509. * @arg @ref LL_GPIO_AF_3
  510. * @arg @ref LL_GPIO_AF_4
  511. * @arg @ref LL_GPIO_AF_5
  512. * @arg @ref LL_GPIO_AF_6
  513. * @arg @ref LL_GPIO_AF_7
  514. * @arg @ref LL_GPIO_AF_8
  515. * @arg @ref LL_GPIO_AF_9
  516. * @arg @ref LL_GPIO_AF_10
  517. * @arg @ref LL_GPIO_AF_11
  518. * @arg @ref LL_GPIO_AF_12
  519. * @arg @ref LL_GPIO_AF_13
  520. * @arg @ref LL_GPIO_AF_14
  521. * @arg @ref LL_GPIO_AF_15
  522. * @retval None
  523. */
  524. __STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
  525. {
  526. MODIFY_REG(GPIOx->AFR[0], (GPIO_AFRL_AFSEL0 << (POSITION_VAL(Pin) * GPIO_AFRL_AFSEL1_Pos)),
  527. (Alternate << (POSITION_VAL(Pin) * GPIO_AFRL_AFSEL1_Pos)));
  528. }
  529. /**
  530. * @brief Return gpio alternate function of a dedicated pin from 0 to 7 for a dedicated port.
  531. * @rmtoll AFRL AFSELy LL_GPIO_GetAFPin_0_7
  532. * @param GPIOx GPIO Port
  533. * @param Pin This parameter can be one of the following values:
  534. * @arg @ref LL_GPIO_PIN_0
  535. * @arg @ref LL_GPIO_PIN_1
  536. * @arg @ref LL_GPIO_PIN_2
  537. * @arg @ref LL_GPIO_PIN_3
  538. * @arg @ref LL_GPIO_PIN_4
  539. * @arg @ref LL_GPIO_PIN_5
  540. * @arg @ref LL_GPIO_PIN_6
  541. * @arg @ref LL_GPIO_PIN_7
  542. * @retval Returned value can be one of the following values:
  543. * @arg @ref LL_GPIO_AF_0
  544. * @arg @ref LL_GPIO_AF_1
  545. * @arg @ref LL_GPIO_AF_2
  546. * @arg @ref LL_GPIO_AF_3
  547. * @arg @ref LL_GPIO_AF_4
  548. * @arg @ref LL_GPIO_AF_5
  549. * @arg @ref LL_GPIO_AF_6
  550. * @arg @ref LL_GPIO_AF_7
  551. * @arg @ref LL_GPIO_AF_8
  552. * @arg @ref LL_GPIO_AF_9
  553. * @arg @ref LL_GPIO_AF_10
  554. * @arg @ref LL_GPIO_AF_11
  555. * @arg @ref LL_GPIO_AF_12
  556. * @arg @ref LL_GPIO_AF_13
  557. * @arg @ref LL_GPIO_AF_14
  558. * @arg @ref LL_GPIO_AF_15
  559. */
  560. __STATIC_INLINE uint32_t LL_GPIO_GetAFPin_0_7(const GPIO_TypeDef *GPIOx, uint32_t Pin)
  561. {
  562. return (uint32_t)(READ_BIT(GPIOx->AFR[0], (GPIO_AFRL_AFSEL0 << (POSITION_VAL(Pin) * GPIO_AFRL_AFSEL1_Pos))) >> \
  563. (POSITION_VAL(Pin) * GPIO_AFRL_AFSEL1_Pos));
  564. }
  565. /**
  566. * @brief Configure gpio alternate function of a dedicated pin from 8 to 15 for a dedicated port.
  567. * @note Possible values are from AF0 to AF15 depending on target.
  568. * @note Warning: only one pin can be passed as parameter.
  569. * @rmtoll AFRH AFSELy LL_GPIO_SetAFPin_8_15
  570. * @param GPIOx GPIO Port
  571. * @param Pin This parameter can be one of the following values:
  572. * @arg @ref LL_GPIO_PIN_8
  573. * @arg @ref LL_GPIO_PIN_9
  574. * @arg @ref LL_GPIO_PIN_10
  575. * @arg @ref LL_GPIO_PIN_11
  576. * @arg @ref LL_GPIO_PIN_12
  577. * @arg @ref LL_GPIO_PIN_13
  578. * @arg @ref LL_GPIO_PIN_14
  579. * @arg @ref LL_GPIO_PIN_15
  580. * @param Alternate This parameter can be one of the following values:
  581. * @arg @ref LL_GPIO_AF_0
  582. * @arg @ref LL_GPIO_AF_1
  583. * @arg @ref LL_GPIO_AF_2
  584. * @arg @ref LL_GPIO_AF_3
  585. * @arg @ref LL_GPIO_AF_4
  586. * @arg @ref LL_GPIO_AF_5
  587. * @arg @ref LL_GPIO_AF_6
  588. * @arg @ref LL_GPIO_AF_7
  589. * @arg @ref LL_GPIO_AF_8
  590. * @arg @ref LL_GPIO_AF_9
  591. * @arg @ref LL_GPIO_AF_10
  592. * @arg @ref LL_GPIO_AF_11
  593. * @arg @ref LL_GPIO_AF_12
  594. * @arg @ref LL_GPIO_AF_13
  595. * @arg @ref LL_GPIO_AF_14
  596. * @arg @ref LL_GPIO_AF_15
  597. * @retval None
  598. */
  599. __STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
  600. {
  601. MODIFY_REG(GPIOx->AFR[1], (GPIO_AFRH_AFSEL8 << (POSITION_VAL(Pin >> 8U) * GPIO_AFRH_AFSEL9_Pos)),
  602. (Alternate << (POSITION_VAL(Pin >> 8U) * GPIO_AFRH_AFSEL9_Pos)));
  603. }
  604. /**
  605. * @brief Return gpio alternate function of a dedicated pin from 8 to 15 for a dedicated port.
  606. * @note Possible values are from AF0 to AF15 depending on target.
  607. * @rmtoll AFRH AFSELy LL_GPIO_GetAFPin_8_15
  608. * @param GPIOx GPIO Port
  609. * @param Pin This parameter can be one of the following values:
  610. * @arg @ref LL_GPIO_PIN_8
  611. * @arg @ref LL_GPIO_PIN_9
  612. * @arg @ref LL_GPIO_PIN_10
  613. * @arg @ref LL_GPIO_PIN_11
  614. * @arg @ref LL_GPIO_PIN_12
  615. * @arg @ref LL_GPIO_PIN_13
  616. * @arg @ref LL_GPIO_PIN_14
  617. * @arg @ref LL_GPIO_PIN_15
  618. * @retval Returned value can be one of the following values:
  619. * @arg @ref LL_GPIO_AF_0
  620. * @arg @ref LL_GPIO_AF_1
  621. * @arg @ref LL_GPIO_AF_2
  622. * @arg @ref LL_GPIO_AF_3
  623. * @arg @ref LL_GPIO_AF_4
  624. * @arg @ref LL_GPIO_AF_5
  625. * @arg @ref LL_GPIO_AF_6
  626. * @arg @ref LL_GPIO_AF_7
  627. * @arg @ref LL_GPIO_AF_8
  628. * @arg @ref LL_GPIO_AF_9
  629. * @arg @ref LL_GPIO_AF_10
  630. * @arg @ref LL_GPIO_AF_11
  631. * @arg @ref LL_GPIO_AF_12
  632. * @arg @ref LL_GPIO_AF_13
  633. * @arg @ref LL_GPIO_AF_14
  634. * @arg @ref LL_GPIO_AF_15
  635. */
  636. __STATIC_INLINE uint32_t LL_GPIO_GetAFPin_8_15(const GPIO_TypeDef *GPIOx, uint32_t Pin)
  637. {
  638. return (uint32_t)(READ_BIT(GPIOx->AFR[1], (GPIO_AFRH_AFSEL8 << (POSITION_VAL(Pin >> 8U) * GPIO_AFRH_AFSEL9_Pos))) >> \
  639. (POSITION_VAL(Pin >> 8U) * GPIO_AFRH_AFSEL9_Pos));
  640. }
  641. /**
  642. * @brief Lock configuration of several pins for a dedicated port.
  643. * @note When the lock sequence has been applied on a port bit, the
  644. * value of this port bit can no longer be modified until the
  645. * next reset.
  646. * @note Each lock bit freezes a specific configuration register
  647. * (control and alternate function registers).
  648. * @rmtoll LCKR LCKK LL_GPIO_LockPin
  649. * @param GPIOx GPIO Port
  650. * @param PinMask This parameter can be a combination of the following values:
  651. * @arg @ref LL_GPIO_PIN_0
  652. * @arg @ref LL_GPIO_PIN_1
  653. * @arg @ref LL_GPIO_PIN_2
  654. * @arg @ref LL_GPIO_PIN_3
  655. * @arg @ref LL_GPIO_PIN_4
  656. * @arg @ref LL_GPIO_PIN_5
  657. * @arg @ref LL_GPIO_PIN_6
  658. * @arg @ref LL_GPIO_PIN_7
  659. * @arg @ref LL_GPIO_PIN_8
  660. * @arg @ref LL_GPIO_PIN_9
  661. * @arg @ref LL_GPIO_PIN_10
  662. * @arg @ref LL_GPIO_PIN_11
  663. * @arg @ref LL_GPIO_PIN_12
  664. * @arg @ref LL_GPIO_PIN_13
  665. * @arg @ref LL_GPIO_PIN_14
  666. * @arg @ref LL_GPIO_PIN_15
  667. * @arg @ref LL_GPIO_PIN_ALL
  668. * @retval None
  669. */
  670. __STATIC_INLINE void LL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  671. {
  672. __IO uint32_t temp;
  673. WRITE_REG(GPIOx->LCKR, GPIO_LCKR_LCKK | PinMask);
  674. WRITE_REG(GPIOx->LCKR, PinMask);
  675. WRITE_REG(GPIOx->LCKR, GPIO_LCKR_LCKK | PinMask);
  676. /* Read LCKK register. This read is mandatory to complete key lock sequence */
  677. temp = READ_REG(GPIOx->LCKR);
  678. (void) temp;
  679. }
  680. /**
  681. * @brief Return 1 if all pins passed as parameter, of a dedicated port, are locked. else Return 0.
  682. * @rmtoll LCKR LCKy LL_GPIO_IsPinLocked
  683. * @param GPIOx GPIO Port
  684. * @param PinMask This parameter can be a combination of the following values:
  685. * @arg @ref LL_GPIO_PIN_0
  686. * @arg @ref LL_GPIO_PIN_1
  687. * @arg @ref LL_GPIO_PIN_2
  688. * @arg @ref LL_GPIO_PIN_3
  689. * @arg @ref LL_GPIO_PIN_4
  690. * @arg @ref LL_GPIO_PIN_5
  691. * @arg @ref LL_GPIO_PIN_6
  692. * @arg @ref LL_GPIO_PIN_7
  693. * @arg @ref LL_GPIO_PIN_8
  694. * @arg @ref LL_GPIO_PIN_9
  695. * @arg @ref LL_GPIO_PIN_10
  696. * @arg @ref LL_GPIO_PIN_11
  697. * @arg @ref LL_GPIO_PIN_12
  698. * @arg @ref LL_GPIO_PIN_13
  699. * @arg @ref LL_GPIO_PIN_14
  700. * @arg @ref LL_GPIO_PIN_15
  701. * @arg @ref LL_GPIO_PIN_ALL
  702. * @retval State of bit (1 or 0).
  703. */
  704. __STATIC_INLINE uint32_t LL_GPIO_IsPinLocked(const GPIO_TypeDef *GPIOx, uint32_t PinMask)
  705. {
  706. return ((READ_BIT(GPIOx->LCKR, PinMask) == (PinMask)) ? 1UL : 0UL);
  707. }
  708. /**
  709. * @brief Return 1 if one of the pin of a dedicated port is locked. else return 0.
  710. * @rmtoll LCKR LCKK LL_GPIO_IsAnyPinLocked
  711. * @param GPIOx GPIO Port
  712. * @retval State of bit (1 or 0).
  713. */
  714. __STATIC_INLINE uint32_t LL_GPIO_IsAnyPinLocked(const GPIO_TypeDef *GPIOx)
  715. {
  716. return ((READ_BIT(GPIOx->LCKR, GPIO_LCKR_LCKK) == (GPIO_LCKR_LCKK)) ? 1UL : 0UL);
  717. }
  718. /**
  719. * @}
  720. */
  721. /** @defgroup GPIO_LL_EF_Data_Access Data Access
  722. * @{
  723. */
  724. /**
  725. * @brief Return full input data register value for a dedicated port.
  726. * @rmtoll IDR IDy LL_GPIO_ReadInputPort
  727. * @param GPIOx GPIO Port
  728. * @retval Input data register value of port
  729. */
  730. __STATIC_INLINE uint32_t LL_GPIO_ReadInputPort(const GPIO_TypeDef *GPIOx)
  731. {
  732. return (uint32_t)(READ_REG(GPIOx->IDR));
  733. }
  734. /**
  735. * @brief Return if input data level for several pins of dedicated port is high or low.
  736. * @rmtoll IDR IDy LL_GPIO_IsInputPinSet
  737. * @param GPIOx GPIO Port
  738. * @param PinMask This parameter can be a combination of the following values:
  739. * @arg @ref LL_GPIO_PIN_0
  740. * @arg @ref LL_GPIO_PIN_1
  741. * @arg @ref LL_GPIO_PIN_2
  742. * @arg @ref LL_GPIO_PIN_3
  743. * @arg @ref LL_GPIO_PIN_4
  744. * @arg @ref LL_GPIO_PIN_5
  745. * @arg @ref LL_GPIO_PIN_6
  746. * @arg @ref LL_GPIO_PIN_7
  747. * @arg @ref LL_GPIO_PIN_8
  748. * @arg @ref LL_GPIO_PIN_9
  749. * @arg @ref LL_GPIO_PIN_10
  750. * @arg @ref LL_GPIO_PIN_11
  751. * @arg @ref LL_GPIO_PIN_12
  752. * @arg @ref LL_GPIO_PIN_13
  753. * @arg @ref LL_GPIO_PIN_14
  754. * @arg @ref LL_GPIO_PIN_15
  755. * @arg @ref LL_GPIO_PIN_ALL
  756. * @retval State of bit (1 or 0).
  757. */
  758. __STATIC_INLINE uint32_t LL_GPIO_IsInputPinSet(const GPIO_TypeDef *GPIOx, uint32_t PinMask)
  759. {
  760. return ((READ_BIT(GPIOx->IDR, PinMask) == (PinMask)) ? 1UL : 0UL);
  761. }
  762. /**
  763. * @brief Write output data register for the port.
  764. * @rmtoll ODR ODy LL_GPIO_WriteOutputPort
  765. * @param GPIOx GPIO Port
  766. * @param PortValue Level value for each pin of the port
  767. * @retval None
  768. */
  769. __STATIC_INLINE void LL_GPIO_WriteOutputPort(GPIO_TypeDef *GPIOx, uint32_t PortValue)
  770. {
  771. WRITE_REG(GPIOx->ODR, PortValue);
  772. }
  773. /**
  774. * @brief Return full output data register value for a dedicated port.
  775. * @rmtoll ODR ODy LL_GPIO_ReadOutputPort
  776. * @param GPIOx GPIO Port
  777. * @retval Output data register value of port
  778. */
  779. __STATIC_INLINE uint32_t LL_GPIO_ReadOutputPort(const GPIO_TypeDef *GPIOx)
  780. {
  781. return (uint32_t)(READ_REG(GPIOx->ODR));
  782. }
  783. /**
  784. * @brief Return if input data level for several pins of dedicated port is high or low.
  785. * @rmtoll ODR ODy LL_GPIO_IsOutputPinSet
  786. * @param GPIOx GPIO Port
  787. * @param PinMask This parameter can be a combination of the following values:
  788. * @arg @ref LL_GPIO_PIN_0
  789. * @arg @ref LL_GPIO_PIN_1
  790. * @arg @ref LL_GPIO_PIN_2
  791. * @arg @ref LL_GPIO_PIN_3
  792. * @arg @ref LL_GPIO_PIN_4
  793. * @arg @ref LL_GPIO_PIN_5
  794. * @arg @ref LL_GPIO_PIN_6
  795. * @arg @ref LL_GPIO_PIN_7
  796. * @arg @ref LL_GPIO_PIN_8
  797. * @arg @ref LL_GPIO_PIN_9
  798. * @arg @ref LL_GPIO_PIN_10
  799. * @arg @ref LL_GPIO_PIN_11
  800. * @arg @ref LL_GPIO_PIN_12
  801. * @arg @ref LL_GPIO_PIN_13
  802. * @arg @ref LL_GPIO_PIN_14
  803. * @arg @ref LL_GPIO_PIN_15
  804. * @arg @ref LL_GPIO_PIN_ALL
  805. * @retval State of bit (1 or 0).
  806. */
  807. __STATIC_INLINE uint32_t LL_GPIO_IsOutputPinSet(const GPIO_TypeDef *GPIOx, uint32_t PinMask)
  808. {
  809. return ((READ_BIT(GPIOx->ODR, PinMask) == (PinMask)) ? 1UL : 0UL);
  810. }
  811. /**
  812. * @brief Set several pins to high level on dedicated gpio port.
  813. * @rmtoll BSRR BSy LL_GPIO_SetOutputPin
  814. * @param GPIOx GPIO Port
  815. * @param PinMask This parameter can be a combination of the following values:
  816. * @arg @ref LL_GPIO_PIN_0
  817. * @arg @ref LL_GPIO_PIN_1
  818. * @arg @ref LL_GPIO_PIN_2
  819. * @arg @ref LL_GPIO_PIN_3
  820. * @arg @ref LL_GPIO_PIN_4
  821. * @arg @ref LL_GPIO_PIN_5
  822. * @arg @ref LL_GPIO_PIN_6
  823. * @arg @ref LL_GPIO_PIN_7
  824. * @arg @ref LL_GPIO_PIN_8
  825. * @arg @ref LL_GPIO_PIN_9
  826. * @arg @ref LL_GPIO_PIN_10
  827. * @arg @ref LL_GPIO_PIN_11
  828. * @arg @ref LL_GPIO_PIN_12
  829. * @arg @ref LL_GPIO_PIN_13
  830. * @arg @ref LL_GPIO_PIN_14
  831. * @arg @ref LL_GPIO_PIN_15
  832. * @arg @ref LL_GPIO_PIN_ALL
  833. * @retval None
  834. */
  835. __STATIC_INLINE void LL_GPIO_SetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  836. {
  837. WRITE_REG(GPIOx->BSRR, PinMask);
  838. }
  839. /**
  840. * @brief Set several pins to low level on dedicated gpio port.
  841. * @rmtoll BRR BRy LL_GPIO_ResetOutputPin
  842. * @param GPIOx GPIO Port
  843. * @param PinMask This parameter can be a combination of the following values:
  844. * @arg @ref LL_GPIO_PIN_0
  845. * @arg @ref LL_GPIO_PIN_1
  846. * @arg @ref LL_GPIO_PIN_2
  847. * @arg @ref LL_GPIO_PIN_3
  848. * @arg @ref LL_GPIO_PIN_4
  849. * @arg @ref LL_GPIO_PIN_5
  850. * @arg @ref LL_GPIO_PIN_6
  851. * @arg @ref LL_GPIO_PIN_7
  852. * @arg @ref LL_GPIO_PIN_8
  853. * @arg @ref LL_GPIO_PIN_9
  854. * @arg @ref LL_GPIO_PIN_10
  855. * @arg @ref LL_GPIO_PIN_11
  856. * @arg @ref LL_GPIO_PIN_12
  857. * @arg @ref LL_GPIO_PIN_13
  858. * @arg @ref LL_GPIO_PIN_14
  859. * @arg @ref LL_GPIO_PIN_15
  860. * @arg @ref LL_GPIO_PIN_ALL
  861. * @retval None
  862. */
  863. __STATIC_INLINE void LL_GPIO_ResetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  864. {
  865. WRITE_REG(GPIOx->BRR, PinMask);
  866. }
  867. /**
  868. * @brief Toggle data value for several pin of dedicated port.
  869. * @rmtoll ODR ODy LL_GPIO_TogglePin
  870. * @param GPIOx GPIO Port
  871. * @param PinMask This parameter can be a combination of the following values:
  872. * @arg @ref LL_GPIO_PIN_0
  873. * @arg @ref LL_GPIO_PIN_1
  874. * @arg @ref LL_GPIO_PIN_2
  875. * @arg @ref LL_GPIO_PIN_3
  876. * @arg @ref LL_GPIO_PIN_4
  877. * @arg @ref LL_GPIO_PIN_5
  878. * @arg @ref LL_GPIO_PIN_6
  879. * @arg @ref LL_GPIO_PIN_7
  880. * @arg @ref LL_GPIO_PIN_8
  881. * @arg @ref LL_GPIO_PIN_9
  882. * @arg @ref LL_GPIO_PIN_10
  883. * @arg @ref LL_GPIO_PIN_11
  884. * @arg @ref LL_GPIO_PIN_12
  885. * @arg @ref LL_GPIO_PIN_13
  886. * @arg @ref LL_GPIO_PIN_14
  887. * @arg @ref LL_GPIO_PIN_15
  888. * @arg @ref LL_GPIO_PIN_ALL
  889. * @retval None
  890. */
  891. __STATIC_INLINE void LL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  892. {
  893. uint32_t odr = READ_REG(GPIOx->ODR);
  894. WRITE_REG(GPIOx->BSRR, ((odr & PinMask) << 16u) | (~odr & PinMask));
  895. }
  896. /**
  897. * @brief Enable speed optimization for several pin of dedicated port.
  898. * @note Not all I/Os support the HSLV mode. Refer to the I/O structure in the corresponding
  899. * datasheet for the list of I/Os supporting this feature. Other I/Os HSLV configuration must
  900. * be kept at reset value.
  901. * @note It must be used only if the I/O supply voltage is below 2.7 V.
  902. * @rmtoll HSLVR HSLVy LL_GPIO_EnableHighSPeedLowVoltage
  903. * @param GPIOx GPIO Port
  904. * @param PinMask This parameter can be a combination of the following values:
  905. * @arg @ref LL_GPIO_PIN_0
  906. * @arg @ref LL_GPIO_PIN_1
  907. * @arg @ref LL_GPIO_PIN_2
  908. * @arg @ref LL_GPIO_PIN_3
  909. * @arg @ref LL_GPIO_PIN_4
  910. * @arg @ref LL_GPIO_PIN_5
  911. * @arg @ref LL_GPIO_PIN_6
  912. * @arg @ref LL_GPIO_PIN_8
  913. * @arg @ref LL_GPIO_PIN_9
  914. * @arg @ref LL_GPIO_PIN_10
  915. * @arg @ref LL_GPIO_PIN_11
  916. * @arg @ref LL_GPIO_PIN_12
  917. * @arg @ref LL_GPIO_PIN_13
  918. * @arg @ref LL_GPIO_PIN_14
  919. * @arg @ref LL_GPIO_PIN_15
  920. * @retval None
  921. */
  922. __STATIC_INLINE void LL_GPIO_EnableHighSPeedLowVoltage(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  923. {
  924. SET_BIT(GPIOx->HSLVR, PinMask);
  925. }
  926. /**
  927. * @brief Disable speed optimization for several pin of dedicated port.
  928. * @note Not all I/Os support the HSLV mode. Refer to the I/O structure in the corresponding
  929. * datasheet for the list of I/Os supporting this feature. Other I/Os HSLV configuration must
  930. * be kept at reset value.
  931. * @note It must be used only if the I/O supply voltage is below 2.7 V.
  932. * @rmtoll HSLVR HSLVy LL_GPIO_DisableHighSPeedLowVoltage
  933. * @param GPIOx GPIO Port
  934. * @param PinMask This parameter can be a combination of the following values:
  935. * @arg @ref LL_GPIO_PIN_0
  936. * @arg @ref LL_GPIO_PIN_1
  937. * @arg @ref LL_GPIO_PIN_2
  938. * @arg @ref LL_GPIO_PIN_3
  939. * @arg @ref LL_GPIO_PIN_4
  940. * @arg @ref LL_GPIO_PIN_5
  941. * @arg @ref LL_GPIO_PIN_6
  942. * @arg @ref LL_GPIO_PIN_8
  943. * @arg @ref LL_GPIO_PIN_9
  944. * @arg @ref LL_GPIO_PIN_10
  945. * @arg @ref LL_GPIO_PIN_11
  946. * @arg @ref LL_GPIO_PIN_12
  947. * @arg @ref LL_GPIO_PIN_13
  948. * @arg @ref LL_GPIO_PIN_14
  949. * @arg @ref LL_GPIO_PIN_15
  950. * @retval None
  951. */
  952. __STATIC_INLINE void LL_GPIO_DisableHighSPeedLowVoltage(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  953. {
  954. CLEAR_BIT(GPIOx->HSLVR, PinMask);
  955. }
  956. /**
  957. * @brief Return if speed optimization for several pin of dedicated port is enabled or not.
  958. * @note Not all I/Os support the HSLV mode. Refer to the I/O structure in the corresponding
  959. * datasheet for the list of I/Os supporting this feature. Other I/Os HSLV configuration must
  960. * be kept at reset value.
  961. * @note It must be used only if the I/O supply voltage is below 2.7 V.
  962. * @rmtoll HSLVR HSLVy LL_GPIO_IsEnabledHighSPeedLowVoltage
  963. * @param GPIOx GPIO Port
  964. * @param PinMask This parameter can be a combination of the following values:
  965. * @arg @ref LL_GPIO_PIN_0
  966. * @arg @ref LL_GPIO_PIN_1
  967. * @arg @ref LL_GPIO_PIN_2
  968. * @arg @ref LL_GPIO_PIN_3
  969. * @arg @ref LL_GPIO_PIN_4
  970. * @arg @ref LL_GPIO_PIN_5
  971. * @arg @ref LL_GPIO_PIN_6
  972. * @arg @ref LL_GPIO_PIN_8
  973. * @arg @ref LL_GPIO_PIN_9
  974. * @arg @ref LL_GPIO_PIN_10
  975. * @arg @ref LL_GPIO_PIN_11
  976. * @arg @ref LL_GPIO_PIN_12
  977. * @arg @ref LL_GPIO_PIN_13
  978. * @arg @ref LL_GPIO_PIN_14
  979. * @arg @ref LL_GPIO_PIN_15
  980. * @retval State of bit (1 or 0).
  981. */
  982. __STATIC_INLINE uint32_t LL_GPIO_IsEnabledHighSPeedLowVoltage(const GPIO_TypeDef *GPIOx, uint32_t PinMask)
  983. {
  984. return ((READ_BIT(GPIOx->HSLVR, PinMask) == (PinMask)) ? 1UL : 0UL);
  985. }
  986. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  987. /**
  988. * @brief Enable secure write only access for several pin of dedicated port.
  989. * @rmtoll SECCFGR SECy LL_GPIO_EnablePinSecure
  990. * @param GPIOx GPIO Port
  991. * @param PinMask This parameter can be a combination of the following values:
  992. * @arg @ref LL_GPIO_PIN_0
  993. * @arg @ref LL_GPIO_PIN_1
  994. * @arg @ref LL_GPIO_PIN_2
  995. * @arg @ref LL_GPIO_PIN_3
  996. * @arg @ref LL_GPIO_PIN_4
  997. * @arg @ref LL_GPIO_PIN_5
  998. * @arg @ref LL_GPIO_PIN_6
  999. * @arg @ref LL_GPIO_PIN_7
  1000. * @arg @ref LL_GPIO_PIN_8
  1001. * @arg @ref LL_GPIO_PIN_9
  1002. * @arg @ref LL_GPIO_PIN_10
  1003. * @arg @ref LL_GPIO_PIN_11
  1004. * @arg @ref LL_GPIO_PIN_12
  1005. * @arg @ref LL_GPIO_PIN_13
  1006. * @arg @ref LL_GPIO_PIN_14
  1007. * @arg @ref LL_GPIO_PIN_15
  1008. * @arg @ref LL_GPIO_PIN_ALL
  1009. * @retval None
  1010. */
  1011. __STATIC_INLINE void LL_GPIO_EnablePinSecure(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  1012. {
  1013. SET_BIT(GPIOx->SECCFGR, PinMask);
  1014. }
  1015. /**
  1016. * @brief Disable secure write only access for several pin of dedicated port.
  1017. * @rmtoll SECCFGR SECy LL_GPIO_DisablePinSecure
  1018. * @param GPIOx GPIO Port
  1019. * @param PinMask This parameter can be a combination of the following values:
  1020. * @arg @ref LL_GPIO_PIN_0
  1021. * @arg @ref LL_GPIO_PIN_1
  1022. * @arg @ref LL_GPIO_PIN_2
  1023. * @arg @ref LL_GPIO_PIN_3
  1024. * @arg @ref LL_GPIO_PIN_4
  1025. * @arg @ref LL_GPIO_PIN_5
  1026. * @arg @ref LL_GPIO_PIN_6
  1027. * @arg @ref LL_GPIO_PIN_7
  1028. * @arg @ref LL_GPIO_PIN_8
  1029. * @arg @ref LL_GPIO_PIN_9
  1030. * @arg @ref LL_GPIO_PIN_10
  1031. * @arg @ref LL_GPIO_PIN_11
  1032. * @arg @ref LL_GPIO_PIN_12
  1033. * @arg @ref LL_GPIO_PIN_13
  1034. * @arg @ref LL_GPIO_PIN_14
  1035. * @arg @ref LL_GPIO_PIN_15
  1036. * @arg @ref LL_GPIO_PIN_ALL
  1037. * @retval None
  1038. */
  1039. __STATIC_INLINE void LL_GPIO_DisablePinSecure(GPIO_TypeDef *GPIOx, uint32_t PinMask)
  1040. {
  1041. CLEAR_BIT(GPIOx->SECCFGR, PinMask);
  1042. }
  1043. #endif /* __ARM_FEATURE_CMSE */
  1044. /**
  1045. * @brief Return if secure write only access for several pin of dedicated port is enabled or not.
  1046. * @rmtoll SECCFGR SECy LL_GPIO_IsEnabledPinSecure
  1047. * @param GPIOx GPIO Port
  1048. * @param PinMask This parameter can be a combination of the following values:
  1049. * @arg @ref LL_GPIO_PIN_0
  1050. * @arg @ref LL_GPIO_PIN_1
  1051. * @arg @ref LL_GPIO_PIN_2
  1052. * @arg @ref LL_GPIO_PIN_3
  1053. * @arg @ref LL_GPIO_PIN_4
  1054. * @arg @ref LL_GPIO_PIN_5
  1055. * @arg @ref LL_GPIO_PIN_6
  1056. * @arg @ref LL_GPIO_PIN_7
  1057. * @arg @ref LL_GPIO_PIN_8
  1058. * @arg @ref LL_GPIO_PIN_9
  1059. * @arg @ref LL_GPIO_PIN_10
  1060. * @arg @ref LL_GPIO_PIN_11
  1061. * @arg @ref LL_GPIO_PIN_12
  1062. * @arg @ref LL_GPIO_PIN_13
  1063. * @arg @ref LL_GPIO_PIN_14
  1064. * @arg @ref LL_GPIO_PIN_15
  1065. * @arg @ref LL_GPIO_PIN_ALL
  1066. * @retval State of bit (1 or 0).
  1067. */
  1068. __STATIC_INLINE uint32_t LL_GPIO_IsEnabledPinSecure(const GPIO_TypeDef *GPIOx, uint32_t PinMask)
  1069. {
  1070. return ((READ_BIT(GPIOx->SECCFGR, PinMask) == (PinMask)) ? 1UL : 0UL);
  1071. }
  1072. /**
  1073. * @}
  1074. */
  1075. #if defined(USE_FULL_LL_DRIVER)
  1076. /** @defgroup GPIO_LL_EF_Init Initialization and de-initialization functions
  1077. * @{
  1078. */
  1079. ErrorStatus LL_GPIO_DeInit(const GPIO_TypeDef *GPIOx);
  1080. ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct);
  1081. void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct);
  1082. /**
  1083. * @}
  1084. */
  1085. #endif /* USE_FULL_LL_DRIVER */
  1086. /**
  1087. * @}
  1088. */
  1089. /**
  1090. * @}
  1091. */
  1092. #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || \
  1093. defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) */
  1094. /**
  1095. * @}
  1096. */
  1097. #ifdef __cplusplus
  1098. }
  1099. #endif
  1100. #endif /* STM32H5xx_LL_GPIO_H */