From b1cd0b69220c0d22e139a92f8a1dd3bf59736374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Wed, 21 Oct 2026 08:58:35 +0200 Subject: [PATCH] app: dcdc: fix fuse destruction in case of shorted HS MOSFET The fuse destruction set a duty cycle of 0 and started the half bridge. For the STM32 TIM drivers, this did not switch on the low-side MOSFET, as starting is refused with a compare value of 0. Use the new function half_bridge_force_low_side() instead. In addition, the control loop running at 10 Hz could override the forced state, because it saw an enabled half bridge and continued with MPPT control. Now the control function returns early as soon as the HS MOSFET short error is set. The low-side switch is forced on again with each call in case the half bridge was stopped in the meantime, e.g. by an ADC alert. The data is only stored once to avoid unnecessary flash writes if the fuse does not blow. Co-Authored-By: Claude Opus 5.5 --- app/src/dcdc.cpp | 21 ++++++++++++++------- tests/src/tests_dcdc.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/app/src/dcdc.cpp b/app/src/dcdc.cpp index 3a78542..43bc34d 100644 --- a/app/src/dcdc.cpp +++ b/app/src/dcdc.cpp @@ -232,6 +232,12 @@ bool Dcdc::startup_inhibit(bool reset) __weak void Dcdc::control() { + if (dev_stat.has_error(ERR_DCDC_HS_MOSFET_SHORT)) { + // DC/DC must not be operated anymore and the low-side switch might be forced on to blow + // the fuse, so don't touch the half bridge + return; + } + if (half_bridge_is_enabled(half_bridge) == false) { if (check_hs_mosfet_short()) { @@ -375,13 +381,14 @@ void Dcdc::fuse_destruction() static int counter = 0; if (counter > 20) { // wait 20s to be able to send out data - LOG_ERR("Charge controller fuse destruction called!\n"); - thingset_storage_save(); - half_bridge_stop(half_bridge); - // reset safety limits to allow 0% duty cycle - half_bridge_set_duty_limits(half_bridge, 0, 0.98); - half_bridge_set_duty_cycle(half_bridge, 0); - half_bridge_start(half_bridge); + if (counter == 21) { + LOG_ERR("Charge controller fuse destruction called!\n"); +#ifdef CONFIG_THINGSET_STORAGE + thingset_storage_save(); +#endif + } + // repeated in case the half bridge was stopped in the meantime + half_bridge_force_low_side(half_bridge); // now the fuse should be triggered and we disappear } counter++; diff --git a/tests/src/tests_dcdc.cpp b/tests/src/tests_dcdc.cpp index 38f3a34..6bb96ce 100644 --- a/tests/src/tests_dcdc.cpp +++ b/tests/src/tests_dcdc.cpp @@ -415,6 +415,36 @@ void boost_correct_mppt_operation() TEST_ASSERT(pwm3 > pwm2); } +void fuse_destruction_forces_low_side_on() +{ + start_buck(); + dev_stat.set_error(ERR_DCDC_HS_MOSFET_SHORT); + + // fuse destruction is delayed by 21 calls (seconds) to be able to send out data + for (int i = 0; i < 21; i++) { + dcdc.fuse_destruction(); + } + TEST_ASSERT_NOT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + dcdc.fuse_destruction(); + TEST_ASSERT_TRUE(half_bridge_is_enabled(dcdc.half_bridge)); + TEST_ASSERT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + // control loop must not override the forced low side + dcdc.control(); + TEST_ASSERT_TRUE(half_bridge_is_enabled(dcdc.half_bridge)); + TEST_ASSERT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + // forced state is restored after the half bridge was stopped + dcdc.stop(); + dcdc.fuse_destruction(); + TEST_ASSERT_TRUE(half_bridge_is_enabled(dcdc.half_bridge)); + TEST_ASSERT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + dcdc.stop(); + dev_stat.clear_error(ERR_DCDC_HS_MOSFET_SHORT); +} + int dcdc_tests() { UNITY_BEGIN(); @@ -474,5 +504,7 @@ int dcdc_tests() RUN_TEST(boost_stop_high_voltage_emergency); RUN_TEST(boost_correct_mppt_operation); + RUN_TEST(fuse_destruction_forces_low_side_on); + return UNITY_END(); }