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.5 KiB

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