main.c 8.1 KB

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