Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jsphuebner/stm32-sine
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed Aug 27, 2024
2 parents a0045bd + 5847e01 commit 0945b42
Show file tree
Hide file tree
Showing 8 changed files with 1,028 additions and 41 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/CI-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ jobs:
with:
name: FOC firmware hex
path: stm32_foc.hex

# Unit tests are currently broken so don't build and run them for now
#- name: Build unit tests on host
# run: |
# make -C test
#
# - name: Run unit tests on host
# run: |
# test/test_sine

- name: Build unit tests on host
run: |
make -C test
- name: Run unit tests on host
run: |
test/test_sine
11 changes: 9 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ CPP = g++
LD = g++
CP = cp
CFLAGS = -std=c99 -ggdb -DSTM32F1 -I../include -I../libopeninv/include -I../libopencm3/include
CPPFLAGS = -ggdb -DSTM32F1 -DCONTROL_FOC=1 -DCONTROL_SINE=0 -DCONTROL=DCONTROL_FOC -I../include -I../libopeninv/include -I../libopencm3/include
CPPFLAGS = -ggdb -DSTM32F1 -DCTRL_FOC=1 -DCTRL_SINE=0 -DCTRL=CTRL_FOC -I../include -I../libopeninv/include -I../libopencm3/include
LDFLAGS = -g
BINARY = test_sine
OBJS = test_main.o fu.o test_fu.o test_fp.o test_vcu.o my_fp.o my_string.o params.o vehiclecontrol.o \
test_throttle.o throttle.o sine_core.o temp_meas.o
test_throttle.o throttle.o sine_core.o temp_meas.o stub_canhardware.o test_canmap.o canmap.o \
stub_libopencm3.o
VPATH = ../src ../libopeninv/src

# Check if the variable GITHUB_RUN_NUMBER exists. When running on the github actions running, this
# variable is automatically available.
# Create a compiler define with the content of the variable. Or, if it does not exist, use replacement value 99999.
CPPFLAGS += $(shell \
if [ -z "$$GITHUB_RUN_NUMBER" ]; then echo "-DGITHUB_RUN_NUMBER=0"; else echo "-DGITHUB_RUN_NUMBER=$$GITHUB_RUN_NUMBER"; fi )

all: $(BINARY)

$(BINARY): $(OBJS)
Expand Down
45 changes: 45 additions & 0 deletions test/stub_canhardware.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of the stm32-sine project.
*
* Copyright (C) 2021 Johannes Huebner <[email protected]>
* Copyright (C) 2024 David J. Fiddes <[email protected]>
*
* 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/>.
*/
#include "stub_canhardware.h"

CanCallback* vcuCan = nullptr;
uint32_t vcuCanId;

CanHardware::CanHardware()
{}

bool CanHardware::AddCallback(CanCallback* cb)
{
vcuCan = cb;
return true;
}

bool CanHardware::RegisterUserMessage(uint32_t canId, uint32_t mask)
{
vcuCanId = canId;
return true;
}

void CanHardware::ClearUserMessages() {}

void CanHardware::HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc)
{
vcuCan->HandleRx(canId, data, dlc);
}
48 changes: 48 additions & 0 deletions test/stub_canhardware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of the stm32-sine project.
*
* Copyright (C) 2021 Johannes Huebner <[email protected]>
* Copyright (C) 2024 David J. Fiddes <[email protected]>
*
* 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/>.
*/
#ifndef TEST_CANHARDWARE_H
#define TEST_CANHARDWARE_H

#include "canhardware.h"
#include <stdint.h>
#include <string.h>
#include <array>

class CanStub: public CanHardware
{
void SetBaudrate(enum baudrates baudrate) {}
void Send(uint32_t canId, uint32_t data[2], uint8_t len)
{
m_canId = canId;
memcpy(&m_data[0], &data[0], sizeof(m_data));
m_len = len;
}
virtual void ConfigureFilters() {}

public:
std::array<uint8_t, 8> m_data;
uint8_t m_len;
uint32_t m_canId;
};

extern CanCallback* vcuCan;
extern uint32_t vcuCanId;

#endif // TEST_CANHARDWARE_H
49 changes: 49 additions & 0 deletions test/stub_libopencm3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of the stm32-sine project.
*
* Copyright (C) 2024 David J. Fiddes <[email protected]>
*
* 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/>.
*/
#include "stdint.h"

void flash_unlock(void)
{
}

void flash_lock(void)
{
}

void flash_set_ws(uint32_t ws)
{
}

void flash_program_word(uint32_t address, uint32_t data)
{
}

void flash_erase_page(uint32_t page_address)
{
}

uint16_t desig_get_flash_size(void)
{
return 8;
}

uint32_t crc_calculate(uint32_t data)
{
return 0xaa55;
}
2 changes: 1 addition & 1 deletion test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern int _failedAssertions;
std::cout << "Test " << __FILE__ << "::" << __func__ << " passed." << std::endl; \
else \
{ \
std::cout << "Assertion failed: " << STRING(c) << " in " __FILE__ " : " << __LINE__ << std::endl; \
std::cout << "Assertion failed: " << STRING(c) << " in " __FILE__ " : " << std::dec << __LINE__ << std::endl; \
_failedAssertions++; \
}

Expand Down
Loading

0 comments on commit 0945b42

Please sign in to comment.