From d43bc81c240400b0b6ce19ba202396e690f190f9 Mon Sep 17 00:00:00 2001 From: NOx-z <50815960+NOx-z@users.noreply.github.com> Date: Sun, 17 May 2020 13:28:05 -0700 Subject: [PATCH] Mc33 vccp uv (#1445) * mc33 flash check * DI sanity checks for setting HV config * mc33 VccP (7v) under voltage detection - before and after DRIVEN, useful for regulator broken - or DC-DC logic converter broken Co-authored-by: Christopher W. Anderson --- firmware/hw_layer/mc33816.cpp | 35 +++++++++++++++++++++++++++++--- firmware/hw_layer/mc33816.h | 1 + firmware/hw_layer/mc33816_data.c | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/firmware/hw_layer/mc33816.cpp b/firmware/hw_layer/mc33816.cpp index 133724ab9e..8dcadcf301 100644 --- a/firmware/hw_layer/mc33816.cpp +++ b/firmware/hw_layer/mc33816.cpp @@ -25,6 +25,7 @@ EXTERN_CONFIG; + static OutputPin chipSelect; static OutputPin resetB; static OutputPin driven; @@ -212,6 +213,10 @@ static unsigned short readDriverStatus(){ return driverStatus; } +static bool checkUndervoltVccP(unsigned short driverStatus){ + return (driverStatus & (1<<0)); +} + static bool checkUndervoltV5(unsigned short driverStatus){ return (driverStatus & (1<<1)); } @@ -458,16 +463,18 @@ static void mcRestart() { setup_spi(); - mcClearDriverStatus(); + mcClearDriverStatus(); // Initial clear necessary mcDriverStatus = readDriverStatus(); if(checkUndervoltV5(mcDriverStatus)){ firmwareError(OBD_PCM_Processor_Fault, "MC33 5V Under-Voltage!"); + mcShutdown(); return; } mcChipId = readId(); if (!validateChipId()) { firmwareError(OBD_PCM_Processor_Fault, "No comm with MC33"); + mcShutdown(); return; } @@ -482,7 +489,7 @@ static void mcRestart() { flag0after = efiReadPin(CONFIG(mc33816_flag0)); if (flag0before || !flag0after) { firmwareError(OBD_PCM_Processor_Fault, "MC33 flag0 transition no buena"); - + mcShutdown(); return; } } @@ -491,22 +498,44 @@ static void mcRestart() { download_register(REG_CH2); // download channel 2 register configurations download_register(REG_IO); // download IO register configurations download_register(REG_DIAG); // download diag register configuration + // Finished downloading, let's run the code enable_flash(); if(!check_flash()) { firmwareError(OBD_PCM_Processor_Fault, "MC33 no flash"); + mcShutdown(); return; } + + mcDriverStatus = readDriverStatus(); + if(checkUndervoltVccP(mcDriverStatus)){ + firmwareError(OBD_PCM_Processor_Fault, "MC33 VccP (7V) Under-Voltage!"); + mcShutdown(); + return; + } + + // Drive High Voltage if possible setBoostVoltage(CONFIG(mc33_hvolt)); driven.setValue(1); // driven = HV - + chThdSleepMilliseconds(10); // Give it a moment mcDriverStatus = readDriverStatus(); if(!checkDrivenEnabled(mcDriverStatus)){ firmwareError(OBD_PCM_Processor_Fault, "MC33 Driven did not stick!"); + mcShutdown(); return; } + mcDriverStatus = readDriverStatus(); + if(checkUndervoltVccP(mcDriverStatus)){ + firmwareError(OBD_PCM_Processor_Fault, "MC33 VccP Under-Voltage After Driven"); // Likely DC-DC LS7 is dead! + mcShutdown(); + return; + } } +static void mcShutdown() { + driven.setValue(0); // ensure HV is off + resetB.setValue(0); // turn off the chip +} #endif /* EFI_MC33816 */ diff --git a/firmware/hw_layer/mc33816.h b/firmware/hw_layer/mc33816.h index 00295b0f5e..27b250260c 100644 --- a/firmware/hw_layer/mc33816.h +++ b/firmware/hw_layer/mc33816.h @@ -25,4 +25,5 @@ enum { }; void initMc33816(Logging *logger); +static void mcShutdown(); diff --git a/firmware/hw_layer/mc33816_data.c b/firmware/hw_layer/mc33816_data.c index 54faeb7b9a..25ac79d152 100644 --- a/firmware/hw_layer/mc33816_data.c +++ b/firmware/hw_layer/mc33816_data.c @@ -51,7 +51,7 @@ const unsigned short MC33816_data_RAM[128] = const unsigned short MC33816_main_config[29] = { 0x0003, 0x1FFE, 0x0000, 0x1200, 0x0000, 0x0000, 0x0001, 0x0000, 0x001F, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };