Skip to content

Commit 2a96f91

Browse files
authored
Basic gate driver support for Telsa Model 3 inverter (#49)
Pull in the tested tesla::GateDriver from commit bc109b82 of the c2000-inverter project for the Tesla Model 3 inverter native. This targets the STGAP1AS but this appears to be identical to the STGAP1BS from a programming perspective. A simple TeslaModel3 class is created to initialise and poll the operation of the gate driver. The Tesla Model 3 inverter board is identified automatically via the expected resistor divider network. The GPIO allocation for the gate driver is a placeholder only and will need further elaboration. Tests: - Core gate driver has been tested with HV on an original Tesla Model 3 inverter with TI C2000 MCU and open-loop PWM generation. No faults experienced in normal operation. Faults trip with incorrect PWM generation (dead-time, deliberate IO glitches, etc). - STM32 code compile tested only.
1 parent 9a2ce33 commit 2a96f91

File tree

12 files changed

+1110
-3
lines changed

12 files changed

+1110
-3
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CFLAGS = -Os -ggdb3 -Wall -Wextra -Iinclude/ -Ilibopeninv/include -Ilibopencm3/
3535
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
3636
-mcpu=cortex-m3 -mthumb -std=gnu99 -ffunction-sections -fdata-sections
3737
CPPFLAGS = -Os -ggdb3 -Wall -Wextra -Iinclude/ -Ilibopeninv/include -Ilibopencm3/include \
38-
-fno-common -std=c++11 -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
38+
-fno-common -std=c++14 -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
3939
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
4040
-ffunction-sections -fdata-sections -fno-builtin -fno-rtti -fno-exceptions -fno-unwind-tables -mcpu=cortex-m3 -mthumb
4141

@@ -51,7 +51,7 @@ OBJSL = stm32_sine.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj
5151
my_string.o digio.o sine_core.o my_fp.o fu.o inc_encoder.o printf.o anain.o \
5252
temp_meas.o param_save.o throttle.o errormessage.o pwmgeneration.o \
5353
picontroller.o terminalcommands.o vehiclecontrol.o \
54-
stm32_can.o canmap.o canhardware.o cansdo.o GD31xxOI.o
54+
stm32_can.o canmap.o canhardware.o cansdo.o GD31xxOI.o crc8.o teslamodel3.o
5555

5656
ifeq ($(CONTROL), SINE)
5757
OBJSL += pwmgeneration-sine.o

include/digio_prj.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
DIG_IO_ENTRY(v5_ctrl,,,) \
3636
DIG_IO_ENTRY(intb_in,,,) \
3737
DIG_IO_ENTRY(inta_in,,,) \
38+
DIG_IO_ENTRY(gate_cs_hi,,,) \
39+
DIG_IO_ENTRY(gate_sd_hi,,,) \
3840

3941
//...Then we assign the physical GPIOs per variant
4042

@@ -91,6 +93,29 @@
9193
DIG_IO_ENTRY(intb_in, GPIOE, GPIO8, PinMode::INPUT_FLT) \
9294
DIG_IO_ENTRY(inta_in, GPIOE, GPIO9, PinMode::INPUT_FLT) \
9395

96+
#define DIG_IO_LIST_TESLAM3 \
97+
DIG_IO_ENTRY(cruise_in, GPIOB, GPIO2, PinMode::INPUT_PD) \
98+
DIG_IO_ENTRY(start_in, GPIOD, GPIO7, PinMode::INPUT_FLT) \
99+
DIG_IO_ENTRY(brake_in, GPIOE, GPIO4, PinMode::INPUT_FLT) \
100+
DIG_IO_ENTRY(mprot_in, GPIOE, GPIO5, PinMode::INPUT_PU) \
101+
DIG_IO_ENTRY(fwd_in, GPIOA, GPIO4, PinMode::INPUT_FLT) \
102+
DIG_IO_ENTRY(rev_in, GPIOA, GPIO3, PinMode::INPUT_FLT) \
103+
DIG_IO_ENTRY(emcystop_in, GPIOC, GPIO7, PinMode::INPUT_FLT) \
104+
DIG_IO_ENTRY(bk_in, GPIOB, GPIO12, PinMode::INPUT_FLT) \
105+
DIG_IO_ENTRY(bms_in, GPIOC, GPIO8, PinMode::INPUT_PD) \
106+
DIG_IO_ENTRY(ocur_in, GPIOE, GPIO2, PinMode::INPUT_FLT) \
107+
DIG_IO_ENTRY(desat_in, GPIOC, GPIO9, PinMode::INPUT_FLT) \
108+
DIG_IO_ENTRY(dcsw_out, GPIOC, GPIO10, PinMode::OUTPUT) \
109+
DIG_IO_ENTRY(fan_out, GPIOC, GPIO15, PinMode::OUTPUT) /* map to unused pin by default */ \
110+
DIG_IO_ENTRY(vtg_out, GPIOC, GPIO14, PinMode::OUTPUT) \
111+
DIG_IO_ENTRY(prec_out, GPIOD, GPIO15, PinMode::OUTPUT) \
112+
DIG_IO_ENTRY(led_out, GPIOC, GPIO12, PinMode::OUTPUT) \
113+
DIG_IO_ENTRY(err_out, GPIOD, GPIO14, PinMode::OUTPUT) \
114+
DIG_IO_ENTRY(temp0_out, GPIOD, GPIO13, PinMode::OUTPUT) \
115+
DIG_IO_ENTRY(speed_out, GPIOD, GPIO12, PinMode::OUTPUT) \
116+
DIG_IO_ENTRY(brk_out, GPIOD, GPIO11, PinMode::OUTPUT) \
117+
DIG_IO_ENTRY(gate_cs_hi, GPIOE, GPIO10, PinMode::OUTPUT) \
118+
DIG_IO_ENTRY(gate_sd_hi, GPIOE, GPIO11, PinMode::OUTPUT) \
94119

95120
#define DIG_IO_BLUEPILL \
96121
DIG_IO_ENTRY(brake_in, GPIOB, GPIO9, PinMode::INPUT_FLT) \

include/errormessage_prj.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424
ERROR_MESSAGE_ENTRY(TMPMMAX, ERROR_DERATE) \
2525
ERROR_MESSAGE_ENTRY(CANCRC, ERROR_STOP) \
2626
ERROR_MESSAGE_ENTRY(CANCOUNTER, ERROR_STOP) \
27+
ERROR_MESSAGE_ENTRY(GATEDRIVEINITFAIL, ERROR_STOP) \
28+
ERROR_MESSAGE_ENTRY(GATEDRIVEFAULT, ERROR_STOP) \
2729

2830
#endif // ERRORMESSAGE_PRJ_H_INCLUDED

0 commit comments

Comments
 (0)