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.

190 lines
5.1 KiB

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