main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/* Private includes ----------------------------------------------------------*/
  21. /* USER CODE BEGIN Includes */
  22. /* USER CODE END Includes */
  23. /* Private typedef -----------------------------------------------------------*/
  24. /* USER CODE BEGIN PTD */
  25. /* USER CODE END PTD */
  26. /* Private define ------------------------------------------------------------*/
  27. /* USER CODE BEGIN PD */
  28. /* USER CODE END PD */
  29. /* Private macro -------------------------------------------------------------*/
  30. /* USER CODE BEGIN PM */
  31. /* USER CODE END PM */
  32. /* Private variables ---------------------------------------------------------*/
  33. /* USER CODE BEGIN PV */
  34. /* USER CODE END PV */
  35. /* Private function prototypes -----------------------------------------------*/
  36. void SystemClock_Config(void);
  37. /* USER CODE BEGIN PFP */
  38. /* USER CODE END PFP */
  39. /* Private user code ---------------------------------------------------------*/
  40. /* USER CODE BEGIN 0 */
  41. /* USER CODE END 0 */
  42. /**
  43. * @brief The application entry point.
  44. * @retval int
  45. */
  46. int main(void)
  47. {
  48. /* USER CODE BEGIN 1 */
  49. /* USER CODE END 1 */
  50. /* MCU Configuration--------------------------------------------------------*/
  51. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  52. HAL_Init();
  53. /* USER CODE BEGIN Init */
  54. /* USER CODE END Init */
  55. /* Configure the system clock */
  56. SystemClock_Config();
  57. /* USER CODE BEGIN SysInit */
  58. /* USER CODE END SysInit */
  59. /* Initialize all configured peripherals */
  60. /* USER CODE BEGIN 2 */
  61. /* USER CODE END 2 */
  62. /* Infinite loop */
  63. /* USER CODE BEGIN WHILE */
  64. while (1)
  65. {
  66. /* USER CODE END WHILE */
  67. /* USER CODE BEGIN 3 */
  68. }
  69. /* USER CODE END 3 */
  70. }
  71. /**
  72. * @brief System Clock Configuration
  73. * @retval None
  74. */
  75. void SystemClock_Config(void)
  76. {
  77. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  78. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  79. /** Configure the main internal regulator output voltage
  80. */
  81. __HAL_RCC_PWR_CLK_ENABLE();
  82. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  83. /** Initializes the RCC Oscillators according to the specified parameters
  84. * in the RCC_OscInitTypeDef structure.
  85. */
  86. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  87. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  88. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  89. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  90. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  91. {
  92. Error_Handler();
  93. }
  94. /** Initializes the CPU, AHB and APB buses clocks
  95. */
  96. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  97. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  98. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  99. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  100. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  101. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  102. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  103. {
  104. Error_Handler();
  105. }
  106. }
  107. /* USER CODE BEGIN 4 */
  108. /* USER CODE END 4 */
  109. /**
  110. * @brief This function is executed in case of error occurrence.
  111. * @retval None
  112. */
  113. void Error_Handler(void)
  114. {
  115. /* USER CODE BEGIN Error_Handler_Debug */
  116. /* User can add his own implementation to report the HAL error return state */
  117. __disable_irq();
  118. while (1)
  119. {
  120. }
  121. /* USER CODE END Error_Handler_Debug */
  122. }
  123. #ifdef USE_FULL_ASSERT
  124. /**
  125. * @brief Reports the name of the source file and the source line number
  126. * where the assert_param error has occurred.
  127. * @param file: pointer to the source file name
  128. * @param line: assert_param error line source number
  129. * @retval None
  130. */
  131. void assert_failed(uint8_t *file, uint32_t line)
  132. {
  133. /* USER CODE BEGIN 6 */
  134. /* User can add his own implementation to report the file name and line number,
  135. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  136. /* USER CODE END 6 */
  137. }
  138. #endif /* USE_FULL_ASSERT */