Compare commits
10 Commits
372d07af84
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a6a512d2e3 | |||
| 6dab1a5eb7 | |||
| 72c26fb758 | |||
| e3080b1f6e | |||
| 77f600ddb3 | |||
| e3a226be54 | |||
| 8b0ca85f3d | |||
| 3d4f9eab74 | |||
| 5ad45cf53d | |||
| bd9d86b168 |
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "stm32g441xx.h"
|
#include "stm32g441xx.h"
|
||||||
#include "stm32g4xx_hal.h"
|
#include "stm32g4xx_hal.h"
|
||||||
|
#include "stm32g4xx_hal_gpio.h"
|
||||||
|
|
||||||
#define TS_INACTIVE 0
|
#define TS_INACTIVE 0
|
||||||
#define TS_PRECHARGE 2
|
#define TS_PRECHARGE 2
|
||||||
@ -24,6 +25,7 @@
|
|||||||
#define ADC_READ_TIMEOUT 500 // in ms
|
#define ADC_READ_TIMEOUT 500 // in ms
|
||||||
#define SDC_LOWER_THRESHOLD 2500 // in ADC Values
|
#define SDC_LOWER_THRESHOLD 2500 // in ADC Values
|
||||||
#define PRECHARGE_95_DURATION 1000 // in ms
|
#define PRECHARGE_95_DURATION 1000 // in ms
|
||||||
|
#define PRECHARGE_OPEN_AFTER 1000 // in ms
|
||||||
// FIXME
|
// FIXME
|
||||||
#define LOWER_VEHICLE_SIDE_VOLTAGE_LIMIT 150000 // in mV
|
#define LOWER_VEHICLE_SIDE_VOLTAGE_LIMIT 150000 // in mV
|
||||||
|
|
||||||
@ -31,6 +33,7 @@ typedef struct {
|
|||||||
|
|
||||||
int32_t BatteryVoltageVehicleSide;
|
int32_t BatteryVoltageVehicleSide;
|
||||||
int32_t BatteryVoltageBatterySide;
|
int32_t BatteryVoltageBatterySide;
|
||||||
|
int32_t shuntCurrent;
|
||||||
uint8_t targetTSState;
|
uint8_t targetTSState;
|
||||||
uint8_t currentTSState;
|
uint8_t currentTSState;
|
||||||
uint32_t precharge95ReachedTimestamp;
|
uint32_t precharge95ReachedTimestamp;
|
||||||
@ -51,4 +54,8 @@ void AIR_Discharge_Position();
|
|||||||
void AIR_Active_Position();
|
void AIR_Active_Position();
|
||||||
void AIR_Error_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_ */
|
#endif /* INC_AIR_STATE_MASCHINE_H_ */
|
||||||
|
|||||||
@ -21,7 +21,9 @@
|
|||||||
#define SLAVE_STATUS_BASE_ADDRESS 0x600
|
#define SLAVE_STATUS_BASE_ADDRESS 0x600
|
||||||
#define SLAVE_CMD_BASE_ADDRESS 0x500 //
|
#define SLAVE_CMD_BASE_ADDRESS 0x500 //
|
||||||
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
|
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
|
||||||
#define TIME_SYNC_ADDRESS 0x002
|
#define CLOCK_SYNC_ADDRESS 0x002
|
||||||
|
#define MASTER_HEARTBEAT_ADDRESS 0x010
|
||||||
|
#define SLAVE_EEPROM_WRITE_ADDRESS 0x020
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int16_t FrameID;
|
int16_t FrameID;
|
||||||
|
|||||||
34
Core/Inc/Clock_Sync.h
Normal file
34
Core/Inc/Clock_Sync.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef INC_CLOCK_SYNC_H_
|
||||||
|
#define INC_CLOCK_SYNC_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file Clock_Sync.h
|
||||||
|
* @author Jasper v. Blanckenburg (j.blanckenburg@fasttube.de)
|
||||||
|
* @brief Clock synchronization mechanism -- master side
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-08-01
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
* The slaves' clocks are fairly inaccurate -- too inaccurate for reliable CAN
|
||||||
|
* communication. In order to synchronize the clock frequencies, the slaves need
|
||||||
|
* an external clock source. Since the HSE doesn't work on all slaves, we use
|
||||||
|
* the master as the external clock source. For more detail, take a look at the
|
||||||
|
* clock sync section in the slave code.
|
||||||
|
*
|
||||||
|
* This file handles the master part of the clock sync mechanism: It sends
|
||||||
|
* CLOCK_SYNC frames every 1000 ms and MASTER_HEARTBEAT frames every 100 ms. In
|
||||||
|
* order to keep the time between packets accurate, they are sent from timer
|
||||||
|
* interrupts.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stm32g4xx_hal.h"
|
||||||
|
#include "stm32g4xx_hal_fdcan.h"
|
||||||
|
#include "stm32g4xx_hal_tim.h"
|
||||||
|
|
||||||
|
void clock_sync_init(FDCAN_HandleTypeDef* can, TIM_HandleTypeDef* sync_timer,
|
||||||
|
TIM_HandleTypeDef* heartbeat_timer);
|
||||||
|
|
||||||
|
void clock_sync_handle_timer_complete(TIM_HandleTypeDef* timer);
|
||||||
|
|
||||||
|
#endif // INC_CLOCK_SYNC_H_
|
||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "stm32g441xx.h"
|
#include "stm32g441xx.h"
|
||||||
|
|
||||||
#define NUMBEROFSLAVES 7
|
#define NUMBEROFSLAVES 9
|
||||||
#define NUMBEROFCELLS 10
|
#define NUMBEROFCELLS 10
|
||||||
#define NUMBEROFTEMPS 32
|
#define NUMBEROFTEMPS 32
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ typedef struct {
|
|||||||
uint8_t error;
|
uint8_t error;
|
||||||
uint8_t timeout;
|
uint8_t timeout;
|
||||||
uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES];
|
uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES];
|
||||||
|
uint8_t error_frame[8];
|
||||||
|
|
||||||
} SlaveHandler;
|
} SlaveHandler;
|
||||||
|
|
||||||
|
|||||||
@ -60,6 +60,7 @@ void FDCAN1_IT0_IRQHandler(void);
|
|||||||
void FDCAN1_IT1_IRQHandler(void);
|
void FDCAN1_IT1_IRQHandler(void);
|
||||||
void TIM1_UP_TIM16_IRQHandler(void);
|
void TIM1_UP_TIM16_IRQHandler(void);
|
||||||
void SPI1_IRQHandler(void);
|
void SPI1_IRQHandler(void);
|
||||||
|
void TIM8_UP_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|||||||
@ -7,7 +7,10 @@
|
|||||||
|
|
||||||
#include "AIR_State_Maschine.h"
|
#include "AIR_State_Maschine.h"
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include "stm32g4xx_hal.h"
|
#include "stm32g4xx_hal.h"
|
||||||
|
#include "stm32g4xx_hal_gpio.h"
|
||||||
|
|
||||||
DMA_HandleTypeDef* air_current_dma = {0};
|
DMA_HandleTypeDef* air_current_dma = {0};
|
||||||
DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||||
@ -15,6 +18,10 @@ DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
|||||||
uint8_t air_adc_complete = 0;
|
uint8_t air_adc_complete = 0;
|
||||||
uint8_t sdc_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 init_AIR_State_Maschine() {
|
||||||
AIRStateHandler airstate = {0};
|
AIRStateHandler airstate = {0};
|
||||||
|
|
||||||
@ -110,6 +117,12 @@ 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 ==
|
else if (airstate->currentTSState ==
|
||||||
TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at
|
TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at
|
||||||
// Vehicle Side
|
// Vehicle Side
|
||||||
@ -178,48 +191,76 @@ void Deactivate_TS(AIRStateHandler* airstate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AIR_Precharge_Position() {
|
void AIR_Precharge_Position() {
|
||||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||||
GPIO_PIN_SET);
|
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_SET);
|
|
||||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
|
||||||
GPIO_PIN_RESET);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIR_Inactive_Position() {
|
void AIR_Inactive_Position() {
|
||||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_RESET);
|
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_RESET);
|
||||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
|
||||||
GPIO_PIN_RESET);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIR_Discharge_Position() {
|
void AIR_Discharge_Position() {
|
||||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||||
GPIO_PIN_SET);
|
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_SET);
|
|
||||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
|
||||||
GPIO_PIN_RESET);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIR_Active_Position() // TODO Deactivate Precharge after a while to
|
void AIR_Active_Position() {
|
||||||
// decrease current Consumption
|
if (pos_air_state == GPIO_PIN_SET &&
|
||||||
{
|
HAL_GetTick() - pos_air_change_timestamp > PRECHARGE_OPEN_AFTER) {
|
||||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_SET);
|
} else {
|
||||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||||
GPIO_PIN_SET);
|
}
|
||||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||||
GPIO_PIN_SET);
|
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIR_Error_Position() {
|
void AIR_Error_Position() {
|
||||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_RESET);
|
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_RESET);
|
||||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||||
GPIO_PIN_RESET);
|
}
|
||||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,11 +14,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// 3 should be programmed with CAN id 2
|
const uint16_t slave_CAN_id_to_slave_index[10] = {
|
||||||
// const uint16_t slave_CAN_id_to_slave_index[7] = {
|
0, 1, 2, 3, 4, 5, 6, 7, 255, 8}; // TODO: Make this pretty pls
|
||||||
// 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};
|
canFrame framebuffer[CANFRAMEBUFFERSIZE] = {0};
|
||||||
uint32_t framebufferwritepointer = 0;
|
uint32_t framebufferwritepointer = 0;
|
||||||
uint32_t framebufferreadpointer = 0;
|
uint32_t framebufferreadpointer = 0;
|
||||||
@ -72,11 +69,9 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) {
|
|||||||
uint8_t messageID = msg & 0x00F;
|
uint8_t messageID = msg & 0x00F;
|
||||||
updateSlaveInfo(slaveID, messageID, rxFrame);
|
updateSlaveInfo(slaveID, messageID, rxFrame);
|
||||||
} else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) {
|
} else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) {
|
||||||
AMSErrorHandle errorframe = {0};
|
uint8_t slave_id = rxFrame.data[0];
|
||||||
errorframe.errorcode = SlavesErrorFrameError;
|
slaves[slave_id].error = 1;
|
||||||
memcpy(errorframe.errorarg, rxFrame.data, 7);
|
memcpy(slaves[slave_id].error_frame, rxFrame.data, 8);
|
||||||
|
|
||||||
AMS_Error_Handler(&errorframe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
Core/Src/Clock_Sync.c
Normal file
35
Core/Src/Clock_Sync.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "Clock_Sync.h"
|
||||||
|
|
||||||
|
#include "CAN_Communication.h"
|
||||||
|
|
||||||
|
#include "stm32g4xx_hal.h"
|
||||||
|
#include "stm32g4xx_hal_fdcan.h"
|
||||||
|
#include "stm32g4xx_hal_tim.h"
|
||||||
|
|
||||||
|
static FDCAN_HandleTypeDef* can;
|
||||||
|
static TIM_HandleTypeDef* sync_timer;
|
||||||
|
static TIM_HandleTypeDef* heartbeat_timer;
|
||||||
|
|
||||||
|
static uint8_t clock_sync_counter = 0;
|
||||||
|
|
||||||
|
void clock_sync_init(FDCAN_HandleTypeDef* can_handle,
|
||||||
|
TIM_HandleTypeDef* sync_timer_handle,
|
||||||
|
TIM_HandleTypeDef* heartbeat_timer_handle) {
|
||||||
|
can = can_handle;
|
||||||
|
sync_timer = sync_timer_handle;
|
||||||
|
heartbeat_timer = heartbeat_timer_handle;
|
||||||
|
HAL_TIM_Base_Start_IT(heartbeat_timer);
|
||||||
|
// Delay between starting the timers so the interrupts don't fire at the same
|
||||||
|
// time
|
||||||
|
HAL_Delay(50);
|
||||||
|
HAL_TIM_Base_Start_IT(sync_timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
spirxbuf[0] << 24 | spirxbuf[1] << 16 | spirxbuf[2] << 8 | spirxbuf[3];
|
||||||
spi_airstates->BatteryVoltageVehicleSide =
|
spi_airstates->BatteryVoltageVehicleSide =
|
||||||
spirxbuf[4] << 24 | spirxbuf[5] << 16 | spirxbuf[6] << 8 | spirxbuf[7];
|
spirxbuf[4] << 24 | spirxbuf[5] << 16 | spirxbuf[6] << 8 | spirxbuf[7];
|
||||||
uint32_t current =
|
spi_airstates->shuntCurrent =
|
||||||
spirxbuf[8] << 24 | spirxbuf[9] << 16 | spirxbuf[10] << 8 | spirxbuf[11];
|
spirxbuf[8] << 24 | spirxbuf[9] << 16 | spirxbuf[10] << 8 | spirxbuf[11];
|
||||||
spi_airstates->targetTSState = spirxbuf[12];
|
spi_airstates->targetTSState = spirxbuf[12];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
#include "stm32g4xx_hal.h"
|
#include "stm32g4xx_hal.h"
|
||||||
#include "stm32g4xx_hal_gpio.h"
|
#include "stm32g4xx_hal_gpio.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
SlaveHandler slaves[NUMBEROFSLAVES];
|
SlaveHandler slaves[NUMBEROFSLAVES];
|
||||||
|
|
||||||
void initSlaves() {
|
void initSlaves() {
|
||||||
@ -63,8 +65,12 @@ uint8_t checkSlaveTimeout() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAL_GetTick() < 20000) {
|
if (slaves[n].error) {
|
||||||
continue;
|
AMSErrorHandle errorframe;
|
||||||
|
errorframe.errorcode = SlavesErrorFrameError;
|
||||||
|
memcpy(errorframe.errorarg, slaves[n].error_frame, 7);
|
||||||
|
AMS_Error_Handler(&errorframe);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) {
|
for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
#include "AIR_State_Maschine.h"
|
#include "AIR_State_Maschine.h"
|
||||||
#include "AMS_Errorcodes.h"
|
#include "AMS_Errorcodes.h"
|
||||||
#include "CAN_Communication.h"
|
#include "CAN_Communication.h"
|
||||||
|
#include "Clock_Sync.h"
|
||||||
#include "Error_Check.h"
|
#include "Error_Check.h"
|
||||||
#include "SPI_Slave_Communication.h"
|
#include "SPI_Slave_Communication.h"
|
||||||
#include "Slave_Monitoring.h"
|
#include "Slave_Monitoring.h"
|
||||||
@ -55,6 +56,7 @@ FDCAN_HandleTypeDef hfdcan1;
|
|||||||
SPI_HandleTypeDef hspi1;
|
SPI_HandleTypeDef hspi1;
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
TIM_HandleTypeDef htim1;
|
||||||
|
TIM_HandleTypeDef htim8;
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ static void MX_FDCAN1_Init(void);
|
|||||||
static void MX_SPI1_Init(void);
|
static void MX_SPI1_Init(void);
|
||||||
static void MX_CRC_Init(void);
|
static void MX_CRC_Init(void);
|
||||||
static void MX_TIM1_Init(void);
|
static void MX_TIM1_Init(void);
|
||||||
|
static void MX_TIM8_Init(void);
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
void setAMSError(void);
|
void setAMSError(void);
|
||||||
/* USER CODE END PFP */
|
/* USER CODE END PFP */
|
||||||
@ -74,8 +77,8 @@ void setAMSError(void);
|
|||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||||
if (htim == &htim1) {
|
if (htim == &htim1 || htim == &htim8) {
|
||||||
CAN_Transmit(&hfdcan1, TIME_SYNC_ADDRESS, NULL, 0);
|
clock_sync_handle_timer_complete(htim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,14 +119,15 @@ int main(void) {
|
|||||||
MX_SPI1_Init();
|
MX_SPI1_Init();
|
||||||
MX_CRC_Init();
|
MX_CRC_Init();
|
||||||
MX_TIM1_Init();
|
MX_TIM1_Init();
|
||||||
|
MX_TIM8_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
airstates = init_AIR_State_Maschine();
|
airstates = init_AIR_State_Maschine();
|
||||||
initSlaves();
|
|
||||||
set_SPI_errorInfo(&defaulterrorhandle);
|
set_SPI_errorInfo(&defaulterrorhandle);
|
||||||
spi_communication_init(&hspi1, &airstates);
|
spi_communication_init(&hspi1, &airstates);
|
||||||
CAN_Init(&hfdcan1);
|
CAN_Init(&hfdcan1);
|
||||||
HAL_TIM_Base_Start_IT(&htim1);
|
clock_sync_init(&hfdcan1, &htim1, &htim8);
|
||||||
|
initSlaves();
|
||||||
|
|
||||||
HAL_GPIO_WritePin(Status_LED_GPIO_Port, Status_LED_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(Status_LED_GPIO_Port, Status_LED_Pin, GPIO_PIN_SET);
|
||||||
// setAMSError();
|
// setAMSError();
|
||||||
@ -339,6 +343,48 @@ static void MX_TIM1_Init(void) {
|
|||||||
/* USER CODE END TIM1_Init 2 */
|
/* USER CODE END TIM1_Init 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM8 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM8_Init(void) {
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM8_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM8_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM8_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM8_Init 1 */
|
||||||
|
htim8.Instance = TIM8;
|
||||||
|
htim8.Init.Prescaler = 1599;
|
||||||
|
htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim8.Init.Period = 999;
|
||||||
|
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim8.Init.RepetitionCounter = 0;
|
||||||
|
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim8) != HAL_OK) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM8_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM8_Init 2 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO Initialization Function
|
* @brief GPIO Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
|
|||||||
@ -315,6 +315,20 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
|||||||
|
|
||||||
/* USER CODE END TIM1_MspInit 1 */
|
/* USER CODE END TIM1_MspInit 1 */
|
||||||
}
|
}
|
||||||
|
else if(htim_base->Instance==TIM8)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM8_MspInit 0 */
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,6 +354,20 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
|||||||
|
|
||||||
/* USER CODE END TIM1_MspDeInit 1 */
|
/* USER CODE END TIM1_MspDeInit 1 */
|
||||||
}
|
}
|
||||||
|
else if(htim_base->Instance==TIM8)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM8_MspDeInit 0 */
|
||||||
|
|
||||||
|
/* 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,6 +60,7 @@
|
|||||||
extern FDCAN_HandleTypeDef hfdcan1;
|
extern FDCAN_HandleTypeDef hfdcan1;
|
||||||
extern SPI_HandleTypeDef hspi1;
|
extern SPI_HandleTypeDef hspi1;
|
||||||
extern TIM_HandleTypeDef htim1;
|
extern TIM_HandleTypeDef htim1;
|
||||||
|
extern TIM_HandleTypeDef htim8;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
|
|
||||||
/* USER CODE END EV */
|
/* USER CODE END EV */
|
||||||
@ -259,6 +260,20 @@ void SPI1_IRQHandler(void)
|
|||||||
/* USER CODE END SPI1_IRQn 1 */
|
/* 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 BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Sat Jul 30 22:35:37 CEST 2022]
|
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Tue Aug 02 18:31:31 CEST 2022]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
|
|||||||
@ -19,7 +19,8 @@ Mcu.IP3=RCC
|
|||||||
Mcu.IP4=SPI1
|
Mcu.IP4=SPI1
|
||||||
Mcu.IP5=SYS
|
Mcu.IP5=SYS
|
||||||
Mcu.IP6=TIM1
|
Mcu.IP6=TIM1
|
||||||
Mcu.IPNb=7
|
Mcu.IP7=TIM8
|
||||||
|
Mcu.IPNb=8
|
||||||
Mcu.Name=STM32G441CBTx
|
Mcu.Name=STM32G441CBTx
|
||||||
Mcu.Package=LQFP48
|
Mcu.Package=LQFP48
|
||||||
Mcu.Pin0=PC13
|
Mcu.Pin0=PC13
|
||||||
@ -36,6 +37,7 @@ Mcu.Pin18=VP_SYS_VS_Systick
|
|||||||
Mcu.Pin19=VP_SYS_VS_DBSignals
|
Mcu.Pin19=VP_SYS_VS_DBSignals
|
||||||
Mcu.Pin2=PC15-OSC32_OUT
|
Mcu.Pin2=PC15-OSC32_OUT
|
||||||
Mcu.Pin20=VP_TIM1_VS_ClockSourceINT
|
Mcu.Pin20=VP_TIM1_VS_ClockSourceINT
|
||||||
|
Mcu.Pin21=VP_TIM8_VS_ClockSourceINT
|
||||||
Mcu.Pin3=PA5
|
Mcu.Pin3=PA5
|
||||||
Mcu.Pin4=PA6
|
Mcu.Pin4=PA6
|
||||||
Mcu.Pin5=PA7
|
Mcu.Pin5=PA7
|
||||||
@ -43,7 +45,7 @@ Mcu.Pin6=PB0
|
|||||||
Mcu.Pin7=PA8
|
Mcu.Pin7=PA8
|
||||||
Mcu.Pin8=PA9
|
Mcu.Pin8=PA9
|
||||||
Mcu.Pin9=PA10
|
Mcu.Pin9=PA10
|
||||||
Mcu.PinsNb=21
|
Mcu.PinsNb=22
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32G441CBTx
|
Mcu.UserName=STM32G441CBTx
|
||||||
@ -63,6 +65,7 @@ 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.SVCall_IRQn=true\:4\:0\:true\:false\:true\:false\:false\:false
|
||||||
NVIC.SysTick_IRQn=true\:4\:0\:true\:false\:true\:false\:true\: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.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
|
NVIC.UsageFault_IRQn=true\:4\:0\:true\:false\:true\:false\:false\:false
|
||||||
PA10.GPIOParameters=GPIO_Label
|
PA10.GPIOParameters=GPIO_Label
|
||||||
PA10.GPIO_Label=Status_LED
|
PA10.GPIO_Label=Status_LED
|
||||||
@ -149,7 +152,7 @@ ProjectManager.StackSize=0x400
|
|||||||
ProjectManager.TargetToolchain=Makefile
|
ProjectManager.TargetToolchain=Makefile
|
||||||
ProjectManager.ToolChainLocation=
|
ProjectManager.ToolChainLocation=
|
||||||
ProjectManager.UnderRoot=false
|
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
|
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
|
||||||
RCC.ADC12Freq_Value=16000000
|
RCC.ADC12Freq_Value=16000000
|
||||||
RCC.AHBFreq_Value=16000000
|
RCC.AHBFreq_Value=16000000
|
||||||
RCC.APB1Freq_Value=16000000
|
RCC.APB1Freq_Value=16000000
|
||||||
@ -204,6 +207,9 @@ TIM1.CounterMode=TIM_COUNTERMODE_UP
|
|||||||
TIM1.IPParameters=Prescaler,CounterMode,PeriodNoDither
|
TIM1.IPParameters=Prescaler,CounterMode,PeriodNoDither
|
||||||
TIM1.PeriodNoDither=9999
|
TIM1.PeriodNoDither=9999
|
||||||
TIM1.Prescaler=1599
|
TIM1.Prescaler=1599
|
||||||
|
TIM8.IPParameters=Prescaler,PeriodNoDither
|
||||||
|
TIM8.PeriodNoDither=999
|
||||||
|
TIM8.Prescaler=1599
|
||||||
VP_CRC_VS_CRC.Mode=CRC_Activate
|
VP_CRC_VS_CRC.Mode=CRC_Activate
|
||||||
VP_CRC_VS_CRC.Signal=CRC_VS_CRC
|
VP_CRC_VS_CRC.Signal=CRC_VS_CRC
|
||||||
VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
|
VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
|
||||||
@ -212,4 +218,6 @@ VP_SYS_VS_Systick.Mode=SysTick
|
|||||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||||
VP_TIM1_VS_ClockSourceINT.Mode=Internal
|
VP_TIM1_VS_ClockSourceINT.Mode=Internal
|
||||||
VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT
|
VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT
|
||||||
|
VP_TIM8_VS_ClockSourceINT.Mode=Internal
|
||||||
|
VP_TIM8_VS_ClockSourceINT.Signal=TIM8_VS_ClockSourceINT
|
||||||
board=custom
|
board=custom
|
||||||
|
|||||||
@ -38,6 +38,7 @@ BUILD_DIR = build
|
|||||||
C_SOURCES = \
|
C_SOURCES = \
|
||||||
Core/Src/AIR_State_Maschine.c \
|
Core/Src/AIR_State_Maschine.c \
|
||||||
Core/Src/CAN_Communication.c \
|
Core/Src/CAN_Communication.c \
|
||||||
|
Core/Src/Clock_Sync.c \
|
||||||
Core/Src/Error_Check.c \
|
Core/Src/Error_Check.c \
|
||||||
Core/Src/SPI_Slave_Communication.c \
|
Core/Src/SPI_Slave_Communication.c \
|
||||||
Core/Src/Slave_Monitoring.c \
|
Core/Src/Slave_Monitoring.c \
|
||||||
|
|||||||
Reference in New Issue
Block a user