You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

326 lines
12 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_ll_gpio.c
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief GPIO LL module driver.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. #if defined(USE_FULL_LL_DRIVER)
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "stm32f7xx_ll_gpio.h"
  40. #include "stm32f7xx_ll_bus.h"
  41. #ifdef USE_FULL_ASSERT
  42. #include "stm32_assert.h"
  43. #else
  44. #define assert_param(expr) ((void)0U)
  45. #endif
  46. /** @addtogroup STM32F7xx_LL_Driver
  47. * @{
  48. */
  49. #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)
  50. /** @addtogroup GPIO_LL
  51. * @{
  52. */
  53. /* Private types -------------------------------------------------------------*/
  54. /* Private variables ---------------------------------------------------------*/
  55. /* Private constants ---------------------------------------------------------*/
  56. /* Private macros ------------------------------------------------------------*/
  57. /** @addtogroup GPIO_LL_Private_Macros
  58. * @{
  59. */
  60. #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
  61. #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
  62. ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
  63. ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
  64. ((__VALUE__) == LL_GPIO_MODE_ANALOG))
  65. #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
  66. ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
  67. #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
  68. ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
  69. ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
  70. ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
  71. #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
  72. ((__VALUE__) == LL_GPIO_PULL_UP) ||\
  73. ((__VALUE__) == LL_GPIO_PULL_DOWN))
  74. #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
  75. ((__VALUE__) == LL_GPIO_AF_1 ) ||\
  76. ((__VALUE__) == LL_GPIO_AF_2 ) ||\
  77. ((__VALUE__) == LL_GPIO_AF_3 ) ||\
  78. ((__VALUE__) == LL_GPIO_AF_4 ) ||\
  79. ((__VALUE__) == LL_GPIO_AF_5 ) ||\
  80. ((__VALUE__) == LL_GPIO_AF_6 ) ||\
  81. ((__VALUE__) == LL_GPIO_AF_7 ) ||\
  82. ((__VALUE__) == LL_GPIO_AF_8 ) ||\
  83. ((__VALUE__) == LL_GPIO_AF_9 ) ||\
  84. ((__VALUE__) == LL_GPIO_AF_10 ) ||\
  85. ((__VALUE__) == LL_GPIO_AF_11 ) ||\
  86. ((__VALUE__) == LL_GPIO_AF_12 ) ||\
  87. ((__VALUE__) == LL_GPIO_AF_13 ) ||\
  88. ((__VALUE__) == LL_GPIO_AF_14 ) ||\
  89. ((__VALUE__) == LL_GPIO_AF_15 ))
  90. /**
  91. * @}
  92. */
  93. /* Private function prototypes -----------------------------------------------*/
  94. /* Exported functions --------------------------------------------------------*/
  95. /** @addtogroup GPIO_LL_Exported_Functions
  96. * @{
  97. */
  98. /** @addtogroup GPIO_LL_EF_Init
  99. * @{
  100. */
  101. /**
  102. * @brief De-initialize GPIO registers (Registers restored to their default values).
  103. * @param GPIOx GPIO Port
  104. * @retval An ErrorStatus enumeration value:
  105. * - SUCCESS: GPIO registers are de-initialized
  106. * - ERROR: Wrong GPIO Port
  107. */
  108. ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
  109. {
  110. ErrorStatus status = SUCCESS;
  111. /* Check the parameters */
  112. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  113. /* Force and Release reset on clock of GPIOx Port */
  114. if (GPIOx == GPIOA)
  115. {
  116. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA);
  117. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA);
  118. }
  119. else if (GPIOx == GPIOB)
  120. {
  121. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB);
  122. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB);
  123. }
  124. else if (GPIOx == GPIOC)
  125. {
  126. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC);
  127. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC);
  128. }
  129. #if defined(GPIOD)
  130. else if (GPIOx == GPIOD)
  131. {
  132. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD);
  133. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD);
  134. }
  135. #endif /* GPIOD */
  136. #if defined(GPIOE)
  137. else if (GPIOx == GPIOE)
  138. {
  139. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE);
  140. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE);
  141. }
  142. #endif /* GPIOE */
  143. #if defined(GPIOF)
  144. else if (GPIOx == GPIOF)
  145. {
  146. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF);
  147. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF);
  148. }
  149. #endif /* GPIOF */
  150. #if defined(GPIOG)
  151. else if (GPIOx == GPIOG)
  152. {
  153. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG);
  154. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG);
  155. }
  156. #endif /* GPIOG */
  157. #if defined(GPIOH)
  158. else if (GPIOx == GPIOH)
  159. {
  160. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH);
  161. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH);
  162. }
  163. #endif /* GPIOH */
  164. #if defined(GPIOI)
  165. else if (GPIOx == GPIOI)
  166. {
  167. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOI);
  168. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOI);
  169. }
  170. #endif /* GPIOI */
  171. #if defined(GPIOJ)
  172. else if (GPIOx == GPIOJ)
  173. {
  174. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOJ);
  175. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOJ);
  176. }
  177. #endif /* GPIOJ */
  178. #if defined(GPIOK)
  179. else if (GPIOx == GPIOK)
  180. {
  181. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOK);
  182. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOK);
  183. }
  184. #endif /* GPIOK */
  185. else
  186. {
  187. status = ERROR;
  188. }
  189. return (status);
  190. }
  191. /**
  192. * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
  193. * @param GPIOx GPIO Port
  194. * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  195. * that contains the configuration information for the specified GPIO peripheral.
  196. * @retval An ErrorStatus enumeration value:
  197. * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
  198. * - ERROR: Not applicable
  199. */
  200. ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
  201. {
  202. uint32_t pinpos = 0x00000000U;
  203. uint32_t currentpin = 0x00000000U;
  204. /* Check the parameters */
  205. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  206. assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
  207. assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
  208. assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
  209. /* ------------------------- Configure the port pins ---------------- */
  210. /* Initialize pinpos on first pin set */
  211. pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
  212. /* Configure the port pins */
  213. while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
  214. {
  215. /* Get current io position */
  216. currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
  217. if (currentpin)
  218. {
  219. /* Pin Mode configuration */
  220. LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
  221. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  222. {
  223. /* Check Speed mode parameters */
  224. assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
  225. /* Speed mode configuration */
  226. LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
  227. }
  228. /* Pull-up Pull down resistor configuration*/
  229. LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
  230. if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
  231. {
  232. /* Check Alternate parameter */
  233. assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
  234. /* Speed mode configuration */
  235. if (POSITION_VAL(currentpin) < 0x00000008U)
  236. {
  237. LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  238. }
  239. else
  240. {
  241. LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  242. }
  243. }
  244. }
  245. pinpos++;
  246. }
  247. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  248. {
  249. /* Check Output mode parameters */
  250. assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
  251. /* Output mode configuration*/
  252. LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
  253. }
  254. return (SUCCESS);
  255. }
  256. /**
  257. * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
  258. * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  259. * whose fields will be set to default values.
  260. * @retval None
  261. */
  262. void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
  263. {
  264. /* Reset GPIO init structure parameters values */
  265. GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
  266. GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
  267. GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
  268. GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  269. GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
  270. GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
  271. }
  272. /**
  273. * @}
  274. */
  275. /**
  276. * @}
  277. */
  278. /**
  279. * @}
  280. */
  281. #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */
  282. /**
  283. * @}
  284. */
  285. #endif /* USE_FULL_LL_DRIVER */
  286. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/