From 9fdf74bc188df82863b8846418a534e9e2239e49 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 2 Dec 2019 20:54:40 -0800 Subject: [PATCH] Base configuration for Proteus (#1040) * cfg * add enum value * add ci * actually build the board config * this is pretty close * proteus case --- .github/workflows/build-firmware.yaml | 6 +- firmware/config/boards/proteus/board.mk | 11 ++ .../boards/proteus/board_configuration.cpp | 166 ++++++++++++++++++ firmware/config/boards/proteus/mapping.yaml | 73 ++++++++ .../controllers/algo/auto_generated_enums.cpp | 2 + .../controllers/algo/engine_configuration.cpp | 1 + firmware/controllers/algo/rusefi_enums.h | 2 + 7 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 firmware/config/boards/proteus/board.mk create mode 100644 firmware/config/boards/proteus/board_configuration.cpp create mode 100644 firmware/config/boards/proteus/mapping.yaml diff --git a/.github/workflows/build-firmware.yaml b/.github/workflows/build-firmware.yaml index 65d110c3c2..5f41b8fb10 100644 --- a/.github/workflows/build-firmware.yaml +++ b/.github/workflows/build-firmware.yaml @@ -12,7 +12,7 @@ jobs: matrix: # What boards should we build for? In the 'include' section below, # set up what each of these boards needs to build. - build-target: [frankenso, mre-f4, mre-f7, prometheus-405, prometheus-469] + build-target: [frankenso, mre-f4, mre-f7, prometheus-405, prometheus-469, proteus] build-type: [debug, release] include: @@ -37,6 +37,10 @@ jobs: efi-cpu: ARCH_STM32F4 efi-board: prometheus/f469 + - build-target: proteus + efi-cpu: ARCH_STM32F7 + efi-board: proteus + # Debug vs. release configuration - build-type: debug extra-params: -DDUMMY diff --git a/firmware/config/boards/proteus/board.mk b/firmware/config/boards/proteus/board.mk new file mode 100644 index 0000000000..eb50754451 --- /dev/null +++ b/firmware/config/boards/proteus/board.mk @@ -0,0 +1,11 @@ +# List of all the board related files. +BOARDSRC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO144_F767ZI/board.c +BOARDSRC_CPP = $(PROJECT_DIR)/config/boards/proteus/board_configuration.cpp + +# Required include directories +BOARDINC = $(PROJECT_DIR)/config/boards/nucleo_f767 $(PROJECT_DIR)/config/stm32f7ems + +LDSCRIPT= $(PROJECT_DIR)/config/boards/nucleo_f767/STM32F76xxI.ld + +# Override DEFAULT_ENGINE_TYPE +DDEFS += -DSTM32F767xx -DEFI_USE_OSC=TRUE -DEFI_FATAL_ERROR_PIN=GPIOE_3 -DFIRMWARE_ID=\"proteus\" -DDEFAULT_ENGINE_TYPE=PROTEUS diff --git a/firmware/config/boards/proteus/board_configuration.cpp b/firmware/config/boards/proteus/board_configuration.cpp new file mode 100644 index 0000000000..0554f34496 --- /dev/null +++ b/firmware/config/boards/proteus/board_configuration.cpp @@ -0,0 +1,166 @@ +/** + * @file boards/proteus/board_configuration.cpp + * + * @brief Configuration defaults for the Proteus board + * + * @author Matthew Kennedy, (c) 2019 + */ + +#include "global.h" +#include "engine.h" +#include "engine_math.h" +#include "allsensors.h" +#include "fsio_impl.h" +#include "engine_configuration.h" + +EXTERN_ENGINE; + +static void setInjectorPins() { + boardConfiguration->injectionPins[0] = GPIOD_7; + boardConfiguration->injectionPins[1] = GPIOG_9; + boardConfiguration->injectionPins[2] = GPIOG_10; + boardConfiguration->injectionPins[3] = GPIOG_11; + boardConfiguration->injectionPins[4] = GPIOG_12; + boardConfiguration->injectionPins[5] = GPIOG_13; + boardConfiguration->injectionPins[6] = GPIOG_14; + boardConfiguration->injectionPins[7] = GPIOB_4; + boardConfiguration->injectionPins[8] = GPIOB_5; + boardConfiguration->injectionPins[9] = GPIOB_6; + boardConfiguration->injectionPins[10] = GPIOB_7; + boardConfiguration->injectionPins[11] = GPIOB_8; + + boardConfiguration->injectionPinMode = OM_DEFAULT; +} + +static void setIgnitionPins() { + boardConfiguration->ignitionPins[0] = GPIOD_4; + boardConfiguration->ignitionPins[1] = GPIOD_3; + boardConfiguration->ignitionPins[2] = GPIOC_9; + boardConfiguration->ignitionPins[3] = GPIOC_8; + boardConfiguration->ignitionPins[4] = GPIOC_7; + boardConfiguration->ignitionPins[5] = GPIOG_8; + boardConfiguration->ignitionPins[6] = GPIOG_7; + boardConfiguration->ignitionPins[7] = GPIOG_6; + boardConfiguration->ignitionPins[8] = GPIOG_5; + boardConfiguration->ignitionPins[9] = GPIOG_4; + boardConfiguration->ignitionPins[10] = GPIOG_3; + boardConfiguration->ignitionPins[11] = GPIOG_2; + + boardConfiguration->ignitionPinMode = OM_DEFAULT; +} + +static void setLedPins() { + engineConfiguration->communicationLedPin = GPIOE_4; + engineConfiguration->runningLedPin = GPIOE_5; + boardConfiguration->triggerErrorPin = GPIOE_6; +} + +static void setupVbatt() { + // 6.8k high side/10k low side = 1.6667 ratio divider + engineConfiguration->analogInputDividerCoefficient = 2.5f / 1.5f; + + // 47k high side/10k low side = 4.7 + engineConfiguration->vbattDividerCoeff = (57.0f / 10.0f); + //engineConfiguration->vbattAdcChannel = TODO; + + engineConfiguration->adcVcc = 3.3f; +} + +static void setupEtb() { + // TLE9201 driver + // This chip has three control pins: + // DIR - sets direction of the motor + // PWM - pwm control (enable high, coast low) + // DIS - disables motor (enable low) + + // Throttle #1 + // PWM pin + engineConfiguration->etbIo[0].controlPin1 = GPIOD_12; + // DIR pin + engineConfiguration->etbIo[0].directionPin1 = GPIOD_10; + // Unused + engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED; + + // Throttle #2 + // PWM pin + engineConfiguration->etbIo[0].controlPin1 = GPIOD_13; + // DIR pin + engineConfiguration->etbIo[0].directionPin1 = GPIOD_9; + // Unused + engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED; + +#if EFI_FSIO + // disable ETB by default + setFsio(7, GPIOD_8, "1" PASS_CONFIG_PARAMETER_SUFFIX); + setFsio(8, GPIOD_11, "1" PASS_CONFIG_PARAMETER_SUFFIX); +#endif /* EFI_FSIO */ + + // we only have pwm/dir, no dira/dirb + engineConfiguration->etb_use_two_wires = false; + engineConfiguration->etbFreq = 800; +} + +static void setupDefaultSensorInputs() { + // trigger inputs + // VR channel 1 as default - others not set + boardConfiguration->triggerInputPins[0] = GPIOC_6; + boardConfiguration->triggerInputPins[1] = GPIO_UNASSIGNED; + boardConfiguration->triggerInputPins[2] = GPIO_UNASSIGNED; + engineConfiguration->camInputs[0] = GPIO_UNASSIGNED; + + // clt = Analog Temp 1 = PC4 + engineConfiguration->clt.adcChannel = EFI_ADC_14; + engineConfiguration->clt.config.bias_resistor = 2700; + + // iat = Analog Temp 2 = PC5 + engineConfiguration->iat.adcChannel = EFI_ADC_15; + engineConfiguration->iat.config.bias_resistor = 2700; + + // TODO: more sensors +} + +void setPinConfigurationOverrides(void) { +} + +void setSerialConfigurationOverrides(void) { + boardConfiguration->useSerialPort = false; + engineConfiguration->binarySerialTxPin = GPIO_UNASSIGNED; + engineConfiguration->binarySerialRxPin = GPIO_UNASSIGNED; + engineConfiguration->consoleSerialTxPin = GPIO_UNASSIGNED; + engineConfiguration->consoleSerialRxPin = GPIO_UNASSIGNED; +} + + +/** + * @brief Board-specific configuration code overrides. + * + * See also setDefaultEngineConfiguration + * + * @todo Add your board-specific code, if any. + */ +void setBoardConfigurationOverrides(void) { + setInjectorPins(); + setIgnitionPins(); + setLedPins(); + setupVbatt(); + setupEtb(); + + // "required" hardware is done - set some reasonable defaults + setupDefaultSensorInputs(); + + // Some sensible defaults for other options + setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); + engineConfiguration->trigger.type = TT_TOOTHED_WHEEL_60_2; + engineConfiguration->useOnlyRisingEdgeForTrigger = true; + setAlgorithm(LM_SPEED_DENSITY PASS_CONFIG_PARAMETER_SUFFIX); + + engineConfiguration->specs.cylindersCount = 8; + engineConfiguration->specs.firingOrder = FO_1_8_7_2_6_5_4_3; + + engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS; + engineConfiguration->crankingInjectionMode = IM_SIMULTANEOUS; + engineConfiguration->injectionMode = IM_SIMULTANEOUS; +} + +void setAdcChannelOverrides(void) { +} diff --git a/firmware/config/boards/proteus/mapping.yaml b/firmware/config/boards/proteus/mapping.yaml new file mode 100644 index 0000000000..2f3b8711ec --- /dev/null +++ b/firmware/config/boards/proteus/mapping.yaml @@ -0,0 +1,73 @@ +outputs: + GPIOD_7: "Lowside 1" + GPIOG_9: "Lowside 2" + GPIOG_10: "Lowside 3" + GPIOG_11: "Lowside 4" + GPIOG_12: "Lowside 5" + GPIOG_13: "Lowside 6" + GPIOG_14: "Lowside 7" + GPIOB_4: "Lowside 8" + GPIOB_5: "Lowside 9" + GPIOB_6: "Lowside 10" + GPIOB_7: "Lowside 11" + GPIOB_8: "Lowside 12" + GPIOB_9: "Lowside 13" + GPIOE_0: "Lowside 14" + GPIOE_1: "Lowside 15" + GPIOE_2: "Lowside 16" + + GPIOD_4: "Ign 1" + GPIOD_3: "Ign 2" + GPIOC_9: "Ign 3" + GPIOC_8: "Ign 4" + GPIOC_7: "Ign 5" + GPIOG_8: "Ign 6" + GPIOG_7: "Ign 7" + GPIOG_6: "Ign 8" + GPIOG_5: "Ign 9" + GPIOG_4: "Ign 10" + GPIOG_3: "Ign 11" + GPIOG_2: "Ign 12" + + GPIOA_9: "Highside 1" + GPIOA_8: "Highside 2" + GPIOD_15: "Highside 3" + GPIOD_14: "Highside 4" + +event_inputs: + GPIOC_6: "Digital 1" + GPIOE_11: "Digital 2" + GPIOE_12: "Digital 3" + GPIOE_13: "Digital 4" + GPIOE_14: "Digital 5" + GPIOE_15: "Digital 6" + GPIOE_7: "Digital 7" + GPIOE_8: "Digital 8" + +switch_inputs: + GPIOC_6: "Digital 1" + GPIOE_11: "Digital 2" + GPIOE_12: "Digital 3" + GPIOE_13: "Digital 4" + GPIOE_14: "Digital 5" + GPIOE_15: "Digital 6" + GPIOE_7: "Digital 7" + GPIOE_8: "Digital 8" + +analog_inputs: + EFI_ADC_0: "Analog Volt 5" + EFI_ADC_1: "Analog Volt 6" + EFI_ADC_2: "Analog Volt 7" + EFI_ADC_3: "Analog Volt 8" + EFI_ADC_4: "Analog Volt 9" + EFI_ADC_5: "Analog Volt 10" + EFI_ADC_6: "Analog Volt 11" + EFI_ADC_7: "Analog Volt 12" + EFI_ADC_8: "Analog Temp 3" + EFI_ADC_9: "Analog Temp 4" + EFI_ADC_10: "Analog Volt 1" + EFI_ADC_11: "Analog Volt 2" + EFI_ADC_12: "Analog Volt 3" + EFI_ADC_13: "Analog Volt 4" + EFI_ADC_14: "Analog Temp 1" + EFI_ADC_15: "Analog Temp 2" diff --git a/firmware/controllers/algo/auto_generated_enums.cpp b/firmware/controllers/algo/auto_generated_enums.cpp index 52c3f9820a..9612068455 100644 --- a/firmware/controllers/algo/auto_generated_enums.cpp +++ b/firmware/controllers/algo/auto_generated_enums.cpp @@ -775,6 +775,8 @@ case SACHS: return "SACHS"; case MRE_MIATA_NA6: return "MRE_MIATA_NA6"; +case PROTEUS: + return "PROTEUS"; case SUBARUEJ20G_DEFAULTS: return "SUBARUEJ20G_DEFAULTS"; case SUBARU_2003_WRX: diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 34525adeee..a579a0b690 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -1131,6 +1131,7 @@ void resetConfigurationExt(Logging * logger, configuration_callback_t boardCallb setEtbTestConfiguration(PASS_CONFIG_PARAMETER_SIGNATURE); break; case MICRO_RUS_EFI: + case PROTEUS: // nothing to do - we do it all in setBoardConfigurationOverrides break; case TLE8888_BENCH_ENGINE: diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 6663b9b009..47e8995567 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -187,6 +187,8 @@ typedef enum { MICRO_RUS_EFI = 60, + PROTEUS = 61, + /** * this configuration has as few pins configured as possible */