From 9979f31922f10d88439870de22d849357f0f0aaf Mon Sep 17 00:00:00 2001 From: Aditya Anand <90068582+AdityaAsGithub@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:04:33 -0500 Subject: [PATCH] Update Main to F4, remove old PDU stuff, add SDC mux implementation (#88) * 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 Co-authored-by: finncorc1 <92646092+finncorc1@users.noreply.github.com> --- .vscode/launch.json | 4 +- common/daq/can_config.json | 26 +- common/daq/daq_config.json | 22 +- common/daq/per_dbc.dbc | 29 ++ common/phal_F4_F7/gpio/gpio.h | 13 +- common/plettenberg/CMakeLists.txt | 2 +- common/plettenberg/plettenberg.h | 19 +- source/main_module/CMakeLists.txt | 4 +- source/main_module/can/can_parse.c | 30 +- source/main_module/can/can_parse.h | 52 +- source/main_module/car/car.c | 60 ++- source/main_module/car/car.h | 31 +- source/main_module/cooling/cooling.c | 209 +++------ source/main_module/cooling/cooling.h | 22 +- source/main_module/daq/daq.c | 30 +- source/main_module/daq/daq.h | 34 +- source/main_module/main.c | 443 +++++++++--------- source/main_module/main.h | 271 ++++------- .../main_module/power_monitor/power_monitor.c | 116 ----- .../main_module/power_monitor/power_monitor.h | 61 --- .../power_monitor/power_monitor.tsc | 166 ------- 21 files changed, 660 insertions(+), 984 deletions(-) delete mode 100644 source/main_module/power_monitor/power_monitor.c delete mode 100644 source/main_module/power_monitor/power_monitor.h delete mode 100644 source/main_module/power_monitor/power_monitor.tsc diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a99b4b4..aab6837d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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", diff --git a/common/daq/can_config.json b/common/daq/can_config.json index bcb2b2bb..bd43b6fc 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -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", @@ -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"} ] }, { diff --git a/common/daq/daq_config.json b/common/daq/daq_config.json index 7f660c06..c22b6bb2 100644 --- a/common/daq/daq_config.json +++ b/common/daq/daq_config.json @@ -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":[] diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index d7975bbe..e449dca8 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -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 @@ -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 ""; diff --git a/common/phal_F4_F7/gpio/gpio.h b/common/phal_F4_F7/gpio/gpio.h index 78f7840e..b7aac3a6 100644 --- a/common/phal_F4_F7/gpio/gpio.h +++ b/common/phal_F4_F7/gpio/gpio.h @@ -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) @@ -193,6 +196,10 @@ 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) @@ -200,6 +207,9 @@ typedef struct #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 @@ -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 diff --git a/common/plettenberg/CMakeLists.txt b/common/plettenberg/CMakeLists.txt index 9a5cbf85..c74ee38a 100644 --- a/common/plettenberg/CMakeLists.txt +++ b/common/plettenberg/CMakeLists.txt @@ -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") \ No newline at end of file +target_link_libraries(${TARGET_NAME} "QUEUE;common_defs;PHAL_F407") \ No newline at end of file diff --git a/common/plettenberg/plettenberg.h b/common/plettenberg/plettenberg.h index de769917..cbd77f66 100644 --- a/common/plettenberg/plettenberg.h +++ b/common/plettenberg/plettenberg.h @@ -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" @@ -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 @@ -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; @@ -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); diff --git a/source/main_module/CMakeLists.txt b/source/main_module/CMakeLists.txt index eca210bd..a4c65017 100644 --- a/source/main_module/CMakeLists.txt +++ b/source/main_module/CMakeLists.txt @@ -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}) diff --git a/source/main_module/can/can_parse.c b/source/main_module/can/can_parse.c index f8405520..9691cc90 100644 --- a/source/main_module/can/can_parse.c +++ b/source/main_module/can/can_parse.c @@ -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; @@ -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 */ } @@ -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); diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index b3bf2263..4a5ee70d 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -13,7 +13,7 @@ #include "common/queue/queue.h" #include "common/psched/psched.h" -#include "common/phal_L4/can/can.h" +#include "common/phal_F4_F7/can/can.h" // Make this match the node name within the can_config.json #define NODE_NAME "Main_Module" @@ -32,6 +32,7 @@ #define ID_MCU_STATUS 0x10001981 #define ID_REAR_MC_STATUS 0x4001941 #define ID_REAR_MOTOR_CURRENTS_TEMPS 0xc0002c1 +#define ID_SDC_STATUS 0xc000381 #define ID_REAR_CONTROLLER_TEMPS 0xc000301 #define ID_REAR_WHEEL_SPEEDS 0x8000381 #define ID_FAULT_SYNC_MAIN_MODULE 0x8ca01 @@ -45,6 +46,7 @@ #define ID_MAIN_MODULE_BL_CMD 0x409c43e #define ID_COOLING_DRIVER_REQUEST 0xc0002c5 #define ID_THROTTLE_REMAPPED 0xc0025b7 +#define ID_PDU_TEST 0x401041f #define ID_FAULT_SYNC_PDU 0x8cb5f #define ID_FAULT_SYNC_DRIVELINE 0x8ca83 #define ID_FAULT_SYNC_DASHBOARD 0x8cb05 @@ -70,6 +72,7 @@ #define DLC_MCU_STATUS 5 #define DLC_REAR_MC_STATUS 6 #define DLC_REAR_MOTOR_CURRENTS_TEMPS 8 +#define DLC_SDC_STATUS 2 #define DLC_REAR_CONTROLLER_TEMPS 2 #define DLC_REAR_WHEEL_SPEEDS 8 #define DLC_FAULT_SYNC_MAIN_MODULE 3 @@ -83,6 +86,7 @@ #define DLC_MAIN_MODULE_BL_CMD 5 #define DLC_COOLING_DRIVER_REQUEST 5 #define DLC_THROTTLE_REMAPPED 4 +#define DLC_PDU_TEST 3 #define DLC_FAULT_SYNC_PDU 3 #define DLC_FAULT_SYNC_DRIVELINE 3 #define DLC_FAULT_SYNC_DASHBOARD 3 @@ -208,6 +212,24 @@ data_a->rear_motor_currents_temps.right_voltage = right_voltage_;\ qSendToBack(&queue, &msg);\ } while(0) +#define SEND_SDC_STATUS(queue, IMD_, BMS_, BSPD_, BOTS_, inertia_, c_estop_, main_, r_estop_, l_estop_, HVD_, hub_, TSMS_, pchg_out_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_SDC_STATUS, .DLC=DLC_SDC_STATUS, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->sdc_status.IMD = IMD_;\ + data_a->sdc_status.BMS = BMS_;\ + data_a->sdc_status.BSPD = BSPD_;\ + data_a->sdc_status.BOTS = BOTS_;\ + data_a->sdc_status.inertia = inertia_;\ + data_a->sdc_status.c_estop = c_estop_;\ + data_a->sdc_status.main = main_;\ + data_a->sdc_status.r_estop = r_estop_;\ + data_a->sdc_status.l_estop = l_estop_;\ + data_a->sdc_status.HVD = HVD_;\ + data_a->sdc_status.hub = hub_;\ + data_a->sdc_status.TSMS = TSMS_;\ + data_a->sdc_status.pchg_out = pchg_out_;\ + qSendToBack(&queue, &msg);\ + } while(0) #define SEND_REAR_CONTROLLER_TEMPS(queue, left_temp_, right_temp_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_REAR_CONTROLLER_TEMPS, .DLC=DLC_REAR_CONTROLLER_TEMPS, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ @@ -249,6 +271,7 @@ #define UP_LWS_STANDARD 15 #define UP_COOLING_DRIVER_REQUEST 5 #define UP_THROTTLE_REMAPPED 15 +#define UP_PDU_TEST 15 /* END AUTO UP DEFS */ #define CHECK_STALE(stale, curr, last, period) if(!stale && \ @@ -393,6 +416,21 @@ typedef union { uint64_t right_temp: 8; uint64_t right_voltage: 16; } rear_motor_currents_temps; + struct { + uint64_t IMD: 1; + uint64_t BMS: 1; + uint64_t BSPD: 1; + uint64_t BOTS: 1; + uint64_t inertia: 1; + uint64_t c_estop: 1; + uint64_t main: 1; + uint64_t r_estop: 1; + uint64_t l_estop: 1; + uint64_t HVD: 1; + uint64_t hub: 1; + uint64_t TSMS: 1; + uint64_t pchg_out: 1; + } sdc_status; struct { uint64_t left_temp: 8; uint64_t right_temp: 8; @@ -456,6 +494,11 @@ typedef union { uint64_t remap_k_rl: 16; uint64_t remap_k_rr: 16; } throttle_remapped; + struct { + uint64_t test_1: 8; + uint64_t test_2: 8; + uint64_t test_3: 8; + } pdu_test; struct { uint64_t idx: 16; uint64_t latched: 1; @@ -558,6 +601,13 @@ typedef struct { uint8_t stale; uint32_t last_rx; } throttle_remapped; + struct { + uint8_t test_1; + uint8_t test_2; + uint8_t test_3; + uint8_t stale; + uint32_t last_rx; + } pdu_test; struct { uint16_t idx; uint8_t latched; diff --git a/source/main_module/car/car.c b/source/main_module/car/car.c index c00f4f34..a10b5cbd 100644 --- a/source/main_module/car/car.c +++ b/source/main_module/car/car.c @@ -1,17 +1,20 @@ #include "car.h" -#include "common/modules/wheel_speeds/wheel_speeds.h" +// #include "common/modules/wheel_speeds/wheel_speeds.h" Car_t car; extern q_handle_t q_tx_can; extern q_handle_t q_tx_usart_l, q_tx_usart_r; -extern usart_rx_buf_t huart_l_rx_buf, huart_r_rx_buf; +// extern usart_rx_buf_t huart_l_rx_buf, huart_r_rx_buf; +// TODO: Just to remove errors for now +usart_rx_buf_t huart_l_rx_buf, huart_r_rx_buf; uint8_t daq_buzzer; +sdc_nodes_t sdc_mux; /* Wheel Speed Config */ -WheelSpeed_t left_wheel = {.tim=TIM2, .invert=true}; -WheelSpeed_t right_wheel = {.tim=TIM5, .invert=true}; -// TODO: test invert -WheelSpeeds_t wheel_speeds = {.l=&left_wheel, .r=&right_wheel}; +// WheelSpeed_t left_wheel = {.tim=TIM2, .invert=true}; +// WheelSpeed_t right_wheel = {.tim=TIM5, .invert=true}; +// // TODO: test invert +// WheelSpeeds_t wheel_speeds = {.l=&left_wheel, .r=&right_wheel}; bool validatePrecharge(); @@ -33,7 +36,11 @@ bool carInit() mcInit(&car.motor_r, MC_R_INVERT, &q_tx_usart_r, &huart_r_rx_buf, &car.pchg.pchg_complete); - wheelSpeedsInit(&wheel_speeds); + PHAL_writeGPIO(SDC_MUX_S0_GPIO_Port, SDC_MUX_S0_Pin, 0); + PHAL_writeGPIO(SDC_MUX_S1_GPIO_Port, SDC_MUX_S1_Pin, 0); + PHAL_writeGPIO(SDC_MUX_S2_GPIO_Port, SDC_MUX_S2_Pin, 0); + PHAL_writeGPIO(SDC_MUX_S3_GPIO_Port, SDC_MUX_S3_Pin, 0); + // wheelSpeedsInit(&wheel_speeds); } void carHeartbeat() @@ -290,10 +297,10 @@ void parseMCDataPeriodic(void) // SEND_REAR_WHEEL_DATA(q_tx_can, wheel_speeds.left_kph_x100, wheel_speeds.right_kph_x100, // shock_l, shock_r); - uint16_t l_speed = (wheel_speeds.l->rad_s / (2*PI)); - uint16_t r_speed = (wheel_speeds.l->rad_s / (2*PI)); - SEND_REAR_WHEEL_SPEEDS(q_tx_can, car.motor_l.rpm, car.motor_r.rpm, - l_speed, r_speed); + // uint16_t l_speed = (wheel_speeds.l->rad_s / (2*PI)); + // uint16_t r_speed = (wheel_speeds.l->rad_s / (2*PI)); + // SEND_REAR_WHEEL_SPEEDS(q_tx_can, car.motor_l.rpm, car.motor_r.rpm, + // l_speed, r_speed); SEND_REAR_MOTOR_CURRENTS_TEMPS(q_tx_can, (uint16_t) car.motor_l.current_x10, (uint16_t) car.motor_r.current_x10, @@ -393,9 +400,6 @@ bool checkFatalFaults() { uint8_t is_error = 0; - if (!DT_FLOW_CHECK_OVERRIDE) is_error += cooling.dt_flow_error; - if (!BAT_FLOW_CHECK_OVERRIDE) is_error += cooling.bat_flow_error; - // TODO: is_error += !PHAL_readGPIO(LIPO_BAT_STAT_GPIO_Port, LIPO_BAT_STAT_Pin); is_error += (can_data.max_cell_temp.max_temp > 500) ? 1 : 0; @@ -466,4 +470,32 @@ bool validatePrecharge() } return car.pchg.pchg_error; +} + +/** + * @brief Update Status of SDC Mux and Send on CAN + * + */ +void monitorSDCPeriodic() +{ + static uint8_t index = 0; + bool *nodes = (bool *) &sdc_mux; + + *(nodes+index++) = PHAL_readGPIO(SDC_MUX_DATA_GPIO_Port, SDC_MUX_DATA_Pin);; + + index = (index == 4) ? (index + 1) : index; + + if (index == SDC_MUX_HIGH_IDX) + { + index = 0; + SEND_SDC_STATUS(q_tx_can, sdc_mux.imd_stat, sdc_mux.bms_stat, sdc_mux.bspd_stat, sdc_mux.bots_stat, + sdc_mux.inertia_stat, sdc_mux.c_stop_stat, sdc_mux.main_stat, sdc_mux.r_stop_stat, sdc_mux.l_stop_stat, + sdc_mux.hvd_stat, sdc_mux.r_hub_stat, sdc_mux.tsms_stat, sdc_mux.pchg_out_stat); + } + + PHAL_writeGPIO(SDC_MUX_S0_GPIO_Port, SDC_MUX_S0_Pin, (index & 0x01)); + PHAL_writeGPIO(SDC_MUX_S1_GPIO_Port, SDC_MUX_S1_Pin, (index & 0x02)); + PHAL_writeGPIO(SDC_MUX_S2_GPIO_Port, SDC_MUX_S2_Pin, (index & 0x04)); + PHAL_writeGPIO(SDC_MUX_S3_GPIO_Port, SDC_MUX_S3_Pin, (index & 0x08)); + } \ No newline at end of file diff --git a/source/main_module/car/car.h b/source/main_module/car/car.h index 2cba3183..327685ab 100644 --- a/source/main_module/car/car.h +++ b/source/main_module/car/car.h @@ -4,16 +4,16 @@ * @brief Master Car Control and Safety Checking * @version 0.1 * @date 2022-03-01 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef _CAR_H_ #define _CAR_H_ #include "can_parse.h" #include "common/faults/faults.h" -#include "common/phal_L4/gpio/gpio.h" +#include "common/phal_F4_F7/gpio/gpio.h" #include "common/plettenberg/plettenberg.h" #include "common/psched/psched.h" #include "cooling.h" @@ -84,5 +84,30 @@ void carHeartbeat(); void carPeriodic(); void parseMCDataPeriodic(void); void calibrateSteeringAngle(uint8_t* success); +void monitorSDCPeriodic(void); + +#define SDC_MUX_HIGH_IDX 14 + +typedef struct +{ + bool main_stat; //y0 + bool c_stop_stat; //y1 + bool inertia_stat; //y2 + bool bots_stat; //y3 + bool nc; //y4 + bool bspd_stat; //y5 + bool bms_stat; //y6 + bool imd_stat; //y7 + bool r_stop_stat; //y8 + bool l_stop_stat; //y9 + bool hvd_stat; //y10 + bool r_hub_stat; //y11 + bool tsms_stat; //y12 + bool pchg_out_stat; //y13 + +} sdc_nodes_t; + +extern sdc_nodes_t sdc_mux; + #endif \ No newline at end of file diff --git a/source/main_module/cooling/cooling.c b/source/main_module/cooling/cooling.c index a42b40dc..ef4ed894 100644 --- a/source/main_module/cooling/cooling.c +++ b/source/main_module/cooling/cooling.c @@ -4,22 +4,11 @@ const float adc_to_ln[] = {0.0f, 3.66932195489841f, 4.36639937878818f, 4.7758102 }; Cooling_t cooling; -volatile uint16_t raw_dt_flow_ct; -volatile uint16_t raw_bat_flow_ct; -uint32_t last_flow_meas_time_ms; -uint32_t dt_pump_start_time_ms; -uint32_t bat_pump_start_time_ms; extern q_handle_t q_tx_can; extern uint32_t APB1ClockRateHz; -// static void setDtCooling(uint8_t on); -// static void setBatCooling(uint8_t on); -static void setDtPump(bool on); -static void setBatPump(bool on, bool on_aux); -static void setBatFan(uint8_t power); -static void setDtFan(uint8_t power); uint8_t lowpass(uint8_t new, uint8_t *old, uint8_t curr); bool coolingInit() @@ -40,35 +29,29 @@ bool coolingInit() // // enable the interrupt handlers // NVIC_EnableIRQ(EXTI9_5_IRQn); - RCC -> APB1ENR1 |= RCC_APB1ENR1_TIM4EN; //0b100; - TIM4 -> CR1 &= ~TIM_CR1_CEN; //Turning off counter - TIM4 -> PSC = (APB1ClockRateHz / (PWM_FREQUENCY * 100)) - 1; - TIM4 -> ARR = 100 - 1; //setting it to 99 so it's easier to use it with Duty Cycle - //Enabling the MOE bit of the dead-time register - // TIM4 -> BDTR |= TIM_BDTR_MOE; - //Set Channels 1 and 2 to 110 (Mode 1 up counter) -> (active while CNT <= CCR) - TIM4 -> CCMR1 &= ~(TIM_CCMR1_OC1M_0); - TIM4 -> CCMR1 &= ~(TIM_CCMR1_OC2M_0); - TIM4 -> CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1; - TIM4 -> CCMR1 |= TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1; - //Setting the preload register - TIM4 -> CCMR1 |= TIM_CCMR1_OC1PE | TIM_CCMR1_OC2PE; - // TIM1 -> CR1 |= TIM_CR1_ARPE; - //Enable Channels 1 and 2 outputs - TIM4 -> CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E; - //Setting pwm to 0 - TIM4 -> CCR1 = 100; // inverted - TIM4 -> CCR2 = 100; - //Enable counter as long as ccrs are 0 - TIM4 -> CR1 |= TIM_CR1_CEN; // turning on counter + // RCC -> APB1ENR1 |= RCC_APB1ENR1_TIM4EN; //0b100; + // TIM4 -> CR1 &= ~TIM_CR1_CEN; //Turning off counter + // TIM4 -> PSC = (APB1ClockRateHz / (PWM_FREQUENCY * 100)) - 1; + // TIM4 -> ARR = 100 - 1; //setting it to 99 so it's easier to use it with Duty Cycle + // //Enabling the MOE bit of the dead-time register + // // TIM4 -> BDTR |= TIM_BDTR_MOE; + // //Set Channels 1 and 2 to 110 (Mode 1 up counter) -> (active while CNT <= CCR) + // TIM4 -> CCMR1 &= ~(TIM_CCMR1_OC1M_0); + // TIM4 -> CCMR1 &= ~(TIM_CCMR1_OC2M_0); + // TIM4 -> CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1; + // TIM4 -> CCMR1 |= TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1; + // //Setting the preload register + // TIM4 -> CCMR1 |= TIM_CCMR1_OC1PE | TIM_CCMR1_OC2PE; + // // TIM1 -> CR1 |= TIM_CR1_ARPE; + // //Enable Channels 1 and 2 outputs + // TIM4 -> CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E; + // //Setting pwm to 0 + // TIM4 -> CCR1 = 100; // inverted + // TIM4 -> CCR2 = 100; + // //Enable counter as long as ccrs are 0 + // TIM4 -> CR1 |= TIM_CR1_CEN; // turning on counter // Default pin configurations - // setDtCooling(0); - // setBatCooling(0); - setDtPump(0); - setBatPump(0, 0); - setDtFan(0); - setBatFan(0); return true; } @@ -97,48 +80,43 @@ void coolingPeriodic() // 568 594 // Since ADC readings happen ~2ms, the next measurement should be ready // temp = rawThermtoCelcius(adc_readings.therm_mux_d); - temp = THERM_A * adc_to_ln[(adc_readings.therm_mux_d / 16)] + THERM_B; - switch(curr_therm) - { - case THERM_MUX_BAT_IN: - cooling.bat_therm_in_C = temp; - break; - case THERM_MUX_BAT_OUT: - cooling.bat_therm_out_C = temp; - break; - case THERM_MUX_DT_IN: - cooling.dt_therm_in_C = temp; - break; - case THERM_MUX_DT_OUT: - cooling.dt_therm_out_C = temp; - break; - } - curr_therm = (curr_therm + 1) & 0x03; - PHAL_writeGPIO(THERM_MUX_S0_GPIO_Port, THERM_MUX_S0_Pin, curr_therm & 0x01); - PHAL_writeGPIO(THERM_MUX_S1_GPIO_Port, THERM_MUX_S1_Pin, curr_therm & 0x02); - - int8_t drivetrain_right_temp = (DT_THERM_A * adc_to_ln[adc_readings.dt_gb_r/16] + DT_THERM_B); - int8_t drivetrain_left_temp = (DT_THERM_A * adc_to_ln[adc_readings.dt_gb_l/16] + DT_THERM_B); - - // Update outputs - if (cooling.daq_override) - { - cooling.out = cooling.out_daq_req; - } - - setDtFan(cooling.out.dt_fan_power); - setBatFan(cooling.out.bat_fan_power); - setBatPump(cooling.out.bat_pump, cooling.out.bat_pump_aux); - setDtPump(cooling.out.dt_pump); - - SEND_FLOWRATE_TEMPS(q_tx_can, cooling.bat_therm_in_C, cooling.bat_therm_out_C, - cooling.dt_therm_in_C, cooling.dt_therm_out_C, - cooling.bat_liters_p_min_x10, cooling.dt_liters_p_min_x10, - 0, 0); - SEND_COOLANT_OUT(q_tx_can, cooling.out.bat_fan_power, cooling.out.dt_fan_power, - cooling.out.bat_pump, cooling.out.bat_pump_aux, - cooling.out.dt_pump); - SEND_GEARBOX(q_tx_can, drivetrain_left_temp, drivetrain_right_temp); + // temp = THERM_A * adc_to_ln[(adc_readings.therm_mux_d / 16)] + THERM_B; + // switch(curr_therm) + // { + // case THERM_MUX_BAT_IN: + // cooling.bat_therm_in_C = temp; + // break; + // case THERM_MUX_BAT_OUT: + // cooling.bat_therm_out_C = temp; + // break; + // case THERM_MUX_DT_IN: + // cooling.dt_therm_in_C = temp; + // break; + // case THERM_MUX_DT_OUT: + // cooling.dt_therm_out_C = temp; + // break; + // } + // curr_therm = (curr_therm + 1) & 0x03; + // PHAL_writeGPIO(THERM_MUX_S0_GPIO_Port, THERM_MUX_S0_Pin, curr_therm & 0x01); + // PHAL_writeGPIO(THERM_MUX_S1_GPIO_Port, THERM_MUX_S1_Pin, curr_therm & 0x02); + + // int8_t drivetrain_right_temp = (DT_THERM_A * adc_to_ln[adc_readings.dt_gb_r/16] + DT_THERM_B); + // int8_t drivetrain_left_temp = (DT_THERM_A * adc_to_ln[adc_readings.dt_gb_l/16] + DT_THERM_B); + + // // Update outputs + // if (cooling.daq_override) + // { + // cooling.out = cooling.out_daq_req; + // } + + // SEND_FLOWRATE_TEMPS(q_tx_can, cooling.bat_therm_in_C, cooling.bat_therm_out_C, + // cooling.dt_therm_in_C, cooling.dt_therm_out_C, + // cooling.bat_liters_p_min_x10, cooling.dt_liters_p_min_x10, + // 0, 0); + // SEND_COOLANT_OUT(q_tx_can, cooling.out.bat_fan_power, cooling.out.dt_fan_power, + // cooling.out.bat_pump, cooling.out.bat_pump_aux, + // cooling.out.dt_pump); + // SEND_GEARBOX(q_tx_can, drivetrain_left_temp, drivetrain_right_temp); return; /* @@ -164,7 +142,7 @@ void coolingPeriodic() //Send CAN messages with flowrates // SEND_FLOWRATE_TEMPS(q_tx_can, cooling.bat_liters_p_min_x10, cooling.bat_therm_in_C, cooling.dt_therm_2_C, // adc_readings.dt_therm_1, adc_readings.dt_therm_2); - DT COOLANT SYSTEM + DT COOLANT SYSTEM // Find max motor temperature (CELSIUS) uint8_t max_motor_temp = MAX(car.motor_l.motor_temp, @@ -191,7 +169,7 @@ void coolingPeriodic() max_motor_temp = 0; // Determine if system should be on - + if ((!cooling.dt_flow_error || DT_FLOW_CHECK_OVERRIDE) && (max_motor_temp > DT_PUMP_ON_TEMP_C || ((prchg_set) && (cooling.dt_temp_error || DT_ALWAYS_COOL)))) @@ -208,7 +186,7 @@ void coolingPeriodic() } setDtCooling(true); - BAT COOLANT SYSTEM + BAT COOLANT SYSTEM // TODO: replace with CAN frame uint8_t max_bat_temp = 0; @@ -232,7 +210,7 @@ void coolingPeriodic() } max_bat_temp = 0; - + // Determine if system should be on if ((!cooling.bat_flow_error || BAT_FLOW_CHECK_OVERRIDE) && (max_bat_temp > BAT_PUMP_ON_TEMP_C || ((prchg_set) && @@ -247,7 +225,7 @@ void coolingPeriodic() else if (cooling.bat_pump) { setBatCooling(false); - } + } setBatCooling(true); */ } @@ -273,52 +251,7 @@ void coolingPeriodic() // PHAL_writeGPIO(BAT_RAD_FAN_CTRL_GPIO_Port, BAT_RAD_FAN_CTRL_Pin, set_bat); }*/ -void setDtPump(bool on) -{ - PHAL_writeGPIO(DT_PUMP_CTRL_GPIO_Port, DT_PUMP_CTRL_Pin, on); - /* - if (!cooling.dt_pump && on) dt_pump_start_time_ms = sched.os_ticks; - if (!on) cooling.dt_rose = 0; - cooling.dt_pump = on; - PHAL_writeGPIO(DT_PUMP_CTRL_GPIO_Port, DT_PUMP_CTRL_Pin, on); - cooling.dt_fan_power = on ? 4 : 0; - // PHAL_writeGPIO(DT_RAD_FAN_CTRL_GPIO_Port, DT_RAD_FAN_CTRL_Pin, on); - */ -} -void setBatPump(bool on, bool on_aux) -{ - PHAL_writeGPIO(BAT_PUMP_CTRL_1_GPIO_Port, BAT_PUMP_CTRL_1_Pin, on); - PHAL_writeGPIO(BAT_PUMP_CTRL_2_GPIO_Port, BAT_PUMP_CTRL_2_Pin, on_aux); - /* - if (!cooling.bat_pump && on) bat_pump_start_time_ms = sched.os_ticks; - if (!on) cooling.bat_rose = 0; - cooling.bat_pump = on; - PHAL_writeGPIO(BAT_PUMP_CTRL_GPIO_Port, BAT_PUMP_CTRL_Pin, on); - cooling.bat_fan_power = on ? 4 : 0; - // PHAL_writeGPIO(BAT_RAD_FAN_CTRL_GPIO_Port, BAT_RAD_FAN_CTRL_Pin, on); - */ -} - -/** - * @brief Set the Bat Fan Speed - * - * @param power 0 - 100% - */ -void setBatFan(uint8_t power) -{ - TIM4->CCR1 = 100 - CLAMP(power, 0, 100); -} - -/** - * @brief Set the DT Fan Speed - * - * @param power 0 - 100% - */ -void setDtFan(uint8_t power) -{ - TIM4->CCR2 = 100 - CLAMP(power, 0, 100); -} float rawThermtoCelcius(uint16_t t) { @@ -349,12 +282,12 @@ static double native_log_computation(const double n) { void cooling_driver_request_CALLBACK(CanParsedData_t* data) { - if (!cooling.daq_override) - { - cooling.out.dt_fan_power = data->cooling_driver_request.dt_fan; - cooling.out.bat_fan_power = data->cooling_driver_request.batt_fan; - cooling.out.bat_pump = data->cooling_driver_request.batt_pump; - cooling.out.bat_pump_aux = data->cooling_driver_request.batt_pump2; - cooling.out.dt_pump = data->cooling_driver_request.dt_pump; - } + // if (!cooling.daq_override) + // { + // cooling.out.dt_fan_power = data->cooling_driver_request.dt_fan; + // cooling.out.bat_fan_power = data->cooling_driver_request.batt_fan; + // cooling.out.bat_pump = data->cooling_driver_request.batt_pump; + // cooling.out.bat_pump_aux = data->cooling_driver_request.batt_pump2; + // cooling.out.dt_pump = data->cooling_driver_request.dt_pump; + // } } \ No newline at end of file diff --git a/source/main_module/cooling/cooling.h b/source/main_module/cooling/cooling.h index 5f14f534..73eb35d7 100644 --- a/source/main_module/cooling/cooling.h +++ b/source/main_module/cooling/cooling.h @@ -15,13 +15,12 @@ #include "can_parse.h" #include "car.h" #include "common/common_defs/common_defs.h" -#include "common/phal_L4/gpio/gpio.h" +#include "common/phal_F4_F7/gpio/gpio.h" #include "common/psched/psched.h" #include #include "main.h" #include #include -#include "stm32l496xx.h" //45 C (off fail state) bat //90 C (drivetrain) @@ -73,20 +72,10 @@ #define AVG_WINDOW_SIZE 10 -typedef struct __attribute__((packed)) -{ - uint8_t dt_pump; // DT pump turned on - uint8_t dt_fan_power; // DT fan turned on - uint8_t bat_pump; // BAT pump turned on - uint8_t bat_pump_aux; // BAT pump 2 turned on - uint8_t bat_fan_power; // BAT fan turned on -} Cooling_output_t; typedef struct { - uint8_t dt_liters_p_min_x10; - uint8_t bat_liters_p_min_x10; float dt_therm_out_C; float dt_therm_in_C; float bat_therm_out_C; @@ -95,17 +84,10 @@ typedef struct uint32_t bat_delta_t; bool daq_override; // Outputs controlled by DAQ - Cooling_output_t out_daq_req; // Outputs requested by DAQ - Cooling_output_t out; // Outputs sent to peripherals uint8_t dt_temp_error; // DT either over temp or not receiving - uint8_t dt_flow_error; // DT flow is too low - uint8_t dt_rose; // DT pump has been on for - // the startup time + uint8_t bat_temp_error;// BAT either over temp or not receiving temps - uint8_t bat_flow_error;// BAT flow is too low - uint8_t bat_rose; // BAT pump has been on for - // the startup time } Cooling_t; extern Cooling_t cooling; diff --git a/source/main_module/daq/daq.c b/source/main_module/daq/daq.c index b5cf4215..88ced317 100644 --- a/source/main_module/daq/daq.c +++ b/source/main_module/daq/daq.c @@ -1,17 +1,17 @@ /** * @file daq.c * @author Luke Oxley (lcoxley@purdue.edu) - * @brief + * @brief * @version 0.1 * @date 2023-01-18 - * + * * @copyright Copyright (c) 2023 - * + * */ #include "daq.h" #include "common/daq/daq_base.h" -#include "common/phal_L4/can/can.h" +#include "common/phal_F4_F7/can/can.h" // BEGIN AUTO VAR INCLUDES #include "cooling.h" @@ -21,19 +21,23 @@ // BEGIN AUTO VAR DEFS daq_variable_t tracked_vars[NUM_VARS] = { - {.is_read_only=1, .bit_length=8, .read_var_a=&cooling.dt_liters_p_min_x10, .write_var_a=NULL, }, - {.is_read_only=1, .bit_length=8, .read_var_a=&cooling.bat_liters_p_min_x10, .write_var_a=NULL, }, - {.is_read_only=1, .bit_length=1, .read_var_a=&cooling.dt_flow_error, .write_var_a=NULL, }, {.is_read_only=1, .bit_length=1, .read_var_a=&cooling.dt_temp_error, .write_var_a=NULL, }, - {.is_read_only=1, .bit_length=1, .read_var_a=&cooling.bat_flow_error, .write_var_a=NULL, }, {.is_read_only=1, .bit_length=1, .read_var_a=&cooling.bat_temp_error, .write_var_a=NULL, }, {.is_read_only=1, .bit_length=1, .has_read_func=1, .read_func_a=(read_func_ptr_t)calibrateSteeringAngle, .write_var_a=NULL, }, {.is_read_only=0, .bit_length=1, .read_var_a=&cooling.daq_override, .write_var_a=&cooling.daq_override, }, - {.is_read_only=0, .bit_length=1, .read_var_a=&cooling.out_daq_req.dt_pump, .write_var_a=&cooling.out_daq_req.dt_pump, }, - {.is_read_only=0, .bit_length=1, .read_var_a=&cooling.out_daq_req.bat_pump, .write_var_a=&cooling.out_daq_req.bat_pump, }, - {.is_read_only=0, .bit_length=1, .read_var_a=&cooling.out_daq_req.bat_pump_aux, .write_var_a=&cooling.out_daq_req.bat_pump_aux, }, - {.is_read_only=0, .bit_length=8, .read_var_a=&cooling.out_daq_req.dt_fan_power, .write_var_a=&cooling.out_daq_req.dt_fan_power, }, - {.is_read_only=0, .bit_length=8, .read_var_a=&cooling.out_daq_req.bat_fan_power, .write_var_a=&cooling.out_daq_req.bat_fan_power, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.main_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.c_stop_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.inertia_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.bots_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.bspd_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.bms_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.imd_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.r_stop_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.l_stop_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.hvd_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.r_hub_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.tsms_stat, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=1, .read_var_a=&sdc_mux.pchg_out_stat, .write_var_a=NULL, }, {.is_read_only=0, .bit_length=1, .read_var_a=&daq_buzzer, .write_var_a=&daq_buzzer, }, }; // END AUTO VAR DEFS diff --git a/source/main_module/daq/daq.h b/source/main_module/daq/daq.h index c8e62b52..01d2eeb6 100644 --- a/source/main_module/daq/daq.h +++ b/source/main_module/daq/daq.h @@ -19,24 +19,28 @@ #define DAQ_UPDATE_PERIOD 15 // ms // BEGIN AUTO VAR COUNT -#define NUM_VARS 14 +#define NUM_VARS 18 // END AUTO VAR COUNT // BEGIN AUTO VAR IDs -#define DAQ_ID_DT_LITERS_P_MIN_X10 0 -#define DAQ_ID_BAT_LITERS_P_MIN_X10 1 -#define DAQ_ID_DT_FLOW_ERROR 2 -#define DAQ_ID_DT_TEMP_ERROR 3 -#define DAQ_ID_BAT_FLOW_ERROR 4 -#define DAQ_ID_BAT_TEMP_ERROR 5 -#define DAQ_ID_CAL_STEER_ANGLE 6 -#define DAQ_ID_COOLING_DAQ_OVERRIDE 7 -#define DAQ_ID_DT_PUMP 8 -#define DAQ_ID_BAT_PUMP 9 -#define DAQ_ID_BAT_PUMP_AUX 10 -#define DAQ_ID_DT_FAN 11 -#define DAQ_ID_BAT_FAN 12 -#define DAQ_ID_DAQ_BUZZER 13 +#define DAQ_ID_DT_TEMP_ERROR 0 +#define DAQ_ID_BAT_TEMP_ERROR 1 +#define DAQ_ID_CAL_STEER_ANGLE 2 +#define DAQ_ID_COOLING_DAQ_OVERRIDE 3 +#define DAQ_ID_SDC_MAIN_STATUS 4 +#define DAQ_ID_SDC_CENTER_STOP_STATUS 5 +#define DAQ_ID_SDC_INERTIA_SW_STATUS 6 +#define DAQ_ID_SDC_BOTS_STAT 7 +#define DAQ_ID_SDC_BSPD_STAT 8 +#define DAQ_ID_SDC_BMS_STAT 9 +#define DAQ_ID_SDC_IMD_STAT 10 +#define DAQ_ID_SDC_R_ESTOP_STAT 11 +#define DAQ_ID_SDC_L_ESTOP_STAT 12 +#define DAQ_ID_SDC_HVD_STAT 13 +#define DAQ_ID_SDC_REAR_HUB_STAT 14 +#define DAQ_ID_SDC_TSMS_STAT 15 +#define DAQ_ID_SDC_PCHG_OUT_STAT 16 +#define DAQ_ID_DAQ_BUZZER 17 // END AUTO VAR IDs // BEGIN AUTO FILE STRUCTS diff --git a/source/main_module/main.c b/source/main_module/main.c index e23c6b33..d0ace7a5 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -1,18 +1,15 @@ /* System Includes */ -#include "stm32l496xx.h" -#include "common/bootloader/bootloader_common.h" +// #include "common/bootloader/bootloader_common.h" #include "common/faults/faults.h" -#include "common/modules/wheel_speeds/wheel_speeds.h" -#include "common/phal_L4/adc/adc.h" -#include "common/phal_L4/can/can.h" -#include "common/phal_L4/eeprom_spi/eeprom_spi.h" -#include "common/phal_L4/dma/dma.h" -#include "common/phal_L4/gpio/gpio.h" -#include "common/phal_L4/i2c/i2c.h" -#include "common/phal_L4/rcc/rcc.h" -#include "common/phal_L4/usart/usart.h" +// #include "common/modules/wheel_speeds/wheel_speeds.h" +#include "common/phal_F4_F7/adc/adc.h" +#include "common/phal_F4_F7/can/can.h" +#include "common/phal_F4_F7/dma/dma.h" +#include "common/phal_F4_F7/gpio/gpio.h" +#include "common/phal_F4_F7/rcc/rcc.h" +#include "common/phal_F4_F7/usart/usart.h" #include "common/plettenberg/plettenberg.h" -#include "common/phal_L4/usart/usart.h" +#include "common/phal_F4_F7/usart/usart.h" #include "common/plettenberg/plettenberg.h" #include "common/psched/psched.h" #include "common/queue/queue.h" @@ -23,190 +20,168 @@ #include "cooling.h" #include "daq.h" #include "main.h" -#include "power_monitor.h" GPIOInitConfig_t gpio_config[] = { - // CAN - GPIO_INIT_CANRX_PD0, - GPIO_INIT_CANTX_PD1, - GPIO_INIT_OUTPUT(SDC_CTRL_GPIO_Port, SDC_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), - // Status Indicators + // Internal Status Indicators GPIO_INIT_OUTPUT(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(CONN_LED_GPIO_Port, CONN_LED_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(HEARTBEAT_GPIO_Port, HEARTBEAT_Pin, GPIO_OUTPUT_LOW_SPEED), + + // External Status Indicators GPIO_INIT_OUTPUT(BRK_LIGHT_GPIO_Port, BRK_LIGHT_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(BUZZER_GPIO_Port, BUZZER_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_OUTPUT(UNDERGLOW_GPIO_Port, UNDERGLOW_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_INPUT(BRK_BUZZER_STAT_GPIO_Port, BRK_BUZZER_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), + GPIO_INIT_INPUT(TSAL_LVAL_STAT_GPIO_Port, TSAL_LVAL_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), + // CAN - GPIO_INIT_CANRX_PD0, - GPIO_INIT_CANTX_PD1, + GPIO_INIT_CANRX_PA11, + GPIO_INIT_CANTX_PA12, + GPIO_INIT_CAN2RX_PB12, GPIO_INIT_CAN2TX_PB13, - // SPI - GPIO_INIT_SPI1_SCK_PE13, - GPIO_INIT_SPI1_MISO_PE14, - GPIO_INIT_SPI1_MOSI_PE15, + + //SPI Peripherals + GPIO_INIT_SPI1_SCK_PA5, + GPIO_INIT_SPI1_MISO_PA6, + GPIO_INIT_SPI1_MOSI_PA7, + GPIO_INIT_OUTPUT(SDC_CTRL_GPIO_Port, SDC_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT(EEPROM_nWP_GPIO_Port, EEPROM_nWP_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(EEPROM_NSS_GPIO_Port, EEPROM_NSS_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_OUTPUT(SD_CARD_NSS_GPIO_Port, SD_CARD_NSS_Pin, GPIO_OUTPUT_LOW_SPEED), - // SDC + + // Shutdown Circuits GPIO_INIT_OUTPUT(SDC_CTRL_GPIO_Port, SDC_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_OUTPUT(BSPD_TEST_CTRL_GPIO_Port, BSPD_TEST_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT(SDC_MUX_S0_GPIO_Port, SDC_MUX_S0_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT(SDC_MUX_S1_GPIO_Port, SDC_MUX_S1_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT(SDC_MUX_S2_GPIO_Port, SDC_MUX_S2_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT(SDC_MUX_S3_GPIO_Port, SDC_MUX_S3_Pin, GPIO_OUTPUT_LOW_SPEED), + + GPIO_INIT_INPUT(SDC_MUX_DATA_GPIO_Port, SDC_MUX_DATA_Pin, GPIO_INPUT_OPEN_DRAIN), + + // HV Bus Information GPIO_INIT_ANALOG(V_MC_SENSE_GPIO_Port, V_MC_SENSE_Pin), GPIO_INIT_ANALOG(V_BAT_SENSE_GPIO_Port, V_BAT_SENSE_Pin), GPIO_INIT_INPUT(BMS_STAT_GPIO_Port, BMS_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), GPIO_INIT_INPUT(PRCHG_STAT_GPIO_Port, PRCHG_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), + // Motor Controllers - GPIO_INIT_USART2TX_PD5, - GPIO_INIT_USART2RX_PD6, + GPIO_INIT_USART2TX_PA2, + GPIO_INIT_USART2RX_PA3, GPIO_INIT_USART1TX_PA9, GPIO_INIT_USART1RX_PA10, - GPIO_INIT_AF(MC_L_PWM_GPIO_Port, MC_L_PWM_Pin, 2, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN), - GPIO_INIT_AF(MC_R_PWM_GPIO_Port, MC_R_PWM_Pin, 2, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN), + // Wheel Speed - GPIO_INIT_AF(MOTOR_L_WS_A_GPIO_Port, MOTOR_L_WS_A_Pin, 2, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_AF(MOTOR_L_WS_B_GPIO_Port, MOTOR_L_WS_B_Pin, 2, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_AF(MOTOR_L_WS_Z_GPIO_Port, MOTOR_L_WS_Z_Pin, 1, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_INPUT(MOTOR_L_WS_ERROR_GPIO_Port, MOTOR_L_WS_ERROR_Pin, GPIO_INPUT_PULL_UP), - GPIO_INIT_AF(MOTOR_R_WS_A_GPIO_Port, MOTOR_R_WS_A_Pin, 1, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_AF(MOTOR_R_WS_B_GPIO_Port, MOTOR_R_WS_B_Pin, 1, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_AF(MOTOR_R_WS_Z_GPIO_Port, MOTOR_R_WS_Z_Pin, 3, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_INPUT(MOTOR_R_WS_ERROR_GPIO_Port, MOTOR_R_WS_ERROR_Pin, GPIO_INPUT_PULL_UP), + GPIO_INIT_AF(MOTOR_R_WS_GPIO_Port, MOTOR_R_WS_Pin, MOTOR_R_WS_AF, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), + GPIO_INIT_AF(MOTOR_L_WS_GPIO_Port, MOTOR_L_WS_Pin, MOTOR_L_WS_AF, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), + // Shock Pots GPIO_INIT_ANALOG(SHOCK_POT_L_GPIO_Port, SHOCK_POT_L_Pin), GPIO_INIT_ANALOG(SHOCK_POT_R_GPIO_Port, SHOCK_POT_R_Pin), - // Drivetrain - GPIO_INIT_ANALOG(DT_GB_THERM_L_GPIO_Port, DT_GB_THERM_L_Pin), - GPIO_INIT_ANALOG(DT_GB_THERM_R_GPIO_Port, DT_GB_THERM_R_Pin), - GPIO_INIT_OUTPUT(DT_PUMP_CTRL_GPIO_Port, DT_PUMP_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_AF(DT_FLOW_RATE_GPIO_Port, DT_FLOW_RATE_Pin, 1, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_AF(DT_FAN_CTRL_GPIO_Port, DT_FAN_CTRL_Pin, 2, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN), - // GPIO_INIT_OUTPUT(DT_FAN_CTRL_GPIO_Port, DT_FAN_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_AF(DT_FAN_TACK_GPIO_Port, DT_FAN_TACK_Pin, 14, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - // HV Battery - GPIO_INIT_OUTPUT(BAT_PUMP_CTRL_1_GPIO_Port, BAT_PUMP_CTRL_1_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_OUTPUT(BAT_PUMP_CTRL_2_GPIO_Port, BAT_PUMP_CTRL_2_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_AF(BAT_FLOW_RATE_GPIO_Port, BAT_FLOW_RATE_Pin, 3, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - GPIO_INIT_AF(BAT_FAN_CTRL_GPIO_Port, BAT_FAN_CTRL_Pin, 2, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN), - // GPIO_INIT_OUTPUT(BAT_FAN_CTRL_GPIO_Port, BAT_FAN_CTRL_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_AF(BAT_FAN_TACK_GPIO_Port, BAT_FAN_TACK_Pin, 14, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), - // LV Status - GPIO_INIT_ANALOG(LV_24V_V_SENSE_GPIO_Port, LV_24V_V_SENSE_Pin), - GPIO_INIT_ANALOG(LV_24V_I_SENSE_GPIO_Port, LV_24V_I_SENSE_Pin), - GPIO_INIT_ANALOG(LV_12V_V_SENSE_GPIO_Port, LV_12V_V_SENSE_Pin), - GPIO_INIT_ANALOG(LV_5V_V_SENSE_GPIO_Port, LV_5V_V_SENSE_Pin), - GPIO_INIT_ANALOG(LV_5V_I_SENSE_GPIO_Port, LV_5V_I_SENSE_Pin), - GPIO_INIT_ANALOG(LV_3V3_V_SENSE_GPIO_Port, LV_3V3_V_SENSE_Pin), - GPIO_INIT_INPUT(LV_3V3_PG_GPIO_Port, LV_3V3_PG_Pin, GPIO_INPUT_OPEN_DRAIN), - GPIO_INIT_INPUT(LV_BAT_STAT_GPIO_Port, LV_BAT_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), + + // Load Sensor + GPIO_INIT_ANALOG(LOAD_L_GPIO_Port, LOAD_L_Pin), + GPIO_INIT_ANALOG(LOAD_R_GPIO_Port, LOAD_R_Pin), + // Thermistor Analog Multiplexer GPIO_INIT_OUTPUT(THERM_MUX_S0_GPIO_Port, THERM_MUX_S0_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(THERM_MUX_S1_GPIO_Port, THERM_MUX_S1_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT(THERM_MUX_S2_GPIO_Port, THERM_MUX_S2_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_ANALOG(THERM_MUX_D_GPIO_Port, THERM_MUX_D_Pin) }; /* USART Configuration */ // Left Motor Controller UART -dma_init_t usart_l_tx_dma_config = USART1_TXDMA_CONT_CONFIG(NULL, 1); -dma_init_t usart_l_rx_dma_config = USART1_RXDMA_CONT_CONFIG(NULL, 2); -char usart_l_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; -volatile usart_rx_buf_t huart_l_rx_buf = { - .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, - .last_msg_loc = 0, .last_rx_time = 0, - .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_l_rx_array -}; -usart_init_t huart_l = { - .baud_rate = 115200, - .word_length = WORD_8, - .hw_flow_ctl = HW_DISABLE, - .mode = MODE_TX_RX, - .stop_bits = SB_ONE, - .parity = PT_NONE, - .obsample = OB_DISABLE, - .ovsample = OV_16, - .adv_feature.rx_inv = false, - .adv_feature.tx_inv = false, - .adv_feature.auto_baud = false, - .adv_feature.data_inv = false, - .adv_feature.msb_first = false, - .adv_feature.overrun = false, - .adv_feature.dma_on_rx_err = false, - .tx_dma_cfg = &usart_l_tx_dma_config, - .rx_dma_cfg = &usart_l_rx_dma_config -}; +// dma_init_t usart_l_tx_dma_config = USART1_TXDMA_CONT_CONFIG(NULL, 1); +// dma_init_t usart_l_rx_dma_config = USART1_RXDMA_CONT_CONFIG(NULL, 2); +// char usart_l_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; +// volatile usart_rx_buf_t huart_l_rx_buf = { +// .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, +// .last_msg_loc = 0, .last_rx_time = 0, +// .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_l_rx_array +// }; +// usart_init_t huart_l = { +// .baud_rate = 115200, +// .word_length = WORD_8, +// .hw_flow_ctl = HW_DISABLE, +// .mode = MODE_TX_RX, +// .stop_bits = SB_ONE, +// .parity = PT_NONE, +// .obsample = OB_DISABLE, +// .ovsample = OV_16, +// .adv_feature.rx_inv = false, +// .adv_feature.tx_inv = false, +// .adv_feature.auto_baud = false, +// .adv_feature.data_inv = false, +// .adv_feature.msb_first = false, +// .adv_feature.overrun = false, +// .adv_feature.dma_on_rx_err = false, +// .tx_dma_cfg = &usart_l_tx_dma_config, +// .rx_dma_cfg = &usart_l_rx_dma_config +// }; // Right Motor Controller UART -dma_init_t usart_r_tx_dma_config = USART2_TXDMA_CONT_CONFIG(NULL, 1); -dma_init_t usart_r_rx_dma_config = USART2_RXDMA_CONT_CONFIG(NULL, 2); -char usart_r_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; -volatile usart_rx_buf_t huart_r_rx_buf = { - .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, - .last_msg_loc = 0, .last_rx_time = 0, - .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_r_rx_array -}; -usart_init_t huart_r = { - .baud_rate = 115200, - .word_length = WORD_8, - .hw_flow_ctl = HW_DISABLE, - .mode = MODE_TX_RX, - .stop_bits = SB_ONE, - .parity = PT_NONE, - .obsample = OB_DISABLE, - .ovsample = OV_16, - .adv_feature.rx_inv = false, - .adv_feature.tx_inv = false, - .adv_feature.auto_baud = false, - .adv_feature.data_inv = false, - .adv_feature.msb_first = false, - .adv_feature.overrun = false, - .adv_feature.dma_on_rx_err = false, - .tx_dma_cfg = &usart_r_tx_dma_config, - .rx_dma_cfg = &usart_r_rx_dma_config -}; +// dma_init_t usart_r_tx_dma_config = USART2_TXDMA_CONT_CONFIG(NULL, 1); +// dma_init_t usart_r_rx_dma_config = USART2_RXDMA_CONT_CONFIG(NULL, 2); +// char usart_r_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; +// volatile usart_rx_buf_t huart_r_rx_buf = { +// .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, +// .last_msg_loc = 0, .last_rx_time = 0, +// .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_r_rx_array +// }; +// usart_init_t huart_r = { +// .baud_rate = 115200, +// .word_length = WORD_8, +// .hw_flow_ctl = HW_DISABLE, +// .mode = MODE_TX_RX, +// .stop_bits = SB_ONE, +// .parity = PT_NONE, +// .obsample = OB_DISABLE, +// .ovsample = OV_16, +// .adv_feature.rx_inv = false, +// .adv_feature.tx_inv = false, +// .adv_feature.auto_baud = false, +// .adv_feature.data_inv = false, +// .adv_feature.msb_first = false, +// .adv_feature.overrun = false, +// .adv_feature.dma_on_rx_err = false, +// .tx_dma_cfg = &usart_r_tx_dma_config, +// .rx_dma_cfg = &usart_r_rx_dma_config +// }; /* ADC Configuration */ ADCInitConfig_t adc_config = { - .clock_prescaler = ADC_CLK_PRESC_16, + .clock_prescaler = ADC_CLK_PRESC_6, .resolution = ADC_RES_12_BIT, .data_align = ADC_DATA_ALIGN_RIGHT, .cont_conv_mode = true, - .overrun = true, .dma_mode = ADC_DMA_CIRCULAR }; /* With 11 items, 16 prescaler, and 640 sample time, each channel gets read every 1.4ms */ volatile ADCReadings_t adc_readings; ADCChannelConfig_t adc_channel_config[] = { - {.channel=V_MC_SENSE_ADC_CHNL, .rank=1, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=V_BAT_SENSE_ADC_CHNL, .rank=2, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=SHOCK_POT_L_ADC_CHNL, .rank=3, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=SHOCK_POT_R_ADC_CHNL, .rank=4, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=LV_24V_V_SENSE_ADC_CHNL, .rank=5, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=LV_24V_I_SENSE_ADC_CHNL, .rank=6, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=LV_12V_V_SENSE_ADC_CHNL, .rank=7, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=LV_5V_V_SENSE_ADC_CHNL, .rank=8, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=LV_5V_I_SENSE_ADC_CHNL, .rank=9, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=LV_3V3_V_SENSE_ADC_CHNL, .rank=10, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=THERM_MUX_D_ADC_CHNL, .rank=11, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=DT_GB_THERM_L_ADC_CHNL, .rank=12, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=DT_GB_THERM_R_ADC_CHNL, .rank=13, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, - {.channel=INTERNAL_THERM_ADC_CHNL, .rank=14, .sampling_time=ADC_CHN_SMP_CYCLES_640_5}, + {.channel=V_MC_SENSE_ADC_CHNL, .rank=1, .sampling_time=ADC_CHN_SMP_CYCLES_480}, + {.channel=V_BAT_SENSE_ADC_CHNL, .rank=2, .sampling_time=ADC_CHN_SMP_CYCLES_480}, + {.channel=SHOCK_POT_L_ADC_CHNL, .rank=3, .sampling_time=ADC_CHN_SMP_CYCLES_480}, + {.channel=SHOCK_POT_R_ADC_CHNL, .rank=4, .sampling_time=ADC_CHN_SMP_CYCLES_480}, + {.channel=THERM_MUX_D_ADC_CHNL, .rank=11, .sampling_time=ADC_CHN_SMP_CYCLES_480}, + {.channel=INTERNAL_THERM_ADC_CHNL, .rank=14, .sampling_time=ADC_CHN_SMP_CYCLES_480}, }; dma_init_t adc_dma_config = ADC1_DMA_CONT_CONFIG((uint32_t) &adc_readings, sizeof(adc_readings) / sizeof(adc_readings.lv_3v3_v_sense), 0b01); /* SPI Configuration */ -dma_init_t spi_rx_dma_config = SPI1_RXDMA_CONT_CONFIG(NULL, 2); -dma_init_t spi_tx_dma_config = SPI1_TXDMA_CONT_CONFIG(NULL, 1); - -SPI_InitConfig_t spi_config = { - .data_len = 8, - .nss_sw = false, - .nss_gpio_port = EEPROM_NSS_GPIO_Port, - .nss_gpio_pin = EEPROM_NSS_Pin, - .rx_dma_cfg = &spi_rx_dma_config, - .tx_dma_cfg = &spi_tx_dma_config, - .periph = SPI1 -}; +// dma_init_t spi_rx_dma_config = SPI1_RXDMA_CONT_CONFIG(NULL, 2); +// dma_init_t spi_tx_dma_config = SPI1_TXDMA_CONT_CONFIG(NULL, 1); + +// SPI_InitConfig_t spi_config = { +// .data_len = 8, +// .nss_sw = false, +// .nss_gpio_port = EEPROM_NSS_GPIO_Port, +// .nss_gpio_pin = EEPROM_NSS_Pin, +// .rx_dma_cfg = &spi_rx_dma_config, +// .tx_dma_cfg = &spi_tx_dma_config, +// .periph = SPI1 +// }; /* Clock Configuration */ @@ -232,7 +207,7 @@ void preflightAnimation(void); void preflightChecks(void); void heartBeatLED(); void usartTxUpdate(void); -void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf); +// void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf); void canTxUpdate(void); void send_fault(uint16_t, bool); extern void HardFault_Handler(); @@ -266,21 +241,22 @@ int main(void){ schedInit(APB1ClockRateHz); configureAnim(preflightAnimation, preflightChecks, 60, 750); - taskCreate(coolingPeriodic, 200); + // taskCreate(coolingPeriodic, 200); taskCreate(heartBeatLED, 500); - taskCreate(carHeartbeat, 100); - taskCreate(carPeriodic, 15); - taskCreate(wheelSpeedsPeriodic, 15); - taskCreate(updatePowerMonitor, 100); - taskCreate(heartBeatTask, 100); - taskCreate(parseMCDataPeriodic, MC_LOOP_DT); - taskCreate(daqPeriodic, DAQ_UPDATE_PERIOD); - taskCreate(memFg, MEM_FG_TIME); - // taskCreate(updateFaults, 1); + taskCreate(monitorSDCPeriodic, 15); + // taskCreate(carHeartbeat, 100); + // taskCreate(carPeriodic, 15); + // taskCreate(wheelSpeedsPeriodic, 15); + // taskCreate(updatePowerMonitor, 100); + // taskCreate(heartBeatTask, 100); + // taskCreate(parseMCDataPeriodic, MC_LOOP_DT); + // taskCreate(daqPeriodic, DAQ_UPDATE_PERIOD); + // taskCreate(memFg, MEM_FG_TIME); + // // taskCreate(updateFaults, 1); taskCreateBackground(canTxUpdate); taskCreateBackground(canRxUpdate); - taskCreateBackground(usartTxUpdate); - taskCreateBackground(memBg); + // taskCreateBackground(usartTxUpdate); + // taskCreateBackground(memBg); // calibrateSteeringAngle(&i); // SEND_LWS_CONFIG(q_tx_can, 0x05, 0, 0); // reset cal @@ -297,16 +273,16 @@ void preflightChecks(void) { switch (state++) { case 0: - huart_l.rx_dma_cfg->circular = true; - if(!PHAL_initUSART(MC_L_UART, &huart_l, APB1ClockRateHz)) - { - HardFault_Handler(); - } - huart_r.rx_dma_cfg->circular = true; - if(!PHAL_initUSART(MC_R_UART, &huart_r, APB2ClockRateHz)) - { - HardFault_Handler(); - } + // huart_l.rx_dma_cfg->circular = true; + // if(!PHAL_initUSART(MC_L_UART, &huart_l, APB1ClockRateHz)) + // { + // HardFault_Handler(); + // } + // huart_r.rx_dma_cfg->circular = true; + // if(!PHAL_initUSART(MC_R_UART, &huart_r, APB2ClockRateHz)) + // { + // HardFault_Handler(); + // } break; case 1: if(!PHAL_initCAN(CAN1, false)) @@ -314,11 +290,11 @@ void preflightChecks(void) { HardFault_Handler(); } NVIC_EnableIRQ(CAN1_RX0_IRQn); - spi_config.data_rate = APB2ClockRateHz / 16; // 5 MHz - if (!PHAL_SPI_init(&spi_config)) - HardFault_Handler(); - if (initMem(EEPROM_nWP_GPIO_Port, EEPROM_nWP_Pin, &spi_config, 1, 1) != E_SUCCESS) - HardFault_Handler(); + // spi_config.data_rate = APB2ClockRateHz / 16; // 5 MHz + // if (!PHAL_SPI_init(&spi_config)) + // HardFault_Handler(); + // if (initMem(EEPROM_nWP_GPIO_Port, EEPROM_nWP_Pin, &spi_config, 1, 1) != E_SUCCESS) + // HardFault_Handler(); break; case 2: if(!PHAL_initADC(ADC1, &adc_config, adc_channel_config, @@ -330,29 +306,28 @@ void preflightChecks(void) { { HardFault_Handler(); } - initPowerMonitor(); PHAL_startTxfer(&adc_dma_config); PHAL_startADC(ADC1); break; case 3: /* UART Initialization */ - MC_L_UART->CR1 &= ~(USART_CR1_RXNEIE | USART_CR1_TCIE | USART_CR1_TXEIE); - NVIC_EnableIRQ(USART1_IRQn); + // MC_L_UART->CR1 &= ~(USART_CR1_RXNEIE | USART_CR1_TCIE | USART_CR1_TXEIE); + // NVIC_EnableIRQ(USART1_IRQn); // initial rx request - PHAL_usartRxDma(MC_L_UART, &huart_l, - (uint16_t *) huart_l_rx_buf.rx_buf, - huart_l_rx_buf.rx_buf_size); - MC_R_UART->CR1 &= ~(USART_CR1_RXNEIE | USART_CR1_TCIE | USART_CR1_TXEIE); - NVIC_EnableIRQ(USART2_IRQn); - // initial rx request - PHAL_usartRxDma(MC_R_UART, &huart_r, - (uint16_t *) huart_r_rx_buf.rx_buf, - huart_r_rx_buf.rx_buf_size); + // PHAL_usartRxDma(MC_L_UART, &huart_l, + // (uint16_t *) huart_l_rx_buf.rx_buf, + // huart_l_rx_buf.rx_buf_size); + // MC_R_UART->CR1 &= ~(USART_CR1_RXNEIE | USART_CR1_TCIE | USART_CR1_TXEIE); + // NVIC_EnableIRQ(USART2_IRQn); + // // initial rx request + // PHAL_usartRxDma(MC_R_UART, &huart_r, + // (uint16_t *) huart_r_rx_buf.rx_buf, + // huart_r_rx_buf.rx_buf_size); break; case 4: /* Module Initialization */ carInit(); - coolingInit(); + // coolingInit(); break; case 5: initCANParse(&q_rx_can); @@ -409,51 +384,51 @@ void heartBeatLED(void) } /* USART Message Handling */ -uint8_t tmp_left[MC_MAX_TX_LENGTH] = {'\0'}; -uint8_t tmp_right[MC_MAX_TX_LENGTH] = {'\0'}; -void usartTxUpdate(void) -{ - if (PHAL_usartTxDmaComplete(&huart_l) && - qReceive(&q_tx_usart_l, tmp_left) == SUCCESS_G) - { - PHAL_usartTxDma(MC_L_UART, &huart_l, (uint16_t *) tmp_left, strlen(tmp_left)); - } - if (PHAL_usartTxDmaComplete(&huart_r) && - qReceive(&q_tx_usart_r, tmp_right) == SUCCESS_G) - { - PHAL_usartTxDma(MC_R_UART, &huart_r, (uint16_t *) tmp_right, strlen(tmp_right)); - } -} - -void USART1_IRQHandler(void) { - if (MC_L_UART->ISR & USART_ISR_IDLE) { - usartIdleIRQ(&huart_l, &huart_l_rx_buf); - MC_L_UART->ICR = USART_ICR_IDLECF; - } -} - -void USART2_IRQHandler(void) { - if (MC_R_UART->ISR & USART_ISR_IDLE) { - usartIdleIRQ(&huart_r, &huart_r_rx_buf); - MC_R_UART->ICR = USART_ICR_IDLECF; - } -} - -void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf) -{ - // TODO: check for overruns, framing errors, etc - uint16_t new_loc = 0; - rx_buf->last_rx_time = sched.os_ticks; - new_loc = rx_buf->rx_buf_size - huart->rx_dma_cfg->channel->CNDTR; // extract last location from DMA - if (new_loc == rx_buf->rx_buf_size) new_loc = 0; // should never happen - else if (new_loc < rx_buf->last_rx_loc) new_loc += rx_buf->rx_buf_size; // wrap around - if (new_loc - rx_buf->last_rx_loc > rx_buf->msg_size) // status msg vs just an echo - { - rx_buf->last_msg_time = sched.os_ticks; - rx_buf->last_msg_loc = (rx_buf->last_rx_loc + 1) % rx_buf->rx_buf_size; - } - rx_buf->last_rx_loc = new_loc % rx_buf->rx_buf_size; -} +// uint8_t tmp_left[MC_MAX_TX_LENGTH] = {'\0'}; +// uint8_t tmp_right[MC_MAX_TX_LENGTH] = {'\0'}; +// void usartTxUpdate(void) +// { +// if (PHAL_usartTxDmaComplete(&huart_l) && +// qReceive(&q_tx_usart_l, tmp_left) == SUCCESS_G) +// { +// PHAL_usartTxDma(MC_L_UART, &huart_l, (uint16_t *) tmp_left, strlen(tmp_left)); +// } +// if (PHAL_usartTxDmaComplete(&huart_r) && +// qReceive(&q_tx_usart_r, tmp_right) == SUCCESS_G) +// { +// PHAL_usartTxDma(MC_R_UART, &huart_r, (uint16_t *) tmp_right, strlen(tmp_right)); +// } +// } + +// void USART1_IRQHandler(void) { +// if (MC_L_UART->ISR & USART_ISR_IDLE) { +// usartIdleIRQ(&huart_l, &huart_l_rx_buf); +// MC_L_UART->ICR = USART_ICR_IDLECF; +// } +// } + +// void USART2_IRQHandler(void) { +// if (MC_R_UART->ISR & USART_ISR_IDLE) { +// usartIdleIRQ(&huart_r, &huart_r_rx_buf); +// MC_R_UART->ICR = USART_ICR_IDLECF; +// } +// } + +// void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf) +// { +// // TODO: check for overruns, framing errors, etc +// uint16_t new_loc = 0; +// rx_buf->last_rx_time = sched.os_ticks; +// new_loc = rx_buf->rx_buf_size - huart->rx_dma_cfg->channel->CNDTR; // extract last location from DMA +// if (new_loc == rx_buf->rx_buf_size) new_loc = 0; // should never happen +// else if (new_loc < rx_buf->last_rx_loc) new_loc += rx_buf->rx_buf_size; // wrap around +// if (new_loc - rx_buf->last_rx_loc > rx_buf->msg_size) // status msg vs just an echo +// { +// rx_buf->last_msg_time = sched.os_ticks; +// rx_buf->last_msg_loc = (rx_buf->last_rx_loc + 1) % rx_buf->rx_buf_size; +// } +// rx_buf->last_rx_loc = new_loc % rx_buf->rx_buf_size; +// } /* CAN Message Handling */ void canTxUpdate(void) @@ -511,8 +486,8 @@ void CAN1_RX0_IRQHandler() void main_module_bl_cmd_CALLBACK(CanParsedData_t *msg_data_a) { - if (can_data.main_module_bl_cmd.cmd == BLCMD_RST) - Bootloader_ResetForFirmwareDownload(); + // if (can_data.main_module_bl_cmd.cmd == BLCMD_RST) + // Bootloader_ResetForFirmwareDownload(); } void HardFault_Handler() diff --git a/source/main_module/main.h b/source/main_module/main.h index 99c4ce76..089efd1b 100644 --- a/source/main_module/main.h +++ b/source/main_module/main.h @@ -19,66 +19,81 @@ #define FAULT_NODE_NAME NODE_MAIN_MODULE -// Status Indicators -#define ERR_LED_GPIO_Port (GPIOE) -#define ERR_LED_Pin (7) -#define CONN_LED_GPIO_Port (GPIOE) -#define CONN_LED_Pin (8) +// Internal Status Indicators +#define ERR_LED_GPIO_Port (GPIOD) +#define ERR_LED_Pin (4) +#define CONN_LED_GPIO_Port (GPIOD) +#define CONN_LED_Pin (3) #define CONN_LED_MS_THRESH (500) -#define HEARTBEAT_GPIO_Port (GPIOE) -#define HEARTBEAT_Pin (5) -#define BRK_LIGHT_GPIO_Port (GPIOA) -#define BRK_LIGHT_Pin (12) -#define BUZZER_GPIO_Port (GPIOB) -#define BUZZER_Pin (2) -#define UNDERGLOW_GPIO_Port (GPIOB) -#define UNDERGLOW_Pin (5) +#define HEARTBEAT_GPIO_Port (GPIOD) +#define HEARTBEAT_Pin (2) + +// External Status Indicators +#define BRK_LIGHT_GPIO_Port (GPIOD) +#define BRK_LIGHT_Pin (14) +#define BUZZER_GPIO_Port (GPIOD) +#define BUZZER_Pin (12) + +#define BRK_BUZZER_STAT_GPIO_Port (GPIOB) +#define BRK_BUZZER_STAT_Pin (15) + +#define TSAL_LVAL_STAT_GPIO_Port (GPIOD) +#define TSAL_LVAL_STAT_Pin (10) // CAN -#define VCAN_RX_GPIO_Port (GPIOD) -#define VCAN_RX_Pin (0) -#define VCAN_TX_GPIO_Port (GPIOD) -#define VCAN_TX_Pin (1) +#define VCAN_RX_GPIO_Port (GPIOA) +#define VCAN_RX_Pin (11) +#define VCAN_TX_GPIO_Port (GPIOA) +#define VCAN_TX_Pin (12) -#define IMUCAN_RX_GPIO_Port (GPIOB) -#define IMUCAN_RX_Pin (12) -#define IMUCAN_TX_GPIO_Port (GPIOB) -#define IMUCAN_TX_Pin (13) +#define EMCAN_RX_GPIO_Port (GPIOB) +#define EMCAN_RX_Pin (12) +#define EMCAN_TX_GPIO_Port (GPIOB) +#define EMCAN_TX_Pin (13) // SPI Peripherals -#define SPI1_SCK_GPIO_Port (GPIOE) -#define SPI1_SCK_Pin (13) -#define SPI1_MISO_GPIO_Port (GPIOE) -#define SPI1_MISO_Pin (14) -#define SPI1_MOSI_GPIO_Port (GPIOE) -#define SPI1_MOSI_Pin (15) +#define SPI1_SCK_GPIO_Port (GPIOA) +#define SPI1_SCK_Pin (5) +#define SPI1_MISO_GPIO_Port (GPIOA) +#define SPI1_MISO_Pin (6) +#define SPI1_MOSI_GPIO_Port (GPIOA) +#define SPI1_MOSI_Pin (7) + +#define EEPROM_nWP_GPIO_Port (GPIOB) +#define EEPROM_nWP_Pin (1) +#define EEPROM_NSS_GPIO_Port (GPIOB) +#define EEPROM_NSS_Pin (0) -#define EEPROM_nWP_GPIO_Port (GPIOE) -#define EEPROM_nWP_Pin (6) -#define EEPROM_NSS_GPIO_Port (GPIOE) -#define EEPROM_NSS_Pin (10) +// Shutdown Circuit +#define SDC_CTRL_GPIO_Port (GPIOD) +#define SDC_CTRL_Pin (11) -#define SD_CARD_NSS_GPIO_Port (GPIOE) -#define SD_CARD_NSS_Pin (12) +#define SDC_MUX_S0_GPIO_Port (GPIOC) +#define SDC_MUX_S0_Pin (9) +#define SDC_MUX_S1_GPIO_Port (GPIOD) +#define SDC_MUX_S1_Pin (15) +#define SDC_MUX_S2_GPIO_Port (GPIOC) +#define SDC_MUX_S2_Pin (6) +#define SDC_MUX_S3_GPIO_Port (GPIOC) +#define SDC_MUX_S3_Pin (7) + +#define SDC_MUX_DATA_GPIO_Port (GPIOC) +#define SDC_MUX_DATA_Pin (8) -// Shutdown Circuit -#define SDC_CTRL_GPIO_Port (GPIOA) -#define SDC_CTRL_Pin (8) -#define BSPD_TEST_CTRL_GPIO_Port (GPIOB) -#define BSPD_TEST_CTRL_Pin (9) +// HV Bus Information +#define V_MC_SENSE_GPIO_Port (GPIOA) +#define V_MC_SENSE_Pin (1) +#define V_MC_SENSE_ADC_CHNL (1) +#define V_BAT_SENSE_GPIO_Port (GPIOA) +#define V_BAT_SENSE_Pin (0) +#define V_BAT_SENSE_ADC_CHNL (0) -#define V_MC_SENSE_GPIO_Port (GPIOC) -#define V_MC_SENSE_Pin (4) -#define V_MC_SENSE_ADC_CHNL (13) -#define V_BAT_SENSE_GPIO_Port (GPIOC) -#define V_BAT_SENSE_Pin (5) -#define V_BAT_SENSE_ADC_CHNL (14) +#define BMS_STAT_GPIO_Port (GPIOD) +#define BMS_STAT_Pin (13) -#define BMS_STAT_GPIO_Port (GPIOC) -#define BMS_STAT_Pin (11) -#define PRCHG_STAT_GPIO_Port (GPIOC) -#define PRCHG_STAT_Pin (13) +#define PRCHG_STAT_GPIO_Port (GPIOE) +#define PRCHG_STAT_Pin (5) // Motor Controllers #define MC_L_INVERT (0) @@ -88,145 +103,57 @@ #define MC_L_UART_RX_GPIO_Port (GPIOA) #define MC_L_UART_RX_GPIO_Pin (10) -#define MC_L_TIM (TIM3) -#define MC_L_TIM_CH (3) -#define MC_L_PWM_GPIO_Port (GPIOC) -#define MC_L_PWM_Pin (8) - #define MC_R_INVERT (0) #define MC_R_UART (USART2) -#define MC_R_UART_TX_GPIO_Port (GPIOD) -#define MC_R_UART_TX_GPIO_Pin (5) -#define MC_R_UART_RX_GPIO_Port (GPIOD) -#define MC_R_UART_RX_GPIO_Pin (6) - -#define MC_R_TIM (TIM3) -#define MC_R_TIM_CH (4) -#define MC_R_PWM_GPIO_Port (GPIOC) -#define MC_R_PWM_Pin (9) +#define MC_R_UART_TX_GPIO_Port (GPIOA) +#define MC_R_UART_TX_GPIO_Pin (2) +#define MC_R_UART_RX_GPIO_Port (GPIOA) +#define MC_R_UART_RX_GPIO_Pin (3) // Wheel Speed -#define MOTOR_L_WS_QUAD_TIM (TIM2) -#define MOTOR_L_WS_A_GPIO_Port (GPIOA) -#define MOTOR_L_WS_A_Pin (15) -#define MOTOR_L_WS_B_GPIO_Port (GPIOB) -#define MOTOR_L_WS_B_Pin (3) +#define MOTOR_R_WS_PWM_TIM (TIM1) +#define MOTOR_R_WS_PWM_CH (1) +#define MOTOR_R_WS_GPIO_Port (GPIOA) +#define MOTOR_R_WS_Pin (8) +#define MOTOR_R_WS_AF (1) -#define MOTOR_L_WS_PWM_TIM (TIM8) // NOTE: SHARED WITH BAT_FLOW +#define MOTOR_L_WS_PWM_TIM (TIM4) #define MOTOR_L_WS_PWM_CH (1) -#define MOTOR_L_WS_Z_GPIO_Port (GPIOC) -#define MOTOR_L_WS_Z_Pin (6) - -#define MOTOR_L_WS_ERROR_GPIO_Port (GPIOB) -#define MOTOR_L_WS_ERROR_Pin (7) +#define MOTOR_L_WS_GPIO_Port (GPIOB) +#define MOTOR_L_WS_Pin (6) +#define MOTOR_L_WS_AF (2) -#define MOTOR_R_WS_QUAD_TIM (TIM5) -#define MOTOR_R_WS_A_GPIO_Port (GPIOA) -#define MOTOR_R_WS_A_Pin (0) -#define MOTOR_R_WS_B_GPIO_Port (GPIOA) -#define MOTOR_R_WS_B_Pin (1) +// Shock Pots +#define SHOCK_POT_L_GPIO_Port (GPIOC) +#define SHOCK_POT_L_Pin (3) +#define SHOCK_POT_L_ADC_CHNL (13) -#define MOTOR_R_WS_PWM_TIM (TIM1) // NOTE: SHARED WITH DT_FLOW -#define MOTOR_R_WS_PWM_TIM_CH (1) -#define MOTOR_R_WS_Z_GPIO_Port (GPIOE) -#define MOTOR_R_WS_Z_Pin (9) +#define SHOCK_POT_R_GPIO_Port (GPIOC) +#define SHOCK_POT_R_Pin (2) +#define SHOCK_POT_R_ADC_CHNL (12) -#define MOTOR_R_WS_ERROR_GPIO_Port (GPIOB) -#define MOTOR_R_WS_ERROR_Pin (6) +// Load Sensors +#define LOAD_R_GPIO_Port (GPIOA) +#define LOAD_R_Pin (4) +#define LOAD_R_ADC_CHNL (4) -// Shock Pots -#define SHOCK_POT_L_GPIO_Port (GPIOA) -#define SHOCK_POT_L_Pin (5) -#define SHOCK_POT_L_ADC_CHNL (10) -#define SHOCK_POT_R_GPIO_Port (GPIOA) -#define SHOCK_POT_R_Pin (2) -#define SHOCK_POT_R_ADC_CHNL (7) - -// Drivetrain -#define DT_GB_THERM_R_GPIO_Port (GPIOC) -#define DT_GB_THERM_R_Pin (0) -#define DT_GB_THERM_R_ADC_CHNL (1) -#define DT_GB_THERM_L_GPIO_Port (GPIOA) -#define DT_GB_THERM_L_Pin (4) -#define DT_GB_THERM_L_ADC_CHNL (9) - -#define DT_PUMP_CTRL_GPIO_Port (GPIOB) -#define DT_PUMP_CTRL_Pin (10) - -#define DT_FLOW_RATE_TIM (TIM1) // NOTE: SHARED WITH R_WS_Z -#define DT_FLOW_RATE_TIM_CH (2) -#define DT_FLOW_RATE_GPIO_Port (GPIOE) -#define DT_FLOW_RATE_Pin (11) - -#define DT_FAN_CTRL_TIM (TIM4) -#define DT_FAN_CTRL_TIM_CH (2) -#define DT_FAN_CTRL_GPIO_Port (GPIOD) -#define DT_FAN_CTRL_Pin (13) - -#define DT_FAN_TACK_TIM (TIM17) -#define DT_FAN_TACK_TIM_CH (1) -#define DT_FAN_TACK_GPIO_Port (GPIOE) -#define DT_FAN_TACK_Pin (1) - -// HV Battery -#define BAT_PUMP_CTRL_1_GPIO_Port (GPIOB) -#define BAT_PUMP_CTRL_1_Pin (14) -#define BAT_PUMP_CTRL_2_GPIO_Port (GPIOB) -#define BAT_PUMP_CTRL_2_Pin (15) - -#define BAT_FLOW_RATE_TIM (TIM8) // NOTE: SHARED WITH L_WS_Z -#define BAT_FLOW_RATE_TIM_CH (CH2) -#define BAT_FLOW_RATE_GPIO_Port (GPIOC) -#define BAT_FLOW_RATE_Pin (7) - -#define BAT_FAN_CTRL_TIM (TIM4) -#define BAT_FAN_CTRL_TIM_CH (1) -#define BAT_FAN_CTRL_GPIO_Port (GPIOD) -#define BAT_FAN_CTRL_Pin (12) - -#define BAT_FAN_TACK_TIM (TIM16) -#define BAT_FAN_TACK_TIM_CH (1) -#define BAT_FAN_TACK_GPIO_Port (GPIOE) -#define BAT_FAN_TACK_Pin (0) - -// LV Status -#define LV_24V_V_SENSE_GPIO_Port (GPIOA) -#define LV_24V_V_SENSE_Pin (6) -#define LV_24V_V_SENSE_ADC_CHNL (11) -#define LV_24V_I_SENSE_GPIO_Port (GPIOC) -#define LV_24V_I_SENSE_Pin (1) -#define LV_24V_I_SENSE_ADC_CHNL (2) - -#define LV_12V_V_SENSE_GPIO_Port (GPIOA) -#define LV_12V_V_SENSE_Pin (7) -#define LV_12V_V_SENSE_ADC_CHNL (12) - -#define LV_5V_V_SENSE_GPIO_Port (GPIOB) -#define LV_5V_V_SENSE_Pin (0) -#define LV_5V_V_SENSE_ADC_CHNL (15) -#define LV_5V_I_SENSE_GPIO_Port (GPIOC) -#define LV_5V_I_SENSE_Pin (2) -#define LV_5V_I_SENSE_ADC_CHNL (3) - -#define LV_3V3_V_SENSE_GPIO_Port (GPIOB) -#define LV_3V3_V_SENSE_Pin (1) -#define LV_3V3_V_SENSE_ADC_CHNL (16) -#define LV_3V3_PG_GPIO_Port (GPIOB) -#define LV_3V3_PG_Pin (8) - -#define LV_BAT_STAT_GPIO_Port (GPIOB) -#define LV_BAT_STAT_Pin (4) +#define LOAD_L_GPIO_Port (GPIOC) +#define LOAD_L_Pin (1) +#define LOAD_L_ADC_CHNL (11) +// MCU Internal Thermistor #define INTERNAL_THERM_ADC_CHNL (17) // Thermistor Analog Multiplexer #define THERM_MUX_S0_GPIO_Port (GPIOE) #define THERM_MUX_S0_Pin (2) -#define THERM_MUX_S1_GPIO_Port (GPIOD) -#define THERM_MUX_S1_Pin (11) -#define THERM_MUX_D_GPIO_Port (GPIOA) -#define THERM_MUX_D_Pin (3) -#define THERM_MUX_D_ADC_CHNL (8) +#define THERM_MUX_S1_GPIO_Port (GPIOE) +#define THERM_MUX_S1_Pin (3) +#define THERM_MUX_S2_GPIO_Port (GPIOE) +#define THERM_MUX_S2_Pin (4) +#define THERM_MUX_D_GPIO_Port (GPIOC) +#define THERM_MUX_D_Pin (0) +#define THERM_MUX_D_ADC_CHNL (10) #define THERM_MUX_BAT_IN (0) #define THERM_MUX_BAT_OUT (1) @@ -234,7 +161,7 @@ #define THERM_MUX_DT_OUT (3) #define ADC_REF_mV (3300UL) // mV -typedef struct +typedef struct { // Do not modify this struct unless // you modify the ADC DMA config diff --git a/source/main_module/power_monitor/power_monitor.c b/source/main_module/power_monitor/power_monitor.c deleted file mode 100644 index 4226ac9d..00000000 --- a/source/main_module/power_monitor/power_monitor.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @file power_monitor.c - * @author Luke Oxley (lcoxley@purdue.edu) - * @brief Monitor voltage and current present on the board - * @version 0.1 - * @date 2023-02-02 - * - * @copyright Copyright (c) 2023 - * - */ - -#include "power_monitor.h" -#include "car.h" -#include "common/faults/faults.h" - -static uint16_t calcCurrent(uint16_t adc_raw); -static uint16_t calcVoltage(uint16_t adc_raw, uint16_t r1, uint16_t r2, uint16_t cal); - -PowerMonitor_t power_monitor; -extern q_handle_t q_tx_can; -static uint16_t ts_cal1_val, ts_cal2_val; - -void initPowerMonitor() -{ - power_monitor = (PowerMonitor_t) {0}; - - // Enable the temperature sensor - ADC123_COMMON->CCR |= ADC_CCR_TSEN; - ts_cal1_val = *(TS_CAL1_ADDR); - ts_cal2_val = *(TS_CAL2_ADDR); - - // Interrupt for full transfer (testing frequency of ADC) - // Toggles the error LED pin on each transfer complete - #ifdef PM_ADC_FREQ_TEST - DMA2_Channel3->CCR |= DMA_CCR_TCIE; - NVIC_EnableIRQ(DMA2_Channel3_IRQn); - #endif -} - -void updatePowerMonitor() -{ - power_monitor.lv_24_v_sense_mV = calcVoltage(adc_readings.lv_24_v_sense, LV_24V_R1, LV_24V_R2, LV_24V_CAL); - power_monitor.lv_24_i_sense_mA = calcCurrent(adc_readings.lv_24_i_sense); - power_monitor.lv_12_v_sense_mV = calcVoltage(adc_readings.lv_12_v_sense, LV_12V_R1, LV_12V_R2, LV_12V_CAL); - power_monitor.lv_5_v_sense_mV = calcVoltage(adc_readings.lv_5_v_sense, LV_5V_R1, LV_5V_R2, LV_5V_CAL); - power_monitor.lv_5_i_sense_mA = calcCurrent(adc_readings.lv_5_i_sense); - power_monitor.lv_3v3_v_sense_mV = calcVoltage(adc_readings.lv_3v3_v_sense, LV_3V3_R1, LV_3V3_R2, LV_3V3_CAL); - power_monitor.lv_3v3_power_good = PHAL_readGPIO(LV_3V3_PG_GPIO_Port, LV_3V3_PG_Pin); - - power_monitor.mcu_temp = (int16_t) ((((int32_t) adc_readings.therm_mcu)*ADC_REF_mV/ TS_CAL_ADC_REF - ts_cal1_val) * - (TS_CAL2_TEMP - TS_CAL1_TEMP) / (ts_cal2_val - ts_cal1_val) + TS_CAL1_TEMP); - - setFault(ID_MCU_TEMP_HIGH_FAULT, power_monitor.mcu_temp); - setFault(ID_LV_BAT_LOW_FAULT, power_monitor.lv_24_v_sense_mV / 1000); - setFault(ID_LV_BAT_VERY_LOW_FAULT, power_monitor.lv_24_v_sense_mV / 1000); - // TODO: BMS Fault (LV_BAT_BMS) - static uint8_t skip; - if (skip++ >= 10) { - SEND_VOLTAGE_RAILS(q_tx_can, power_monitor.lv_24_v_sense_mV, power_monitor.lv_12_v_sense_mV, - power_monitor.lv_5_v_sense_mV, power_monitor.lv_3v3_v_sense_mV); - SEND_CURRENT_MEAS(q_tx_can, power_monitor.lv_24_i_sense_mA, power_monitor.lv_5_i_sense_mA, - power_monitor.mcu_temp, power_monitor.lv_3v3_power_good); - skip = 0; - } - - // TODO: add power monitoring faults -} - - -#ifdef PM_ADC_FREQ_TEST -void DMA2_Channel3_IRQHandler() -{ - if (DMA2->ISR & DMA_ISR_TCIF3) - { - PHAL_toggleGPIO(ERR_LED_GPIO_Port, ERR_LED_Pin); - } - DMA2->IFCR = DMA_IFCR_CGIF3; -} -#endif - -/** - * @brief Calculates the low voltage system current - * draw based on the output of a current - * sense amplifier - * - * @param adc_raw 12-bit adc reading - * @return uint16_t current in mA - */ -static uint16_t calcCurrent(uint16_t adc_raw) -{ - uint32_t tmp; - // V_out = adc_raw * adc_v_ref / adc_max - tmp = ((uint32_t) adc_raw * ADC_REF_mV) / 0xFFFUL; - // I_load = ((V_out - V_ref (0)) / R_sense / gain) - return (uint16_t) tmp * 1000 / LV_I_SENSE_GAIN / LV_I_SENSE_R; -} - -/** - * @brief Calculate the rail voltage given the adc - * reading from a voltage divider - * - * @param adc_raw 12-bit adc reading - * @param r1 Top resistor (Ohms) - * @param r2 Bottom resistor (Ohms) - * @param cal Constant calibration factor - * @return uint16_t V_out (mV) - */ -static uint16_t calcVoltage(uint16_t adc_raw, uint16_t r1, uint16_t r2, uint16_t cal) -{ - uint32_t tmp; - // V_out = adc_raw * adc_v_ref / adc_max - tmp = ((uint32_t) adc_raw * ((ADC_REF_mV * (uint32_t) cal) / 1000)) / 0xFFFUL; - if (r2 == 0) return tmp; - // V_in = (V_out * (r1 + r2)) / r2 - return (uint16_t) (tmp * ((uint32_t) r1 + (uint32_t) r2) / r2); -} \ No newline at end of file diff --git a/source/main_module/power_monitor/power_monitor.h b/source/main_module/power_monitor/power_monitor.h deleted file mode 100644 index ce892142..00000000 --- a/source/main_module/power_monitor/power_monitor.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file power_monitor.h - * @author Luke Oxley (lcoxley@purdue.edu) - * @brief Monitor voltage and current present on the board - * @version 0.1 - * @date 2023-02-02 - * - * @copyright Copyright (c) 2023 - * - */ - -#ifndef _POWER_MONITOR_H_ -#define _POWER_MONITOR_H_ - -#include - -/* VOLTAGE SENSE */ -/* R1 is top, R2 is bottom in voltage divider */ -#define LV_24V_R1 47000 // Ohms -#define LV_24V_R2 3300 // Ohms -#define LV_12V_R1 15800 // Ohms -#define LV_12V_R2 3300 // Ohms -#define LV_5V_R1 4300 // Ohms -#define LV_5V_R2 3300 // Ohms -#define LV_3V3_R1 4300 // Ohms -#define LV_3V3_R2 10000 // Ohms - -#define LV_24V_CAL (1015) // V_actual / V_measured * 1000 -#define LV_12V_CAL (LV_24V_CAL) -#define LV_5V_CAL (LV_24V_CAL) -#define LV_3V3_CAL (LV_24V_CAL) - -/* CURRENT SENSE */ -#define LV_I_SENSE_GAIN 100 // V/V -#define LV_I_SENSE_R 2 // mOhm - -/* INTENERAL TEMPERATURE SENSOR */ -#define TS_CAL1_ADDR ((uint16_t*) 0x1FFF75A8UL) -#define TS_CAL2_ADDR ((uint16_t*) 0x1FFF75CAUL) -#define TS_CAL1_TEMP ((int32_t) 30) // C +/-5 -#define TS_CAL2_TEMP ((int32_t) 130) // C +/-5 -#define TS_CAL_ADC_REF (3000UL) // mV - -typedef struct -{ - uint16_t lv_24_v_sense_mV; - uint16_t lv_24_i_sense_mA; - uint16_t lv_12_v_sense_mV; - uint16_t lv_5_v_sense_mV; - uint16_t lv_5_i_sense_mA; - uint16_t lv_3v3_v_sense_mV; - uint8_t lv_3v3_power_good; - int16_t mcu_temp; -} PowerMonitor_t; - -extern PowerMonitor_t power_monitor; - -void initPowerMonitor(); -void updatePowerMonitor(); - -#endif \ No newline at end of file diff --git a/source/main_module/power_monitor/power_monitor.tsc b/source/main_module/power_monitor/power_monitor.tsc deleted file mode 100644 index f4cb8044..00000000 --- a/source/main_module/power_monitor/power_monitor.tsc +++ /dev/null @@ -1,166 +0,0 @@ -#STM Touch Studio user settings - do not edit -#Sat Feb 04 20:46:03 EST 2023 -ExprVariable.Col0ModelIdx=0 -ExprVariable.Col0Width=15 -ExprVariable.Col1ModelIdx=1 -ExprVariable.Col1Width=92 -ExprVariable.Col2ModelIdx=2 -ExprVariable.Col2Width=92 -ExprVariable.Col3ModelIdx=3 -ExprVariable.Col3Width=91 -ExprVariable.Col4ModelIdx=4 -ExprVariable.Col4Width=40 -ExprVariable.Number=0 -GdbVar.ExecDate=1675548620190 -GdbVar.LastExecRelative=..\\..\\output\\main_module\\main_module.elf -GdbVar.Version=1 -GeneralPurpose.HorizontalSplit=350 -GeneralPurpose.ScrollAcq.Height=136 -GeneralPurpose.ScrollExpr.Height=68 -GeneralPurpose.ScrollPlugin.Height=68 -GeneralPurpose.ScrollStat.Height=68 -GeneralPurpose.Version=3 -GeneralPurpose.VerticalSplit1=68 -GeneralPurpose.VerticalSplit2=141 -GeneralPurpose.VerticalSplit3=137 -GeneralPurpose.VerticalSplit4=418 -Interface.LogPostProcessingEnable=true -Interface.RefreshRate=20 -Interface.Target=ST-Link SWD -Interface.Version=2 -Log.AcqAllVariables=true -Log.AcqRate=-1 -Log.AcqVariablesVisible=false -Log.AppendMode=false -Log.CriticalLockAddr=0 -Log.DetectStm8LP=false -Log.DirectSynchronized=false -Log.EnableLog=true -Log.ExhaustiveDisplay=false -Log.FilenameRelative=..\\..\\..\\..\\OneDrive\\Documents\\STMicroelectronics\\STMStudio\\log.txt -Log.GuiRate=false -Log.LittleEndian=true -Log.MaxConsecutiveCommErrors=10 -Log.MaxConsecutiveHalt=40 -Log.OnlyVariations=false -Log.RawFrame=false -Log.ReInitComm=true -Log.Replay=false -Log.SubSamplingSnapshot=1 -Log.TraceHeaderAddr=0 -Log.Trigger.AutoRestart=false -Log.Trigger.BySymbol=false -Log.Trigger.IgnoreTrig=false -Log.Trigger.NameBySymbol=Unknown -Log.Trigger.ParamStop=0 -Log.Trigger.RestartTimestamp=false -Log.Trigger.SnapshotMode=false -Log.Trigger.StartMode=0 -Log.Trigger.StopMode=0 -Log.Trigger.Threshold=0 -Log.Trigger.ThresholdBySymbol=0 -Log.Trigger.TrigToAllVar=false -Log.Trigger.VarAddr=0 -Log.Trigger.VarType=0 -Log.Trigger.nPreTrig=0 -Log.Version=13 -Main.Version=6 -StatVariable.Col0ModelIdx=0 -StatVariable.Col0Width=15 -StatVariable.Col1ModelIdx=1 -StatVariable.Col1Width=69 -StatVariable.Col2ModelIdx=2 -StatVariable.Col2Width=69 -StatVariable.Col3ModelIdx=3 -StatVariable.Col3Width=69 -StatVariable.Col4ModelIdx=4 -StatVariable.Col4Width=68 -StatVariable.Col5ModelIdx=5 -StatVariable.Col5Width=40 -StatVariable.Number=0 -TouchPointViewer.Name=Point Viewer -TouchPointViewer.Number=1 -TouchPointViewer.SecondScreen=false -TouchPointViewer.Version=3 -TouchPointViewer.Visible=false -TouchPointViewer.XRange.Low=-255 -TouchPointViewer.XRange.Up=255 -TouchPointViewer.YRange.Low=-255 -TouchPointViewer.YRange.Up=255 -VarViewer.DisplayAllMode=Curve -VarViewer.Number=2 -VarViewer.SelectedTab=2 -VarViewer.ShowIndex=false -VarViewer.Version=4 -VarViewer1.DisplayMode=Bargraph -VarViewer1.Hexa=false -VarViewer1.Name=VarViewer1 -VarViewer1.Range.Low=-16800.0 -VarViewer1.Range.Up=51300.0 -VarViewer1.SecondScreen=false -VarViewer1.Var.Nb=6 -VarViewer1.Var0.Name=power_monitor.lv_24_v_sense_mV -VarViewer1.Var1.Name=power_monitor.lv_24_i_sense_mA -VarViewer1.Var2.Name=power_monitor.lv_12_v_sense_mV -VarViewer1.Var3.Name=power_monitor.lv_5_v_sense_mV -VarViewer1.Var4.Name=power_monitor.lv_5_i_sense_mA -VarViewer1.Var5.Name=power_monitor.lv_3v3_v_sense_mV -VarViewer1.Visible=true -Variable.Col0ModelIdx=0 -Variable.Col0Width=15 -Variable.Col1ModelIdx=1 -Variable.Col1Width=92 -Variable.Col2ModelIdx=2 -Variable.Col2Width=92 -Variable.Col3ModelIdx=3 -Variable.Col3Width=91 -Variable.Col4ModelIdx=4 -Variable.Col4Width=40 -Variable.Number=6 -Variable.Version=5 -Variable0.AcqMode=false -Variable0.Address=536874584 -Variable0.Color=0x6699ff -Variable0.Name=power_monitor.lv_24_v_sense_mV -Variable0.Type=unsigned 16-bit -Variable1.AcqMode=false -Variable1.Address=536874586 -Variable1.Color=0x999999 -Variable1.Name=power_monitor.lv_24_i_sense_mA -Variable1.Type=unsigned 16-bit -Variable2.AcqMode=false -Variable2.Address=536874588 -Variable2.Color=0x9966ff -Variable2.Name=power_monitor.lv_12_v_sense_mV -Variable2.Type=unsigned 16-bit -Variable3.AcqMode=false -Variable3.Address=536874590 -Variable3.Color=0x00cc33 -Variable3.Name=power_monitor.lv_5_v_sense_mV -Variable3.Type=unsigned 16-bit -Variable4.AcqMode=false -Variable4.Address=536874592 -Variable4.Color=0xff6633 -Variable4.Name=power_monitor.lv_5_i_sense_mA -Variable4.Type=unsigned 16-bit -Variable5.AcqMode=false -Variable5.Address=536874594 -Variable5.Color=0x006666 -Variable5.Name=power_monitor.lv_3v3_v_sense_mV -Variable5.Type=unsigned 16-bit -Viewers.Synchronized=false -ViewersLayout.Position.0=-1 -ViewersLayout.Position.1=0 -ViewersLayout.Position.Size=2 -ViewersLayout.Version=1 -WriteVariable.Col0ModelIdx=0 -WriteVariable.Col0Width=15 -WriteVariable.Col1ModelIdx=1 -WriteVariable.Col1Width=79 -WriteVariable.Col2ModelIdx=2 -WriteVariable.Col2Width=79 -WriteVariable.Col3ModelIdx=3 -WriteVariable.Col3Width=79 -WriteVariable.Col4ModelIdx=4 -WriteVariable.Col4Width=78 -WriteVariable.Number=0