forked from achamaikin/CCSModuleSW30Web
latest version
This commit is contained in:
139
Core/Src/main.c
Executable file → Normal file
139
Core/Src/main.c
Executable file → Normal file
@@ -1,26 +1,12 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "adc.h"
|
||||
#include "can.h"
|
||||
#include "crc.h"
|
||||
#include "rtc.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
@@ -35,6 +21,8 @@
|
||||
#include "j1939.h"
|
||||
#include "lock.h"
|
||||
#include "connector.h"
|
||||
#include "serial_control.h"
|
||||
#include "charger_config.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@@ -46,8 +34,6 @@
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
#include "edcan_config.h"
|
||||
#include "edcan_defines.h"
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -70,6 +56,70 @@ void SystemClock_Config(void);
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/**
|
||||
* @brief Vector base address configuration. It should no longer be at the start of
|
||||
* flash memory but moved forward because the first part of flash is
|
||||
* reserved for the bootloader. Note that this is already done by the
|
||||
* bootloader before starting this program. Unfortunately, function
|
||||
* SystemInit() overwrites this change again.
|
||||
* @return none.
|
||||
*/
|
||||
static void VectorBase_Config(void)
|
||||
{
|
||||
/* The constant array with vectors of the vector table is declared externally in the
|
||||
* c-startup code.
|
||||
*/
|
||||
extern const unsigned long g_pfnVectors[];
|
||||
|
||||
/* Remap the vector table to where the vector table is located for this program. */
|
||||
SCB->VTOR = (unsigned long)&g_pfnVectors[0];
|
||||
}
|
||||
|
||||
uint8_t ED_TraceWarning(uint8_t flag, uint8_t id){
|
||||
static uint8_t memory[32];
|
||||
if(id > 31) return 0;
|
||||
uint8_t result = 0;
|
||||
if(memory[id] != flag){
|
||||
result = 1;
|
||||
}
|
||||
memory[id] = flag;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ED_Delay(uint32_t Delay)
|
||||
{
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
uint32_t wait = Delay;
|
||||
|
||||
/* Add a freq to guarantee minimum wait */
|
||||
if (wait < HAL_MAX_DELAY)
|
||||
{
|
||||
wait += (uint32_t)(uwTickFreq);
|
||||
}
|
||||
|
||||
while ((HAL_GetTick() - tickstart) < wait){
|
||||
CONN_CC_ReadStateFiltered();
|
||||
GBT_ManageLockMotor();
|
||||
CONN_Task();
|
||||
GBT_ChargerTask();
|
||||
LED_Task();
|
||||
SC_Task();
|
||||
// if(huart2.gState != HAL_UART_STATE_BUSY_TX) debug_buffer_send(); // TEST
|
||||
}
|
||||
}
|
||||
|
||||
void StopButtonControl(){
|
||||
|
||||
//Charging do nothing
|
||||
if(!IN_ReadInput(IN_ESTOP)){
|
||||
CONN.connControl = CMD_STOP;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t temp0, temp1;
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -78,8 +128,9 @@ void SystemClock_Config(void);
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
VectorBase_Config();
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
@@ -88,7 +139,7 @@ int main(void)
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
HAL_RCC_DeInit();
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
@@ -103,24 +154,30 @@ int main(void)
|
||||
MX_ADC1_Init();
|
||||
MX_CAN1_Init();
|
||||
MX_CAN2_Init();
|
||||
MX_USART2_UART_Init();
|
||||
MX_RTC_Init();
|
||||
MX_TIM4_Init();
|
||||
MX_USART2_UART_Init();
|
||||
MX_CRC_Init();
|
||||
MX_UART5_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_USART3_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
CAN_ReInit();
|
||||
Init_Peripheral();
|
||||
LED_Init();
|
||||
|
||||
HAL_Delay(300);
|
||||
GBT_Init();
|
||||
set_Time(1721651966);
|
||||
printf("Startup (type \'help\' for command list)\n");
|
||||
debug_init();
|
||||
EDCAN_Init(SW_GetAddr()); //0x20..0x23
|
||||
EDCAN_printf(LOG_INFO, "Startup\n");
|
||||
//EDCAN_Init(0x20); //Адрес EDCAN
|
||||
SC_Init();
|
||||
log_printf(LOG_INFO, "GBT Charger v%d.%d\n", GBT_CH_VER_MAJOR, GBT_CH_VER_MINOR);
|
||||
ReadVersion();
|
||||
log_printf(LOG_INFO, "Serial number: %d\n", infoPacket.serialNumber);
|
||||
log_printf(LOG_INFO, "Board revision: %d\n", infoPacket.boardVersion);
|
||||
log_printf(LOG_INFO, "FW version: %d.%d.%d\n", infoPacket.fw_version_major, infoPacket.fw_version_minor, infoPacket.fw_version_patch);
|
||||
GBT_SetConfig();
|
||||
GBT_CAN_ReInit();
|
||||
CAN_ReInit();
|
||||
|
||||
PSU_Init();
|
||||
CONN_Init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@@ -130,14 +187,17 @@ int main(void)
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
// HAL_Delay(1);
|
||||
EDCAN_Loop();
|
||||
//can_task();
|
||||
debug_task();
|
||||
CONN_CC_ReadStateFiltered();
|
||||
GBT_ManageLock();
|
||||
CONN_Task();
|
||||
GBT_ChargerTask();
|
||||
|
||||
|
||||
PSU_ReadWrite();
|
||||
PSU_Task();
|
||||
ED_Delay(10);
|
||||
METER_CalculateEnergy();
|
||||
CONN_Loop();
|
||||
LED_Write();
|
||||
ED_Delay(10);
|
||||
StopButtonControl();
|
||||
ED_Delay(50);
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
@@ -217,8 +277,7 @@ void Error_Handler(void)
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
|
||||
Reference in New Issue
Block a user