Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/CI-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ jobs:

- name: Build unit tests on host
run: |
make -C test
make Test

- name: Run unit tests on host
- name: Run stm32-sine unit tests on host
run: |
test/test_sine

- name: Run libopeninv unit tests on host
run: |
libopeninv/test/test_libopeninv
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ OBJSL = stm32_sine.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj
my_string.o digio.o sine_core.o my_fp.o fu.o inc_encoder.o printf.o anain.o \
temp_meas.o param_save.o throttle.o errormessage.o pwmgeneration.o \
picontroller.o terminalcommands.o vehiclecontrol.o \
stm32_can.o canmap.o canhardware.o cansdo.o
stm32_can.o canmap.o canhardware.o cansdo.o GD31xxOI.o

ifeq ($(CONTROL), SINE)
OBJSL += pwmgeneration-sine.o
Expand Down
46 changes: 46 additions & 0 deletions include/GD31xxOI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of the stm32-sine project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
* Copyright (C) 2019 Nail Guzel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Simplified library for interfacing with the NXP GD3100 gate drivers
* found on the MG inverter platform.
*/

#include "stddef.h"
#include "stdbool.h"
#include <stdint.h>
#include "delay.h"

#define REQ_ADC_EXT 0x4001
#define REQ_STAT1 0x2800
#define REQ_STAT2 0x3000
#define REQ_STAT3 0x3800

/// SPI channels
enum SpiChannelMG
{
MGSPI1_H = 1,
MGSPI2_H = 2,
MGSPI3_H = 3,
MGSPI1_L = 4,
MGSPI2_L = 5,
MGSPI3_L = 6,
};

extern uint32_t Send16 (enum SpiChannelMG channel,uint16_t txData16);
extern uint32_t Config_MG (enum SpiChannelMG channel);
38 changes: 24 additions & 14 deletions include/digio_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
#include "hwdefs.h"

#define DIG_IO_LIST \
DIG_IO_ENTRY(cruise_in, GPIOB, GPIO5, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(start_in, GPIOB, GPIO6, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(brake_in, GPIOA, GPIO2, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(mprot_in, GPIOA, GPIO3, PinMode::INPUT_PU) \
DIG_IO_ENTRY(cruise_in, GPIOB, GPIO2, PinMode::INPUT_PD) \
DIG_IO_ENTRY(start_in, GPIOD, GPIO7, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(brake_in, GPIOE, GPIO4, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(mprot_in, GPIOE, GPIO5, PinMode::INPUT_PU) \
DIG_IO_ENTRY(fwd_in, GPIOA, GPIO4, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(rev_in, GPIOC, GPIO6, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(rev_in, GPIOA, GPIO3, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(emcystop_in, GPIOC, GPIO7, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(bk_in, GPIOB, GPIO12, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(bms_in, GPIOC, GPIO8, PinMode::INPUT_PD) \
DIG_IO_ENTRY(ocur_in, GPIOA, GPIO1, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(ocur_in, GPIOE, GPIO2, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(desat_in, GPIOC, GPIO9, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(dcsw_out, GPIOC, GPIO13, PinMode::OUTPUT) \
DIG_IO_ENTRY(fan_out, GPIOA, GPIO0, PinMode::OUTPUT) /* map to unused pin by default */ \
DIG_IO_ENTRY(vtg_out, GPIOC, GPIO11, PinMode::OUTPUT) \
DIG_IO_ENTRY(prec_out, GPIOB, GPIO1, PinMode::OUTPUT) \
DIG_IO_ENTRY(dcsw_out, GPIOC, GPIO10, PinMode::OUTPUT) \
DIG_IO_ENTRY(fan_out, GPIOC, GPIO15, PinMode::OUTPUT) /* map to unused pin by default */ \
DIG_IO_ENTRY(vtg_out, GPIOC, GPIO14, PinMode::OUTPUT) \
DIG_IO_ENTRY(prec_out, GPIOD, GPIO15, PinMode::OUTPUT) \
DIG_IO_ENTRY(led_out, GPIOC, GPIO12, PinMode::OUTPUT) \
DIG_IO_ENTRY(err_out, GPIOC, GPIO10, PinMode::OUTPUT) \
DIG_IO_ENTRY(temp0_out, GPIOC, GPIO10, PinMode::OUTPUT) \
DIG_IO_ENTRY(speed_out, GPIOB, GPIO9, PinMode::OUTPUT) \
DIG_IO_ENTRY(brk_out, GPIOC, GPIO5, PinMode::OUTPUT) \
DIG_IO_ENTRY(err_out, GPIOD, GPIO14, PinMode::OUTPUT) \
DIG_IO_ENTRY(temp0_out, GPIOD, GPIO13, PinMode::OUTPUT) \
DIG_IO_ENTRY(speed_out, GPIOD, GPIO12, PinMode::OUTPUT) \
DIG_IO_ENTRY(brk_out, GPIOD, GPIO11, PinMode::OUTPUT) \
DIG_IO_ENTRY(cs1_hi, GPIOE, GPIO10, PinMode::OUTPUT) \
DIG_IO_ENTRY(cs2_hi, GPIOE, GPIO11, PinMode::OUTPUT) \
DIG_IO_ENTRY(cs3_hi, GPIOE, GPIO12, PinMode::OUTPUT) \
DIG_IO_ENTRY(cs1_lo, GPIOE, GPIO13, PinMode::OUTPUT) \
DIG_IO_ENTRY(cs2_lo, GPIOE, GPIO14, PinMode::OUTPUT) \
DIG_IO_ENTRY(cs3_lo, GPIOE, GPIO15, PinMode::OUTPUT) \
DIG_IO_ENTRY(v5_ctrl, GPIOD, GPIO6, PinMode::OUTPUT) \
DIG_IO_ENTRY(intb_in, GPIOE, GPIO8, PinMode::INPUT_FLT) \
DIG_IO_ENTRY(inta_in, GPIOE, GPIO9, PinMode::INPUT_FLT) \


#define DIG_IO_BLUEPILL \
DIG_IO_ENTRY(brake_in, GPIOB, GPIO9, PinMode::INPUT_FLT) \
Expand Down
1 change: 1 addition & 0 deletions include/hwinit.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void usart_setup(void);
void nvic_setup(void);
void rtc_setup(void);
void tim_setup(void);
void tim5_setup(void);
void spi_setup(void);
HWREV detect_hw(void);
void write_bootloader_pininit(bool bootprec, bool pwmActiveLow);
Expand Down
42 changes: 41 additions & 1 deletion include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
3. Display values
*/
//Next param id (increase when adding new parameter!): 159
//Next value Id: 2055
//Next value Id: 2066
/* category name unit min max default id */

#define MOTOR_PARAMETERS_COMMON \
Expand Down Expand Up @@ -166,6 +166,7 @@
VALUE_ENTRY(opmode, OPMODES, 2000 ) \
VALUE_ENTRY(lasterr, errorListString, 2038 ) \
VALUE_ENTRY(status, STATUS, 2044 ) \
VALUE_ENTRY(status_GD3100, STATUS3100, 2063 ) \
VALUE_ENTRY(udc, "V", 2001 ) \
VALUE_ENTRY(idc, "A", 2002 ) \
VALUE_ENTRY(il1, "A", 2003 ) \
Expand Down Expand Up @@ -201,6 +202,12 @@
VALUE_ENTRY(din_bms, ONOFF, 2032 ) \
VALUE_ENTRY(uptime, "10ms", 2054 ) \
VALUE_ENTRY(cpuload, "%", 2035 ) \
VALUE_ENTRY(MG_Rx0, "dig", 2056 ) \
VALUE_ENTRY(MG_Rx1, "dig", 2057 ) \
VALUE_ENTRY(MG_Rx2, "dig", 2058 ) \
VALUE_ENTRY(MG_Rx3, "dig", 2059 ) \
VALUE_ENTRY(INT_L, ONOFF, 2064 ) \
VALUE_ENTRY(INT_H, ONOFF, 2065 ) \

#define VALUES_SINE \
VALUE_ENTRY(ilmax, "A", 2005 ) \
Expand Down Expand Up @@ -281,6 +288,7 @@
#define SWAPS "0=None, 1=Currents12, 2=SinCos, 4=PWMOutput13, 8=PWMOutput23"
#define OUTMODES "0=DcSw, 1=TmpmThresh, 2=TmphsThresh"
#define STATUS "0=None, 1=UdcLow, 2=UdcHigh, 4=UdcBelowUdcSw, 8=UdcLim, 16=EmcyStop, 32=MProt, 64=PotPressed, 128=TmpHs, 256=WaitStart, 512=BrakeCheck"
#define STATUS3100 "0=None, 1=IGBTOC, 2=IGBTSC, 3=DESAT, 4=CLAMP, 5=TempWarn, 6=Temp_Shdn, 7=DIEOT, 8=VSUPOV, 9=VCCREGUV, 10=VCCREGOV, 11=VEEOR, 12=VREFOR, 13=DIECOMM, 14=WDOG, 15=VGE, 16=CRCERR,17=SPIERR,18=PWMDT,19=VDDOR,20=BISTFail,21=VGEPIN,22=INTPIN,23=FSENBPIN,24=FSSTATPIN,25=PWMALTPIN,26=PWMPIN,27=FSISOPIN"
#define CHECKS "0=CounterOnly, 1=StmCrc8"
#define CAT_MOTOR "Motor"
#define CAT_INVERTER "Inverter"
Expand Down Expand Up @@ -417,6 +425,38 @@ enum status
STAT_BRAKECHECK = 512
};

enum status_GD3100
{
None = 0,
IGBT_OVER_CURRENT = 1,
IGBT_SHORT_CIRCUIT = 2,
VCE_DESAT_EVENT = 3,
VCE_CLAMP_EVENT = 4,
IGBT_OVERTEMP_WARN = 5,
IGBT_OVERTEMP_SHUTDN = 6,
DIE_OVERTEMP_SHUTDN = 7,
VSUP_OVER_VOLTAGE = 8,
VCCREG_UNDER_VOLTAGE = 9,
VCC_OVER_VOLTAGE = 10,
VEE_OUT_OF_RANGE = 11,
VREF_OUT_OF_RANGE = 12,
DIE_COMM_ERROR = 13,
WDOG_FAULT = 14,
VGE_FAULT = 15,
CONFIG_CRC_ERROR = 16,
SPI_ERROR = 17,
PWM_DEADTIME_FAULT = 18,
VDD_OUT_OF_RANGE = 19,
BIST_FAILURE = 20,
VGE_PIN_STATE = 21,
INTB_PIN_STATE = 22,
FSENB_PIN_STATE = 23,
FSSTATE_PIN_STATE = 24,
PWMALT_PIN_STATE = 25,
PWM_PIN_STATE = 26,
FSISO_PIN_STATE=27
};

//Generated enum-string for possible errors
extern const char* errorListString;

55 changes: 55 additions & 0 deletions sinus.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
<Add directory="include" />
</Compiler>
</Target>
<Target title="Test libopeninv">
<Option output="libopeninv/test/test_libopeninv" prefix_auto="1" extension_auto="1" />
<Option working_dir="libopeninv/test" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add directory="include" />
</Compiler>
</Target>
</Build>
<Unit filename="Makefile">
<Option target="SlipControl" />
Expand All @@ -77,6 +86,7 @@
<Unit filename="libopeninv/include/anain.h" />
<Unit filename="libopeninv/include/canhardware.h" />
<Unit filename="libopeninv/include/canmap.h" />
<Unit filename="libopeninv/include/canobd2.h" />
<Unit filename="libopeninv/include/cansdo.h" />
<Unit filename="libopeninv/include/crc8.h" />
<Unit filename="libopeninv/include/delay.h" />
Expand All @@ -101,6 +111,7 @@
<Unit filename="libopeninv/src/anain.cpp" />
<Unit filename="libopeninv/src/canhardware.cpp" />
<Unit filename="libopeninv/src/canmap.cpp" />
<Unit filename="libopeninv/src/canobd2.cpp" />
<Unit filename="libopeninv/src/cansdo.cpp" />
<Unit filename="libopeninv/src/crc8.cpp" />
<Unit filename="libopeninv/src/digio.cpp" />
Expand All @@ -125,6 +136,40 @@
<Unit filename="libopeninv/src/stm32scheduler.cpp" />
<Unit filename="libopeninv/src/terminal.cpp" />
<Unit filename="libopeninv/src/terminalcommands.cpp" />
<Unit filename="libopeninv/test/Makefile">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/stub_canhardware.cpp">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/stub_canhardware.h">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/stub_libopencm3.c">
<Option compilerVar="CC" />
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test-include/hwdefs.h">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test-include/param_prj.h">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test.h">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test_canmap.cpp">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test_fp.cpp">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test_fu.cpp">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="libopeninv/test/test_main.cpp">
<Option target="Test libopeninv" />
</Unit>
<Unit filename="src/hwinit.cpp" />
<Unit filename="src/inc_encoder.cpp" />
<Unit filename="src/pwmgeneration-foc.cpp" />
Expand All @@ -142,6 +187,16 @@
<Unit filename="test/Makefile">
<Option target="Test" />
</Unit>
<Unit filename="test/stub_canhardware.cpp">
<Option target="Test" />
</Unit>
<Unit filename="test/stub_canhardware.h">
<Option target="Test" />
</Unit>
<Unit filename="test/stub_libopencm3.c">
<Option compilerVar="CC" />
<Option target="Test" />
</Unit>
<Unit filename="test/test.h">
<Option target="Test" />
</Unit>
Expand Down
Loading