main.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2025 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 "tim.h"
  25. #include "usart.h"
  26. #include "gpio.h"
  27. #include "stdbool.h"
  28. /* Private includes ----------------------------------------------------------*/
  29. /* USER CODE BEGIN Includes */
  30. #include "soft_can.h"
  31. #include "soft_uart.h"
  32. #include "soft_adc.h"
  33. #include "soft_flow.h"
  34. #include "hard_led.h"
  35. #include "soft_timer.h"
  36. #include "soft_test.h"
  37. #include "soft_bms.h"
  38. #include "soft_okcell.h"
  39. #include "soft_tattu.h"
  40. #include "soft_poweramp.h"
  41. #include "soft_obstacle.h"
  42. #include "soft_p_2_c.h"
  43. #include "soft_terrain.h"
  44. #include "string.h"
  45. #include "soft_engine.h"
  46. #include "soft_calibration.h"
  47. #include "soft_eft.h"
  48. #include "soft_flash.h"
  49. #include "soft_seed_device.h"
  50. #include "soft_flow.h"
  51. #include "soft_version.h"
  52. #include "config.h"
  53. #include "math.h"
  54. #include "stdio.h"
  55. #include "soft_update.h"
  56. #include "can_debug.h"
  57. /* USER CODE END Includes */
  58. /* Private typedef -----------------------------------------------------------*/
  59. /* USER CODE BEGIN PTD */
  60. /* USER CODE END PTD */
  61. /* Private define ------------------------------------------------------------*/
  62. /* USER CODE BEGIN PD */
  63. /* USER CODE END PD */
  64. /* Private macro -------------------------------------------------------------*/
  65. /* USER CODE BEGIN PM */
  66. /* USER CODE END PM */
  67. /* Private variables ---------------------------------------------------------*/
  68. /* USER CODE BEGIN PV */
  69. /* USER CODE END PV */
  70. /* Private function prototypes -----------------------------------------------*/
  71. void SystemClock_Config(void);
  72. /* USER CODE BEGIN PFP */
  73. /* USER CODE END PFP */
  74. /* Private user code ---------------------------------------------------------*/
  75. /* USER CODE BEGIN 0 */
  76. /* USER CODE END 0 */
  77. /**
  78. * @brief The application entry point.
  79. * @retval int
  80. */
  81. int main(void)
  82. {
  83. /* USER CODE BEGIN 1 */
  84. SCB->VTOR = FLASH_BASE | 0x8007800; //偏移
  85. /* USER CODE END 1 */
  86. /* MCU Configuration--------------------------------------------------------*/
  87. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  88. HAL_Init();
  89. /* USER CODE BEGIN Init */
  90. /* USER CODE END Init */
  91. /* Configure the system clock */
  92. SystemClock_Config();
  93. /* USER CODE BEGIN SysInit */
  94. /* USER CODE END SysInit */
  95. /* Initialize all configured peripherals */
  96. MX_GPIO_Init();
  97. MX_DMA_Init();
  98. MX_CAN_Init();
  99. MX_USART2_UART_Init();
  100. MX_USART3_UART_Init();
  101. MX_ADC1_Init();
  102. MX_TIM2_Init();
  103. MX_TIM3_Init();
  104. MX_TIM4_Init();
  105. /* USER CODE BEGIN 2 */
  106. user_init();
  107. //cm_backtrace_init("CmBacktrace", HARDWARE_VERSION, SOFTWARE_VERSION);
  108. //获取时钟频率
  109. uint32_t Freq = 0;
  110. Freq = HAL_RCC_GetSysClockFreq();//72M
  111. (void)Freq;
  112. /* USER CODE END 2 */
  113. /* Infinite loop */
  114. /* USER CODE BEGIN WHILE */
  115. while (1)
  116. {
  117. /* USER CODE END WHILE */
  118. //点亮pmu内部led灯
  119. pmu_inside_led();
  120. //AD电压50HZ采集
  121. adc_gather_hz();
  122. // //PMU向飞控定时发送数据 定时器
  123. timer_function();
  124. // //uart2发送数据给主控制器 雷达升级不发送数据
  125. pmu_to_fcu();
  126. //UART2 接收主控制器数据
  127. uart_recv_con_msg();
  128. //刚上电需要发送的信息
  129. pmu_start_info();
  130. //更新播撒,称重,水泵,离心喷头,流量计等设备信息
  131. update_device_type_data();
  132. DM_obs_test();
  133. //获取外设版本和SN号
  134. get_device_version_and_sn();
  135. //写flash相关功能
  136. flash_write_pmu_par();
  137. //雷达相关功能
  138. lidar_function();
  139. //外部LED灯循环
  140. led_blink_repeat();
  141. //发动机相关功能
  142. engine_function();
  143. //智能电池相关功能
  144. bms_function();
  145. //流量计相关功能
  146. flow_function();
  147. //液位计相关功能
  148. L1L2_GPIO_check();
  149. #ifdef mimo_update
  150. mimo_obs_update_func();
  151. #else
  152. //设备升级
  153. Vk_Update_Device_Protocol();
  154. #endif
  155. send_uartfifo_msg();
  156. //CAN DEBUG
  157. if(planep.Candebug_flag == true)
  158. {
  159. seek_can_debug_buf_adr();
  160. }
  161. /* USER CODE BEGIN 3 */
  162. }
  163. /* USER CODE END 3 */
  164. }
  165. /**
  166. * @brief System Clock Configuration
  167. * @retval None
  168. */
  169. void SystemClock_Config(void)
  170. {
  171. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  172. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  173. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  174. /** Initializes the RCC Oscillators according to the specified parameters
  175. * in the RCC_OscInitTypeDef structure.
  176. */
  177. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  178. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  179. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  180. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  181. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  182. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  183. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  184. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  185. {
  186. Error_Handler();
  187. }
  188. /** Initializes the CPU, AHB and APB buses clocks
  189. */
  190. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  191. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  192. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  193. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  194. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  195. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  196. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  197. {
  198. Error_Handler();
  199. }
  200. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_USART3
  201. |RCC_PERIPHCLK_ADC12;
  202. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  203. PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
  204. PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1;
  205. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  206. {
  207. Error_Handler();
  208. }
  209. }
  210. /* USER CODE BEGIN 4 */
  211. /* USER CODE END 4 */
  212. /**
  213. * @brief Period elapsed callback in non blocking mode
  214. * @note This function is called when TIM1 interrupt took place, inside
  215. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  216. * a global variable "uwTick" used as application time base.
  217. * @param htim : TIM handle
  218. * @retval None
  219. */
  220. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  221. {
  222. /* USER CODE BEGIN Callback 0 */
  223. /* USER CODE END Callback 0 */
  224. if (htim->Instance == TIM1)
  225. {
  226. HAL_IncTick();
  227. }
  228. /* USER CODE BEGIN Callback 1 */
  229. /* USER CODE END Callback 1 */
  230. }
  231. /**
  232. * @brief This function is executed in case of error occurrence.
  233. * @retval None
  234. */
  235. void Error_Handler(void)
  236. {
  237. /* USER CODE BEGIN Error_Handler_Debug */
  238. /* User can add his own implementation to report the HAL error return state */
  239. __disable_irq();
  240. while (1)
  241. {
  242. }
  243. /* USER CODE END Error_Handler_Debug */
  244. }
  245. #ifdef USE_FULL_ASSERT
  246. /**
  247. * @brief Reports the name of the source file and the source line number
  248. * where the assert_param error has occurred.
  249. * @param file: pointer to the source file name
  250. * @param line: assert_param error line source number
  251. * @retval None
  252. */
  253. void assert_failed(uint8_t *file, uint32_t line)
  254. {
  255. /* USER CODE BEGIN 6 */
  256. /* User can add his own implementation to report the file name and line number,
  257. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  258. /* USER CODE END 6 */
  259. }
  260. #endif /* USE_FULL_ASSERT */