gpio.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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) 2016 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. PA8 ------> RCC_MCO_1
  52. */
  53. void MX_GPIO_Init(void)
  54. {
  55. GPIO_InitTypeDef GPIO_InitStruct;
  56. /* GPIO Ports Clock Enable */
  57. __GPIOE_CLK_ENABLE();
  58. __GPIOC_CLK_ENABLE();
  59. __GPIOH_CLK_ENABLE();
  60. __GPIOA_CLK_ENABLE();
  61. __GPIOB_CLK_ENABLE();
  62. __GPIOD_CLK_ENABLE();
  63. /*Configure GPIO pins : PEPin PEPin PEPin PEPin */
  64. GPIO_InitStruct.Pin = FPGA_GPIO2_Pin|UNUSED_PE5_Pin|UNUSED_PE6_Pin;
  65. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  66. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  67. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  68. /*Configure GPIO pin : PE3 */
  69. GPIO_InitStruct.Pin = FPGA_GPIO3_Pin;
  70. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  71. GPIO_InitStruct.Pull = GPIO_NOPULL;
  72. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  73. /*Configure GPIO pin : PE4 */
  74. GPIO_InitStruct.Pin = GPIO_PIN_4;
  75. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  76. GPIO_InitStruct.Pull = GPIO_NOPULL;
  77. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  78. /*Configure GPIO pins : PCPin PCPin PCPin PCPin
  79. PCPin PCPin PCPin PCPin
  80. PCPin */
  81. GPIO_InitStruct.Pin = UNUSED_PC13_Pin|UNUSED_PC14_Pin|UNUSED_PC15_Pin|UNUSED_PC0_Pin
  82. |UNUSED_PC1_Pin|UNUSED_PC2_Pin|UNUSED_PC3_Pin|UNUSED_PC4_Pin
  83. |UNUSED_PC5_Pin;
  84. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  85. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  86. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  87. /*Configure GPIO pins : PAPin PAPin PAPin PAPin */
  88. GPIO_InitStruct.Pin = UNUSED_PA0_Pin|UNUSED_PA1_Pin|UNUSED_PA2_Pin|UNUSED_PA3_Pin;
  89. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  90. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  91. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  92. /*Configure GPIO pin : PtPin */
  93. GPIO_InitStruct.Pin = nSPICFG_CS_Pin;
  94. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  95. GPIO_InitStruct.Pull = GPIO_NOPULL;
  96. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  97. HAL_GPIO_Init(nSPICFG_CS_GPIO_Port, &GPIO_InitStruct);
  98. /*Configure GPIO pin : PtPin */
  99. GPIO_InitStruct.Pin = LED_Pin;
  100. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  101. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  102. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  103. HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
  104. /*Configure GPIO pin : PtPin */
  105. GPIO_InitStruct.Pin = nTERM_EN_Pin;
  106. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  107. GPIO_InitStruct.Pull = GPIO_NOPULL;
  108. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  109. HAL_GPIO_Init(nTERM_EN_GPIO_Port, &GPIO_InitStruct);
  110. /*Configure GPIO pins : PBPin PBPin PBPin */
  111. GPIO_InitStruct.Pin = BOOT1_Pin|UNUSED_PB5_Pin|UNUSED_PB6_Pin;
  112. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  113. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  114. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  115. /*Configure GPIO pins : PBPin PBPin */
  116. GPIO_InitStruct.Pin = UNUSED_PB12_Pin|UNUSED_PB13_Pin;
  117. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  118. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  119. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  120. /*Configure GPIO pins : PD6, PD12 */
  121. // PD6: FSMC NWAIT, not used yet.PULLED UP in fpga pin config
  122. // PD12: FPGA_GPIO1, not used.
  123. GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_12;
  124. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  125. GPIO_InitStruct.Pull = GPIO_PULLUP;
  126. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  127. /*Configure GPIO pins : PDPin PDPin */
  128. GPIO_InitStruct.Pin = UNUSED_PD11_Pin|FSMC_UNUSED_CLK_Pin;
  129. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  130. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  131. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  132. /*Configure GPIO pin : PtPin */
  133. GPIO_InitStruct.Pin = FPGA_RST_Pin;
  134. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  135. GPIO_InitStruct.Pull = GPIO_NOPULL;
  136. GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  137. HAL_GPIO_Init(FPGA_RST_GPIO_Port, &GPIO_InitStruct);
  138. /*Configure GPIO pins : PCPin PCPin */
  139. GPIO_InitStruct.Pin = nFGPA_CRESET_B_Pin|nFGPA_CDONE_Pin;
  140. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  141. GPIO_InitStruct.Pull = GPIO_NOPULL;
  142. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  143. /*Configure GPIO pin : PA8 */
  144. GPIO_InitStruct.Pin = GPIO_PIN_8;
  145. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  146. GPIO_InitStruct.Pull = GPIO_NOPULL;
  147. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  148. GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
  149. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  150. /*Configure GPIO pin : PA10 */
  151. // USB Host OTG ID pin
  152. GPIO_InitStruct.Pin = GPIO_PIN_10;
  153. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  154. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  155. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  156. // USB Host pins, currently unused.
  157. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  158. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  159. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  160. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  161. /*Configure GPIO pins : PBPin PBPin */
  162. GPIO_InitStruct.Pin = nSD_WP_Pin|nSD_CD_Pin;
  163. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  164. GPIO_InitStruct.Pull = GPIO_PULLUP;
  165. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  166. /* EXTI interrupt init*/
  167. HAL_NVIC_SetPriority(EXTI4_IRQn, 10, 0);
  168. HAL_NVIC_EnableIRQ(EXTI4_IRQn);
  169. }
  170. /* USER CODE BEGIN 2 */
  171. /* USER CODE END 2 */
  172. /**
  173. * @}
  174. */
  175. /**
  176. * @}
  177. */
  178. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/