gpio.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. ******************************************************************************
  3. * File Name : gpio.c
  4. * Description : This file provides code for the configuration
  5. * of all used GPIO pins.
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2019 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "gpio.h"
  36. /* USER CODE BEGIN 0 */
  37. /* USER CODE END 0 */
  38. /*----------------------------------------------------------------------------*/
  39. /* Configure GPIO */
  40. /*----------------------------------------------------------------------------*/
  41. /* USER CODE BEGIN 1 */
  42. /* USER CODE END 1 */
  43. /** Configure pins as
  44. * Analog
  45. * Input
  46. * Output
  47. * EVENT_OUT
  48. * EXTI
  49. * Free pins are configured automatically as Analog (this feature is enabled through
  50. * the Code Generation settings)
  51. PA6 ------> SPI1_MISO
  52. PA7 ------> SPI1_MOSI
  53. PA8 ------> RCC_MCO_1
  54. PB3 ------> SPI1_SCK
  55. */
  56. void MX_GPIO_Init(void)
  57. {
  58. GPIO_InitTypeDef GPIO_InitStruct;
  59. /* GPIO Ports Clock Enable */
  60. __GPIOE_CLK_ENABLE();
  61. __GPIOC_CLK_ENABLE();
  62. __GPIOH_CLK_ENABLE();
  63. __GPIOA_CLK_ENABLE();
  64. __GPIOB_CLK_ENABLE();
  65. __GPIOD_CLK_ENABLE();
  66. /*Configure GPIO pins : PEPin PEPin */
  67. GPIO_InitStruct.Pin = FPGA_GPIO2_Pin|UNUSED_PE6_Pin;
  68. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  69. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  70. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  71. /*Configure GPIO pin : PtPin */
  72. GPIO_InitStruct.Pin = FPGA_GPIO3_Pin;
  73. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  74. GPIO_InitStruct.Pull = GPIO_NOPULL;
  75. HAL_GPIO_Init(FPGA_GPIO3_GPIO_Port, &GPIO_InitStruct);
  76. /*Configure GPIO pin : PE4 */
  77. GPIO_InitStruct.Pin = GPIO_PIN_4;
  78. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  79. GPIO_InitStruct.Pull = GPIO_NOPULL;
  80. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  81. /*Configure GPIO pin : PtPin */
  82. GPIO_InitStruct.Pin = USB_ID_PASSTHRU_Pin;
  83. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  84. GPIO_InitStruct.Pull = GPIO_NOPULL;
  85. HAL_GPIO_Init(USB_ID_PASSTHRU_GPIO_Port, &GPIO_InitStruct);
  86. /*Configure GPIO pins : PC13 PC14 PC15 PC1 */
  87. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_1;
  88. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  89. GPIO_InitStruct.Pull = GPIO_NOPULL;
  90. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  91. /*Configure GPIO pins : PAPin PAPin */
  92. GPIO_InitStruct.Pin = nULPI_RESET_Pin|nSPICFG_CS_Pin;
  93. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  94. GPIO_InitStruct.Pull = GPIO_NOPULL;
  95. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  96. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  97. /*Configure GPIO pins : PA6 PA7 */
  98. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  99. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  100. GPIO_InitStruct.Pull = GPIO_NOPULL;
  101. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  102. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  103. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  104. /*Configure GPIO pins : PCPin PCPin */
  105. GPIO_InitStruct.Pin = VER_ID1_Pin|VER_ID2_Pin;
  106. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  107. GPIO_InitStruct.Pull = GPIO_PULLUP;
  108. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  109. /*Configure GPIO pin : PtPin */
  110. GPIO_InitStruct.Pin = BOOT1_Pin;
  111. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  112. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  113. HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
  114. /*Configure GPIO pins : PBPin PBPin */
  115. GPIO_InitStruct.Pin = nTERM_EN_Pin|LED_IO_Pin;
  116. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  117. GPIO_InitStruct.Pull = GPIO_NOPULL;
  118. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  119. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  120. /*Configure GPIO pins : PD11 PDPin */
  121. GPIO_InitStruct.Pin = GPIO_PIN_11|NWAIT_UNUSED_Pin;
  122. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  123. GPIO_InitStruct.Pull = GPIO_NOPULL;
  124. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  125. /*Configure GPIO pin : PtPin */
  126. GPIO_InitStruct.Pin = FPGA_RST_Pin;
  127. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  128. GPIO_InitStruct.Pull = GPIO_NOPULL;
  129. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  130. HAL_GPIO_Init(FPGA_RST_GPIO_Port, &GPIO_InitStruct);
  131. /*Configure GPIO pins : PCPin PCPin */
  132. GPIO_InitStruct.Pin = nFGPA_CRESET_B_Pin|nFGPA_CDONE_Pin;
  133. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  134. GPIO_InitStruct.Pull = GPIO_NOPULL;
  135. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  136. /*Configure GPIO pin : PA8 */
  137. GPIO_InitStruct.Pin = GPIO_PIN_8;
  138. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  139. GPIO_InitStruct.Pull = GPIO_NOPULL;
  140. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  141. GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
  142. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  143. /*Configure GPIO pin : PtPin */
  144. GPIO_InitStruct.Pin = OTG_FS_VBUS_UNUSED_Pin;
  145. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  146. GPIO_InitStruct.Pull = GPIO_NOPULL;
  147. HAL_GPIO_Init(OTG_FS_VBUS_UNUSED_GPIO_Port, &GPIO_InitStruct);
  148. /*Configure GPIO pin : PtPin */
  149. GPIO_InitStruct.Pin = FSMC_UNUSED_CLK_Pin;
  150. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  151. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  152. HAL_GPIO_Init(FSMC_UNUSED_CLK_GPIO_Port, &GPIO_InitStruct);
  153. /*Configure GPIO pin : PB3 */
  154. GPIO_InitStruct.Pin = GPIO_PIN_3;
  155. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  156. GPIO_InitStruct.Pull = GPIO_NOPULL;
  157. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  158. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  159. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  160. /*Configure GPIO pin : PB6 */
  161. GPIO_InitStruct.Pin = GPIO_PIN_6;
  162. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  163. GPIO_InitStruct.Pull = GPIO_NOPULL;
  164. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  165. /*Configure GPIO pins : PBPin PBPin */
  166. GPIO_InitStruct.Pin = nSD_WP_Pin|nSD_CD_Pin;
  167. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  168. GPIO_InitStruct.Pull = GPIO_PULLUP;
  169. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  170. /* EXTI interrupt init*/
  171. HAL_NVIC_SetPriority(EXTI4_IRQn, 10, 0);
  172. HAL_NVIC_EnableIRQ(EXTI4_IRQn);
  173. }
  174. /* USER CODE BEGIN 2 */
  175. /* USER CODE END 2 */
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @}
  181. */
  182. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/