gpio.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. ******************************************************************************
  3. * File Name : gpio.c
  4. * Description : This file provides code for the configuration
  5. * of all used GPIO pins.
  6. ******************************************************************************
  7. * This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * Copyright (c) 2019 STMicroelectronics International N.V.
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted, provided that the following conditions are met:
  18. *
  19. * 1. Redistribution of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of other
  25. * contributors to this software may be used to endorse or promote products
  26. * derived from this software without specific written permission.
  27. * 4. This software, including modifications and/or derivative works of this
  28. * software, must execute solely and exclusively on microcontroller or
  29. * microprocessor devices manufactured by or for STMicroelectronics.
  30. * 5. Redistribution and use of this software other than as permitted under
  31. * this license is void and will automatically terminate your rights under
  32. * this license.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "gpio.h"
  51. #include "KeySlave485.h"
  52. //#include "main.h"
  53. /* USER CODE BEGIN 0 */
  54. /* USER CODE END 0 */
  55. /*----------------------------------------------------------------------------*/
  56. /* Configure GPIO */
  57. /*----------------------------------------------------------------------------*/
  58. /* USER CODE BEGIN 1 */
  59. /* USER CODE END 1 */
  60. /** Configure pins as
  61. * Analog
  62. * Input
  63. * Output
  64. * EVENT_OUT
  65. * EXTI
  66. */
  67. void MX_GPIO_Init(void)
  68. {
  69. GPIO_InitTypeDef GPIO_InitStruct = {0};
  70. /* GPIO Ports Clock Enable */
  71. __HAL_RCC_GPIOE_CLK_ENABLE();
  72. __HAL_RCC_GPIOH_CLK_ENABLE();
  73. __HAL_RCC_GPIOC_CLK_ENABLE();
  74. __HAL_RCC_GPIOA_CLK_ENABLE();
  75. __HAL_RCC_GPIOB_CLK_ENABLE();
  76. __HAL_RCC_GPIOD_CLK_ENABLE();
  77. /*Configure GPIO pin Output Level */
  78. HAL_GPIO_WritePin(GPIOE, BEEP_Pin|LED1_Pin|LED2_Pin|LED3_Pin
  79. |LED4_Pin|LED5_Pin|SPI4_FM25_NSS_Pin, GPIO_PIN_SET);
  80. /*Configure GPIO pin Output Level */
  81. HAL_GPIO_WritePin(GPIOC, DWI_Pin|EN_USART1_Pin, GPIO_PIN_RESET);
  82. /*Configure GPIO pin Output Level */
  83. HAL_GPIO_WritePin(EN_USART2_GPIO_Port, EN_USART2_Pin, GPIO_PIN_SET);
  84. /*Configure GPIO pin Output Level */
  85. HAL_GPIO_WritePin(EN_USART3_GPIO_Port, EN_USART3_Pin, GPIO_PIN_SET);
  86. /*Configure GPIO pin Output Level */
  87. HAL_GPIO_WritePin(EN_USART4_GPIO_Port, EN_USART4_Pin, GPIO_PIN_SET);
  88. /*Configure GPIO pins : PEPin PEPin PEPin PEPin
  89. PEPin PEPin PEPin */
  90. GPIO_InitStruct.Pin = BEEP_Pin|LED1_Pin|LED2_Pin|LED3_Pin
  91. |LED4_Pin|LED5_Pin|EN_USART3_Pin;
  92. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  93. GPIO_InitStruct.Pull = GPIO_NOPULL;
  94. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  95. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  96. //看门狗配置 初始化
  97. /*Configure GPIO pin : PtPin */
  98. GPIO_InitStruct.Pin = DWI_Pin;
  99. if(WATCH_DOG_ON)//打开看门狗sp706
  100. //if(1)//打开看门狗sp706
  101. {
  102. //
  103. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  104. }
  105. else
  106. {
  107. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  108. }
  109. GPIO_InitStruct.Pull = GPIO_NOPULL;
  110. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  111. HAL_GPIO_Init(DWI_GPIO_Port, &GPIO_InitStruct);
  112. /*Configure GPIO pin : PtPin */
  113. GPIO_InitStruct.Pin = EN_USART2_Pin;
  114. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  115. GPIO_InitStruct.Pull = GPIO_NOPULL;
  116. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  117. HAL_GPIO_Init(EN_USART2_GPIO_Port, &GPIO_InitStruct);
  118. /*Configure GPIO pin : PtPin */
  119. GPIO_InitStruct.Pin = SPI4_FM25_NSS_Pin;
  120. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  121. GPIO_InitStruct.Pull = GPIO_NOPULL;
  122. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  123. HAL_GPIO_Init(SPI4_FM25_NSS_GPIO_Port, &GPIO_InitStruct);
  124. /*Configure GPIO pin : PtPin */
  125. GPIO_InitStruct.Pin = EN_USART1_Pin;
  126. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  127. GPIO_InitStruct.Pull = GPIO_NOPULL;
  128. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  129. HAL_GPIO_Init(EN_USART1_GPIO_Port, &GPIO_InitStruct);
  130. /*Configure GPIO pin : PtPin */
  131. GPIO_InitStruct.Pin = EN_USART4_Pin;
  132. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  133. GPIO_InitStruct.Pull = GPIO_NOPULL;
  134. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  135. HAL_GPIO_Init(EN_USART4_GPIO_Port, &GPIO_InitStruct);
  136. /*Configure GPIO pins : PDPin PDPin PDPin PDPin */
  137. // GPIO_InitStruct.Pin = Key10_Pin|Key11_Pin|Key12_Pin|Key13_Pin;
  138. // GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  139. // GPIO_InitStruct.Pull = GPIO_PULLUP;
  140. // HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  141. /*Configure GPIO pin : PtPin */
  142. GPIO_InitStruct.Pin = Feeler_Lever_Pin;
  143. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  144. GPIO_InitStruct.Pull = GPIO_PULLUP;
  145. HAL_GPIO_Init(Feeler_Lever_GPIO_Port, &GPIO_InitStruct);
  146. /* EXTI interrupt init*/
  147. HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
  148. HAL_NVIC_EnableIRQ(EXTI0_IRQn);
  149. // HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
  150. // HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  151. }
  152. /* USER CODE BEGIN 2 */
  153. /* USER CODE END 2 */
  154. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/