main.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. extern Menu_table menu;
  41. extern bool refresh;
  42. /* USER CODE END PM */
  43. /* Private variables ---------------------------------------------------------*/
  44. /* USER CODE BEGIN PV */
  45. uint8_t recvBuff[2048];
  46. /* USER CODE END PV */
  47. /* Private function prototypes -----------------------------------------------*/
  48. void SystemClock_Config(void);
  49. void MX_FREERTOS_Init(void);
  50. /* USER CODE BEGIN PFP */
  51. /* USER CODE END PFP */
  52. /* Private user code ---------------------------------------------------------*/
  53. /* USER CODE BEGIN 0 */
  54. /* USER CODE END 0 */
  55. /**
  56. * @brief The application entry point.
  57. * @retval int
  58. */
  59. int main(void)
  60. {
  61. /* USER CODE BEGIN 1 */
  62. /* USER CODE END 1 */
  63. /* MCU Configuration--------------------------------------------------------*/
  64. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  65. HAL_Init();
  66. /* USER CODE BEGIN Init */
  67. /* USER CODE END Init */
  68. /* Configure the system clock */
  69. SystemClock_Config();
  70. /* USER CODE BEGIN SysInit */
  71. /* USER CODE END SysInit */
  72. /* Initialize all configured peripherals */
  73. MX_GPIO_Init();
  74. MX_DMA_Init();
  75. MX_SPI1_Init();
  76. MX_TIM2_Init();
  77. MX_TIM3_Init();
  78. MX_USART1_UART_Init();
  79. MX_USART2_UART_Init();
  80. MX_USART3_UART_Init();
  81. MX_UART4_Init();
  82. MX_UART5_Init();
  83. MX_SPI2_Init();
  84. MX_CAN_Init();
  85. MX_RTC_Init();
  86. /* USER CODE BEGIN 2 */
  87. TIM_Start(&htim2); //wdi
  88. TIM_Start(&htim3); //led
  89. OLED_DISPLAY(0,0); //color>1 反色;display>1 翻转
  90. RXNE_UART(&huart5); //开启蓝牙串口中断
  91. HELLO("\r\t\tDtuStart...");
  92. #if Test_old ==1
  93. MBA32A_Init_demo();
  94. #else
  95. MBA32A_Init();
  96. #endif
  97. /* USER CODE END 2 */
  98. /* Call init function for freertos objects (in freertos.c) */
  99. MX_FREERTOS_Init();
  100. /* Start scheduler */
  101. osKernelStart();
  102. /* We should never get here as control is now taken by the scheduler */
  103. /* Infinite loop */
  104. /* USER CODE BEGIN WHILE */
  105. while (1)
  106. {
  107. /* USER CODE END WHILE */
  108. /* USER CODE BEGIN 3 */
  109. }
  110. /* USER CODE END 3 */
  111. }
  112. /**
  113. * @brief System Clock Configuration
  114. * @retval None
  115. */
  116. void SystemClock_Config(void)
  117. {
  118. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  119. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  120. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  121. /** Initializes the RCC Oscillators according to the specified parameters
  122. * in the RCC_OscInitTypeDef structure.
  123. */
  124. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  125. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  126. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  127. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  128. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  129. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  130. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  131. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  132. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  133. {
  134. Error_Handler();
  135. }
  136. /** Initializes the CPU, AHB and APB buses clocks
  137. */
  138. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  139. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  140. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  141. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  142. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  143. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  144. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  145. {
  146. Error_Handler();
  147. }
  148. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  149. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  150. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  151. {
  152. Error_Handler();
  153. }
  154. }
  155. /* USER CODE BEGIN 4 */
  156. /* USER CODE END 4 */
  157. /**
  158. * @brief Period elapsed callback in non blocking mode
  159. * @note This function is called when TIM1 interrupt took place, inside
  160. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  161. * a global variable "uwTick" used as application time base.
  162. * @param htim : TIM handle
  163. * @retval None
  164. */
  165. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  166. {
  167. /* USER CODE BEGIN Callback 0 */
  168. /* USER CODE END Callback 0 */
  169. if (htim->Instance == TIM1) {
  170. HAL_IncTick();
  171. }
  172. /* USER CODE BEGIN Callback 1 */
  173. //喂看门狗
  174. TOGGLE_WDI_PIN(&htim2);
  175. /* USER CODE END Callback 1 */
  176. }
  177. /**
  178. * @brief This function is executed in case of error occurrence.
  179. * @retval None
  180. */
  181. void Error_Handler(void)
  182. {
  183. /* USER CODE BEGIN Error_Handler_Debug */
  184. /* User can add his own implementation to report the HAL error return state */
  185. __disable_irq();
  186. while (1)
  187. {
  188. }
  189. /* USER CODE END Error_Handler_Debug */
  190. }
  191. #ifdef USE_FULL_ASSERT
  192. /**
  193. * @brief Reports the name of the source file and the source line number
  194. * where the assert_param error has occurred.
  195. * @param file: pointer to the source file name
  196. * @param line: assert_param error line source number
  197. * @retval None
  198. */
  199. void assert_failed(uint8_t *file, uint32_t line)
  200. {
  201. /* USER CODE BEGIN 6 */
  202. /* User can add his own implementation to report the file name and line number,
  203. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  204. /* USER CODE END 6 */
  205. }
  206. #endif /* USE_FULL_ASSERT */