Skip to content

Commit

Permalink
Merge commit '631a39383a0fdc0a79ecaaa895bbaa1d5482b07a' into experime…
Browse files Browse the repository at this point in the history
…ntal
  • Loading branch information
dzid26 committed Apr 17, 2024
2 parents 5b0414a + 631a393 commit 1dec64b
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 46 deletions.
47 changes: 37 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ on:
- "src/**/*"

env:
SDCC_VERSION: 4.2.0
SDCC_VERSION: 4.4.0

jobs:
Build_Windows:
runs-on: windows-latest
steps:
- name: install SDCC
run: | #install silent and then unpack missing installation libraries
Invoke-WebRequest https://altushost-swe.dl.sourceforge.net/project/sdcc/sdcc-win64/$env:SDCC_VERSION/sdcc-$env:SDCC_VERSION-x64-setup.exe -OutFile sdcc_setup.exe
Invoke-WebRequest https://altushost-swe.dl.sourceforge.net/project/sdcc/sdcc-win64/$env:SDCC_VERSION/sdcc-$env:SDCC_VERSION-rc3-x64-setup.exe -OutFile sdcc_setup.exe
ls
Start-Process -wait -FilePath "sdcc_setup.exe" -ArgumentList "/S", "/D=C:\Program Files\SDCC"
- uses: actions/checkout@v2
echo "Adding sdcc to PATH"
Add-Content $env:GITHUB_PATH "C:\Program Files\SDCC\bin"
- uses: actions/checkout@v4
- name: Build
run: |
cd src/controller
./compile.bat
- uses: actions/upload-artifact@v3
../../tools/cygwin/bin/make.exe clean
../../tools/cygwin/bin/make.exe CFLAGS=--Werror
- uses: actions/upload-artifact@v4
with:
name: firmware
name: firmware_from_windows
path: bin/main.ihx


Expand All @@ -43,18 +47,41 @@ jobs:
run: |
cd ~
wget https://altushost-swe.dl.sourceforge.net/project/sdcc/sdcc-linux-amd64/$SDCC_VERSION/sdcc-$SDCC_VERSION-amd64-unknown-linux2.5.tar.bz2
ls
sudo tar xf sdcc-$SDCC_VERSION-amd64-unknown-linux2.5.tar.bz2
cd sdcc-$SDCC_VERSION/
sudo cp -r * /usr/local
sdcc --version
sdcc --print-search-dirs
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Build
run: |
cd src/controller
make clean
make
- uses: actions/upload-artifact@v3
make CFLAGS=--Werror
- uses: actions/upload-artifact@v4
with:
name: firmware
name: firmware_from_linux
path: bin/main.ihx


Compare_builds:
needs: [Build_Windows, Build_Linux]
runs-on: ubuntu-22.04
steps:
- name: Download Windows build
uses: actions/download-artifact@v4
with:
name: firmware_from_windows
path: firmware_from_windows
- name: Download Linux build
uses: actions/download-artifact@v4
with:
name: firmware_from_linux
path: firmware_from_linux
- name: Compare build files
run: |
ls
echo "Comparing build files"
git diff firmware_from_windows/main.ihx firmware_from_linux/main.ihx --word-diff=color --ignore-space-at-eol --exit-code
echo "Done comparing build files. Files are the same."
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "stm8",
"includePath": [
"./src/controller",
"./src/common",
"./src/common/STM8S_StdPeriph_Lib/inc"
],
"defines": [
"STM8S105",
"__interrupt(SDCC_IntelliSense_Hack)="
],
"cStandard": "c99",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-vscode.cpptools"
]
}
57 changes: 57 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "SDCC build",
"command": "make",
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"args": [
"all"
],
"options": {
"cwd": "${workspaceFolder}/src/controller/"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "process",
"label": "STM8 Flash",
"windows": {
"command": "flash.bat"
},
"osx": { //untested
"command": "make flash",
},
"linux": { //untested
"command": "make flash",
},
"options": {
"cwd": "${workspaceFolder}/src/controller"
},
"dependsOn": [
"SDCC build"
],
"presentation": {
"echo": false,
"reveal": "always",
"focus": true,
"close": false
},
"problemMatcher": []
}
],
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ This project is being developed and maintained for free by a community of users.

# For more information, go to the [wiki](https://github.com/emmebrusa/TSDZ2-Smart-EBike-1/wiki) instructions.

## Development / contributing
### Setup
1. Clone this repository
2. Install the SDCC compiler

### Compile the firmware
`cd src/controller/` and use `make` or `compile.bat` to compile the firmware.

### Editing environment
1. VScode can be used for the development.
a) open project top folder as workspace
b) install extensions from recommended popup
c) configure Intellisense by going to Settings `ctrl+,` and specifying `@id:C_Cpp.default.systemIncludePath` according to SDCC installation folder, e.g: `C:\\Program Files\\SDCC\\include`
d) `Ctrl+Shift+b` to build the firmware


## IMPORTANT NOTES
* Installing this firmware will void your warranty of the TSDZ2 mid drive.
* We are not responsible for any personal injuries or accidents caused by use of this firmware.
Expand Down
2 changes: 2 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef COMMON_COMMON_H_
#define COMMON_COMMON_H_

#include <stdint.h>

// riding modes
#define OFF_MODE 0
#define POWER_ASSIST_MODE 1
Expand Down
22 changes: 0 additions & 22 deletions src/controller/.vscode/c_cpp_properties.json

This file was deleted.

6 changes: 3 additions & 3 deletions src/controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ ebike_app.h pins.h eeprom.h lights.h config.h
# The list of .rel files can be derived from the list of their source files
RELS = $(addprefix $(ODIR)/,$(notdir $(EXTRASRCS:.c=.rel)))

INCLUDES = -I$(IDIR) -I$(IDIR1)
CFLAGS = -m$(PLATFORM) -D$(DEVICE) -Ddouble=float --std-c99 --nolospre --opt-code-speed --peep-asm --peep-file peep.txt
DEBUG_FLAGS = --out-fmt-ihx --debug
override INCLUDES += -I$(IDIR) -I$(IDIR1)
override CFLAGS += -m$(PLATFORM) -D$(DEVICE) -Ddouble=float --std-c99 --nolospre --opt-code-speed --peep-asm --peep-file peep.txt
override DEBUG_FLAGS += --out-fmt-ihx --debug
LIBS =

# This just provides the conventional target name "all"; it is optional
Expand Down
3 changes: 2 additions & 1 deletion src/controller/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdint.h>
#include <stdio.h>
#include "stm8s.h"
#include "stm8s_uart2.h"
#include "stm8s_gpio.h"
#include "main.h"
#include "interrupts.h"
Expand Down Expand Up @@ -3295,7 +3296,7 @@ static void uart_send_package(void)
// send the full package to UART
for(ui8_i = 0; ui8_i < UART_TX_BUFFER_LEN; ui8_i++)
{
putchar(ui8_tx_buffer[ui8_i]);
uart_put_char(ui8_tx_buffer[ui8_i]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define THROTTLE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_DEFAULT 98 // 80 at 15.625KHz
#define THROTTLE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_MIN 49 // 40 at 15.625KHz

#define MOTOR_SPEED_FIELD_WEAKEANING_MIN 300 // ERPS
#define MOTOR_SPEED_FIELD_WEAKENING_MIN 300 // ERPS

// cadence sensor
#define CADENCE_SENSOR_NUMBER_MAGNETS 20U
Expand Down
2 changes: 1 addition & 1 deletion src/controller/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
}
#if FIELD_WEAKENING_ENABLED
} else if ((ui8_g_duty_cycle == PWM_DUTY_CYCLE_MAX)
&& (ui16_motor_speed_erps > MOTOR_SPEED_FIELD_WEAKEANING_MIN) // do not enable at low motor speed / low cadence
&& (ui16_motor_speed_erps > MOTOR_SPEED_FIELD_WEAKENING_MIN) // do not enable at low motor speed / low cadence
&& (ui8_fw_angle_max > 0)
&& (ui8_adc_battery_current_filtered < ui8_controller_adc_battery_current_target)) {
// reset duty cycle ramp down counter (filter)
Expand Down
8 changes: 4 additions & 4 deletions src/controller/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void uart2_init(void) {
}

#if __SDCC_REVISION < 9624
void putchar(char c)
void uart_put_char(char c)
{
//Write a character to the UART2
UART2_SendData8(c);
Expand All @@ -41,7 +41,7 @@ void putchar(char c)
while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET);
}
#else
int putchar(int c)
int uart_put_char(int c)
{
//Write a character to the UART2
UART2_SendData8(c);
Expand All @@ -54,9 +54,9 @@ int putchar(int c)
#endif

#if __SDCC_REVISION < 9989
char getchar(void)
char uart_get_char(void)
#else
int getchar(void)
int uart_get_char(void)
#endif
{
uint8_t c = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/controller/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
void uart2_init(void);

#if __SDCC_REVISION < 9624
void putchar(char c);
void uart_put_char(char c);
#else
int putchar(int c);
int uart_put_char(int c);
#endif

#if __SDCC_REVISION < 9989
char getchar(void);
char uart_get_char(void);
#else
int getchar(void);
int uart_get_char(void);
#endif

#endif /* _UART_H */
Expand Down

0 comments on commit 1dec64b

Please sign in to comment.