/** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** ** This notice applies to any and all portions of this file * that are not between comment pairs USER CODE BEGIN and * USER CODE END. Other portions of this file, whether * inserted by the user or by software development tools * are owned by their respective copyright owners. * * COPYRIGHT(c) 2019 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f1xx_hal.h" #include "adc.h" #include "can.h" #include "dma.h" #include "iwdg.h" #include "usart.h" #include "gpio.h" /* USER CODE BEGIN Includes */ #include "uart_process.h" #include "can_process.h" #include "flash_read_protection.h" #include "Update.h" #include "ctf_process.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * * @retval None */ int main(void) { /* USER CODE BEGIN 1 */ //APP跳转 IAP_Init(); //Falsh读保护 //Flash_ReadProtection(); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_CAN_Init(); MX_IWDG_Init(); MX_USART1_UART_Init(9600); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ CAN_RxBuf_Init(); //采集适配器输入电压和P+输入电压 ADC_Start(); HAL_Delay(200); //根据P+输入电压确定是否开启PowerSwitch if(ADC1_Result[1] < 1000) //检测到P+电压小于18V开启 { HAL_GPIO_WritePin(PowerSwitch_GPIO_Port, PowerSwitch_Pin, GPIO_PIN_SET); } //读取设备物理ID和授权码 IsCtfFlag = Read_Ctf_Info(); Transmit_UARTOrCAN = 2; HAL_Delay(100); HAL_GPIO_WritePin(CommSwitch_GPIO_Port, CommSwitch_Pin1, GPIO_PIN_SET); HAL_GPIO_WritePin(CommSwitch_GPIO_Port, CommSwitch_Pin2, GPIO_PIN_SET); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ //看门狗计数清零 HAL_IWDG_Refresh(&hiwdg); //UART3/UART1数据解析 Uart1_RxData_Process(&UART_RxBuff_Struct1, 200); Uart3_RxData_Process(&UART_RxBuff_Struct3, 200); //控制上下电 PowerOnOff(&Power_mode); if(IsCtfFlag == TRUE) { //CAN数据解析 uint16_t i = 0; for(i=0; i