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.

201 lines
5.2 KiB

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