main.c 7.9 KB

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