Skip to content

Commit 486a7b8

Browse files
committed
Merge branch 'master' into jordan_keller
# Conflicts: # include/param_prj.h # src/stm32_sine.cpp
2 parents a961ffc + 21f784f commit 486a7b8

29 files changed

+907
-354
lines changed

.github/workflows/CI-build.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
name: build-linux
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
submodules: recursive
16+
17+
- name: Install build package dependencies
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install gcc-arm-none-eabi
21+
22+
- name: Build dependencies
23+
run: |
24+
echo "Number of processors:" `nproc`
25+
make get-deps -j `nproc`
26+
27+
- name: Build SINE firmware
28+
run: |
29+
make CONTROL=SINE clean all
30+
31+
- uses: actions/upload-artifact@v4
32+
with:
33+
name: SINE firmware binary
34+
path: stm32_sine.bin
35+
36+
- uses: actions/upload-artifact@v4
37+
with:
38+
name: SINE firmware hex
39+
path: stm32_sine.hex
40+
41+
- name: Build FOC firmware
42+
run: |
43+
make CONTROL=FOC clean all
44+
45+
- uses: actions/upload-artifact@v4
46+
with:
47+
name: FOC firmware binary
48+
path: stm32_foc.bin
49+
50+
- uses: actions/upload-artifact@v4
51+
with:
52+
name: FOC firmware hex
53+
path: stm32_foc.hex
54+
55+
# Unit tests are currently broken so don't build and run them for now
56+
#- name: Build unit tests on host
57+
# run: |
58+
# make -C test
59+
#
60+
# - name: Run unit tests on host
61+
# run: |
62+
# test/test_sine
63+

Makefile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,27 @@ OBJDUMP = $(PREFIX)-objdump
3131
MKDIR_P = mkdir -p
3232
TERMINAL_DEBUG ?= 0
3333
CFLAGS = -Os -ggdb3 -Wall -Wextra -Iinclude/ -Ilibopeninv/include -Ilibopencm3/include \
34-
-fno-common -fno-builtin -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
35-
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
36-
-mcpu=cortex-m3 -mthumb -std=gnu99 -ffunction-sections -fdata-sections
34+
-fno-common -fno-builtin -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
35+
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
36+
-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) \
39-
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
40-
-ffunction-sections -fdata-sections -fno-builtin -fno-rtti -fno-exceptions -fno-unwind-tables -mcpu=cortex-m3 -mthumb
38+
-fno-common -std=c++11 -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
39+
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
40+
-ffunction-sections -fdata-sections -fno-builtin -fno-rtti -fno-exceptions -fno-unwind-tables -mcpu=cortex-m3 -mthumb
41+
42+
# Check if the variable GITHUB_RUN_NUMBER exists. When running on the github actions running, this
43+
# variable is automatically available.
44+
# Create a compiler define with the content of the variable. Or, if it does not exist, use replacement value 99999.
45+
EXTRACOMPILERFLAGS = $(shell \
46+
if [ -z "$$GITHUB_RUN_NUMBER" ]; then echo "-DGITHUB_RUN_NUMBER=0"; else echo "-DGITHUB_RUN_NUMBER=$$GITHUB_RUN_NUMBER"; fi )
47+
4148
LDSCRIPT = stm32_sine.ld
4249
LDFLAGS = -Llibopencm3/lib -ggdb3 -T$(LDSCRIPT) -march=armv7 -nostartfiles -Wl,--gc-sections,-Map,linker.map
4350
OBJSL = stm32_sine.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj.o \
4451
my_string.o digio.o sine_core.o my_fp.o fu.o inc_encoder.o printf.o anain.o \
4552
temp_meas.o param_save.o throttle.o errormessage.o pwmgeneration.o \
4653
picontroller.o terminalcommands.o vehiclecontrol.o \
47-
stm32_can.o canmap.o canhardware.o
54+
stm32_can.o canmap.o canhardware.o cansdo.o
4855

4956
ifeq ($(CONTROL), SINE)
5057
OBJSL += pwmgeneration-sine.o
@@ -54,6 +61,7 @@ ifeq ($(CONTROL), FOC)
5461
endif
5562

5663
OBJS = $(patsubst %.o,obj/%.o, $(OBJSL))
64+
DEPENDS = $(patsubst %.o,obj/%.d, $(OBJSL))
5765
vpath %.c src/ libopeninv/src
5866
vpath %.cpp src/ libopeninv/src
5967

@@ -107,13 +115,15 @@ $(BINARY): $(OBJS) $(LDSCRIPT)
107115
@printf " LD $(subst $(shell pwd)/,,$(@))\n"
108116
$(Q)$(LD) $(LDFLAGS) -o $(BINARY) $(OBJS) -lopencm3_stm32f1
109117

118+
-include $(DEPENDS)
119+
110120
$(OUT_DIR)/%.o: %.c Makefile
111121
@printf " CC $(subst $(shell pwd)/,,$(@))\n"
112-
$(Q)$(CC) $(CFLAGS) -o $@ -c $<
122+
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
113123

114124
$(OUT_DIR)/%.o: %.cpp Makefile
115125
@printf " CPP $(subst $(shell pwd)/,,$(@))\n"
116-
$(Q)$(CPP) $(CPPFLAGS) -o $@ -c $<
126+
$(Q)$(CPP) $(CPPFLAGS) $(EXTRACOMPILERFLAGS) -MMD -MP -o $@ -c $<
117127

118128
clean:
119129
@printf " CLEAN ${OUT_DIR}\n"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.com/jsphuebner/stm32-sine.svg?branch=master)](https://travis-ci.com/jsphuebner/stm32-sine)
1+
[![Build status](../../actions/workflows/CI-build.yml/badge.svg)](../../actions/workflows/CI-build.yml)
22

33
# stm32-sine
44
Main firmware of the Huebner inverter project

include/anain_prj.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include "hwdefs.h"
55

6+
#define ADC_COUNT 2
7+
68
#if CONTROL == CTRL_SINE
7-
#define NUM_SAMPLES 12
9+
#define NUM_SAMPLES 3
810
#define SAMPLE_TIME ADC_SMPR_SMP_7DOT5CYC
911
#elif CONTROL == CTRL_FOC
1012
#define NUM_SAMPLES 3
11-
#define SAMPLE_TIME ADC_SMPR_SMP_7DOT5CYC
13+
#define SAMPLE_TIME ADC_SMPR_SMP_1DOT5CYC
1214
#endif // CONTROL
1315

1416
#define ANA_IN_LIST \
@@ -19,7 +21,7 @@
1921
ANA_IN_ENTRY(tmphs, GPIOC, 4) \
2022
ANA_IN_ENTRY(uaux, GPIOA, 3) \
2123
ANA_IN_ENTRY(il1, GPIOA, 5) \
22-
ANA_IN_ENTRY(il2, GPIOB, 0)
24+
ANA_IN_ENTRY(il2, GPIOB, 0) \
2325

2426
//Alternative list. Must contain exactly the same names and number of
2527
//entries as ANA_IN_LIST but may contain different IO pins

include/errormessage_prj.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ERROR_MESSAGE_ENTRY(OVERCURRENT, ERROR_STOP) \
88
ERROR_MESSAGE_ENTRY(THROTTLE1, ERROR_DISPLAY) \
99
ERROR_MESSAGE_ENTRY(THROTTLE2, ERROR_DISPLAY) \
10-
ERROR_MESSAGE_ENTRY(CANTIMEOUT, ERROR_DISPLAY) \
10+
ERROR_MESSAGE_ENTRY(CANTIMEOUT, ERROR_STOP) \
1111
ERROR_MESSAGE_ENTRY(EMCYSTOP, ERROR_STOP) \
1212
ERROR_MESSAGE_ENTRY(MPROT, ERROR_STOP) \
1313
ERROR_MESSAGE_ENTRY(DESAT, ERROR_STOP) \
@@ -22,5 +22,7 @@
2222
ERROR_MESSAGE_ENTRY(HIRESOFS, ERROR_DISPLAY) \
2323
ERROR_MESSAGE_ENTRY(LORESAMP, ERROR_DISPLAY) \
2424
ERROR_MESSAGE_ENTRY(TMPMMAX, ERROR_DERATE) \
25+
ERROR_MESSAGE_ENTRY(CANCRC, ERROR_STOP) \
26+
ERROR_MESSAGE_ENTRY(CANCOUNTER, ERROR_STOP) \
2527

2628
#endif // ERRORMESSAGE_PRJ_H_INCLUDED

include/hwdefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
typedef enum
4747
{
48-
HW_REV1, HW_REV2, HW_REV3, HW_TESLA, HW_BLUEPILL, HW_PRIUS
48+
HW_REV1, HW_REV2, HW_REV3, HW_TESLA, HW_BLUEPILL, HW_PRIUS, HW_MINI, HW_LEAF2, HW_LEAF3, HW_BMWI3
4949
} HWREV;
5050

5151
extern HWREV hwRev;

include/param_prj.h

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
#define VER 5.30.B
20+
#define VERSION 5.36.B
2121

2222
/* Entries should be ordered as follows:
2323
1. Saveable parameters
2424
2. Temporary parameters
2525
3. Display values
2626
*/
27-
//Next param id (increase when adding new parameter!): 155
28-
//Next value Id: 2052
27+
//Next param id (increase when adding new parameter!): 159
28+
//Next value Id: 2055
2929
/* category name unit min max default id */
3030

3131
#define MOTOR_PARAMETERS_COMMON \
@@ -72,10 +72,10 @@
7272
PARAM_ENTRY(CAT_INVERTER,udcgain, "dig/V", 0, 4095, 6.175, 29 ) \
7373
PARAM_ENTRY(CAT_INVERTER,udcofs, "dig", 0, 4095, 0, 77 ) \
7474
PARAM_ENTRY(CAT_INVERTER,udclim, "V", 0, 1000, 540, 48 ) \
75-
PARAM_ENTRY(CAT_INVERTER,snshs, SNS_HS, 0, 7, 0, 45 )
75+
PARAM_ENTRY(CAT_INVERTER,snshs, SNS_HS, 0, 7, 0, 45 ) \
76+
PARAM_ENTRY(CAT_INVERTER,pinswap, SWAPS, 0, 15, 0, 109 ) \
7677

7778
#define INVERTER_PARAMETERS_FOC \
78-
PARAM_ENTRY(CAT_INVERTER,pinswap, SWAPS, 0, 15, 0, 109 ) \
7979
PARAM_ENTRY(CAT_INVERTER,modmax, "dig", 37000, 45000, 37836, 148 )
8080

8181
#define DERATE_PARAMETERS_COMMON \
@@ -109,8 +109,8 @@
109109
PARAM_ENTRY(CAT_CHARGER, chargepwmax, "%", 0, 99, 90, 79 )
110110

111111
#define THROTTLE_PARAMETERS_COMMON \
112-
PARAM_ENTRY(CAT_THROTTLE,potmin, "dig", 0, 4095, 0, 17 ) \
113-
PARAM_ENTRY(CAT_THROTTLE,potmax, "dig", 0, 4095, 4095, 18 ) \
112+
PARAM_ENTRY(CAT_THROTTLE,potmin, "dig", 0, 3500, 0, 17 ) \
113+
PARAM_ENTRY(CAT_THROTTLE,potmax, "dig", 0, 3500, 3500, 18 ) \
114114
PARAM_ENTRY(CAT_THROTTLE,pot2min, "dig", 0, 4095, 4095, 63 ) \
115115
PARAM_ENTRY(CAT_THROTTLE,pot2max, "dig", 0, 4095, 4095, 64 ) \
116116
PARAM_ENTRY(CAT_THROTTLE,potmode, POTMODES, 0, 6, 0, 82 ) \
@@ -133,6 +133,7 @@
133133
PARAM_ENTRY(CAT_REGEN, offthrotregen,"%", -100, 0, -30, 49 ) \
134134
PARAM_ENTRY(CAT_REGEN, cruiseregen, "%", -100, 0, -30, 124 ) \
135135
PARAM_ENTRY(CAT_REGEN, regenrampstr,"Hz", 0, 400, 10, 39 ) \
136+
PARAM_ENTRY(CAT_REGEN, maxregentravelhz,"Hz", 0, 1000, 0, 158 ) \
136137
PARAM_ENTRY(CAT_REGEN, brklightout, "%", -100, -1, -50, 67 )
137138

138139
#define AUTOMATION_CONTACT_PWM_COMM_PARAMETERS \
@@ -142,7 +143,7 @@
142143
PARAM_ENTRY(CAT_AUTOM, holdkp, "", -100, 0, -0.25, 138 ) \
143144
PARAM_ENTRY(CAT_AUTOM, speedkp, "", 0, 100, 0.25, 53 ) \
144145
PARAM_ENTRY(CAT_AUTOM, speedflt, "", 0, 16, 5, 57 ) \
145-
PARAM_ENTRY(CAT_AUTOM, cruisemode, CRUISEMODS,0, 3, 0, 62 ) \
146+
PARAM_ENTRY(CAT_AUTOM, cruisemode, CRUISEMODS,0, 4, 0, 62 ) \
146147
PARAM_ENTRY(CAT_AUTOM, cruisethrotlim,"%", 0, 100, 50, 155 ) \
147148
PARAM_ENTRY(CAT_CONTACT, udcsw, "V", 0, 1000, 330, 20 ) \
148149
PARAM_ENTRY(CAT_CONTACT, udcswbuck, "V", 0, 1000, 540, 80 ) \
@@ -156,6 +157,8 @@
156157
PARAM_ENTRY(CAT_COMM, canspeed, CANSPEEDS, 0, 4, 2, 83 ) \
157158
PARAM_ENTRY(CAT_COMM, canperiod, CANPERIODS,0, 1, 0, 88 ) \
158159
PARAM_ENTRY(CAT_COMM, nodeid, "", 1, 63, 1, 129 ) \
160+
PARAM_ENTRY(CAT_COMM, controlid, "", 1, 2047, 63, 156 ) \
161+
PARAM_ENTRY(CAT_COMM, controlcheck,CHECKS, 0, 1, 1, 157 ) \
159162
TESTP_ENTRY(CAT_TEST, manualstart, ONOFF, 0, 1, 0, 150 ) \
160163

161164
#define VALUE_BLOCK1 \
@@ -181,7 +184,8 @@
181184
VALUE_ENTRY(pot2, "dig", 2016 ) \
182185
VALUE_ENTRY(regenpreset, "%", 2051 ) \
183186
VALUE_ENTRY(potnom, "%", 2017 ) \
184-
VALUE_ENTRY(dir, DIRS, 2018 ) \
187+
VALUE_ENTRY(seldir, DIRS, 2018 ) \
188+
VALUE_ENTRY(rotordir, DIRS, 2053 ) \
185189
VALUE_ENTRY(tmphs, "°C", 2019 ) \
186190
VALUE_ENTRY(tmpm, "°C", 2020 ) \
187191
VALUE_ENTRY(uaux, "V", 2021 ) \
@@ -197,6 +201,7 @@
197201
VALUE_ENTRY(din_ocur, OKERR, 2030 ) \
198202
VALUE_ENTRY(din_desat, OKERR, 2031 ) \
199203
VALUE_ENTRY(din_bms, ONOFF, 2032 ) \
204+
VALUE_ENTRY(uptime, "10ms", 2054 ) \
200205
VALUE_ENTRY(cpuload, "%", 2035 ) \
201206

202207
#define VALUES_SINE \
@@ -263,7 +268,7 @@
263268
#define SNS_M "12=KTY83-110, 13=KTY84-130, 14=Leaf, 15=KTY81-110, 16=Toyota, 21=OutlanderFront, 22=EpcosB57861-S, 23=ToyotaGen2"
264269
#define PWMFUNCS "0=tmpm, 1=tmphs, 2=speed, 3=speedfrq"
265270
#define SINECURVES "0=VoltageSlip, 1=Simultaneous"
266-
#define CRUISEMODS "0=Off, 1=Switch, 2=CAN, 3=ThrottlePot"
271+
#define CRUISEMODS "0=Off, 1=Switch, 2=CAN, 3=ThrottlePot, 4=Limiter"
267272
#define DIRMODES "0=Button, 1=Switch, 2=ButtonReversed, 3=SwitchReversed, 4=DefaultForward"
268273
#define IDLEMODS "0=Always, 1=NoBrake, 2=Cruise, 3=Off, 4=HillHold"
269274
#define ONOFF "0=Off, 1=On, 2=na"
@@ -274,10 +279,11 @@
274279
#define CANSPEEDS "0=125k, 1=250k, 2=500k, 3=800k, 4=1M"
275280
#define CANIOS "1=Cruise, 2=Start, 4=Brake, 8=Fwd, 16=Rev, 32=Bms"
276281
#define CANPERIODS "0=100ms, 1=10ms"
277-
#define HWREVS "0=Rev1, 1=Rev2, 2=Rev3, 3=Tesla, 4=BluePill, 5=Prius"
282+
#define HWREVS "0=Rev1, 1=Rev2, 2=Rev3, 3=Tesla, 4=BluePill, 5=Prius, 6=MiniMainboard, 7=Leaf2, 8=Leaf3, 9=BMWi3"
278283
#define SWAPS "0=None, 1=Currents12, 2=SinCos, 4=PWMOutput13, 8=PWMOutput23"
279284
#define OUTMODES "0=DcSw, 1=TmpmThresh, 2=TmphsThresh"
280285
#define STATUS "0=None, 1=UdcLow, 2=UdcHigh, 4=UdcBelowUdcSw, 8=UdcLim, 16=EmcyStop, 32=MProt, 64=PotPressed, 128=TmpHs, 256=WaitStart, 512=BrakeCheck"
286+
#define CHECKS "0=CounterOnly, 1=StmCrc8"
281287
#define CAT_MOTOR "Motor"
282288
#define CAT_INVERTER "Inverter"
283289
#define CAT_THROTTLE "Throttle"
@@ -295,10 +301,20 @@
295301
#define CAN_PERIOD_100MS 0
296302
#define CAN_PERIOD_10MS 1
297303

304+
#define PARAM_ID_SUM_START_OFFSET GITHUB_RUN_NUMBER
305+
306+
#if GITHUB_RUN_NUMBER == 0 //local build
307+
#define VER(G) VERSION.R
308+
#else //github runner build
309+
#define VER(G) VERSION.##G.B
310+
#endif
311+
312+
#define VER2(G) VER(G)
313+
298314
#if CONTROL == CTRL_SINE
299-
#define VERSTR STRINGIFY(4=VER-sine)
315+
#define VERSTR STRINGIFY(4=VER2(GITHUB_RUN_NUMBER)-sine)
300316
#elif CONTROL == CTRL_FOC
301-
#define VERSTR STRINGIFY(4=VER-foc)
317+
#define VERSTR STRINGIFY(4=VER2(GITHUB_RUN_NUMBER)-foc)
302318
#endif // CONTROL
303319

304320
enum _outmodes
@@ -313,7 +329,8 @@ enum cruisemodes
313329
CRUISE_OFF = 0,
314330
CRUISE_SWITCH = 1,
315331
CRUISE_CAN = 2,
316-
CRUISE_POT = 3
332+
CRUISE_POT = 3,
333+
CRUISE_LIMITER = 4
317334
};
318335

319336
enum _potmodes

include/pwmgeneration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define PWMGENERATION_H
2121

2222
#include <stdint.h>
23+
#include <libopencm3/stm32/timer.h>
2324
#include "my_fp.h"
2425
#include "anain.h"
2526

@@ -39,6 +40,7 @@ class PwmGeneration
3940
static int GetCpuLoad();
4041
static void SetChargeCurrent(float cur);
4142
static void SetPolePairRatio(int ratio) { polePairRatio = ratio; }
43+
static void SetFwCurMax(float c);
4244

4345
private:
4446
enum EdgeType { NoEdge, PosEdge, NegEdge };
@@ -73,6 +75,7 @@ class PwmGeneration
7375
static int opmode;
7476
static s32fp ilofs[2];
7577
static int polePairRatio;
78+
static tim_oc_id ocChannels[3];
7679
};
7780

7881
#endif // PWMGENERATION_H

include/throttle.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class Throttle
2626
{
2727
public:
28-
static bool CheckAndLimitRange(int* potval, int potIdx);
28+
static bool CheckAndLimitRange(int* potval, uint8_t potIdx);
2929
static float DigitsToPercent(int potval, int potidx);
3030
static float CalcThrottle(float potval, float pot2val, bool brkpedal);
3131
static float CalcThrottleBiDir(float potval, bool brkpedal);
@@ -39,6 +39,8 @@ class Throttle
3939
static void AccelerationLimitCommand(float& finalSpnt, int speed);
4040
static void FrequencyLimitCommand(float& finalSpnt, float frequency);
4141
static float RampThrottle(float finalSpnt);
42+
static void UpdateDynamicRegenTravel(float regenTravelMax, float frequency);
43+
static bool IsThrottlePressed(int pot1);
4244
static int potmin[2];
4345
static int potmax[2];
4446
static float brknom;
@@ -66,6 +68,7 @@ class Throttle
6668
static float idcmax;
6769
static float idckp;
6870
static float fmax;
71+
static float maxregentravelhz;
6972

7073
private:
7174
static int speedFiltered;

0 commit comments

Comments
 (0)