main.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.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. /* USER CODE BEGIN PFP */
  40. /* USER CODE END PFP */
  41. /* Private user code ---------------------------------------------------------*/
  42. /* USER CODE BEGIN 0 */
  43. /* USER CODE END 0 */
  44. /**
  45. * @brief The application entry point.
  46. * @retval int
  47. */
  48. int main(void)
  49. {
  50. /* USER CODE BEGIN 1 */
  51. /* USER CODE END 1 */
  52. /* MCU Configuration--------------------------------------------------------*/
  53. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  54. HAL_Init();
  55. /* USER CODE BEGIN Init */
  56. /* USER CODE END Init */
  57. /* Configure the system clock */
  58. SystemClock_Config();
  59. /* USER CODE BEGIN SysInit */
  60. /* USER CODE END SysInit */
  61. /* Initialize all configured peripherals */
  62. /* USER CODE BEGIN 2 */
  63. /* USER CODE END 2 */
  64. /* Infinite loop */
  65. /* USER CODE BEGIN WHILE */
  66. while (1)
  67. {
  68. /* USER CODE END WHILE */
  69. /* USER CODE BEGIN 3 */
  70. }
  71. /* USER CODE END 3 */
  72. }
  73. /**
  74. * @brief System Clock Configuration
  75. * @retval None
  76. */
  77. void SystemClock_Config(void)
  78. {
  79. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  80. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  81. /** Configure the main internal regulator output voltage
  82. */
  83. if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2) != HAL_OK)
  84. {
  85. Error_Handler();
  86. }
  87. /** Initializes the RCC Oscillators according to the specified parameters
  88. * in the RCC_OscInitTypeDef structure.
  89. */
  90. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  91. RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  92. RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
  93. RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
  94. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  95. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  96. {
  97. Error_Handler();
  98. }
  99. /** Initializes the CPU, AHB and APB buses clocks
  100. */
  101. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  102. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  103. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  104. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  105. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  106. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  107. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  108. {
  109. Error_Handler();
  110. }
  111. }
  112. /* USER CODE BEGIN 4 */
  113. /* USER CODE END 4 */
  114. /**
  115. * @brief This function is executed in case of error occurrence.
  116. * @retval None
  117. */
  118. void Error_Handler(void)
  119. {
  120. /* USER CODE BEGIN Error_Handler_Debug */
  121. /* User can add his own implementation to report the HAL error return state */
  122. __disable_irq();
  123. while (1)
  124. {
  125. }
  126. /* USER CODE END Error_Handler_Debug */
  127. }
  128. #ifdef USE_FULL_ASSERT
  129. /**
  130. * @brief Reports the name of the source file and the source line number
  131. * where the assert_param error has occurred.
  132. * @param file: pointer to the source file name
  133. * @param line: assert_param error line source number
  134. * @retval None
  135. */
  136. void assert_failed(uint8_t *file, uint32_t line)
  137. {
  138. /* USER CODE BEGIN 6 */
  139. /* User can add his own implementation to report the file name and line number,
  140. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  141. /* USER CODE END 6 */
  142. }
  143. #endif /* USE_FULL_ASSERT */
  144. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/