Skip to content

Commit

Permalink
Update Main to F4, remove old PDU stuff, add SDC mux implementation (#88
Browse files Browse the repository at this point in the history
)

* Update Main to F4, remove old PDU stuff, add SDC mux implementation

* Abox pin init and tmu setup

* luke pls review

---------

Co-authored-by: AdityaAsGithub <[email protected]>
Co-authored-by: finncorc1 <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2024
1 parent 35840c6 commit 9979f31
Show file tree
Hide file tree
Showing 21 changed files with 660 additions and 984 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"type": "cortex-debug",
"servertype": "openocd",
"device:": "STM32L432KC",
"svdFile": "${workspaceRoot}/common/svd/STM32L4x2.svd",
"svdFile": "${workspaceRoot}/common/svd/STM32F407.svd",
"configFiles": [
"interface/stlink.cfg",
"target/stm32l4x.cfg"
"target/stm32f4x.cfg"
],
"debuggerArgs": [
"-d",
Expand Down
26 changes: 25 additions & 1 deletion common/daq/can_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@
"msg_hlp": 3,
"msg_pgn": 11
},
{
"msg_name": "sdc_status",
"msg_desc": "Shutdown Circuit Status",
"signals": [
{"sig_name": "IMD", "type":"uint8_t", "length":1},
{"sig_name": "BMS", "type":"uint8_t", "length":1},
{"sig_name": "BSPD", "type":"uint8_t", "length":1},
{"sig_name": "BOTS", "type":"uint8_t", "length":1},
{"sig_name": "inertia", "type":"uint8_t", "length":1},
{"sig_name": "c_estop", "type":"uint8_t", "length":1},
{"sig_name": "main", "type":"uint8_t", "length":1},
{"sig_name": "r_estop", "type":"uint8_t", "length":1},
{"sig_name": "l_estop", "type":"uint8_t", "length":1},
{"sig_name": "HVD", "type":"uint8_t", "length":1},
{"sig_name": "hub", "type":"uint8_t", "length":1},
{"sig_name": "TSMS", "type":"uint8_t", "length":1},
{"sig_name": "pchg_out", "type":"uint8_t", "length":1}

],
"msg_period": 165,
"msg_hlp": 3,
"msg_pgn": 14
},
{
"msg_name": "rear_controller_temps",
"msg_desc": "Temperature of motor controllers",
Expand Down Expand Up @@ -207,7 +230,8 @@
{"msg_name": "LWS_Standard"},
{"msg_name": "main_module_bl_cmd" , "callback": true},
{"msg_name": "cooling_driver_request", "callback": true},
{"msg_name": "throttle_remapped"}
{"msg_name": "throttle_remapped"},
{"msg_name": "pdu_test"}
]
},
{
Expand Down
22 changes: 13 additions & 9 deletions common/daq/daq_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
"node_name":"Main_Module",
"includes":"#include \"cooling.h\"\n#include\"main.h\"\n#include\"car.h\"",
"variables": [
{"var_name":"dt_liters_p_min_x10", "access_phrase":"cooling.dt_liters_p_min_x10", "read_only": true, "type":"uint8_t", "length": 8},
{"var_name":"bat_liters_p_min_x10", "access_phrase":"cooling.bat_liters_p_min_x10", "read_only": true, "type":"uint8_t", "length": 8},
{"var_name":"dt_flow_error", "access_phrase":"cooling.dt_flow_error", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"dt_temp_error", "access_phrase":"cooling.dt_temp_error", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"bat_flow_error", "access_phrase":"cooling.bat_flow_error", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"bat_temp_error", "access_phrase":"cooling.bat_temp_error", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"cal_steer_angle", "access_phrase": "calibrateSteeringAngle", "has_read_func":true, "read_only":true, "type":"uint8_t", "length": 1},
{"var_name":"cooling_daq_override", "access_phrase": "cooling.daq_override", "read_only": false, "type":"uint8_t", "length": 1},
{"var_name":"dt_pump", "access_phrase": "cooling.out_daq_req.dt_pump", "read_only": false, "type": "uint8_t", "length": 1},
{"var_name":"bat_pump", "access_phrase": "cooling.out_daq_req.bat_pump", "read_only": false, "type": "uint8_t", "length": 1},
{"var_name":"bat_pump_aux", "access_phrase": "cooling.out_daq_req.bat_pump_aux", "read_only": false, "type": "uint8_t", "length": 1},
{"var_name":"dt_fan", "access_phrase": "cooling.out_daq_req.dt_fan_power", "read_only": false, "type": "uint8_t", "unit": "%"},
{"var_name":"bat_fan", "access_phrase": "cooling.out_daq_req.bat_fan_power", "read_only": false, "type": "uint8_t", "unit": "%"},
{"var_name":"sdc_main_status", "access_phrase": "sdc_mux.main_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_center_stop_status", "access_phrase": "sdc_mux.c_stop_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_inertia_sw_status", "access_phrase": "sdc_mux.inertia_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_bots_stat", "access_phrase": "sdc_mux.bots_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_bspd_stat", "access_phrase": "sdc_mux.bspd_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_bms_stat", "access_phrase": "sdc_mux.bms_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_imd_stat", "access_phrase": "sdc_mux.imd_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_r_estop_stat", "access_phrase": "sdc_mux.r_stop_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_l_estop_stat", "access_phrase": "sdc_mux.l_stop_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_hvd_stat", "access_phrase": "sdc_mux.hvd_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_rear_hub_stat", "access_phrase": "sdc_mux.r_hub_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_tsms_stat", "access_phrase": "sdc_mux.tsms_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"sdc_pchg_out_stat", "access_phrase": "sdc_mux.pchg_out_stat", "read_only": true, "type":"uint8_t", "length": 1},
{"var_name":"daq_buzzer", "access_phrase": "daq_buzzer", "read_only": false, "type": "uint8_t", "length": 1, "unit": "%"}
],
"files":[]
Expand Down
29 changes: 29 additions & 0 deletions common/daq/per_dbc.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ BO_ 2348810945 rear_motor_currents_temps: 8 Main_Module
SG_ right_current : 16|16@1+ (0.1,0) [0|0] "Amp" Vector__XXX
SG_ left_current : 0|16@1+ (0.1,0) [0|0] "Amp" Vector__XXX

BO_ 2348811137 sdc_status: 2 Main_Module
SG_ pchg_out : 12|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ TSMS : 11|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ hub : 10|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ HVD : 9|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ l_estop : 8|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ r_estop : 7|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ main : 6|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ c_estop : 5|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ inertia : 4|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ BOTS : 3|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ BSPD : 2|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ BMS : 1|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ IMD : 0|1@1+ (1,0) [0|0] "" Vector__XXX

BO_ 2348811009 rear_controller_temps: 2 Main_Module
SG_ right_temp : 8|8@1+ (1,0) [0|0] "C" Vector__XXX
SG_ left_temp : 0|8@1+ (1,0) [0|0] "C" Vector__XXX
Expand Down Expand Up @@ -937,6 +952,20 @@ CM_ SG_ 2348810945 right_temp "";
CM_ SG_ 2348810945 left_temp "";
CM_ SG_ 2348810945 right_current "";
CM_ SG_ 2348810945 left_current "";
CM_ BO_ 2348811137 "Shutdown Circuit Status";
CM_ SG_ 2348811137 pchg_out "";
CM_ SG_ 2348811137 TSMS "";
CM_ SG_ 2348811137 hub "";
CM_ SG_ 2348811137 HVD "";
CM_ SG_ 2348811137 l_estop "";
CM_ SG_ 2348811137 r_estop "";
CM_ SG_ 2348811137 main "";
CM_ SG_ 2348811137 c_estop "";
CM_ SG_ 2348811137 inertia "";
CM_ SG_ 2348811137 BOTS "";
CM_ SG_ 2348811137 BSPD "";
CM_ SG_ 2348811137 BMS "";
CM_ SG_ 2348811137 IMD "";
CM_ BO_ 2348811009 "Temperature of motor controllers";
CM_ SG_ 2348811009 right_temp "";
CM_ SG_ 2348811009 left_temp "";
Expand Down
13 changes: 10 additions & 3 deletions common/phal_F4_F7/gpio/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ typedef struct
#define GPIO_INIT_CANRX_PA11 GPIO_INIT_AF(GPIOA, 11, 9, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_CANTX_PA12 GPIO_INIT_AF(GPIOA, 12, 9, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)

#define GPIO_INIT_CAN2RX_PB12 GPIO_INIT_AF(GPIOB, 12, 9, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_CAN2TX_PB13 GPIO_INIT_AF(GPIOB, 13, 9, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)

//SPI
#define GPIO_INIT_SPI2_SCK_PB13 GPIO_INIT_AF(GPIOB, 13, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)
#define GPIO_INIT_SPI2_MISO_PB14 GPIO_INIT_AF(GPIOB, 14, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
Expand All @@ -193,13 +196,20 @@ typedef struct
#define GPIO_INIT_SPI1_SCK_PB3 GPIO_INIT_AF(GPIOB, 3, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)
#define GPIO_INIT_SPI1_MOSI_PB5 GPIO_INIT_AF(GPIOB, 5, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)

#define GPIO_INIT_SPI1_SCK_PA5 GPIO_INIT_AF(GPIOA, 5, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)
#define GPIO_INIT_SPI1_MISO_PA6 GPIO_INIT_AF(GPIOA, 6, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_SPI1_MOSI_PA7 GPIO_INIT_AF(GPIOA, 7, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)


//UART/USART
#define GPIO_INIT_USART3TX_PC10 GPIO_INIT_AF(GPIOC, 10, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART3RX_PC11 GPIO_INIT_AF(GPIOC, 11, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)

#define GPIO_INIT_USART2TX_PA2 GPIO_INIT_AF(GPIOA, 2, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART2RX_PA3 GPIO_INIT_AF(GPIOA, 3, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)

#define GPIO_INIT_USART1TX_PA9 GPIO_INIT_AF(GPIOA, 9, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART1RX_PA10 GPIO_INIT_AF(GPIOA, 10, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#endif

#ifdef STM32F732xx
Expand All @@ -217,9 +227,6 @@ typedef struct
#define GPIO_INIT_UART4RX_PA1 GPIO_INIT_AF(GPIOA, 1, 8, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#endif

#define GPIO_INIT_USART1TX_PA9 GPIO_INIT_AF(GPIOA, 9, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART1RX_PA10 GPIO_INIT_AF(GPIOA, 10, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)

/**
* @brief Initilize the GPIO perpheral given a list of configuration fields for all of the GPIO pins.
* Will also enable the GPIO RCC clock
Expand Down
2 changes: 1 addition & 1 deletion common/plettenberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ target_sources(${TARGET_NAME} PRIVATE "plettenberg.c")
# For libraries, these directories are all referenced to the top level firmware directory, CMAKE_SOURCE_DIR
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_SOURCE_DIR})

target_link_libraries(${TARGET_NAME} "QUEUE;common_defs;PHAL_L496")
target_link_libraries(${TARGET_NAME} "QUEUE;common_defs;PHAL_F407")
19 changes: 15 additions & 4 deletions common/plettenberg/plettenberg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __PLETTENBERG_H__

#include "common/common_defs/common_defs.h"
#include "common/phal_L4/usart/usart.h"
#include "common/phal_F4_F7/usart/usart.h"
#include "common/psched/psched.h"
#include "common/queue/queue.h"
#include "string.h"
Expand Down Expand Up @@ -57,7 +57,18 @@ typedef enum
MC_ERROR // :(
} motor_state_t;

typedef struct
typedef struct
{
uint32_t last_msg_time; // Time of last rx message that was size of msg_size
uint16_t msg_size; // Size of typical msg
uint16_t last_msg_loc; // Index of first byte of last msg received
uint32_t last_rx_time; // Time of the last rx
uint16_t rx_buf_size; // Size of rx circular buffer for DMA
uint16_t last_rx_loc; // Index of byte of last rx
char *rx_buf; // Buffer location
} usart_rx_buf_t;

typedef struct
{
// Motor status
uint16_t init_time; // Current init timing
Expand All @@ -75,7 +86,7 @@ typedef struct
uint32_t rx_timeout; // Dynamically set timeout to determine connection status

// Motor outputs
uint16_t voltage_x10;
uint16_t voltage_x10;
uint16_t current_x10;
uint16_t curr_power_x10; // Last torque command percent output sent x10
uint32_t rpm;
Expand All @@ -88,7 +99,7 @@ typedef struct
volatile usart_rx_buf_t *rx_buf; // Circular buffer for receiving via DMA
} motor_t;

void mcInit(motor_t *m, bool is_inverted, q_handle_t *tx_queue,
void mcInit(motor_t *m, bool is_inverted, q_handle_t *tx_queue,
usart_rx_buf_t *rx_buf, const bool *hv_present);
void mcSetPower(float power, motor_t *m);
void mcPeriodic(motor_t *m);
Expand Down
4 changes: 2 additions & 2 deletions source/main_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_executable(${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES
COMPONENT_NAME ${COMPONENT_NAME}
COMPONENT_DIR ${CMAKE_CURRENT_LIST_DIR}
LINKER_SCRIPT "STM32L496VGTx_FLASH"
COMMON_LIBS "CMSIS_L496;PSCHED_L496;QUEUE;DAQ_L496;PHAL_L496;FAULTS_L496;BOOTLOADER_COMMON_L496;PLETTENBERG;WHEEL_SPEEDS_L496"
LINKER_SCRIPT "STM32F407VGTx_FLASH"
COMMON_LIBS "CMSIS_F407;PSCHED_F407;QUEUE;DAQ_F407;PHAL_F407;FAULTS_F407;PLETTENBERG"
)
COMMON_FIRMWARE_COMPONENT(${TARGET_NAME})
30 changes: 21 additions & 9 deletions source/main_module/can/can_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ void canRxUpdate()
can_data.throttle_remapped.stale = 0;
can_data.throttle_remapped.last_rx = sched.os_ticks;
break;
case ID_PDU_TEST:
can_data.pdu_test.test_1 = msg_data_a->pdu_test.test_1;
can_data.pdu_test.test_2 = msg_data_a->pdu_test.test_2;
can_data.pdu_test.test_3 = msg_data_a->pdu_test.test_3;
can_data.pdu_test.stale = 0;
can_data.pdu_test.last_rx = sched.os_ticks;
break;
case ID_FAULT_SYNC_PDU:
can_data.fault_sync_pdu.idx = msg_data_a->fault_sync_pdu.idx;
can_data.fault_sync_pdu.latched = msg_data_a->fault_sync_pdu.latched;
Expand Down Expand Up @@ -185,6 +192,9 @@ void canRxUpdate()
CHECK_STALE(can_data.throttle_remapped.stale,
sched.os_ticks, can_data.throttle_remapped.last_rx,
UP_THROTTLE_REMAPPED);
CHECK_STALE(can_data.pdu_test.stale,
sched.os_ticks, can_data.pdu_test.last_rx,
UP_PDU_TEST);
/* END AUTO STALE CHECKS */
}

Expand Down Expand Up @@ -216,19 +226,21 @@ bool initCANFilter()
CAN1->sFilterRegister[3].FR2 = (ID_COOLING_DRIVER_REQUEST << 3) | 4;
CAN1->FA1R |= (1 << 4); // configure bank 4
CAN1->sFilterRegister[4].FR1 = (ID_THROTTLE_REMAPPED << 3) | 4;
CAN1->sFilterRegister[4].FR2 = (ID_FAULT_SYNC_PDU << 3) | 4;
CAN1->sFilterRegister[4].FR2 = (ID_PDU_TEST << 3) | 4;
CAN1->FA1R |= (1 << 5); // configure bank 5
CAN1->sFilterRegister[5].FR1 = (ID_FAULT_SYNC_DRIVELINE << 3) | 4;
CAN1->sFilterRegister[5].FR2 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4;
CAN1->sFilterRegister[5].FR1 = (ID_FAULT_SYNC_PDU << 3) | 4;
CAN1->sFilterRegister[5].FR2 = (ID_FAULT_SYNC_DRIVELINE << 3) | 4;
CAN1->FA1R |= (1 << 6); // configure bank 6
CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_A_BOX << 3) | 4;
CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_TORQUE_VECTOR_FPGA << 3) | 4;
CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4;
CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_A_BOX << 3) | 4;
CAN1->FA1R |= (1 << 7); // configure bank 7
CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4;
CAN1->sFilterRegister[7].FR2 = (ID_SET_FAULT << 3) | 4;
CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_TORQUE_VECTOR_FPGA << 3) | 4;
CAN1->sFilterRegister[7].FR2 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4;
CAN1->FA1R |= (1 << 8); // configure bank 8
CAN1->sFilterRegister[8].FR1 = (ID_RETURN_FAULT_CONTROL << 3) | 4;
CAN1->sFilterRegister[8].FR2 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4;
CAN1->sFilterRegister[8].FR1 = (ID_SET_FAULT << 3) | 4;
CAN1->sFilterRegister[8].FR2 = (ID_RETURN_FAULT_CONTROL << 3) | 4;
CAN1->FA1R |= (1 << 9); // configure bank 9
CAN1->sFilterRegister[9].FR1 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4;
/* END AUTO FILTER */
CAN1->FA1R |= (1 << 6); // configure bank 6
CAN1->sFilterRegister[6].FR1 = (ID_LWS_STANDARD << 21);
Expand Down
Loading

0 comments on commit 9979f31

Please sign in to comment.