Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

209 Zeilen
5.3 KiB

  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2026 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "usb_device.h"
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN PTD */
  27. /* USER CODE END PTD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN PD */
  30. /* USER CODE END PD */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN PM */
  33. /* USER CODE END PM */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* USER CODE BEGIN PV */
  36. /* USER CODE END PV */
  37. /* Private function prototypes -----------------------------------------------*/
  38. void SystemClock_Config(void);
  39. static void MX_GPIO_Init(void);
  40. /* USER CODE BEGIN PFP */
  41. /* USER CODE END PFP */
  42. /* Private user code ---------------------------------------------------------*/
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. /**
  46. * @brief The application entry point.
  47. * @retval int
  48. */
  49. int main(void)
  50. {
  51. /* USER CODE BEGIN 1 */
  52. /* USER CODE END 1 */
  53. /* MCU Configuration--------------------------------------------------------*/
  54. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  55. HAL_Init();
  56. /* USER CODE BEGIN Init */
  57. /* USER CODE END Init */
  58. /* Configure the system clock */
  59. SystemClock_Config();
  60. /* USER CODE BEGIN SysInit */
  61. /* USER CODE END SysInit */
  62. /* Initialize all configured peripherals */
  63. MX_GPIO_Init();
  64. MX_USB_DEVICE_Init();
  65. /* USER CODE BEGIN 2 */
  66. /* USER CODE END 2 */
  67. /* Infinite loop */
  68. /* USER CODE BEGIN WHILE */
  69. while (1)
  70. {
  71. /* USER CODE END WHILE */
  72. /* USER CODE BEGIN 3 */
  73. }
  74. /* USER CODE END 3 */
  75. }
  76. /**
  77. * @brief System Clock Configuration
  78. * @retval None
  79. */
  80. void SystemClock_Config(void)
  81. {
  82. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  83. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  84. /** Configure the main internal regulator output voltage
  85. */
  86. __HAL_RCC_PWR_CLK_ENABLE();
  87. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  88. /** Initializes the RCC Oscillators according to the specified parameters
  89. * in the RCC_OscInitTypeDef structure.
  90. */
  91. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  92. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  93. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  94. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  95. RCC_OscInitStruct.PLL.PLLM = 12;
  96. RCC_OscInitStruct.PLL.PLLN = 336;
  97. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  98. RCC_OscInitStruct.PLL.PLLQ = 7;
  99. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  100. {
  101. Error_Handler();
  102. }
  103. /** Initializes the CPU, AHB and APB buses clocks
  104. */
  105. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  106. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  107. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  108. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  109. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  110. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  111. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  112. {
  113. Error_Handler();
  114. }
  115. /** Enables the Clock Security System
  116. */
  117. HAL_RCC_EnableCSS();
  118. }
  119. /**
  120. * @brief GPIO Initialization Function
  121. * @param None
  122. * @retval None
  123. */
  124. static void MX_GPIO_Init(void)
  125. {
  126. /* USER CODE BEGIN MX_GPIO_Init_1 */
  127. /* USER CODE END MX_GPIO_Init_1 */
  128. /* GPIO Ports Clock Enable */
  129. __HAL_RCC_GPIOH_CLK_ENABLE();
  130. __HAL_RCC_GPIOA_CLK_ENABLE();
  131. /* USER CODE BEGIN MX_GPIO_Init_2 */
  132. /* USER CODE END MX_GPIO_Init_2 */
  133. }
  134. /* USER CODE BEGIN 4 */
  135. /* USER CODE END 4 */
  136. /**
  137. * @brief This function is executed in case of error occurrence.
  138. * @retval None
  139. */
  140. void Error_Handler(void)
  141. {
  142. /* USER CODE BEGIN Error_Handler_Debug */
  143. /* User can add his own implementation to report the HAL error return state */
  144. __disable_irq();
  145. while (1)
  146. {
  147. }
  148. /* USER CODE END Error_Handler_Debug */
  149. }
  150. #ifdef USE_FULL_ASSERT
  151. /**
  152. * @brief Reports the name of the source file and the source line number
  153. * where the assert_param error has occurred.
  154. * @param file: pointer to the source file name
  155. * @param line: assert_param error line source number
  156. * @retval None
  157. */
  158. void assert_failed(uint8_t *file, uint32_t line)
  159. {
  160. /* USER CODE BEGIN 6 */
  161. /* User can add his own implementation to report the file name and line number,
  162. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  163. /* USER CODE END 6 */
  164. }
  165. #endif /* USE_FULL_ASSERT */