gpio.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file gpio.c
  5. * @brief This file provides code for the configuration
  6. * of all used GPIO pins.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2025 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "gpio.h"
  22. /* USER CODE BEGIN 0 */
  23. /* USER CODE END 0 */
  24. /*----------------------------------------------------------------------------*/
  25. /* Configure GPIO */
  26. /*----------------------------------------------------------------------------*/
  27. /* USER CODE BEGIN 1 */
  28. /* USER CODE END 1 */
  29. /** Configure pins as
  30. * Analog
  31. * Input
  32. * Output
  33. * EVENT_OUT
  34. * EXTI
  35. * Free pins are configured automatically as Analog (this feature is enabled through
  36. * the Code Generation settings)
  37. */
  38. void MX_GPIO_Init(void)
  39. {
  40. GPIO_InitTypeDef GPIO_InitStruct = {0};
  41. /* GPIO Ports Clock Enable */
  42. __HAL_RCC_GPIOC_CLK_ENABLE();
  43. __HAL_RCC_GPIOF_CLK_ENABLE();
  44. __HAL_RCC_GPIOA_CLK_ENABLE();
  45. __HAL_RCC_GPIOB_CLK_ENABLE();
  46. /*Configure GPIO pin Output Level */
  47. HAL_GPIO_WritePin(GPIOA, LED1_Pin|LED2_Pin|LED3_Pin|LED4_Pin
  48. |CAN_SLIENT_Pin, GPIO_PIN_SET);
  49. /*Configure GPIO pin Output Level */
  50. HAL_GPIO_WritePin(GPIOB, LED_R_Pin|LED_G_Pin|LED_B_Pin|GPIO_PIN_14, GPIO_PIN_RESET);
  51. /*Configure GPIO pins : PC13 PC14 PC15 */
  52. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  53. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  54. GPIO_InitStruct.Pull = GPIO_NOPULL;
  55. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  56. /*Configure GPIO pins : PA1 PA9 PA10 */
  57. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_9|GPIO_PIN_10;
  58. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  59. GPIO_InitStruct.Pull = GPIO_NOPULL;
  60. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  61. /*Configure GPIO pins : LED1_Pin LED2_Pin LED3_Pin LED4_Pin
  62. CAN_SLIENT_Pin */
  63. GPIO_InitStruct.Pin = LED1_Pin|LED3_Pin
  64. |CAN_SLIENT_Pin;
  65. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  66. GPIO_InitStruct.Pull = GPIO_NOPULL;
  67. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  68. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  69. GPIO_InitStruct.Pin = LED2_Pin;
  70. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  71. GPIO_InitStruct.Pull = GPIO_NOPULL;
  72. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  73. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  74. /*Configure GPIO pins : LED_R_Pin LED_G_Pin LED_B_Pin PB15 */
  75. GPIO_InitStruct.Pin = LED_R_Pin|LED_G_Pin|LED_B_Pin;
  76. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  77. GPIO_InitStruct.Pull = GPIO_NOPULL;
  78. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  79. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  80. GPIO_InitStruct.Pin = GPIO_PIN_14;
  81. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  82. GPIO_InitStruct.Pull = GPIO_PULLUP;
  83. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  84. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  85. /*Configure GPIO pins : PB12 PB13 PB14 */
  86. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13;
  87. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  88. GPIO_InitStruct.Pull = GPIO_NOPULL;
  89. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  90. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  91. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  92. GPIO_InitStruct.Pull = GPIO_PULLUP;
  93. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  94. }
  95. /* USER CODE BEGIN 2 */
  96. void init_gpio(uint8_t uav_type)
  97. {
  98. if(uav_type == 18)
  99. {
  100. GPIO_InitTypeDef GPIO_InitStruct = {0};
  101. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  102. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  103. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  104. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  105. }
  106. }
  107. /* USER CODE END 2 */