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.

192 lines
5.1 KiB

2 years ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 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 "spi.h"
  22. #include "tim.h"
  23. #include "usart.h"
  24. #include "gpio.h"
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27. /* USER CODE END Includes */
  28. /* Private typedef -----------------------------------------------------------*/
  29. /* USER CODE BEGIN PTD */
  30. /* USER CODE END PTD */
  31. /* Private define ------------------------------------------------------------*/
  32. /* USER CODE BEGIN PD */
  33. /* USER CODE END PD */
  34. /* Private macro -------------------------------------------------------------*/
  35. /* USER CODE BEGIN PM */
  36. /* USER CODE END PM */
  37. /* Private variables ---------------------------------------------------------*/
  38. /* USER CODE BEGIN PV */
  39. /* USER CODE END PV */
  40. /* Private function prototypes -----------------------------------------------*/
  41. void SystemClock_Config(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_SPI1_Init();
  67. MX_TIM2_Init();
  68. MX_USART1_UART_Init();
  69. /* USER CODE BEGIN 2 */
  70. /* USER CODE END 2 */
  71. /* Infinite loop */
  72. /* USER CODE BEGIN WHILE */
  73. while (1)
  74. {
  75. /* USER CODE END WHILE */
  76. /* USER CODE BEGIN 3 */
  77. }
  78. /* USER CODE END 3 */
  79. }
  80. /**
  81. * @brief System Clock Configuration
  82. * @retval None
  83. */
  84. void SystemClock_Config(void)
  85. {
  86. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  87. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  88. /** Configure the main internal regulator output voltage
  89. */
  90. if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  91. {
  92. Error_Handler();
  93. }
  94. /** Initializes the RCC Oscillators according to the specified parameters
  95. * in the RCC_OscInitTypeDef structure.
  96. */
  97. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  98. RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  99. RCC_OscInitStruct.MSICalibrationValue = 0;
  100. RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
  101. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  102. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
  103. RCC_OscInitStruct.PLL.PLLM = 1;
  104. RCC_OscInitStruct.PLL.PLLN = 40;
  105. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
  106. RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  107. RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  108. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  109. {
  110. Error_Handler();
  111. }
  112. /** Initializes the CPU, AHB and APB buses clocks
  113. */
  114. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  115. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  116. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  117. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  118. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  119. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  120. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  121. {
  122. Error_Handler();
  123. }
  124. }
  125. /* USER CODE BEGIN 4 */
  126. /* USER CODE END 4 */
  127. /**
  128. * @brief This function is executed in case of error occurrence.
  129. * @retval None
  130. */
  131. void Error_Handler(void)
  132. {
  133. /* USER CODE BEGIN Error_Handler_Debug */
  134. /* User can add his own implementation to report the HAL error return state */
  135. __disable_irq();
  136. while (1)
  137. {
  138. }
  139. /* USER CODE END Error_Handler_Debug */
  140. }
  141. #ifdef USE_FULL_ASSERT
  142. /**
  143. * @brief Reports the name of the source file and the source line number
  144. * where the assert_param error has occurred.
  145. * @param file: pointer to the source file name
  146. * @param line: assert_param error line source number
  147. * @retval None
  148. */
  149. void assert_failed(uint8_t *file, uint32_t line)
  150. {
  151. /* USER CODE BEGIN 6 */
  152. /* User can add his own implementation to report the file name and line number,
  153. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  154. /* USER CODE END 6 */
  155. }
  156. #endif /* USE_FULL_ASSERT */