main.c 8.1 KB

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