main.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "adc.h"
  23. #include "can.h"
  24. #include "dma.h"
  25. #include "tim.h"
  26. #include "usart.h"
  27. #include "gpio.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 | 0x2800; //偏移
  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_ADC1_Init();
  99. MX_CAN_Init();
  100. MX_TIM2_Init();
  101. MX_TIM3_Init();
  102. MX_TIM4_Init();
  103. MX_USART3_UART_Init();
  104. MX_USART2_UART_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. //点亮pmu内部led灯
  117. pmu_inside_led();
  118. //AD电压50HZ采集
  119. adc_gather_hz();
  120. //PMU向飞控定时发送数据 定时器
  121. timer_function();
  122. //uart2发送数据给主控制器 雷达升级不发送数据
  123. pmu_to_fcu();
  124. //UART2 接收主控制器数据
  125. uart_recv_con_msg();
  126. //刚上电需要发送的信息
  127. pmu_start_info();
  128. //更新播撒,称重,水泵,离心喷头,流量计等设备信息
  129. update_device_type_data();
  130. //debug test
  131. #ifdef Debug_Mode
  132. #else
  133. //获取外设版本和SN号
  134. get_device_version_and_sn();
  135. //写flash相关功能
  136. write_flash_function();
  137. //读flash相关功能
  138. read_flash_function();
  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. send_uartfifo_msg();
  158. //CAN DEBUG
  159. if(planep.Candebug_flag == true)
  160. {
  161. seek_can_debug_buf_adr();
  162. }
  163. #endif
  164. /* USER CODE END WHILE */
  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 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  195. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  196. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  197. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  198. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  199. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  200. {
  201. Error_Handler();
  202. }
  203. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  204. PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  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. /* USER CODE END Error_Handler_Debug */
  240. }
  241. #ifdef USE_FULL_ASSERT
  242. /**
  243. * @brief Reports the name of the source file and the source line number
  244. * where the assert_param error has occurred.
  245. * @param file: pointer to the source file name
  246. * @param line: assert_param error line source number
  247. * @retval None
  248. */
  249. void assert_failed(uint8_t *file, uint32_t line)
  250. {
  251. /* USER CODE BEGIN 6 */
  252. /* User can add his own implementation to report the file name and line number,
  253. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  254. /* USER CODE END 6 */
  255. }
  256. #endif /* USE_FULL_ASSERT */
  257. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/