From 108adb5d32a95c3deb3f2fb2a61e97ed9a455b6a Mon Sep 17 00:00:00 2001 From: BlakeFreer Date: Fri, 29 Nov 2024 17:58:48 -0500 Subject: [PATCH 1/4] Remove LVIoCheckout project --- .../debug/LVIocheckout/CMakeLists.txt | 18 - .../projects/debug/LVIocheckout/README.md | 1 - .../projects/debug/LVIocheckout/inc/app.hpp | 25 -- .../debug/LVIocheckout/inc/bindings.hpp | 35 -- firmware/projects/debug/LVIocheckout/main.cc | 68 ---- .../LVIocheckout/platforms/cli/CMakeLists.txt | 8 - .../LVIocheckout/platforms/cli/bindings.cc | 46 --- .../platforms/cli/mcal_conf.cmake | 1 - .../platforms/stm32f767/CMakeLists.txt | 14 - .../platforms/stm32f767/bindings.cc | 112 ------ .../platforms/stm32f767/cubemx/.gitignore | 6 - .../platforms/stm32f767/cubemx/CMakeLists.txt | 1 - .../stm32f767/cubemx/board_config.ioc | 323 ------------------ .../platforms/stm32f767/mcal_conf.cmake | 1 - 14 files changed, 659 deletions(-) delete mode 100644 firmware/projects/debug/LVIocheckout/CMakeLists.txt delete mode 100644 firmware/projects/debug/LVIocheckout/README.md delete mode 100644 firmware/projects/debug/LVIocheckout/inc/app.hpp delete mode 100644 firmware/projects/debug/LVIocheckout/inc/bindings.hpp delete mode 100644 firmware/projects/debug/LVIocheckout/main.cc delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/cli/CMakeLists.txt delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/cli/bindings.cc delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/cli/mcal_conf.cmake delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/stm32f767/CMakeLists.txt delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/stm32f767/bindings.cc delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/.gitignore delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/CMakeLists.txt delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/board_config.ioc delete mode 100644 firmware/projects/debug/LVIocheckout/platforms/stm32f767/mcal_conf.cmake diff --git a/firmware/projects/debug/LVIocheckout/CMakeLists.txt b/firmware/projects/debug/LVIocheckout/CMakeLists.txt deleted file mode 100644 index 5b3d7b7b9..000000000 --- a/firmware/projects/debug/LVIocheckout/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Samuel Parent -# April 27, 2024 - -# The target executable 'main' is created in the master CMakeLists. Do not change its name. -# We only need to add the source code files and include directories. - -target_sources(main -PRIVATE - main.cc -) - -target_include_directories(main -PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/inc -) - -# Notice that we don't include any mcal/ subdirectory in this CMake file. -# The master CMakeLists handles platform selection and library linking. \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/README.md b/firmware/projects/debug/LVIocheckout/README.md deleted file mode 100644 index 0dfe9797c..000000000 --- a/firmware/projects/debug/LVIocheckout/README.md +++ /dev/null @@ -1 +0,0 @@ -# LV Controller diff --git a/firmware/projects/debug/LVIocheckout/inc/app.hpp b/firmware/projects/debug/LVIocheckout/inc/app.hpp deleted file mode 100644 index 3c650669c..000000000 --- a/firmware/projects/debug/LVIocheckout/inc/app.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "shared/periph/gpio.hpp" - -class Subsystem { -public: - /** - * @brief Construct a new Subsystem object - * - * @param enable_output Digital Output which enables the subsystem. - * enabled). - */ - Subsystem(shared::periph::DigitalOutput& enable_output) - : enable_output_(enable_output) {} - - inline virtual void Enable() const { - enable_output_.SetHigh(); - } - - inline virtual void Disable() const { - enable_output_.SetLow(); - } - - shared::periph::DigitalOutput& enable_output_; - -private: -}; \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/inc/bindings.hpp b/firmware/projects/debug/LVIocheckout/inc/bindings.hpp deleted file mode 100644 index 3290929bc..000000000 --- a/firmware/projects/debug/LVIocheckout/inc/bindings.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/// @author Blake Freer -/// @date 2024-04-24 - -#pragma once - -#include - -#include "shared/periph/gpio.hpp" -#include "shared/periph/pwm.hpp" - -namespace bindings { - -extern shared::periph::DigitalOutput&& tsal_en; -extern shared::periph::DigitalOutput&& raspberry_pi_en; -extern shared::periph::DigitalOutput&& front_controller_en; -extern shared::periph::DigitalOutput&& speedgoat_en; -extern shared::periph::DigitalOutput&& accumulator_en; -extern shared::periph::DigitalOutput&& motor_ctrl_precharge_en; -extern shared::periph::DigitalOutput&& motor_ctrl_en; -extern shared::periph::DigitalOutput&& imu_gps_en; -extern shared::periph::DigitalOutput&& shutdown_circuit_en; -extern shared::periph::DigitalOutput&& inverter_en; - -extern shared::periph::DigitalOutput&& dcdc_en; -extern shared::periph::DigitalInput&& dcdc_valid; -extern shared::periph::DigitalOutput&& dcdc_led_en; -extern shared::periph::DigitalOutput&& powertrain_pump_en; -extern shared::periph::DigitalOutput&& powertrain_fan_en; -extern shared::periph::PWMOutput&& powertrain_fan_pwm; - -extern void Initialize(); - -extern void DelayMS(uint32_t ms); - -} // namespace bindings \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/main.cc b/firmware/projects/debug/LVIocheckout/main.cc deleted file mode 100644 index 014c50efc..000000000 --- a/firmware/projects/debug/LVIocheckout/main.cc +++ /dev/null @@ -1,68 +0,0 @@ -/// @author Samuel Parent -/// @date 2024-04-27 - -#include -#include - -#include "app.hpp" -#include "bindings.hpp" -#include "shared/periph/gpio.hpp" -#include "shared/periph/pwm.hpp" -#include "shared/util/mappers/identity.hpp" -#include "shared/util/mappers/mapper.hpp" - -Subsystem front_controller{bindings::front_controller_en}; - -int main(void) { - bindings::Initialize(); - - while (true) { - // bool dcdc_valid = bindings::dcdc_valid.Read(); - // TODO: set a digital out to this value. - // bindings::accumulator_en.SetHigh(); - // bindings::dcdc_en.SetHigh(); - // bindings::tsal_en.SetHigh(); - // bindings::raspberry_pi_en.SetHigh(); - // bindings::front_controller_en.SetHigh(); - - for (int i = 0; i < 4; i++) { - front_controller.Enable(); - bindings::DelayMS(500); - front_controller.Disable(); - bindings::DelayMS(500); - } - - // bindings::DelayMS(1000); - - // for (int i = 0; i < 2; i++) { - // bindings::front_controller_en.SetHigh(); - // bindings::DelayMS(1000); - // bindings::front_controller_en.SetLow(); - // bindings::DelayMS(1000); - // } - // bindings::DelayMS(1000); - - // bindings::speedgoat_en.SetHigh(); - // bindings::motor_ctrl_precharge_en.SetHigh(); - // bindings::motor_ctrl_en.SetHigh(); - // bindings::imu_gps_en.SetHigh(); - // bindings::shutdown_circuit_en.SetHigh(); - // bindings::inverter_en.SetHigh(); - - // bindings::accumulator_en.SetLow(); - // bindings::dcdc_en.SetLow(); - // bindings::tsal_en.SetLow(); - // bindings::raspberry_pi_en.SetLow(); - - // bindings::speedgoat_en.SetLow(); - // bindings::motor_ctrl_precharge_en.SetLow(); - // bindings::motor_ctrl_en.SetLow(); - // bindings::imu_gps_en.SetLow(); - // bindings::shutdown_circuit_en.SetLow(); - // bindings::inverter_en.SetLow(); - - // bindings::DelayMS(1000); - } - - return 0; -} \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/cli/CMakeLists.txt b/firmware/projects/debug/LVIocheckout/platforms/cli/CMakeLists.txt deleted file mode 100644 index 54d4ec523..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/cli/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -target_sources(bindings -PRIVATE - bindings.cc -) - -target_include_directories(bindings PRIVATE ${DIR_PROJECT}/inc) - -target_link_libraries(bindings PUBLIC mcal-cli) \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/cli/bindings.cc b/firmware/projects/debug/LVIocheckout/platforms/cli/bindings.cc deleted file mode 100644 index 8cd492ee8..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/cli/bindings.cc +++ /dev/null @@ -1,46 +0,0 @@ -/// @author Blake Freer -/// @date 2023-12-25 -#include -#include -#include -#include -#include - -#include "bindings.hpp" -#include "mcal/cli/periph/gpio.hpp" -#include "mcal/cli/periph/pwm.hpp" -#include "shared/periph/gpio.hpp" -#include "shared/util/mappers/identity.hpp" - -namespace bindings { -using namespace mcal::cli::periph; - -// clang-format off -shared::periph::DigitalOutput&& tsal_en = DigitalOutput{"TSAL Enable"}; -shared::periph::DigitalOutput&& raspberry_pi_en = DigitalOutput{"RASPI Enable"}; -shared::periph::DigitalOutput&& front_controller_en = DigitalOutput{"FRONT CONTROLLER Enable"}; -shared::periph::DigitalOutput&& speedgoat_en = DigitalOutput{"SPEEDGOAT Enable"}; -shared::periph::DigitalOutput&& accumulator_en = DigitalOutput{"ACCUMULATOR Enable"}; -shared::periph::DigitalOutput&& motor_ctrl_precharge_en = DigitalOutput{"MOTOR CTRL LV PRECHARGE Enable"}; -shared::periph::DigitalOutput&& motor_ctrl_en = DigitalOutput{"MOTOR CTRL LV Enable"}; -shared::periph::DigitalOutput&& imu_gps_en = DigitalOutput{"IMU GPS Enable"}; -shared::periph::DigitalOutput&& shutdown_circuit_en = DigitalOutput{"SHUTDOWN CIRCUIT Enable"}; - -shared::periph::DigitalOutput&& dcdc_en = DigitalOutput{"DCDC Enable"}; -shared::periph::DigitalInput&& dcdc_valid = DigitalInput{"DCDC Valid"}; -shared::periph::DigitalOutput&& dcdc_led_en = DigitalOutput{"DCDC LED Enable"}; -shared::periph::DigitalOutput&& powertrain_fan_en = DigitalOutput{"POWERTRAIN FAN Enable"}; -shared::periph::DigitalOutput&& powertrain_pump_en = DigitalOutput{"POWERTRAIN PUMP Enable"}; -shared::periph::PWMOutput&& powertrain_fan_pwm = PWMOutput{"POWERTRAIN FAN PWM"}; -// clang-format on - -void Initialize() { - std::cout << "Initializing CLI..." << std::endl; -} - -void DelayMS(uint32_t milliseconds) { - std::cout << "[Delaying for " << milliseconds << " milliseconds]" - << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); -} -} // namespace bindings \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/cli/mcal_conf.cmake b/firmware/projects/debug/LVIocheckout/platforms/cli/mcal_conf.cmake deleted file mode 100644 index a30e90e12..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/cli/mcal_conf.cmake +++ /dev/null @@ -1 +0,0 @@ -set(MCAL cli) \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/CMakeLists.txt b/firmware/projects/debug/LVIocheckout/platforms/stm32f767/CMakeLists.txt deleted file mode 100644 index e8e940f3a..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Blake Freer -# January 8, 2024 - -target_sources(bindings - PUBLIC - bindings.cc -) - -target_include_directories(bindings PUBLIC ${DIR_PROJECT}/inc) # access to app.hpp - -add_subdirectory(cubemx) - -# must be public so that the 'main' executable can see its headers when including bindings.hpp -target_link_libraries(bindings PUBLIC driver mcal-stm32f767) diff --git a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/bindings.cc b/firmware/projects/debug/LVIocheckout/platforms/stm32f767/bindings.cc deleted file mode 100644 index 78f0bcf18..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/bindings.cc +++ /dev/null @@ -1,112 +0,0 @@ -/// @author Blake Freer -/// @date 2023-12-25 - -// cubemx files -// fw includes - -// CubeMX -#include "adc.h" -#include "gpio.h" -#include "main.h" -#include "stm32f767xx.h" -#include "stm32f7xx_hal.h" -#include "stm32f7xx_hal_tim.h" -#include "tim.h" - -// Firmware -#include "mcal/stm32f767/periph/gpio.hpp" -#include "mcal/stm32f767/periph/pwm.hpp" -#include "shared/periph/gpio.hpp" -#include "shared/periph/pwm.hpp" -#include "shared/util/mappers/identity.hpp" -#include "shared/util/mappers/mapper.hpp" - -extern "C" { -/** - * This requires extern since it is not declared in a header, only defined - * in cubemx/../main.c - */ -void SystemClock_Config(); -} - -namespace bindings { -using namespace mcal::stm32f767::periph; - -shared::periph::DigitalOutput&& tsal_en = DigitalOutput{ - TSAL_EN_GPIO_Port, - TSAL_EN_Pin, -}; -shared::periph::DigitalOutput&& raspberry_pi_en = DigitalOutput{ - RASPI_EN_GPIO_Port, - RASPI_EN_Pin, -}; - -DigitalOutput fc{ - RED_LED_GPIO_Port, RED_LED_Pin, - // FRONT_CONTROLLER_EN_GPIO_Port, - // FRONT_CONTROLLER_EN_Pin, -}; -shared::periph::DigitalOutput& front_controller_en = fc; -shared::periph::DigitalOutput&& speedgoat_en = DigitalOutput{ - SPEEDGOAT_EN_GPIO_Port, - SPEEDGOAT_EN_Pin, -}; -shared::periph::DigitalOutput&& accumulator_en = DigitalOutput{ - ACCUMULATOR_EN_GPIO_Port, - ACCUMULATOR_EN_Pin, -}; -shared::periph::DigitalOutput&& motor_ctrl_precharge_en = DigitalOutput{ - MOTOR_CONTROLLER_PRECHARGE_EN_GPIO_Port, - MOTOR_CONTROLLER_PRECHARGE_EN_Pin, -}; -shared::periph::DigitalOutput&& motor_ctrl_en = DigitalOutput{ - MOTOR_CONTROLLER_EN_GPIO_Port, - MOTOR_CONTROLLER_EN_Pin, -}; -shared::periph::DigitalOutput&& imu_gps_en = DigitalOutput{ - IMU_GPS_EN_GPIO_Port, - IMU_GPS_EN_Pin, -}; -shared::periph::DigitalOutput&& shutdown_circuit_en = DigitalOutput{ - SHUTDOWN_CIRCUIT_EN_GPIO_Port, - SHUTDOWN_CIRCUIT_EN_Pin, -}; -shared::periph::DigitalOutput&& inverter_en = DigitalOutput{ - INVERTER_EN_GPIO_Port, - INVERTER_EN_Pin, -}; -shared::periph::DigitalOutput&& dcdc_en = DigitalOutput{ - DCDC_EN_GPIO_Port, - DCDC_EN_Pin, -}; -shared::periph::DigitalInput&& dcdc_valid = DigitalInput{ - MUX_DCDC_VALID_GPIO_Port, - MUX_DCDC_VALID_Pin, -}; -shared::periph::DigitalOutput&& dcdc_led_en = DigitalOutput{ - DCDC_ON_LED_EN_GPIO_Port, - DCDC_ON_LED_EN_Pin, -}; -shared::periph::DigitalOutput&& powertrain_fan_en = DigitalOutput{ - POWERTRAIN_FAN_EN_GPIO_Port, - POWERTRAIN_FAN_EN_Pin, -}; -DigitalOutput powertrain_pump_en{ - POWERTRAIN_PUMP_EN_GPIO_Port, - POWERTRAIN_PUMP_EN_Pin, -}; -shared::periph::PWMOutput&& powertrain_fan_pwm = PWMOutput{ - &htim2, - HAL_TIM_ACTIVE_CHANNEL_1, -}; - -void Initialize() { - SystemClock_Config(); - HAL_Init(); - MX_GPIO_Init(); -} - -void DelayMS(uint32_t milliseconds) { - HAL_Delay(milliseconds); -} -} // namespace bindings \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/.gitignore b/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/.gitignore deleted file mode 100644 index b67b3e37b..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -* -!*.ioc -!.gitignore -!README -!CMakeLists.txt -!generate.mk \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/CMakeLists.txt b/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/CMakeLists.txt deleted file mode 100644 index 4786834bb..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include(${CMAKE_SOURCE_DIR}/cmake/build_cubemx.cmake) \ No newline at end of file diff --git a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/board_config.ioc b/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/board_config.ioc deleted file mode 100644 index dfd3e3a27..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/cubemx/board_config.ioc +++ /dev/null @@ -1,323 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_10 -ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag -ADC1.NbrOfConversionFlag=1 -ADC1.Rank-0\#ChannelRegularConversion=1 -ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES -ADC1.master=1 -CAD.formats= -CAD.pinconfig= -CAD.provider= -CAN1.CalculateBaudRate=333333 -CAN1.CalculateTimeBit=3000 -CAN1.CalculateTimeQuantum=1000.0 -CAN1.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate -File.Version=6 -GPIO.groupedBy=Group By Peripherals -KeepUserPlacement=false -Mcu.CPN=STM32F767ZIT6 -Mcu.Family=STM32F7 -Mcu.IP0=ADC1 -Mcu.IP1=CAN1 -Mcu.IP2=CORTEX_M7 -Mcu.IP3=NVIC -Mcu.IP4=RCC -Mcu.IP5=SYS -Mcu.IP6=TIM1 -Mcu.IP7=TIM2 -Mcu.IPNb=8 -Mcu.Name=STM32F767ZITx -Mcu.Package=LQFP144 -Mcu.Pin0=PE2 -Mcu.Pin1=PE3 -Mcu.Pin10=PF14 -Mcu.Pin11=PF15 -Mcu.Pin12=PG0 -Mcu.Pin13=PG1 -Mcu.Pin14=PB14 -Mcu.Pin15=PG2 -Mcu.Pin16=PG3 -Mcu.Pin17=PG4 -Mcu.Pin18=PG5 -Mcu.Pin19=PG6 -Mcu.Pin2=PC0 -Mcu.Pin20=PG7 -Mcu.Pin21=PG8 -Mcu.Pin22=PA8 -Mcu.Pin23=PA11 -Mcu.Pin24=PA12 -Mcu.Pin25=PA13 -Mcu.Pin26=PA14 -Mcu.Pin27=PA15 -Mcu.Pin28=PG9 -Mcu.Pin29=PG10 -Mcu.Pin3=PC1 -Mcu.Pin30=PG11 -Mcu.Pin31=PG12 -Mcu.Pin32=PB3 -Mcu.Pin33=PB4 -Mcu.Pin34=PE0 -Mcu.Pin35=PE1 -Mcu.Pin36=VP_SYS_VS_Systick -Mcu.Pin37=VP_TIM1_VS_ClockSourceINT -Mcu.Pin38=VP_TIM2_VS_ClockSourceINT -Mcu.Pin4=PC2 -Mcu.Pin5=PC3 -Mcu.Pin6=PA0/WKUP -Mcu.Pin7=PA4 -Mcu.Pin8=PC4 -Mcu.Pin9=PC5 -Mcu.PinsNb=39 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32F767ZITx -MxCube.Version=6.12.0 -MxDb.Version=DB.6.0.120 -NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.ForceEnableDMAVector=true -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA0/WKUP.GPIOParameters=GPIO_Label -PA0/WKUP.GPIO_Label=FAN_PWM -PA0/WKUP.Locked=true -PA0/WKUP.Signal=S_TIM2_CH1_ETR -PA11.Locked=true -PA11.Mode=CAN_Activate -PA11.Signal=CAN1_RX -PA12.Locked=true -PA12.Mode=CAN_Activate -PA12.Signal=CAN1_TX -PA13.GPIOParameters=GPIO_Label -PA13.GPIO_Label=JTAG_TMS -PA13.Mode=JTAG_5_pins -PA13.Signal=SYS_JTMS-SWDIO -PA14.GPIOParameters=GPIO_Label -PA14.GPIO_Label=JTAG_TCK -PA14.Mode=JTAG_5_pins -PA14.Signal=SYS_JTCK-SWCLK -PA15.GPIOParameters=GPIO_Label -PA15.GPIO_Label=JTAG_TDI_CAN2_TX -PA15.Locked=true -PA15.Mode=JTAG_5_pins -PA15.Signal=SYS_JTDI -PA4.GPIOParameters=GPIO_Label -PA4.GPIO_Label=RASPI_EN -PA4.Locked=true -PA4.Signal=GPIO_Output -PA8.GPIOParameters=GPIO_Label -PA8.GPIO_Label=CAN2_RX -PA8.Locked=true -PA8.Signal=CAN3_RX -PB14.GPIOParameters=GPIO_Label -PB14.GPIO_Label=RED_LED -PB14.Locked=true -PB14.Signal=GPIO_Output -PB3.GPIOParameters=GPIO_Label -PB3.GPIO_Label=JTAG_TDO -PB3.Locked=true -PB3.Mode=JTAG_5_pins -PB3.Signal=SYS_JTDO-SWO -PB4.GPIOParameters=GPIO_Label -PB4.GPIO_Label=JTAG_NRST -PB4.Locked=true -PB4.Mode=JTAG_5_pins -PB4.Signal=SYS_JTRST -PC0.GPIOParameters=GPIO_Label -PC0.GPIO_Label=LV_BATTERY_VOLTAGE -PC0.Locked=true -PC0.Signal=ADCx_IN10 -PC1.GPIOParameters=GPIO_Label -PC1.GPIO_Label=LV_BATTERY_ISENSE -PC1.Locked=true -PC1.Signal=ADCx_IN11 -PC2.GPIOParameters=GPIO_Label -PC2.GPIO_Label=DCDC_VSENSE -PC2.Locked=true -PC2.Signal=ADCx_IN12 -PC3.GPIOParameters=GPIO_Label -PC3.GPIO_Label=DCDC_ISENSE -PC3.Locked=true -PC3.Signal=ADCx_IN13 -PC4.GPIOParameters=GPIO_Label -PC4.GPIO_Label=STP4_SIG -PC4.Locked=true -PC4.Signal=ADCx_IN14 -PC5.GPIOParameters=GPIO_Label -PC5.GPIO_Label=STP3_SIG -PC5.Locked=true -PC5.Signal=ADCx_IN15 -PE0.GPIOParameters=GPIO_Label -PE0.GPIO_Label=MUX_DCDC_VALID -PE0.Locked=true -PE0.Signal=GPIO_Input -PE1.GPIOParameters=GPIO_Label -PE1.GPIO_Label=MUX_LVBATT_VALID -PE1.Locked=true -PE1.Signal=GPIO_Input -PE2.GPIOParameters=GPIO_Label -PE2.GPIO_Label=LV_BATTERY_FAULT_DIAG -PE2.Locked=true -PE2.Signal=GPIO_Input -PE3.GPIOParameters=GPIO_Label -PE3.GPIO_Label=DCDC_FAULT_DIAG -PE3.Locked=true -PE3.Signal=GPIO_Input -PF14.GPIOParameters=GPIO_Label -PF14.GPIO_Label=BRAKE_LIGHT_EN -PF14.Locked=true -PF14.Signal=GPIO_Output -PF15.GPIOParameters=GPIO_Label -PF15.GPIO_Label=STATUS_LED_EN -PF15.Locked=true -PF15.Signal=GPIO_Output -PG0.GPIOParameters=PinState,GPIO_Label -PG0.GPIO_Label=POWERTRAIN_FAN_EN -PG0.Locked=true -PG0.PinState=GPIO_PIN_RESET -PG0.Signal=GPIO_Output -PG1.GPIOParameters=GPIO_Label -PG1.GPIO_Label=IMU_GPS_EN -PG1.Locked=true -PG1.Signal=GPIO_Output -PG10.GPIOParameters=GPIO_Label -PG10.GPIO_Label=SPEEDGOAT_EN -PG10.Locked=true -PG10.Signal=GPIO_Output -PG11.GPIOParameters=GPIO_Label -PG11.GPIO_Label=POWERTRAIN_PUMP_EN -PG11.Locked=true -PG11.Signal=GPIO_Output -PG12.GPIOParameters=GPIO_Label -PG12.GPIO_Label=INVERTER_EN -PG12.Locked=true -PG12.Signal=GPIO_Output -PG2.GPIOParameters=PinState,GPIO_Label -PG2.GPIO_Label=FRONT_CONTROLLER_EN -PG2.Locked=true -PG2.PinState=GPIO_PIN_RESET -PG2.Signal=GPIO_Output -PG3.GPIOParameters=GPIO_Label -PG3.GPIO_Label=MOTOR_CONTROLLER_EN -PG3.Locked=true -PG3.Signal=GPIO_Output -PG4.GPIOParameters=GPIO_Label -PG4.GPIO_Label=DCDC_ON_LED_EN -PG4.Locked=true -PG4.Signal=GPIO_Output -PG5.GPIOParameters=GPIO_Label -PG5.GPIO_Label=TSAL_EN -PG5.Locked=true -PG5.Signal=GPIO_Output -PG6.GPIOParameters=PinState,GPIO_Label -PG6.GPIO_Label=SHUTDOWN_CIRCUIT_EN -PG6.Locked=true -PG6.PinState=GPIO_PIN_RESET -PG6.Signal=GPIO_Output -PG7.GPIOParameters=PinState,GPIO_Label -PG7.GPIO_Label=MOTOR_CONTROLLER_PRECHARGE_EN -PG7.Locked=true -PG7.PinState=GPIO_PIN_RESET -PG7.Signal=GPIO_Output -PG8.GPIOParameters=PinState,GPIO_Label -PG8.GPIO_Label=DCDC_EN -PG8.Locked=true -PG8.PinState=GPIO_PIN_SET -PG8.Signal=GPIO_Output -PG9.GPIOParameters=PinState,GPIO_Label -PG9.GPIO_Label=ACCUMULATOR_EN -PG9.Locked=true -PG9.PinState=GPIO_PIN_SET -PG9.Signal=GPIO_Output -PinOutPanel.RotationAngle=0 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32F767ZITx -ProjectManager.FirmwarePackage=STM32Cube FW_F7 V1.17.1 -ProjectManager.FreePins=false -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=false -ProjectManager.LastFirmware=false -ProjectManager.LibraryCopy=1 -ProjectManager.MainLocation=Src -ProjectManager.NoMain=true -ProjectManager.PreviousToolchain=STM32CubeIDE -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=board_config.ioc -ProjectManager.ProjectName=board_config -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=Makefile -ProjectManager.ToolChainLocation= -ProjectManager.UAScriptAfterPath= -ProjectManager.UAScriptBeforePath= -ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_CAN1_Init-CAN1-false-HAL-true,5-MX_TIM1_Init-TIM1-false-HAL-true,6-MX_TIM2_Init-TIM2-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true -RCC.CECFreq_Value=32786.88524590164 -RCC.DFSDMFreq_Value=16000000 -RCC.FamilyName=M -RCC.HSE_VALUE=25000000 -RCC.HSI_VALUE=16000000 -RCC.I2SFreq_Value=96000000 -RCC.IPParameters=CECFreq_Value,DFSDMFreq_Value,FamilyName,HSE_VALUE,HSI_VALUE,I2SFreq_Value,LCDTFTFreq_Value,LSE_VALUE,LSI_VALUE,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLQCLKFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIRCLKFreq_Value,PLLSAIoutputFreq_Value,RNGFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMC2Freq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,USBFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAIOutputFreq_Value -RCC.LCDTFTFreq_Value=48000000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.PLLCLKFreq_Value=96000000 -RCC.PLLI2SPCLKFreq_Value=96000000 -RCC.PLLI2SQCLKFreq_Value=96000000 -RCC.PLLI2SRCLKFreq_Value=96000000 -RCC.PLLQCLKFreq_Value=96000000 -RCC.PLLSAIPCLKFreq_Value=96000000 -RCC.PLLSAIQCLKFreq_Value=96000000 -RCC.PLLSAIRCLKFreq_Value=96000000 -RCC.PLLSAIoutputFreq_Value=96000000 -RCC.RNGFreq_Value=96000000 -RCC.SAI1Freq_Value=96000000 -RCC.SAI2Freq_Value=96000000 -RCC.SDMMC2Freq_Value=16000000 -RCC.SDMMCFreq_Value=16000000 -RCC.SPDIFRXFreq_Value=96000000 -RCC.USBFreq_Value=96000000 -RCC.VCOI2SOutputFreq_Value=192000000 -RCC.VCOInputFreq_Value=1000000 -RCC.VCOOutputFreq_Value=192000000 -RCC.VCOSAIOutputFreq_Value=192000000 -SH.ADCx_IN10.0=ADC1_IN10,IN10 -SH.ADCx_IN10.ConfNb=1 -SH.ADCx_IN11.0=ADC1_IN11,IN11 -SH.ADCx_IN11.ConfNb=1 -SH.ADCx_IN12.0=ADC1_IN12,IN12 -SH.ADCx_IN12.ConfNb=1 -SH.ADCx_IN13.0=ADC1_IN13,IN13 -SH.ADCx_IN13.ConfNb=1 -SH.ADCx_IN14.0=ADC1_IN14,IN14 -SH.ADCx_IN14.ConfNb=1 -SH.ADCx_IN15.0=ADC1_IN15,IN15 -SH.ADCx_IN15.ConfNb=1 -SH.S_TIM2_CH1_ETR.0=TIM2_CH1,PWM Generation1 CH1 -SH.S_TIM2_CH1_ETR.ConfNb=1 -TIM2.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 -TIM2.IPParameters=Channel-PWM Generation1 CH1 -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -VP_TIM1_VS_ClockSourceINT.Mode=Internal -VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT -VP_TIM2_VS_ClockSourceINT.Mode=Internal -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -board=custom diff --git a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/mcal_conf.cmake b/firmware/projects/debug/LVIocheckout/platforms/stm32f767/mcal_conf.cmake deleted file mode 100644 index 7c5404f10..000000000 --- a/firmware/projects/debug/LVIocheckout/platforms/stm32f767/mcal_conf.cmake +++ /dev/null @@ -1 +0,0 @@ -set(MCAL stm32f767) \ No newline at end of file From 60f513420edd322bd44e27e44ade032703a313a7 Mon Sep 17 00:00:00 2001 From: BlakeFreer Date: Fri, 29 Nov 2024 18:51:50 -0500 Subject: [PATCH 2/4] Minimal LV Update for new CAN --- firmware/projects/LVController/inc/app.hpp | 12 ++--- firmware/projects/LVController/main.cc | 47 +++++++++---------- .../platforms/stm32f767/bindings.cc | 7 --- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/firmware/projects/LVController/inc/app.hpp b/firmware/projects/LVController/inc/app.hpp index 10444fb42..3f014dcf2 100644 --- a/firmware/projects/LVController/inc/app.hpp +++ b/firmware/projects/LVController/inc/app.hpp @@ -3,8 +3,8 @@ #include -#include "../generated/can/veh_can_messages.hpp" -#include "shared/comms/can/can_bus.hpp" +#include "../generated/can/veh_bus.hpp" +#include "../generated/can/veh_messages.hpp" #include "shared/os/mutex.hpp" #include "shared/periph/gpio.hpp" #include "shared/periph/pwm.hpp" @@ -13,17 +13,17 @@ class StateBroadcaster { public: - StateBroadcaster(shared::can::CanBus& can_bus) : can_bus_(can_bus) {} + StateBroadcaster(generated::can::VehBus& can_bus) : can_bus_(can_bus) {} void UpdateState(generated::can::LvControllerState state) { - generated::can::LvControllerStatus lv_status; - lv_status.lv_controller_state = static_cast(state); + generated::can::TxLvControllerStatus lv_status{ + .lv_controller_state = static_cast(state)}; can_bus_.Send(lv_status); } private: - shared::can::CanBus can_bus_; + generated::can::VehBus& can_bus_; }; /** diff --git a/firmware/projects/LVController/main.cc b/firmware/projects/LVController/main.cc index 57cb8323c..c27acdaac 100644 --- a/firmware/projects/LVController/main.cc +++ b/firmware/projects/LVController/main.cc @@ -5,22 +5,17 @@ #include #include "bindings.hpp" -#include "generated/can/veh_msg_registry.hpp" +#include "generated/can/veh_bus.hpp" +#include "generated/can/veh_messages.hpp" #include "inc/app.hpp" -#include "shared/comms/can/can_bus.hpp" #include "shared/periph/gpio.hpp" #include "shared/periph/pwm.hpp" #include "shared/util/mappers/identity.hpp" #include "shared/util/mappers/mapper.hpp" -using LvControllerState = generated::can::LvControllerState; +using namespace generated::can; -generated::can::VehMsgRegistry veh_msg_registry{}; - -shared::can::CanBus veh_can = shared::can::CanBus{ - bindings::veh_can_base, - veh_msg_registry, -}; +VehBus veh_can{bindings::veh_can_base}; StateBroadcaster state_tx{veh_can}; @@ -146,31 +141,33 @@ void DoPowertrainDisableSequence() { } bool IsContactorsOpen() { - generated::can::ContactorStates contactor_states; - veh_can.ReadWithUpdate(contactor_states); + auto contactor_states = veh_can.GetRxContactorStates(); - return (contactor_states.tick_timestamp != 0 && - contactor_states.pack_positive == 0 && - contactor_states.pack_negative == 0 && - contactor_states.pack_precharge == 0); + if (contactor_states) { + return (contactor_states->PackPositive() == 0 && + contactor_states->PackNegative() == 0 && + contactor_states->PackPrecharge() == 0); + } else { + return false; // No data received yet + } } bool IsContactorsClosed() { - generated::can::ContactorStates contactor_states; - veh_can.ReadWithUpdate(contactor_states); + auto contactor_states = veh_can.GetRxContactorStates(); - return (contactor_states.tick_timestamp != 0 && - contactor_states.pack_positive == 1 && - contactor_states.pack_negative == 1 && - contactor_states.pack_precharge == 0); + if (contactor_states) { + return (contactor_states->PackPositive() == 1 && + contactor_states->PackNegative() == 1 && + contactor_states->PackPrecharge() == 0); + } else { + return false; // No data received yet + } } void DoInverterSwitchCheck() { - generated::can::InverterCommand inverter_command; - veh_can.ReadWithUpdate(inverter_command); + auto inverter_command = veh_can.GetRxInverterCommand(); - if (inverter_command.tick_timestamp != 0 && - inverter_command.enable_inverter == true) { + if (inverter_command && inverter_command->EnableInverter()) { inverter.Enable(); } else { inverter.Disable(); diff --git a/firmware/projects/LVController/platforms/stm32f767/bindings.cc b/firmware/projects/LVController/platforms/stm32f767/bindings.cc index 0fb16e0e4..2fb3cbe1c 100644 --- a/firmware/projects/LVController/platforms/stm32f767/bindings.cc +++ b/firmware/projects/LVController/platforms/stm32f767/bindings.cc @@ -145,11 +145,4 @@ void DelayMS(uint32_t milliseconds) { HAL_Delay(milliseconds); } -extern "C" { -void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan) { - if (hcan == &hcan3) { - mcal::veh_can_base.AddRxMessageToQueue(); - } -} -} } // namespace bindings \ No newline at end of file From 9f0b040a5c6699d4671e83d1b8606ff4f2dca818 Mon Sep 17 00:00:00 2001 From: BlakeFreer Date: Fri, 29 Nov 2024 19:28:05 -0500 Subject: [PATCH 3/4] Bump to C++23 to support std::optional.transform --- firmware/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index a0ec8eff1..82109f3b3 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -105,10 +105,11 @@ enable_language(C CXX ASM) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_CXX_STANDARD 20) # required for c++ concepts +set(CMAKE_CXX_STANDARD 23) # required for c++ concepts set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) set(CMAKE_CXX_EXTENSIONS ON) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") add_executable(main) From d94308b79d6cc78fc8cc857f4b7c6bda4524a1f2 Mon Sep 17 00:00:00 2001 From: BlakeFreer Date: Fri, 29 Nov 2024 19:30:34 -0500 Subject: [PATCH 4/4] refactor: Clean up LV Controller Remove some old abstractions like Indicator and StateBroadcaster to simplify the code. Move state broadcasts out of loops to prevent message floods. Update IsContactors functions to be more functional on the optional datatype to highlight how they may have empty data. --- firmware/projects/LVController/inc/app.hpp | 74 ++------- firmware/projects/LVController/main.cc | 157 ++++++++---------- .../platforms/stm32f767/bindings.cc | 3 - 3 files changed, 81 insertions(+), 153 deletions(-) diff --git a/firmware/projects/LVController/inc/app.hpp b/firmware/projects/LVController/inc/app.hpp index 3f014dcf2..fde52523c 100644 --- a/firmware/projects/LVController/inc/app.hpp +++ b/firmware/projects/LVController/inc/app.hpp @@ -3,40 +3,16 @@ #include -#include "../generated/can/veh_bus.hpp" -#include "../generated/can/veh_messages.hpp" -#include "shared/os/mutex.hpp" #include "shared/periph/gpio.hpp" #include "shared/periph/pwm.hpp" #include "shared/util/mappers/clamper.hpp" #include "shared/util/mappers/mapper.hpp" -class StateBroadcaster { -public: - StateBroadcaster(generated::can::VehBus& can_bus) : can_bus_(can_bus) {} - - void UpdateState(generated::can::LvControllerState state) { - generated::can::TxLvControllerStatus lv_status{ - .lv_controller_state = static_cast(state)}; - - can_bus_.Send(lv_status); - } - -private: - generated::can::VehBus& can_bus_; -}; - -/** - * @brief A Subsystem which can be enabled / disabled. - */ +/// @brief A Subsystem which can be enabled / disabled. class Subsystem { public: - /** - * @brief Construct a new Subsystem object - * - * @param enable_output Digital Output which enables the subsystem. - * enabled). - */ + // Use shared::periph::InverseDigitalOutput if the subsystem is enabled by + // a low signal. Subsystem(shared::periph::DigitalOutput& enable_output) : enable_output_(enable_output) {} @@ -52,26 +28,6 @@ class Subsystem { shared::periph::DigitalOutput& enable_output_; }; -class Indicator { -public: - Indicator(shared::periph::DigitalOutput& output) : output_(output) {} - - inline void TurnOn() { - output_.SetHigh(); - } - - inline void TurnOff() { - output_.SetLow(); - } - - inline void SetState(bool value) { - output_.Set(value); - } - -private: - shared::periph::DigitalOutput& output_; -}; - class Fan : public Subsystem { public: Fan(shared::periph::DigitalOutput& enable_output, @@ -96,24 +52,16 @@ class Fan : public Subsystem { duty_per_second_ = max_duty_per_second; } - /** - * @brief Set the Power Now. - * @warning THIS IS DANGEROUS as large jumps can caused significant current - * rushes. Prefer SetTargetPower() and Update() - * - * @param power - */ + /// @brief Set the Power Now. + /// @warning THIS IS DANGEROUS as large jumps can caused significant current + /// rushes. Prefer SetTargetPower() and Update() void Dangerous_SetPowerNow(float power) { SetPower(power); } - /** - * @brief Update the duty cycle towards the target duty cycle. The argument - * is the elapsed time between calls which is required to adjust the duty - * cycle by the rate specified in SetTargetPower. - * - * @param interval_sec - */ + /// @brief Update the duty cycle towards the target duty cycle. The argument + /// is the elapsed time between calls which is required to adjust the duty + /// cycle by the rate specified in SetTargetPower. void Update(float interval_sec) const { // max_duty_step must be greater than any platform's PWM duty cycle // resolution @@ -154,11 +102,11 @@ class DCDC : public Subsystem { bool CheckValid() { bool is_valid = valid_input_.Read(); - led_.SetState(is_valid); + led_.Set(is_valid); return is_valid; } private: shared::periph::DigitalInput& valid_input_; - Indicator led_; + shared::periph::DigitalOutput& led_; }; \ No newline at end of file diff --git a/firmware/projects/LVController/main.cc b/firmware/projects/LVController/main.cc index c27acdaac..89bd0440e 100644 --- a/firmware/projects/LVController/main.cc +++ b/firmware/projects/LVController/main.cc @@ -2,23 +2,18 @@ /// @date 2023-12-25 #include -#include #include "bindings.hpp" #include "generated/can/veh_bus.hpp" #include "generated/can/veh_messages.hpp" #include "inc/app.hpp" #include "shared/periph/gpio.hpp" -#include "shared/periph/pwm.hpp" #include "shared/util/mappers/identity.hpp" -#include "shared/util/mappers/mapper.hpp" using namespace generated::can; VehBus veh_can{bindings::veh_can_base}; -StateBroadcaster state_tx{veh_can}; - Subsystem tsal{bindings::tsal_en}; Subsystem raspberry_pi{bindings::raspberry_pi_en}; Subsystem front_controller{bindings::front_controller_en}; @@ -29,19 +24,11 @@ Subsystem motor_ctrl{bindings::motor_ctrl_en}; Subsystem imu_gps{bindings::imu_gps_en}; Subsystem shutdown_circuit{bindings::shutdown_circuit_en}; Subsystem inverter{bindings::inverter_switch_en}; +Subsystem powertrain_pump{bindings::powertrain_pump_en}; -auto dcdc_en_inverted = - shared::periph::InvertedDigitalOutput(bindings::dcdc_en); - -DCDC dcdc{ - dcdc_en_inverted, - bindings::dcdc_valid, - bindings::dcdc_led_en, -}; +shared::periph::InvertedDigitalOutput dcdc_en_inverted(bindings::dcdc_en); -Subsystem powertrain_pump{ - bindings::powertrain_pump_en, -}; +DCDC dcdc{dcdc_en_inverted, bindings::dcdc_valid, bindings::dcdc_led_en}; auto powertrain_fan_power_to_duty = shared::util::IdentityMap(); Fan powertrain_fan{ @@ -53,115 +40,112 @@ Fan powertrain_fan{ Subsystem all_subsystems[] = { tsal, raspberry_pi, front_controller, speedgoat, accumulator, motor_ctrl_precharge, motor_ctrl, imu_gps, - dcdc, powertrain_pump, powertrain_fan, -}; + dcdc, powertrain_pump, powertrain_fan, shutdown_circuit}; + +void BroadcastState(LvControllerState state) { + veh_can.Send(TxLvControllerStatus{static_cast(state)}); +} void DoPowerupSequence() { tsal.Enable(); - - state_tx.UpdateState(LvControllerState::TsalEnabled); + BroadcastState(LvControllerState::TsalEnabled); bindings::DelayMS(50); - // raspberry_pi.Enable(); - state_tx.UpdateState(LvControllerState::RaspiEnabled); + raspberry_pi.Enable(); + BroadcastState(LvControllerState::RaspiEnabled); bindings::DelayMS(50); front_controller.Enable(); - state_tx.UpdateState(LvControllerState::FrontControllerEnabled); + BroadcastState(LvControllerState::FrontControllerEnabled); bindings::DelayMS(100); - // speedgoat.Enable(); - state_tx.UpdateState(LvControllerState::SpeedgoatEnabled); + speedgoat.Enable(); + BroadcastState(LvControllerState::SpeedgoatEnabled); bindings::DelayMS(100); motor_ctrl_precharge.Enable(); - state_tx.UpdateState(LvControllerState::MotorControllerPrechargeEnabled); + BroadcastState(LvControllerState::MotorControllerPrechargeEnabled); bindings::DelayMS(2000); motor_ctrl.Enable(); - state_tx.UpdateState(LvControllerState::MotorControllerEnabled); + BroadcastState(LvControllerState::MotorControllerEnabled); bindings::DelayMS(50); motor_ctrl_precharge.Disable(); - state_tx.UpdateState(LvControllerState::MotorControllerPrechargeDisabled); + BroadcastState(LvControllerState::MotorControllerPrechargeDisabled); bindings::DelayMS(50); - // imu_gps.Enable(); - state_tx.UpdateState(LvControllerState::ImuGpsEnabled); + imu_gps.Enable(); + BroadcastState(LvControllerState::ImuGpsEnabled); } -void DoPowertrainEnableSequence() { +void SweepFanBlocking() { constexpr float kDutyInitial = 30.0f; constexpr float kDutyFinal = 100.0f; constexpr float kSweepPeriodSec = 3.0f; constexpr float kMaxDutyRate = (kDutyFinal - kDutyInitial) / kSweepPeriodSec; - constexpr float kUpdatePeriodSec = 0.01f; + constexpr uint32_t kUpdatePeriodMS = 10; + + powertrain_fan.Dangerous_SetPowerNow(kDutyInitial); + powertrain_fan.SetTargetPower(kDutyFinal, kMaxDutyRate); + while (!powertrain_fan.IsAtTarget()) { + bindings::DelayMS(kUpdatePeriodMS); + powertrain_fan.Update(kUpdatePeriodMS / 1000.0f); + } +} + +void DoPowertrainEnableSequence() { dcdc.Enable(); - state_tx.UpdateState(LvControllerState::DcdcEnabled); + BroadcastState(LvControllerState::DcdcEnabled); - do { - state_tx.UpdateState(LvControllerState::WaitingForDcdcValid); - bindings::DelayMS(50); - } while (!dcdc.CheckValid()); + BroadcastState(LvControllerState::WaitingForDcdcValid); + while (!dcdc.CheckValid()) bindings::DelayMS(50); bindings::DelayMS(50); powertrain_pump.Enable(); - state_tx.UpdateState(LvControllerState::DcdcLedEnabled); + BroadcastState(LvControllerState::DcdcLedEnabled); bindings::DelayMS(100); powertrain_fan.Enable(); - state_tx.UpdateState(LvControllerState::PowertrainFanEnabled); + BroadcastState(LvControllerState::PowertrainFanEnabled); bindings::DelayMS(50); - powertrain_fan.Dangerous_SetPowerNow(kDutyInitial); - powertrain_fan.SetTargetPower(kDutyFinal, kMaxDutyRate); - - do { - state_tx.UpdateState(LvControllerState::PowertrainFanSweeping); - bindings::DelayMS(uint32_t(kUpdatePeriodSec * 1000)); - powertrain_fan.Update(kUpdatePeriodSec); - } while (!powertrain_fan.IsAtTarget()); -} - -void DoPowertrainDisableSequence() { - powertrain_pump.Disable(); - powertrain_fan.Disable(); + BroadcastState(LvControllerState::PowertrainFanSweeping); + SweepFanBlocking(); // is it possible that this never returns? } bool IsContactorsOpen() { - auto contactor_states = veh_can.GetRxContactorStates(); - - if (contactor_states) { - return (contactor_states->PackPositive() == 0 && - contactor_states->PackNegative() == 0 && - contactor_states->PackPrecharge() == 0); - } else { - return false; // No data received yet - } + auto logic = [](auto contactor_states) { + return (contactor_states.PackPositive() == 0 && + contactor_states.PackNegative() == 0 && + contactor_states.PackPrecharge() == 0); + }; + + // If the contactor states are not available, return false. + return veh_can.GetRxContactorStates().transform(logic).value_or(false); } bool IsContactorsClosed() { - auto contactor_states = veh_can.GetRxContactorStates(); - - if (contactor_states) { - return (contactor_states->PackPositive() == 1 && - contactor_states->PackNegative() == 1 && - contactor_states->PackPrecharge() == 0); - } else { - return false; // No data received yet - } + auto logic = [](auto contactor_states) { + return (contactor_states.PackPositive() == 1 && + contactor_states.PackNegative() == 1 && + contactor_states.PackPrecharge() == 0); + }; + + // If the contactor states are not available, return false. + return veh_can.GetRxContactorStates().transform(logic).value_or(false); } void DoInverterSwitchCheck() { @@ -177,44 +161,43 @@ void DoInverterSwitchCheck() { int main(void) { bindings::Initialize(); - state_tx.UpdateState(LvControllerState::Startup); + BroadcastState(LvControllerState::Startup); // Ensure all subsystems are disabled to start. - for (auto sys : all_subsystems) { + for (auto& sys : all_subsystems) { sys.Disable(); } - // Powerup sequence DoPowerupSequence(); - while (true) continue; // stop after fc enable debug - - do { - state_tx.UpdateState(LvControllerState::WaitingForOpenContactors); + BroadcastState(LvControllerState::WaitingForOpenContactors); + while (!IsContactorsOpen()) { bindings::DelayMS(50); - } while (!IsContactorsOpen()); + } shutdown_circuit.Enable(); - state_tx.UpdateState(LvControllerState::ShutdownCircuitEnabled); + BroadcastState(LvControllerState::ShutdownCircuitEnabled); while (true) { - do { - state_tx.UpdateState(LvControllerState::WaitingForClosedContactors); + BroadcastState(LvControllerState::WaitingForClosedContactors); + while (!IsContactorsClosed()) { bindings::DelayMS(50); - } while (!IsContactorsClosed()); + } DoPowertrainEnableSequence(); + BroadcastState(LvControllerState::SequenceComplete); - do { - state_tx.UpdateState(LvControllerState::SequenceComplete); + while (dcdc.CheckValid()) { DoInverterSwitchCheck(); - } while (dcdc.CheckValid()); + bindings::DelayMS(50); + } - state_tx.UpdateState(LvControllerState::LostDcdcValid); + BroadcastState(LvControllerState::LostDcdcValid); inverter.Disable(); - DoPowertrainDisableSequence(); + powertrain_pump.Disable(); + powertrain_fan.Disable(); } return 0; diff --git a/firmware/projects/LVController/platforms/stm32f767/bindings.cc b/firmware/projects/LVController/platforms/stm32f767/bindings.cc index 2fb3cbe1c..7c47f4b39 100644 --- a/firmware/projects/LVController/platforms/stm32f767/bindings.cc +++ b/firmware/projects/LVController/platforms/stm32f767/bindings.cc @@ -11,7 +11,6 @@ #include "main.h" #include "mcal/stm32f767/periph/can.hpp" #include "shared/periph/can.hpp" -#include "stm32f767xx.h" #include "stm32f7xx_hal.h" #include "stm32f7xx_hal_tim.h" #include "tim.h" @@ -22,8 +21,6 @@ #include "mcal/stm32f767/periph/pwm.hpp" #include "shared/periph/gpio.hpp" #include "shared/periph/pwm.hpp" -#include "shared/util/mappers/identity.hpp" -#include "shared/util/mappers/mapper.hpp" extern "C" { /**