Merge achamaikin/CCSModuleSW30Web upstream with fire alarm retained.

Take upstream board rev2, heater, and project cleanup; preserve fire alarm latch, CMD_FIRE_ALARM, and ESTOP maintenance logic.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
raduet
2026-06-11 13:45:40 +02:00
co-authored by Cursor
91 changed files with 41261 additions and 53693 deletions
+1 -17
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file adc.c
* @brief This file provides code for the configuration
* of the ADC instances.
******************************************************************************
* @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 "adc.h"
+25 -18
View File
@@ -1,13 +1,9 @@
#include "main.h"
#include "board.h"
#include "adc.h"
#include "tim.h"
#include "sma_filter.h"
//TODO:
//TEMP READ
// Connector temperature sensors
#include "adc.h"
#include "main.h"
#include "sma_filter.h"
#include "tim.h"
InfoBlock_t *InfoBlock = (InfoBlock_t *)(VERSION_OFFSET);
@@ -74,19 +70,31 @@ uint8_t IN_ReadInput(inputNum_t input_n){
}
}
uint8_t GetBoardTemp(){
//TODO
// HAL_ADC_Start(&hadc1); // start the adc
//
// HAL_ADC_PollForConversion(&hadc1, 100); // poll for conversion
//
// adc_val = HAL_ADC_GetValue(&hadc1); // get the adc value
//
// HAL_ADC_Stop(&hadc1); // stop adc
/* Заглушка: температура платы не измеряется (нет реализации АЦП для канала). */
uint8_t GetBoardTemp(void){
return 0;
}
/**
* @brief Force PC12 (HEATER) as GPIO output via CRH/ODR, overriding UART5 MspInit.
* CubeMX assigns PC12 to UART5_TX; on the board it drives the heater relay.
*/
static void Heater_PinForceOutput(void)
{
const uint32_t pin_cfg = GPIO_SPEED_FREQ_LOW; /* MODE=10, CNF=00: GP output PP, 2 MHz */
__HAL_RCC_GPIOC_CLK_ENABLE();
MODIFY_REG(HEATER_GPIO_Port->CRH,
(GPIO_CRH_MODE12 | GPIO_CRH_CNF12),
(pin_cfg << GPIO_CRH_MODE12_Pos));
HEATER_GPIO_Port->BSRR = (uint32_t)HEATER_Pin << 16U;
}
void Init_Peripheral(){
Heater_PinForceOutput();
HAL_GPIO_WritePin(HEATER_GPIO_Port, HEATER_Pin, GPIO_PIN_RESET);
HAL_ADCEx_Calibration_Start(&hadc1);
ADC_ScanStart();
@@ -138,7 +146,6 @@ int16_t CONN_ReadTemp(uint8_t ch){
return 20; //Термодатчик не подключен
}
// int adc_value = 2048; // Пример значения АЦП
float Vref = 3.3; // Напряжение опорное
float Vin = 5.0; // Входное напряжение
float R = 1000; // Сопротивление резистора в Омах
+1 -17
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file can.c
* @brief This file provides code for the configuration
* of the CAN instances.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 "can.h"
+5 -22
View File
@@ -1,14 +1,12 @@
#include "charger_control.h"
#include "charger_config.h"
#include "psu_control.h"
#include "connector.h"
#include "debug.h"
#include "fire_alarm.h"
#include "psu_control.h"
ChargingConnector_t CONN;
CONN_State_t connectorState;
extern uint8_t config_initialized;
void CONN_Init(){
@@ -36,24 +34,16 @@ void CONN_Loop(){
CONN.chargingError = CONN_ERR_CONTACTOR;
} else if(PSU0.psu_fault){
CONN.chargingError = CONN_ERR_PSU_FAULT;
// } else if(!CTRL.ac_ok) {
// CONN.chargingError = CONN_ERR_AC_FAULT;
// } else
}else if (CONN.EvConnected == 0){
CONN.chargingError = CONN_NO_ERROR;
}
if(ED_TraceWarning(CONN.chargingError, 0)) printf("CONN%d Error: %d\n", 0, CONN.chargingError);
if(ED_TraceWarning(CONN.chargingError, 0)) {
log_printf(LOG_WARN, "CONN0 Error: %d\n", (int)CONN.chargingError);
}
}
void CONN_Task(){
/* CCS state machine is handled in serial.c.
* Keep this task lightweight for scheduler compatibility.
*/
return;
}
void CONN_SetState(CONN_State_t state){
if (connectorState == state) {
CONN.connState = state;
@@ -79,10 +69,3 @@ void CONN_SetState(CONN_State_t state){
CONN.connState = state;
}
void CONN_PrintChargingTotal(){
printf("CONN%d Charging Finished:\n", 0);
// printf("Charging Time: %d\n", CONN.chargingTime);
printf("Charging Energy: %d\n", CONN.Energy);
// printf("Charging Power: %d\n", CONN.chargingPower);
}
+1
View File
@@ -1,4 +1,5 @@
#include "cp.h"
#include "adc.h"
#include "board.h"
#include "debug.h"
+1 -17
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file crc.c
* @brief This file provides code for the configuration
* of the CRC instances.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 "crc.h"
+7 -14
View File
@@ -1,21 +1,14 @@
/*
* debug.c
*
* Created on: Apr 16, 2024
* Author: colorbass
*/
#include "main.h"
#include "board.h"
#include "connector.h"
#include "debug.h"
#include "serial_control.h"
#include "usart.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include "debug.h"
#include "board.h"
#include "usart.h"
#include <time.h>
#include <connector.h>
#include "serial_control.h"
// Кольцевой буфер для отладочных сообщений
#define DEBUG_BUFFER_SIZE 1024
+1 -17
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.c
* @brief This file provides code for the configuration
* of all the requested memory to memory DMA transfers.
******************************************************************************
* @attention
*
* Copyright (c) 2026 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 ------------------------------------------------------------------*/
+5 -20
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.c
* @brief This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @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 ------------------------------------------------------------------*/
@@ -54,7 +38,8 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, DBG1_Pin|RELAY_CP_Pin|LOCK_A_Pin|LOCK_B_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, DBG1_Pin|RELAY_CP_Pin|LOCK_A_Pin|LOCK_B_Pin
|LED_DATA_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, DBG2_Pin|DBG3_Pin|RELAY_CC_Pin, GPIO_PIN_RESET);
@@ -76,8 +61,8 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(DBG1_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : RELAY_CP_Pin LOCK_A_Pin LOCK_B_Pin */
GPIO_InitStruct.Pin = RELAY_CP_Pin|LOCK_A_Pin|LOCK_B_Pin;
/*Configure GPIO pins : RELAY_CP_Pin LOCK_A_Pin LOCK_B_Pin LED_DATA_Pin */
GPIO_InitStruct.Pin = RELAY_CP_Pin|LOCK_A_Pin|LOCK_B_Pin|LED_DATA_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+11 -10
View File
@@ -1,4 +1,5 @@
/* USER CODE BEGIN Header */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
@@ -13,15 +14,17 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "can.h"
#include "board.h"
#include <stdio.h>
#include "debug.h"
#include "soft_rtc.h"
#include "connector.h"
#include "serial_control.h"
#include "charger_config.h"
#include "connector.h"
#include "debug.h"
#include "meter.h"
#include "psu_control.h"
#include "rgb_controller.h"
#include "serial.h"
#include "serial_control.h"
#include "soft_rtc.h"
#include <stdio.h>
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -53,6 +56,7 @@ void SystemClock_Config(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static void StopButtonControl(void);
/**
* @brief Vector base address configuration. It should no longer be at the start of
@@ -99,13 +103,12 @@ void ED_Delay(uint32_t Delay)
CCS_SerialLoop();
StopButtonControl();
CP_Loop();
CONN_Task();
LED_Task();
SC_Task();
}
}
void StopButtonControl(){
static void StopButtonControl(void){
static uint32_t tick;
static uint32_t hold_time;
static uint8_t stop_btn_fault = 1;
@@ -146,8 +149,6 @@ void StopButtonControl(){
}
}
uint8_t temp0, temp1;
static void CAN1_MinimalReInit(void)
{
HAL_CAN_Stop(&hcan1);
+1 -9
View File
@@ -1,13 +1,5 @@
/*
* meter.c
*
* Created on: 27 сент. 2024 г.
* Author: root
*/
#include "meter.h"
#include "charger_config.h"
#include "charger_control.h"
+8 -15
View File
@@ -1,14 +1,13 @@
#include "psu_control.h"
#include <psu_control.h>
#include "board.h"
#include "can.h"
#include "string.h"
#include "stdio.h"
#include "charger_config.h"
#include "charger_control.h"
#include "board.h"
#include "debug.h"
#include "isr_opt.h"
#include <stdio.h>
#include <string.h>
PSU_02_t PSU_02;
PSU_04_t PSU_04;
@@ -31,6 +30,8 @@ uint32_t can_lastpacket;
extern CAN_HandleTypeDef hcan2;
static void PSU_SendCmd(uint8_t source, uint8_t destination, uint8_t cmd, void *data);
static void PSU_SwitchState(PSU_State_t state){
PSU0.state = state;
PSU0.statetick = HAL_GetTick();
@@ -227,7 +228,6 @@ void PSU_SendCmd(uint8_t source, uint8_t destination, uint8_t cmd, void *data){
/* если отправка удалась, выход */
if(CAN_result == HAL_OK) {
return;
retry_counter = 0;
}
}
ED_Delay(1);
@@ -237,11 +237,6 @@ void PSU_SendCmd(uint8_t source, uint8_t destination, uint8_t cmd, void *data){
}
uint32_t max(uint32_t a, uint32_t b){
if(a>b) return a;
else return b;
}
void PSU_ReadWrite(){
uint8_t zero_data[8] = {0,0,0,0,0,0,0,0};
@@ -264,8 +259,8 @@ void PSU_ReadWrite(){
CONN.RequestedPower = CONN.RequestedCurrent * CONN.RequestedVoltage / 10;
if(PSU0.ready){
if (CONN.RequestedVoltage == 500) { // fake
PSU_SetVoltageCurrent(0, 300, 10); // Normal mode
if (CONN.RequestedVoltage == FAKE_EVREQ_VOLTAGE_V) {
PSU_SetVoltageCurrent(0, (uint16_t)FAKE_PSU_VOLTAGE_V, (uint16_t)FAKE_PSU_CURRENT_0P1A);
}else{
PSU_SetVoltageCurrent(0, CONN.RequestedVoltage, CONN.RequestedCurrent); // Normal mode
}
@@ -288,7 +283,6 @@ void PSU_ReadWrite(){
void PSU_Task(void){
static uint32_t psu_on_tick = 0;
static uint32_t dc_on_tick = 0;
static uint32_t cont_ok_tick = 0;
// Обновляем ONLINE/READY по таймауту
@@ -368,7 +362,6 @@ void PSU_Task(void){
case PSU_WAIT_ACK_ON:
if(PSU0.PSU_enabled && PSU0.ready){
dc_on_tick = HAL_GetTick();
PSU_SwitchState(PSU_CONT_WAIT_ACK_ON);
}else if(PSU_StateTime() > 10000){
PSU0.psu_fault = 1;
+4 -29
View File
@@ -1,11 +1,11 @@
#include "rgb_controller.h"
#include "board.h"
#include "charger_control.h"
#include "fire_alarm.h"
#include "main.h"
#include "string.h"
#include "charger_control.h"
#include "board.h"
#include "tim.h"
#include <string.h>
RGB_State_t LED_State;
RGB_Cycle_t LED_Cycle;
@@ -203,36 +203,11 @@ void LED_Init(){
RGB_SetColor(&color);
}
// void LED_PhaseSync(uint8_t led_n){
// if(LED_State[led_n].phasesync){
// LED_State[led_n].phasesync = 0;
// //default settings
// LED_State[led_n].state = LED_HIGH;
// LED_State[led_n].tick = 0;
// //ищем среди всех светодиодов такую же последовательность
// for (uint8_t led_n1 = 0; led_n1 < 5; led_n1++){
// if ((LED_Cycle[led_n].Tf == LED_Cycle[led_n1].Tf) &&
// (LED_Cycle[led_n].Tr == LED_Cycle[led_n1].Tr) &&
// (LED_Cycle[led_n].Th == LED_Cycle[led_n1].Th) &&
// (LED_Cycle[led_n].Tl == LED_Cycle[led_n1].Tl) &&
// (led_n != led_n1)){
// //если нашли, то копируем фазу оттуда
// LED_State[led_n].state = LED_State[led_n1].state;
// LED_State[led_n].tick = LED_State[led_n1].tick;
// return;
// }
// }
// }
// }
void LED_Task(){
static uint32_t led_tick;
if((HAL_GetTick() - led_tick) > 20){
led_tick = HAL_GetTick();
LED_State.tick++;
// LED_PhaseSync(led_n);
switch(LED_State.state){
case LED_RISING:
interpolateColors(&LED_Cycle.Color2, &LED_Cycle.Color1, LED_State.tick, LED_Cycle.Tr, &LED_State.color);
+7 -12
View File
@@ -1,15 +1,16 @@
#include "serial.h"
#include "cp.h"
#include "connector.h"
#include "board.h"
#include "charger_config.h"
#include "connector.h"
#include "cp.h"
#include "debug.h"
#include "isr_opt.h"
#include <stdint.h>
#include <string.h>
#include "charger_config.h"
#include "fire_alarm.h"
#include "psu_control.h"
#include "serial_control.h"
#include "fire_alarm.h"
#include <stdint.h>
#include <string.h>
extern UART_HandleTypeDef huart3;
extern uint8_t config_initialized;
@@ -29,15 +30,9 @@ CONN_Control_t last_cmd = CMD_NONE;
uint8_t ev_enable_output = 0;
#define CMD_INTERVAL 10
#define MAX_TX_BUFFER_SIZE 256
#define MAX_RX_BUFFER_SIZE 256
#define EVEREST_TIMEOUT_WARN_MS 5000u
#define EVEREST_TIMEOUT_STOP_MS 10000u
#define UART3_REINIT_TIMEOUT_MS 1500u
/* Everest requests 500 V -> PSU really gets 300 V / 1 A, state still reports 500 V. */
#define FAKE_EVREQ_VOLTAGE_V 500u
#define FAKE_PSU_VOLTAGE_V 300u
#define FAKE_PSU_CURRENT_0P1A 10u
static uint8_t rx_buffer[MAX_RX_BUFFER_SIZE];
static uint8_t tx_buffer[MAX_TX_BUFFER_SIZE];
+3 -2
View File
@@ -1,9 +1,10 @@
#include "serial_control.h"
#include "usart.h"
#include "board.h"
#include "serial.h"
#include "debug.h"
#include "isr_opt.h"
#include "serial.h"
#include "usart.h"
// Приватные функции
ISR_FAST static uint32_t calculate_crc32(const uint8_t* data, uint16_t length);
+6 -7
View File
@@ -1,15 +1,15 @@
#include "serial_control.h"
#include "usart.h"
#include "charger_control.h"
#include "board.h"
#include "psu_control.h"
#include "charger_control.h"
#include "debug.h"
#include "fire_alarm.h"
#include "psu_control.h"
#include "usart.h"
#include <string.h>
#ifdef USE_WEB_INTERFACE
extern volatile SC_Source_t g_sc_command_source;
static void monitoring_data_callback(void);
IsolationStatusPacket_t ISO = {
.isolationResistance = 0xFFFF
@@ -133,7 +133,7 @@ void SC_CommandHandler(ReceivedCommand_t* cmd) {
// Колбэк для заполнения данных мониторинга
void monitoring_data_callback() {
static void monitoring_data_callback(void) {
// Информация о зарядной сессии
statusPacket.SOC = CONN.SOC;
@@ -213,4 +213,3 @@ void monitoring_data_callback() {
}
#endif
+2 -22
View File
@@ -1,11 +1,4 @@
/*
* rtc.c
*
* Created on: Jul 22, 2024
* Author: colorbass
*/
#include <soft_rtc.h>
#include "soft_rtc.h"
#include <stdint.h>
#include <time.h>
@@ -63,20 +56,7 @@ uint8_t getTimeReg(uint8_t reg_number){
}else{
return 0x00;
}
};
//int main() {
// uint32_t unix_time = 1672531199; // Example Unix timestamp
// uint8_t time[8];
//
// unix_to_bcd(unix_time, time);
//
// // Print the BCD values for verification
// for (int i = 0; i < 8; i++) {
// log_printf(LOG_INFO, "time[%d]: %02X\n", i, time[i]);
// }
//
// return 0;
//}
}
/**
* @brief Read the time counter available in RTC_CNT registers.
+1 -17
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @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 ------------------------------------------------------------------*/
+1 -16
View File
@@ -1,20 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @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 ------------------------------------------------------------------*/
+1 -17
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.c
* @brief This file provides code for the configuration
* of the TIM instances.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 "tim.h"
+4 -20
View File
@@ -1,21 +1,5 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.c
* @brief This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 "usart.h"
@@ -167,10 +151,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
PC12 ------> UART5_TX
PD2 ------> UART5_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Pin = HEATER_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_Init(HEATER_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
@@ -361,7 +345,7 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
PC12 ------> UART5_TX
PD2 ------> UART5_RX
*/
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_12);
HAL_GPIO_DeInit(HEATER_GPIO_Port, HEATER_Pin);
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);