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.

213 lines
5.7 KiB

11 months ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 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. /* Private includes ----------------------------------------------------------*/
  22. /* USER CODE BEGIN Includes */
  23. #include "app_core.h"
  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. uint8_t processbuf[128];
  45. /* USER CODE END 0 */
  46. /**
  47. * @brief The application entry point.
  48. * @retval int
  49. */
  50. int main(void)
  51. {
  52. /* USER CODE BEGIN 1 */
  53. /* USER CODE END 1 */
  54. /* MCU Configuration--------------------------------------------------------*/
  55. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  56. HAL_Init();
  57. /* USER CODE BEGIN Init */
  58. /* USER CODE END Init */
  59. /* Configure the system clock */
  60. SystemClock_Config();
  61. /* USER CODE BEGIN SysInit */
  62. /* USER CODE END SysInit */
  63. /* Initialize all configured peripherals */
  64. MX_GPIO_Init();
  65. /* USER CODE BEGIN 2 */
  66. /* USER CODE END 2 */
  67. umain();
  68. /* Infinite loop */
  69. /* USER CODE BEGIN WHILE */
  70. /* USER CODE END 3 */
  71. }
  72. /**
  73. * @brief System Clock Configuration
  74. * @retval None
  75. */
  76. void SystemClock_Config(void)
  77. {
  78. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  79. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  80. /** Configure the main internal regulator output voltage
  81. */
  82. __HAL_RCC_PWR_CLK_ENABLE();
  83. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  84. /** Initializes the RCC Oscillators according to the specified parameters
  85. * in the RCC_OscInitTypeDef structure.
  86. */
  87. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  88. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  89. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  90. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  91. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  92. RCC_OscInitStruct.PLL.PLLM = 4;
  93. RCC_OscInitStruct.PLL.PLLN = 144;
  94. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV6;
  95. RCC_OscInitStruct.PLL.PLLQ = 6;
  96. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  97. {
  98. Error_Handler();
  99. }
  100. /** Initializes the CPU, AHB and APB buses clocks
  101. */
  102. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  103. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  104. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  105. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  106. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  107. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  108. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  109. {
  110. Error_Handler();
  111. }
  112. }
  113. /**
  114. * @brief GPIO Initialization Function
  115. * @param None
  116. * @retval None
  117. */
  118. static void MX_GPIO_Init(void)
  119. {
  120. GPIO_InitTypeDef GPIO_InitStruct = {0};
  121. /* USER CODE BEGIN MX_GPIO_Init_1 */
  122. /* USER CODE END MX_GPIO_Init_1 */
  123. /* GPIO Ports Clock Enable */
  124. __HAL_RCC_GPIOE_CLK_ENABLE();
  125. __HAL_RCC_GPIOC_CLK_ENABLE();
  126. __HAL_RCC_GPIOH_CLK_ENABLE();
  127. __HAL_RCC_GPIOA_CLK_ENABLE();
  128. /*Configure GPIO pin Output Level */
  129. HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
  130. /*Configure GPIO pin : PE2 */
  131. GPIO_InitStruct.Pin = GPIO_PIN_2;
  132. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  133. GPIO_InitStruct.Pull = GPIO_NOPULL;
  134. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  135. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  136. /* USER CODE BEGIN MX_GPIO_Init_2 */
  137. /* USER CODE END MX_GPIO_Init_2 */
  138. }
  139. /* USER CODE BEGIN 4 */
  140. /* USER CODE END 4 */
  141. /**
  142. * @brief This function is executed in case of error occurrence.
  143. * @retval None
  144. */
  145. void Error_Handler(void)
  146. {
  147. /* USER CODE BEGIN Error_Handler_Debug */
  148. /* User can add his own implementation to report the HAL error return state */
  149. __disable_irq();
  150. while (1)
  151. {
  152. }
  153. /* USER CODE END Error_Handler_Debug */
  154. }
  155. #ifdef USE_FULL_ASSERT
  156. /**
  157. * @brief Reports the name of the source file and the source line number
  158. * where the assert_param error has occurred.
  159. * @param file: pointer to the source file name
  160. * @param line: assert_param error line source number
  161. * @retval None
  162. */
  163. void assert_failed(uint8_t *file, uint32_t line)
  164. {
  165. /* USER CODE BEGIN 6 */
  166. /* User can add his own implementation to report the file name and line number,
  167. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  168. /* USER CODE END 6 */
  169. }
  170. #endif /* USE_FULL_ASSERT */