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.

187 lines
5.1 KiB

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) 2022 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_TIM1_Init();
  69. MX_TIM2_Init();
  70. MX_USART1_UART_Init();
  71. MX_USART2_UART_Init();
  72. MX_TIM4_Init();
  73. /* USER CODE BEGIN 2 */
  74. extern void user_main();
  75. user_main();
  76. /* USER CODE END 2 */
  77. /* Infinite loop */
  78. /* USER CODE BEGIN WHILE */
  79. while (1)
  80. {
  81. /* USER CODE END WHILE */
  82. /* USER CODE BEGIN 3 */
  83. }
  84. /* USER CODE END 3 */
  85. }
  86. /**
  87. * @brief System Clock Configuration
  88. * @retval None
  89. */
  90. void SystemClock_Config(void)
  91. {
  92. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  93. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  94. /** Initializes the RCC Oscillators according to the specified parameters
  95. * in the RCC_OscInitTypeDef structure.
  96. */
  97. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  98. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  99. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  100. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  101. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  102. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  103. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  104. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  105. {
  106. Error_Handler();
  107. }
  108. /** Initializes the CPU, AHB and APB buses clocks
  109. */
  110. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  111. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  112. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  113. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  114. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  115. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  116. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  117. {
  118. Error_Handler();
  119. }
  120. }
  121. /* USER CODE BEGIN 4 */
  122. /* USER CODE END 4 */
  123. /**
  124. * @brief This function is executed in case of error occurrence.
  125. * @retval None
  126. */
  127. void Error_Handler(void)
  128. {
  129. /* USER CODE BEGIN Error_Handler_Debug */
  130. /* User can add his own implementation to report the HAL error return state */
  131. __disable_irq();
  132. while (1)
  133. {
  134. }
  135. /* USER CODE END Error_Handler_Debug */
  136. }
  137. #ifdef USE_FULL_ASSERT
  138. /**
  139. * @brief Reports the name of the source file and the source line number
  140. * where the assert_param error has occurred.
  141. * @param file: pointer to the source file name
  142. * @param line: assert_param error line source number
  143. * @retval None
  144. */
  145. void assert_failed(uint8_t *file, uint32_t line)
  146. {
  147. /* USER CODE BEGIN 6 */
  148. /* User can add his own implementation to report the file name and line number,
  149. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  150. /* USER CODE END 6 */
  151. }
  152. #endif /* USE_FULL_ASSERT */
  153. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/