Skip to content

Commit

Permalink
Merge pull request #106 from davefiddes/build-improvements
Browse files Browse the repository at this point in the history
Build improvements
  • Loading branch information
damienmaguire authored Sep 25, 2024
2 parents 8220a43 + 33f52c5 commit 58745cf
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 32 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/CI-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI
on:
push:
pull_request:

jobs:
build:
name: build-linux
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install build package dependencies
run: |
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi
- name: Build dependencies
run: |
echo "Number of processors:" `nproc`
make get-deps -j `nproc`
- name: Build Stm32-vcu firmware
run: |
make
- uses: actions/upload-artifact@v4
with:
name: Stm32-vcu firmware binary
path: stm32_vcu.bin

- uses: actions/upload-artifact@v4
with:
name: Stm32-vcu firmware hex
path: stm32_vcu.hex

- name: Build unit tests on host
run: |
make Test
- name: Run unit tests on host
run: |
test/test_vcu
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
],
"externalConsole": false,
"cwd": "${workspaceFolder}"
},
{
"name": "test_vcu debug with gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test/test_vcu",
"cwd": "${workspaceFolder}",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set output-radix 16"
}
]
}
]
}
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ Q := @
NULL := 2>/dev/null
endif

# try-run
# Usage: option = $(call try-run, command,option-ok,otherwise)
# Exit code chooses option.
try-run = $(shell set -e; \
if ($(1)) >/dev/null 2>&1; \
then echo "$(2)"; \
else echo "$(3)"; \
fi)

# Test a linker (ld) option and return the gcc link command equivalent
comma := ,
link_command := -Wl$(comma)
ld-option = $(call try-run, $(PREFIX)-ld $(1) -v,$(link_command)$(1))

# Test whether we can suppress a safe warning about rwx segments
# only supported on binutils 2.39 or later
LDFLAGS += $(call ld-option,--no-warn-rwx-segments)

all: directories images
Debug:images
Release: images
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# stm32-vcu

[![Build status](../../actions/workflows/CI-build.yml/badge.svg)](../../actions/workflows/CI-build.yml)

Project based on the OpenInverter System by Johannes Huebner to provide a universal VCU (Vehicle Control Unit) for electric vehicle conversion projects.

Please visit the development thread on the Openinverter Forum for more information : https://openinverter.org/forum/viewtopic.php?f=3&t=1277
Expand Down Expand Up @@ -51,15 +54,13 @@ Now you can compile stm32-vcu by typing

# Tests

`cd tests`

Build the tests

`make`
`make Tests`

Run the tests

`./test_vcu`
`./test/test_vcu`

And upload it to your board using a JTAG/SWD adapter, the updater.py script or the esp8266 web interface

Expand Down
2 changes: 1 addition & 1 deletion include/stm32_vcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
#include "dcdc.h"
#include "TeslaDCDC.h"
#include "BMW_E31.h"
#include "DigiPot.h"
#include "digipot.h"
#include "shifter.h"
#include "F30_Lever.h"
#include "E65_Lever.h"
Expand Down
24 changes: 8 additions & 16 deletions include/utils.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
#ifndef UTILS_H
#define UTILS_H

#include "BMW_E65.h"
#include "my_fp.h"
#include "my_math.h"
#include "errormessage.h"
#include "params.h"
#include "digio.h"
#include <libopencm3/stm32/rtc.h>
#include "canhardware.h"
#include "anain.h"
#include "throttle.h"
#include "isa_shunt.h"
#include "bmw_sbox.h"
#include "vag_sbox.h"
#include "vehicle.h"
#include "shifter.h"
#include <libopencm3/stm32/timer.h>
#include "iomatrix.h"

#include "canhardware.h"
#include "errormessage.h"

namespace utils
{
int32_t change(int32_t, int32_t, int32_t, int32_t, int32_t);
inline int32_t change(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

float GetUserThrottleCommand(CanHardware*);
float ProcessThrottle(int);
float ProcessUdc(int);
Expand Down
1 change: 1 addition & 0 deletions src/BMW_E31.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include "BMW_E31.h"
#include "hwinit.h"
#include "my_math.h"
#include <libopencm3/stm32/timer.h>
#include <libopencm3/stm32/gpio.h>
/*
Expand Down
1 change: 1 addition & 0 deletions src/BMW_E39.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "stm32_can.h"
#include "utils.h"
#include "digio.h"
#include "my_math.h"

static uint8_t counter_329 = 0;
static uint8_t ABSMsg = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/BMW_E65.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void BMW_E65::Engine_Data()

}

bool BMW_E65::GetGear(Vehicle::gear& outGear)
bool BMW_E65::GetGear(Vehicle::gear& outGear __attribute__((unused)))
{
return false;
}
15 changes: 9 additions & 6 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#include "utils.h"

#include "iomatrix.h"
#include "throttle.h"
#include "vag_sbox.h"
#include "bmw_sbox.h"
#include "isa_shunt.h"
#include "my_math.h"
#include <libopencm3/stm32/timer.h>
#include <libopencm3/stm32/rtc.h>

namespace utils
{

Expand All @@ -8,12 +17,6 @@ namespace utils
float SOCVal=0;
int32_t NetWh=0;


int32_t change(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void PostErrorIfRunning(ERROR_MESSAGE_NUM err)
{
if (Param::GetInt(Param::opmode) == MOD_RUN)
Expand Down
6 changes: 3 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ CC = gcc
CPP = g++
LD = g++
CP = cp
CFLAGS = -std=c99 -g -I../include -I../libopeninv/include
CPPFLAGS = -g -I../include -I../libopeninv/include
CFLAGS = -std=c99 -ggdb -I../include -I../libopeninv/include
CPPFLAGS = -ggdb -I../include -I../libopeninv/include
LDFLAGS = -g
BINARY = test_vcu
OBJS = test_main.o my_string.o throttle.o test_throttle.o
OBJS = test_main.o my_string.o params.o throttle.o test_throttle.o
VPATH = ../src ../libopeninv/src

all: $(BINARY)
Expand Down
12 changes: 11 additions & 1 deletion test/test_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@

using namespace std;

void Param::Change(Param::PARAM_NUM p)
{
// Dummy function - we ignore parameter changes in these tests
}

// Include a dummy error list to allow the tests to link. It is unused.
const char* errorListString = "";

static void TestSetup()
{
//percentage of deadzone
Throttle::throtdead = 5;
Throttle::potmin[0] = 100;
Throttle::potmax[0] = 4000;
Throttle::throtmax = 100;
Param::SetInt(Param::dir, 1);
}

// TEMPERATURE DERATING
Expand Down Expand Up @@ -82,7 +92,7 @@ static void TestCalcThrottleIs0WhenInDeadZone() {

static void TestCalcThrottleIsAbove0WhenJustOutOfDeadZone() {
//deadzone is first 5% of travel between 100 and 4000
ASSERT(Throttle::CalcThrottle(296, 0, false) > 0);
ASSERT(Throttle::CalcThrottle(496, 0, false) > 0);
}

static void TestCalcThrottleIs100WhenMax() {
Expand Down

0 comments on commit 58745cf

Please sign in to comment.