Compare commits
1 Commits
master
...
aa64d93253
| Author | SHA1 | Date | |
|---|---|---|---|
| aa64d93253 |
@ -12,7 +12,6 @@
|
||||
|
||||
#include "stm32g441xx.h"
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
#define TS_INACTIVE 0
|
||||
#define TS_PRECHARGE 2
|
||||
@ -25,7 +24,6 @@
|
||||
#define ADC_READ_TIMEOUT 500 // in ms
|
||||
#define SDC_LOWER_THRESHOLD 2500 // in ADC Values
|
||||
#define PRECHARGE_95_DURATION 1000 // in ms
|
||||
#define PRECHARGE_OPEN_AFTER 1000 // in ms
|
||||
// FIXME
|
||||
#define LOWER_VEHICLE_SIDE_VOLTAGE_LIMIT 150000 // in mV
|
||||
|
||||
@ -33,7 +31,6 @@ typedef struct {
|
||||
|
||||
int32_t BatteryVoltageVehicleSide;
|
||||
int32_t BatteryVoltageBatterySide;
|
||||
int32_t shuntCurrent;
|
||||
uint8_t targetTSState;
|
||||
uint8_t currentTSState;
|
||||
uint32_t precharge95ReachedTimestamp;
|
||||
@ -54,8 +51,4 @@ void AIR_Discharge_Position();
|
||||
void AIR_Active_Position();
|
||||
void AIR_Error_Position();
|
||||
|
||||
typedef enum { RELAY_AIR_NEG, RELAY_AIR_POS, RELAY_PRECHARGE } Relay;
|
||||
|
||||
void Set_Relay_Position(Relay relay, GPIO_PinState position);
|
||||
|
||||
#endif /* INC_AIR_STATE_MASCHINE_H_ */
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
|
||||
#define CLOCK_SYNC_ADDRESS 0x002
|
||||
#define MASTER_HEARTBEAT_ADDRESS 0x010
|
||||
#define SLAVE_EEPROM_WRITE_ADDRESS 0x020
|
||||
|
||||
typedef struct {
|
||||
int16_t FrameID;
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
#include "stm32g441xx.h"
|
||||
|
||||
#define NUMBEROFSLAVES 9
|
||||
#define NUMBEROFSLAVES 7
|
||||
#define NUMBEROFCELLS 10
|
||||
#define NUMBEROFTEMPS 32
|
||||
|
||||
@ -32,7 +32,6 @@ typedef struct {
|
||||
uint8_t error;
|
||||
uint8_t timeout;
|
||||
uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES];
|
||||
uint8_t error_frame[8];
|
||||
|
||||
} SlaveHandler;
|
||||
|
||||
|
||||
@ -60,7 +60,6 @@ void FDCAN1_IT0_IRQHandler(void);
|
||||
void FDCAN1_IT1_IRQHandler(void);
|
||||
void TIM1_UP_TIM16_IRQHandler(void);
|
||||
void SPI1_IRQHandler(void);
|
||||
void TIM8_UP_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
@ -7,10 +7,7 @@
|
||||
|
||||
#include "AIR_State_Maschine.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
DMA_HandleTypeDef* air_current_dma = {0};
|
||||
DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||
@ -18,10 +15,6 @@ DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||
uint8_t air_adc_complete = 0;
|
||||
uint8_t sdc_adc_complete = 0;
|
||||
|
||||
static uint32_t pos_air_change_timestamp, neg_air_change_timestamp,
|
||||
precharge_change_timestamp;
|
||||
static GPIO_PinState neg_air_state, pos_air_state, precharge_state;
|
||||
|
||||
AIRStateHandler init_AIR_State_Maschine() {
|
||||
AIRStateHandler airstate = {0};
|
||||
|
||||
@ -117,12 +110,6 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
}
|
||||
}
|
||||
|
||||
else if (airstate->currentTSState == TS_CHARGING) {
|
||||
if (airstate->shuntCurrent < 0) {
|
||||
airstate->currentTSState = TS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
else if (airstate->currentTSState ==
|
||||
TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at
|
||||
// Vehicle Side
|
||||
@ -191,76 +178,48 @@ void Deactivate_TS(AIRStateHandler* airstate) {
|
||||
}
|
||||
|
||||
void AIR_Precharge_Position() {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Inactive_Position() {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Discharge_Position() {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Active_Position() {
|
||||
if (pos_air_state == GPIO_PIN_SET &&
|
||||
HAL_GetTick() - pos_air_change_timestamp > PRECHARGE_OPEN_AFTER) {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||
} else {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
}
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_SET);
|
||||
void AIR_Active_Position() // TODO Deactivate Precharge after a while to
|
||||
// decrease current Consumption
|
||||
{
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void AIR_Error_Position() {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void Set_Relay_Position(Relay relay, GPIO_PinState position) {
|
||||
// Add a small delay after closing relays in order to not draw too much
|
||||
// current
|
||||
switch (relay) {
|
||||
case RELAY_AIR_NEG:
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
position);
|
||||
if (position != neg_air_state) {
|
||||
neg_air_change_timestamp = HAL_GetTick();
|
||||
}
|
||||
if (position == GPIO_PIN_SET && neg_air_state == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
neg_air_state = position;
|
||||
break;
|
||||
case RELAY_AIR_POS:
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
position);
|
||||
if (position != pos_air_state) {
|
||||
pos_air_change_timestamp = HAL_GetTick();
|
||||
}
|
||||
if (position == GPIO_PIN_SET && pos_air_state == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
pos_air_state = position;
|
||||
break;
|
||||
case RELAY_PRECHARGE:
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
position);
|
||||
if (position != precharge_state) {
|
||||
precharge_change_timestamp = HAL_GetTick();
|
||||
}
|
||||
if (position == GPIO_PIN_SET && precharge_state == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
precharge_state = position;
|
||||
break;
|
||||
}
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
@ -14,8 +14,11 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
const uint16_t slave_CAN_id_to_slave_index[10] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 255, 8}; // TODO: Make this pretty pls
|
||||
// 3 should be programmed with CAN id 2
|
||||
// const uint16_t slave_CAN_id_to_slave_index[7] = {
|
||||
// 255, 255, 0, 255, 255, 255, 1}; // TODO: Make this pretty pls
|
||||
const uint16_t slave_CAN_id_to_slave_index[7] = {
|
||||
0, 1, 2, 3, 4, 5, 6}; // TODO: Make this pretty pls
|
||||
canFrame framebuffer[CANFRAMEBUFFERSIZE] = {0};
|
||||
uint32_t framebufferwritepointer = 0;
|
||||
uint32_t framebufferreadpointer = 0;
|
||||
@ -69,9 +72,11 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) {
|
||||
uint8_t messageID = msg & 0x00F;
|
||||
updateSlaveInfo(slaveID, messageID, rxFrame);
|
||||
} else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) {
|
||||
uint8_t slave_id = rxFrame.data[0];
|
||||
slaves[slave_id].error = 1;
|
||||
memcpy(slaves[slave_id].error_frame, rxFrame.data, 8);
|
||||
AMSErrorHandle errorframe = {0};
|
||||
errorframe.errorcode = SlavesErrorFrameError;
|
||||
memcpy(errorframe.errorarg, rxFrame.data, 7);
|
||||
|
||||
AMS_Error_Handler(&errorframe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ void clock_sync_init(FDCAN_HandleTypeDef* can_handle,
|
||||
void clock_sync_handle_timer_complete(TIM_HandleTypeDef* timer) {
|
||||
if (timer == sync_timer) {
|
||||
CAN_Transmit(can, CLOCK_SYNC_ADDRESS, &clock_sync_counter, 1);
|
||||
clock_sync_counter++;
|
||||
} else if (timer == heartbeat_timer) {
|
||||
CAN_Transmit(can, MASTER_HEARTBEAT_ADDRESS, NULL, 0);
|
||||
}
|
||||
|
||||
@ -348,7 +348,7 @@ void InterSTMFrame() {
|
||||
spirxbuf[0] << 24 | spirxbuf[1] << 16 | spirxbuf[2] << 8 | spirxbuf[3];
|
||||
spi_airstates->BatteryVoltageVehicleSide =
|
||||
spirxbuf[4] << 24 | spirxbuf[5] << 16 | spirxbuf[6] << 8 | spirxbuf[7];
|
||||
spi_airstates->shuntCurrent =
|
||||
uint32_t current =
|
||||
spirxbuf[8] << 24 | spirxbuf[9] << 16 | spirxbuf[10] << 8 | spirxbuf[11];
|
||||
spi_airstates->targetTSState = spirxbuf[12];
|
||||
}
|
||||
|
||||
@ -13,8 +13,6 @@
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
SlaveHandler slaves[NUMBEROFSLAVES];
|
||||
|
||||
void initSlaves() {
|
||||
@ -65,12 +63,8 @@ uint8_t checkSlaveTimeout() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (slaves[n].error) {
|
||||
AMSErrorHandle errorframe;
|
||||
errorframe.errorcode = SlavesErrorFrameError;
|
||||
memcpy(errorframe.errorarg, slaves[n].error_frame, 7);
|
||||
AMS_Error_Handler(&errorframe);
|
||||
return 1;
|
||||
if (HAL_GetTick() < 20000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) {
|
||||
|
||||
@ -322,9 +322,6 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
/* USER CODE END TIM8_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM8_CLK_ENABLE();
|
||||
/* TIM8 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM8_UP_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM8_UP_IRQn);
|
||||
/* USER CODE BEGIN TIM8_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM8_MspInit 1 */
|
||||
@ -361,9 +358,6 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
/* USER CODE END TIM8_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM8_CLK_DISABLE();
|
||||
|
||||
/* TIM8 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(TIM8_UP_IRQn);
|
||||
/* USER CODE BEGIN TIM8_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM8_MspDeInit 1 */
|
||||
|
||||
@ -60,7 +60,6 @@
|
||||
extern FDCAN_HandleTypeDef hfdcan1;
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim8;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
@ -260,20 +259,6 @@ void SPI1_IRQHandler(void)
|
||||
/* USER CODE END SPI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM8 update interrupt.
|
||||
*/
|
||||
void TIM8_UP_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim8);
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Tue Aug 02 18:31:31 CEST 2022]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Mon Aug 01 08:27:49 CEST 2022]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
||||
@ -65,7 +65,6 @@ NVIC.SPI1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.SVCall_IRQn=true\:4\:0\:true\:false\:true\:false\:false\:false
|
||||
NVIC.SysTick_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:false
|
||||
NVIC.TIM1_UP_TIM16_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.TIM8_UP_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:4\:0\:true\:false\:true\:false\:false\:false
|
||||
PA10.GPIOParameters=GPIO_Label
|
||||
PA10.GPIO_Label=Status_LED
|
||||
@ -152,7 +151,7 @@ ProjectManager.StackSize=0x400
|
||||
ProjectManager.TargetToolchain=Makefile
|
||||
ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_CRC_Init-CRC-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM8_Init-TIM8-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_CRC_Init-CRC-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true
|
||||
RCC.ADC12Freq_Value=16000000
|
||||
RCC.AHBFreq_Value=16000000
|
||||
RCC.APB1Freq_Value=16000000
|
||||
|
||||
Reference in New Issue
Block a user