You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

245 lines
6.1 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. UART_HandleTypeDef huart1;
  36. /* USER CODE BEGIN PV */
  37. /* USER CODE END PV */
  38. /* Private function prototypes -----------------------------------------------*/
  39. void SystemClock_Config(void);
  40. static void MX_GPIO_Init(void);
  41. static void MX_USART1_UART_Init(void);
  42. /* USER CODE BEGIN PFP */
  43. /* USER CODE END PFP */
  44. /* Private user code ---------------------------------------------------------*/
  45. /* USER CODE BEGIN 0 */
  46. /* USER CODE END 0 */
  47. /**
  48. * @brief The application entry point.
  49. * @retval int
  50. */
  51. int main(void)
  52. {
  53. /* USER CODE BEGIN 1 */
  54. /* USER CODE END 1 */
  55. /* MCU Configuration--------------------------------------------------------*/
  56. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  57. HAL_Init();
  58. /* USER CODE BEGIN Init */
  59. /* USER CODE END Init */
  60. /* Configure the system clock */
  61. SystemClock_Config();
  62. /* USER CODE BEGIN SysInit */
  63. /* USER CODE END SysInit */
  64. /* Initialize all configured peripherals */
  65. MX_GPIO_Init();
  66. MX_USB_DEVICE_Init();
  67. MX_USART1_UART_Init();
  68. /* USER CODE BEGIN 2 */
  69. /* USER CODE END 2 */
  70. /* Infinite loop */
  71. /* USER CODE BEGIN WHILE */
  72. while (1)
  73. {
  74. /* USER CODE END WHILE */
  75. /* USER CODE BEGIN 3 */
  76. }
  77. /* USER CODE END 3 */
  78. }
  79. /**
  80. * @brief System Clock Configuration
  81. * @retval None
  82. */
  83. void SystemClock_Config(void)
  84. {
  85. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  86. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  87. /** Configure the main internal regulator output voltage
  88. */
  89. __HAL_RCC_PWR_CLK_ENABLE();
  90. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  91. /** Initializes the RCC Oscillators according to the specified parameters
  92. * in the RCC_OscInitTypeDef structure.
  93. */
  94. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  95. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  96. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  97. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  98. RCC_OscInitStruct.PLL.PLLM = 12;
  99. RCC_OscInitStruct.PLL.PLLN = 336;
  100. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  101. RCC_OscInitStruct.PLL.PLLQ = 7;
  102. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  103. {
  104. Error_Handler();
  105. }
  106. /** Initializes the CPU, AHB and APB buses clocks
  107. */
  108. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  109. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  110. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  111. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  112. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  113. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  114. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  115. {
  116. Error_Handler();
  117. }
  118. /** Enables the Clock Security System
  119. */
  120. HAL_RCC_EnableCSS();
  121. }
  122. /**
  123. * @brief USART1 Initialization Function
  124. * @param None
  125. * @retval None
  126. */
  127. static void MX_USART1_UART_Init(void)
  128. {
  129. /* USER CODE BEGIN USART1_Init 0 */
  130. /* USER CODE END USART1_Init 0 */
  131. /* USER CODE BEGIN USART1_Init 1 */
  132. /* USER CODE END USART1_Init 1 */
  133. huart1.Instance = USART1;
  134. huart1.Init.BaudRate = 115200;
  135. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  136. huart1.Init.StopBits = UART_STOPBITS_1;
  137. huart1.Init.Parity = UART_PARITY_EVEN;
  138. huart1.Init.Mode = UART_MODE_TX_RX;
  139. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  140. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  141. if (HAL_UART_Init(&huart1) != HAL_OK)
  142. {
  143. Error_Handler();
  144. }
  145. /* USER CODE BEGIN USART1_Init 2 */
  146. /* USER CODE END USART1_Init 2 */
  147. }
  148. /**
  149. * @brief GPIO Initialization Function
  150. * @param None
  151. * @retval None
  152. */
  153. static void MX_GPIO_Init(void)
  154. {
  155. /* USER CODE BEGIN MX_GPIO_Init_1 */
  156. /* USER CODE END MX_GPIO_Init_1 */
  157. /* GPIO Ports Clock Enable */
  158. __HAL_RCC_GPIOH_CLK_ENABLE();
  159. __HAL_RCC_GPIOA_CLK_ENABLE();
  160. /* USER CODE BEGIN MX_GPIO_Init_2 */
  161. /* USER CODE END MX_GPIO_Init_2 */
  162. }
  163. /* USER CODE BEGIN 4 */
  164. /* USER CODE END 4 */
  165. /**
  166. * @brief This function is executed in case of error occurrence.
  167. * @retval None
  168. */
  169. void Error_Handler(void)
  170. {
  171. /* USER CODE BEGIN Error_Handler_Debug */
  172. /* User can add his own implementation to report the HAL error return state */
  173. __disable_irq();
  174. while (1)
  175. {
  176. }
  177. /* USER CODE END Error_Handler_Debug */
  178. }
  179. #ifdef USE_FULL_ASSERT
  180. /**
  181. * @brief Reports the name of the source file and the source line number
  182. * where the assert_param error has occurred.
  183. * @param file: pointer to the source file name
  184. * @param line: assert_param error line source number
  185. * @retval None
  186. */
  187. void assert_failed(uint8_t *file, uint32_t line)
  188. {
  189. /* USER CODE BEGIN 6 */
  190. /* User can add his own implementation to report the file name and line number,
  191. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  192. /* USER CODE END 6 */
  193. }
  194. #endif /* USE_FULL_ASSERT */