main.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * Copyright (c) 2019 STMicroelectronics International N.V.
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted, provided that the following conditions are met:
  18. *
  19. * 1. Redistribution of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of other
  25. * contributors to this software may be used to endorse or promote products
  26. * derived from this software without specific written permission.
  27. * 4. This software, including modifications and/or derivative works of this
  28. * software, must execute solely and exclusively on microcontroller or
  29. * microprocessor devices manufactured by or for STMicroelectronics.
  30. * 5. Redistribution and use of this software other than as permitted under
  31. * this license is void and will automatically terminate your rights under
  32. * this license.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /*
  50. 修改记录:
  51. 2021-1-26:增了终端与中控板交互的0x64的报文头处理,主要修改在:TerminalSlave485.c,
  52. 可通过查找 :"2021-1-26"来查看相关修改。 --- modify by Daiyf at 2021-1-26
  53. 2021-1-30:扩展了91命令IO响应的数据位,固定8仓*4=32字节。
  54. --- modify by Daiyf at 2021-1-30
  55. ******************************************************************************
  56. */
  57. /* USER CODE END Header */
  58. /*
  59. 更改记录:
  60. Q2021-1-26: 1、福建装车现场反馈主控LED破封报警显示延时长达8S,经常发现是内部判断次数过长,造成延时过长,经过与相关工程师交流,改为约1.8S后报警显示。
  61. 2、对中控板的LED显示作了定义进行调整,方便观察中控固件运行状态
  62. LED1:中控反与采集板信指示灯: 连接:闪亮, 断开连接:不亮或长亮; (注:原LED1 与采集板的通信息,保持一致)
  63. LED2:采集板上4卸油阀的的状态状态: 正常:不亮, 异常:长亮或闪亮; (注:原LED2-4 用于4个卸油阀的的状态在中控板显示,实际意义不大,改用一个LED作指示)
  64. LED3:中控板OS中通讯任务运行指示灯: 正常:闪亮, 异常:不亮或长亮;
  65. LED4:采中控板OS中数据处理任务运行指示灯: 正常:不亮, 异常:长亮或闪亮;
  66. LED5:破封产生指标灯: 破风成立:长亮, 破风信号产生:闪亮, 无破风:不亮;
  67. 3、相关修改通过查找“2021-2-3”和“Daiyf”可获取。
  68. Note by Daiyf at 2021-2-3
  69. */
  70. /* Includes ------------------------------------------------------------------*/
  71. #include "main.h"
  72. #include "cmsis_os.h"
  73. #include "dma.h"
  74. #include "spi.h"
  75. #include "tim.h"
  76. #include "usart.h"
  77. #include "gpio.h"
  78. #include "DS1302.h"
  79. #include "KeySlave485.h"
  80. #include "usart.h"
  81. uint32_t sd000,sd001;//浮点数转换为实时显示的参数,4字节
  82. uint16_t uart4RxCounter=0; //串口4接收数据计数器
  83. /* Private includes ----------------------------------------------------------*/
  84. /* USER CODE BEGIN Includes */
  85. /* USER CODE END Includes */
  86. /* Private typedef -----------------------------------------------------------*/
  87. /* USER CODE BEGIN PTD */
  88. /* USER CODE END PTD */
  89. /* Private define ------------------------------------------------------------*/
  90. /* USER CODE BEGIN PD */
  91. /* USER CODE END PD */
  92. /* Private macro -------------------------------------------------------------*/
  93. /* USER CODE BEGIN PM */
  94. /* USER CODE END PM */
  95. /* Private variables ---------------------------------------------------------*/
  96. /* USER CODE BEGIN PV */
  97. /* Private variables ---------------------------------------------------------*/
  98. /* USER CODE END PV */
  99. /* Private function prototypes -----------------------------------------------*/
  100. void SystemClock_Config(void);
  101. void MX_FREERTOS_Init(void);
  102. /* USER CODE BEGIN PFP */
  103. /* Private function prototypes -----------------------------------------------*/
  104. /* USER CODE END PFP */
  105. /* Private user code ---------------------------------------------------------*/
  106. /* USER CODE BEGIN 0 */
  107. /* USER CODE END 0 */
  108. /**
  109. * @brief The application entry point.
  110. * @retval int
  111. */
  112. int main(void)
  113. {
  114. /* USER CODE BEGIN 1 */
  115. extern SemaphoreHandle_t xSemaphore_uart4;
  116. extern uint8_t USART_RX_BUF_U2[Uart2_BUF_SIZE]; /*为UART2、3专门开一个DMA接收存储区 2021-4-12 by Daiyf*///static
  117. //int LenMain;
  118. __set_FAULTMASK(1);//先关闭全局中断
  119. #if IR_ROM1 == 0x8000000
  120. Start_BootLoader();
  121. #else
  122. SCB->VTOR = 0x08080000;
  123. //Start_BootLoader();
  124. __set_PRIMASK(0);
  125. #endif
  126. /* USER CODE END 1 */
  127. /* MCU Configuration--------------------------------------------------------*/
  128. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  129. HAL_Init();
  130. /* USER CODE BEGIN Init */
  131. /* USER CODE END Init */
  132. /* Configure the system clock */
  133. SystemClock_Config();
  134. /* USER CODE BEGIN SysInit */
  135. if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
  136. {
  137. //这是上电复位
  138. PrintCnt=99;
  139. }
  140. else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
  141. {
  142. //这是外部RST管脚复位RCC_GetFlagStatus
  143. PrintCnt=88;
  144. }
  145. else if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)!= RESET)
  146. {
  147. ////软件复位
  148. }
  149. else if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST))//独立看门狗复位
  150. {
  151. ;//
  152. }
  153. //RCC_ClearFlag();//清除RCC中复位标志
  154. __HAL_RCC_CLEAR_RESET_FLAGS();//清除所有复位标识,用于复位类型的判断
  155. /* USER CODE END SysInit */
  156. /* Initialize all configured peripherals */
  157. MX_GPIO_Init();
  158. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  159. MX_DMA_Init();
  160. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  161. MX_TIM6_Init();
  162. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  163. MX_USART2_UART_Init(); // Collect Board commincation port 采集板 采集器 19200
  164. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  165. MX_USART3_UART_Init(); // DWIN LCD comminucation port 液晶屏 迪文屏 19200
  166. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  167. MX_UART4_Init(); // Keyboard comminucation port 按键以及打印机,语音播报器 9600
  168. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  169. MX_TIM2_Init();
  170. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  171. MX_USART1_UART_Init(); // Terminal comminucation port终端 9600
  172. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  173. // MX_SPI4_Init();
  174. /* USER CODE BEGIN 2 */
  175. FM25L16B_Init();
  176. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  177. HAL_TIM_Base_Start_IT(&htim2);
  178. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  179. HAL_TIM_Base_Start_IT(&htim6);
  180. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  181. Uart_Mode_Init();
  182. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
  183. //HAL_UART_Receive_DMA(&huart2, USART_RX_BUF_U2,Uart2_BUF_SIZE);
  184. /* USER CODE END 2 */
  185. /* Call init function for freertos objects (in freertos.c) */
  186. MX_FREERTOS_Init();
  187. /* 创建互斥信号量 */
  188. xSemaphore_uart4 = xSemaphoreCreateMutex();
  189. /* Start scheduler */
  190. osKernelStart();
  191. /* We should never get here as control is now taken by the scheduler */
  192. /* Infinite loop */
  193. /* USER CODE BEGIN WHILE */
  194. while (1)
  195. {
  196. /* USER CODE END WHILE */
  197. /* USER CODE BEGIN 3 */
  198. }
  199. /* USER CODE END 3 */
  200. }
  201. /**
  202. * @brief System Clock Configuration
  203. * @retval None
  204. */
  205. void SystemClock_Config(void)
  206. {
  207. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  208. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  209. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  210. /**Configure the main internal regulator output voltage
  211. */
  212. __HAL_RCC_PWR_CLK_ENABLE();
  213. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  214. /**Initializes the CPU, AHB and APB busses clocks
  215. */
  216. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  217. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  218. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  219. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  220. RCC_OscInitStruct.PLL.PLLM = 25;
  221. RCC_OscInitStruct.PLL.PLLN = 432;
  222. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  223. RCC_OscInitStruct.PLL.PLLQ = 2;
  224. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  225. {
  226. Error_Handler();
  227. }
  228. /**Activate the Over-Drive mode
  229. */
  230. if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  231. {
  232. Error_Handler();
  233. }
  234. /**Initializes the CPU, AHB and APB busses clocks
  235. */
  236. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  237. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  238. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  239. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  240. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  241. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  242. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
  243. {
  244. Error_Handler();
  245. }
  246. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2
  247. |RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_UART4;
  248. PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  249. PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  250. PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
  251. PeriphClkInitStruct.Uart4ClockSelection = RCC_UART4CLKSOURCE_PCLK1;
  252. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  253. {
  254. Error_Handler();
  255. }
  256. }
  257. /* USER CODE BEGIN 4 */
  258. /* USER CODE END 4 */
  259. /**
  260. * @brief Period elapsed callback in non blocking mode
  261. * @note This function is called when TIM1 interrupt took place, inside
  262. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  263. * a global variable "uwTick" used as application time base.
  264. * @param htim : TIM handle
  265. * @retval None
  266. */
  267. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  268. {
  269. /* USER CODE BEGIN Callback 0 */
  270. /* USER CODE END Callback 0 */
  271. if (htim->Instance == TIM1) {
  272. HAL_IncTick();
  273. }
  274. /* USER CODE BEGIN Callback 1 */
  275. /* USER CODE END Callback 1 */
  276. }
  277. /**
  278. * @brief This function is executed in case of error occurrence.
  279. * @retval None
  280. */
  281. void Error_Handler(void)
  282. {
  283. /* USER CODE BEGIN Error_Handler_Debug */
  284. /* User can add his own implementation to report the HAL error return state */
  285. while(1)
  286. {
  287. }
  288. /* USER CODE END Error_Handler_Debug */
  289. }
  290. #ifdef USE_FULL_ASSERT
  291. /**
  292. * @brief Reports the name of the source file and the source line number
  293. * where the assert_param error has occurred.
  294. * @param file: pointer to the source file name
  295. * @param line: assert_param error line source number
  296. * @retval None
  297. */
  298. void assert_failed(uint8_t *file, uint32_t line)
  299. {
  300. /* USER CODE BEGIN 6 */
  301. /* User can add his own implementation to report the file name and line number,
  302. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  303. /* USER CODE END 6 */
  304. }
  305. #endif /* USE_FULL_ASSERT */
  306. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/