main.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 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 "cmsis_os.h"
  22. #include "can.h"
  23. #include "dma.h"
  24. #include "rtc.h"
  25. #include "spi.h"
  26. #include "tim.h"
  27. #include "usart.h"
  28. #include "gpio.h"
  29. /* Private includes ----------------------------------------------------------*/
  30. /* USER CODE BEGIN Includes */
  31. /* USER CODE END Includes */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* USER CODE BEGIN PTD */
  34. /* USER CODE END PTD */
  35. /* Private define ------------------------------------------------------------*/
  36. /* USER CODE BEGIN PD */
  37. /* USER CODE END PD */
  38. /* Private macro -------------------------------------------------------------*/
  39. /* USER CODE BEGIN PM */
  40. /* USER CODE END PM */
  41. /* Private variables ---------------------------------------------------------*/
  42. /* USER CODE BEGIN PV */
  43. uint16_t connectedDev[4];
  44. bool startdtu=false;
  45. extern Menu_table menu;
  46. extern bool BT_CONN;
  47. extern bool refresh;
  48. /* USER CODE END PV */
  49. /* Private function prototypes -----------------------------------------------*/
  50. void SystemClock_Config(void);
  51. void MX_FREERTOS_Init(void);
  52. /* USER CODE BEGIN PFP */
  53. /* USER CODE END PFP */
  54. /* Private user code ---------------------------------------------------------*/
  55. /* USER CODE BEGIN 0 */
  56. /* USER CODE END 0 */
  57. /**
  58. * @brief The application entry point.
  59. * @retval int
  60. */
  61. int main(void)
  62. {
  63. /* USER CODE BEGIN 1 */
  64. /* USER CODE END 1 */
  65. /* MCU Configuration--------------------------------------------------------*/
  66. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  67. HAL_Init();
  68. /* USER CODE BEGIN Init */
  69. /* USER CODE END Init */
  70. /* Configure the system clock */
  71. SystemClock_Config();
  72. /* USER CODE BEGIN SysInit */
  73. /* USER CODE END SysInit */
  74. /* Initialize all configured peripherals */
  75. MX_GPIO_Init();
  76. MX_DMA_Init();
  77. MX_SPI1_Init();
  78. MX_TIM2_Init();
  79. MX_TIM3_Init();
  80. MX_USART1_UART_Init();
  81. MX_USART2_UART_Init();
  82. MX_USART3_UART_Init();
  83. MX_UART4_Init();
  84. MX_UART5_Init();
  85. MX_SPI2_Init();
  86. MX_CAN_Init();
  87. MX_RTC_Init();
  88. /* USER CODE BEGIN 2 */
  89. #ifdef timHand
  90. #if timHand == 1
  91. TIM2_IT_EN()
  92. TIM3_IT_EN()
  93. #endif
  94. #endif
  95. #ifdef oledOpen
  96. #if oledOpen == 1
  97. OLED_INIT_EN();
  98. OLED_COLOR_EN();
  99. OLED_DISPLAY_EN();
  100. //dtustart();
  101. #endif
  102. #endif
  103. #ifdef uartHand
  104. //UART_DMA_1_EN(recvBuff)
  105. //UART_DMA_2_EN(recvBuff)
  106. //UART_DMA_3_EN(recvBuff)
  107. #ifdef init_4G
  108. #if init_4G == 1
  109. UART_DMA_4_EN(recvBuff)
  110. #endif
  111. #endif
  112. #ifdef init_BT
  113. #if init_BT == 1
  114. UART_IT_5_EN(g_MBA32A_8buf)
  115. #endif
  116. #endif
  117. #endif
  118. #ifdef respects
  119. #if respects == 1
  120. HELLO()
  121. #endif
  122. #endif
  123. #ifdef init_4G
  124. #if init_4G == 1
  125. ML307A_Init();
  126. #endif
  127. #endif
  128. #ifdef init_BT
  129. #if init_BT == 1
  130. startdtu=true;
  131. execute_function(menu);
  132. OLED_Refresh();
  133. MBA32A_Init();
  134. #endif
  135. #endif
  136. /* USER CODE END 2 */
  137. /* Call init function for freertos objects (in freertos.c) */
  138. MX_FREERTOS_Init();
  139. /* Start scheduler */
  140. osKernelStart();
  141. /* We should never get here as control is now taken by the scheduler */
  142. /* Infinite loop */
  143. /* USER CODE BEGIN WHILE */
  144. while (1)
  145. {
  146. /* USER CODE END WHILE */
  147. /* USER CODE BEGIN 3 */
  148. }
  149. /* USER CODE END 3 */
  150. }
  151. /**
  152. * @brief System Clock Configuration
  153. * @retval None
  154. */
  155. void SystemClock_Config(void)
  156. {
  157. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  158. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  159. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  160. /** Initializes the RCC Oscillators according to the specified parameters
  161. * in the RCC_OscInitTypeDef structure.
  162. */
  163. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  164. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  165. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  166. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  167. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  168. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  169. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  170. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  171. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  172. {
  173. Error_Handler();
  174. }
  175. /** Initializes the CPU, AHB and APB buses clocks
  176. */
  177. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  178. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  179. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  180. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  181. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  182. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  183. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  184. {
  185. Error_Handler();
  186. }
  187. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  188. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  189. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  190. {
  191. Error_Handler();
  192. }
  193. }
  194. /* USER CODE BEGIN 4 */
  195. /* USER CODE END 4 */
  196. /**
  197. * @brief Period elapsed callback in non blocking mode
  198. * @note This function is called when TIM1 interrupt took place, inside
  199. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  200. * a global variable "uwTick" used as application time base.
  201. * @param htim : TIM handle
  202. * @retval None
  203. */
  204. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  205. {
  206. /* USER CODE BEGIN Callback 0 */
  207. /* USER CODE END Callback 0 */
  208. if (htim->Instance == TIM1) {
  209. HAL_IncTick();
  210. }
  211. /* USER CODE BEGIN Callback 1 */
  212. #ifdef WDI_EN
  213. #if WDI_EN == 1
  214. if (htim->Instance == TIM2)
  215. {
  216. HAL_GPIO_TogglePin(WDI_GPIO_Port, WDI_Pin);
  217. //printf("not WEIGOU\r\n");
  218. }
  219. #endif
  220. #endif
  221. /* USER CODE END Callback 1 */
  222. }
  223. /**
  224. * @brief This function is executed in case of error occurrence.
  225. * @retval None
  226. */
  227. void Error_Handler(void)
  228. {
  229. /* USER CODE BEGIN Error_Handler_Debug */
  230. /* User can add his own implementation to report the HAL error return state */
  231. __disable_irq();
  232. while (1)
  233. {
  234. }
  235. /* USER CODE END Error_Handler_Debug */
  236. }
  237. #ifdef USE_FULL_ASSERT
  238. /**
  239. * @brief Reports the name of the source file and the source line number
  240. * where the assert_param error has occurred.
  241. * @param file: pointer to the source file name
  242. * @param line: assert_param error line source number
  243. * @retval None
  244. */
  245. void assert_failed(uint8_t *file, uint32_t line)
  246. {
  247. /* USER CODE BEGIN 6 */
  248. /* User can add his own implementation to report the file name and line number,
  249. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  250. /* USER CODE END 6 */
  251. }
  252. #endif /* USE_FULL_ASSERT */