Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial protocol, watchdog, ADC Input, platform.io #72

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b21e6dd
Add platformio.ini file, update README.md, and .gitignore
btsimonh Aug 31, 2018
765f890
case sensitive Folder names, small changes
p-h-a-i-l Sep 3, 2018
9e38f2b
Merge remote-tracking branch 'origin/master' into pio
p-h-a-i-l Sep 20, 2018
fcd76b3
Integrate interrupt based uart an minimal version of serial protocol …
p-h-a-i-l Dec 5, 2018
ffe0744
soft watchdog
p-h-a-i-l Dec 6, 2018
3de2294
kicking the watchdog can be prevented while debugging
p-h-a-i-l Dec 6, 2018
d413928
main can be put into infinite loop via debugger
p-h-a-i-l Dec 6, 2018
b4a22a5
set watchdog period to 100ms
p-h-a-i-l Dec 6, 2018
522d21e
added human protocol password
p-h-a-i-l Dec 6, 2018
106aba6
no crashes... stashing commit
p-h-a-i-l Dec 6, 2018
9fa4f8e
Changed config to work with woodenboard.
BruegelN Dec 9, 2018
78dd341
Added smaller struct to protocol.
BruegelN Dec 9, 2018
7a62877
Added temporary fix to turn off the board using the buildin buttons w…
BruegelN Dec 9, 2018
70532b9
Softatchdog polished and included in config
p-h-a-i-l Dec 9, 2018
799f34a
poweroff on watchdog and activate on first event
p-h-a-i-l Dec 9, 2018
48fdacd
Merge branch 'testSoftWatchdog' of git.hacknology.de:phel/bewegungsap…
p-h-a-i-l Dec 9, 2018
4ced4be
Merge branch 'testSoftWatchdog' into serialprotocol
p-h-a-i-l Dec 9, 2018
c087153
Merge remote-tracking branch 'niklasfauth/master' into serialprotocol
p-h-a-i-l Dec 9, 2018
2761c01
readme
p-h-a-i-l Dec 9, 2018
78e8f4b
added crc check
p-h-a-i-l Sep 5, 2018
9867145
hybrid nunchuck and ADC input
p-h-a-i-l Sep 5, 2018
d0f0b27
CONTROL_USART can no be selected to be on any sensor cable
p-h-a-i-l Nov 18, 2018
9083e15
Debug and Control can coexist on same uarts now. Untested.
p-h-a-i-l Nov 19, 2018
1ba495f
ADC can coexist with other Input Methos, Platooning configured
p-h-a-i-l Nov 25, 2018
b680b9c
readme
p-h-a-i-l Nov 26, 2018
37dac01
Merge branch 'serialprotocol' into bewegungsappar.at
p-h-a-i-l Dec 9, 2018
4d7148c
readme
p-h-a-i-l Dec 10, 2018
6f05495
add timeout to protocol base pwms
p-h-a-i-l Dec 10, 2018
bec572d
include guards for serial protocol, rename serial uarts, crc selectable
p-h-a-i-l Dec 10, 2018
9583cc7
config can now be done with platformio environments
p-h-a-i-l Dec 10, 2018
87686eb
inactivity shutdown warning
p-h-a-i-l Dec 10, 2018
35e3ec0
implemented hall interrupts for speed information
p-h-a-i-l Dec 10, 2018
7ec81af
fixup
p-h-a-i-l Dec 10, 2018
955c882
Merge branch 'bewegungsappar.at' into hallinterrupts
p-h-a-i-l Dec 10, 2018
c58aa22
no timeout during immediate mode
p-h-a-i-l Dec 10, 2018
8983451
readme
p-h-a-i-l Dec 10, 2018
27ef84b
allow reading of global speed and steer
p-h-a-i-l Dec 10, 2018
7b8beaf
whitespace massacre
p-h-a-i-l Dec 10, 2018
fdfe1f7
prevent double replies to messages
p-h-a-i-l Dec 11, 2018
b6bc418
STM32 Cube MX project file
p-h-a-i-l Dec 11, 2018
08262ef
TIMEOUT 5
p-h-a-i-l Dec 11, 2018
81e6df0
Merge branch 'bewegungsappar.at' of git.hacknology.de:phel/bewegungsa…
p-h-a-i-l Dec 11, 2018
febadeb
poweroff optimization
p-h-a-i-l Dec 16, 2018
576eeef
paddelece config
p-h-a-i-l Dec 22, 2018
779ca57
Buzzer via serial protocol
p-h-a-i-l Dec 25, 2018
957de0c
good gametrak settings
p-h-a-i-l Dec 26, 2018
c541607
change baud rate
p-h-a-i-l Dec 27, 2018
c84f3d4
Motors are disabled as soon as poweroff() is called.
p-h-a-i-l Jan 2, 2019
1d53978
add sample code for protocol
p-h-a-i-l Feb 5, 2019
e01099e
project moved to bipropellant
p-h-a-i-l Jul 2, 2019
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
build/*
!build/hover.hex
.pioenvs
.piolibdeps
.vscode/*
.travis.yml
lib/readme.txt
154 changes: 0 additions & 154 deletions Inc/config.h

This file was deleted.

27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Src/system_stm32f1xx.c \
Src/setup.c \
Src/control.c \
Src/main.c \
Src/bldc.c \
Src/comms.c \
Src/stm32f1xx_it.c \
src/system_stm32f1xx.c \
src/setup.c \
src/control.c \
src/main.c \
src/bldc.c \
src/comms.c \
src/protocol.c \
src/hallinterrupts.c \
src/stm32f1xx_it.c \

# ASM sources
ASM_SOURCES = \
Expand Down Expand Up @@ -89,11 +91,12 @@ AS_INCLUDES =

# C includes
C_INCLUDES = \
-IInc \
-Iinc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include
-IDrivers/CMSIS/Include \
-Ilib/crc/src


# compile gcc flags
Expand Down Expand Up @@ -135,10 +138,10 @@ vpath %.c $(sort $(dir $(C_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))

$(BUILD_DIR)/%.o: %.c Inc/config.h Makefile | $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.c inc/config.h Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

$(BUILD_DIR)/%.o: %.s Inc/config.h Makefile | $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.s inc/config.h Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
Expand All @@ -155,7 +158,7 @@ $(BUILD_DIR):
mkdir -p $@

format:
find Src/ Inc/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i
find src/ inc/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i
#######################################
# clean up
#######################################
Expand Down
87 changes: 85 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# NOTE: This project has moved to

[BiPropellant Repos](https://github.com/bipropellant).

All features from this repo are or will be merged to bipropellant. This branch here will not be updated anymore.

# Deviations to [main repo](https://github.com/NiklasFauth/hoverboard-firmware-hack)
* Build Environment is platform.io. Old Makefile based system should work too, but not tested.
* UART Control can be configured to Connect to USART2 or USART3
* Added CRC Checksum to UART Control. This way, the protocol just loses sync but the board does not try to kill you anymore (at least less often)
* UART Control and Debug can be active on the same cable
* Extended ADC Input Control config options. Default is platooning / "transpotter"
* ADC Input Control can coexist with all other control Methods as long as the other Method uses the other cable
* Watchdog Implemented which monitors if main is still running. Stops motors and shuts down if not.
* Serial Protocol implemented (very shrunk down version from [btsimonh's pidcontrol](https://github.com/btsimonh/hoverboard-firmware-hack))
* PWM can be set and read
* Humand readable ASCII Protocol can coexist with machine parseable Messages
* Buzzer commands
* Hall Interrupts for Speed Feedback

---

# hoverboard-firmware-hack

![](https://raw.githubusercontent.com/NiklasFauth/hoverboard-firmware-hack/master/docs/pictures/armchair.gif) ![](https://raw.githubusercontent.com/NiklasFauth/hoverboard-firmware-hack/master/docs/pictures/bobbycar.gif)
Expand All @@ -10,6 +32,7 @@ The firmware you can find here allows you to use your Hoverboard Hardware (like
If you want an overview of what you can do with this firmware, here is a ~40min video of a talk about this project:
https://media.ccc.de/v/gpn18-95-howto-moving-objects


---

## Build Instructions
Expand All @@ -30,10 +53,70 @@ Both USART2 & 3 can be used for UART and I2C, PA2&3 can be used as 12bit ADCs.
The reverse-engineered schematics of the mainboard can be found here:
http://vocke.tv/lib/exe/fetch.php?media=20150722_hoverboard_sch.pdf


### Inputs
Plenty of input Methods can be used to control the board.
You can configure your preferred Method in config.h.
#### Analog Values
Probably the most reliable Method. 2 Potis can be connected to one of the old sensor board connections. Make sure to reference the Poti voltages to 3.3V, not 12V or 15V. The gametrak Controller in the TranspOtter project is an examample for analog input.
#### PPM Input
[Pulse Pause Modulated](https://en.wikipedia.org/wiki/Pulse-position_modulation) Signals.
#### I2C/Nunchuck
A nunchuck, which communicates via I2C can be connected to the board. Have a look into the troubleshooting section if you have trouble with the Nunchucks.
#### UART
A complete protocol is implemented to communicate with the board. Have a look at protocol.c to find out how it works.
Sample code to send speed and steer:

` setHoverboardPWM(200,50); // sends 200 as speed and 50 steer `
```
typedef struct MsgToHoverboard_t{
unsigned char SOM; // 0x02
unsigned char len; // len is len of ALL bytes to follow, including CS
unsigned char cmd; // 'W'
unsigned char code; // code of value to write
int16_t base_pwm; // absolute value ranging from -1000 to 1000 .. base_pwm plus/minus steer is the raw PWM value
int16_t steer; // absolute value ranging from -1000 to 1000 .. wether steer is added or substracted depends on the side R/L
unsigned char CS; // checksumm
};

typedef union UART_Packet_t{
MsgToHoverboard_t msgToHover;
byte UART_Packet[sizeof(MsgToHoverboard_t)];
};

void setHoverboardPWM( int16_t base_pwm, int16_t steer )
{
UART_Packet_t ups;

ups.msgToHover.SOM = 2 ; // PROTOCOL_SOM; //Start of Message;
ups.msgToHover.len = 7; // payload + SC only
ups.msgToHover.cmd = 'W'; // PROTOCOL_CMD_WRITEVAL; // Write value
ups.msgToHover.code = 0x07; // speed data from params array
ups.msgToHover.base_pwm = base_pwm;
ups.msgToHover.steer = steer;
ups.msgToHover.CS = 0;

for (int i = 0; i < ups.msgToHover.len; i++){
ups.msgToHover.CS -= ups.UART_Packet[i+1];
}

Serial1.write(ups.UART_Packet,sizeof(UART_Packet_t));
}
```
a project which makes use of the protocol (ESP32) can be found at https://github.com/p-h-a-i-l/hoverboard-control

---

## Compiling
To build the firmware, just type "make". Make sure you have specified your gcc-arm-none-eabi binary (version 7 works, there is a version that does not!) location in the Makefile ("PREFIX = ...").

The firmware will also build (and flash) very easily from platform.io, plaformio.ini file included. Simply open the folder in the IDE of choice (vscode or Atom), and press the 'PlatformIO:Build' or the 'PlatformIO:Upload' button (bottom left in vscode).

(Note: if you have no buttons, use Debug/Add Configuration, and select 'PlatformIO Debugger'; seems to kick it into life).


## Flashing
To build the firmware, just type "make". Make sure you have specified your gcc-arm-none-eabi binary (version 7 works, there is a version that does not!) location in the Makefile ("PREFIX = ..."). Right to the STM32, there is a debugging header with GND, 3V3, SWDIO and SWCLK. Connect GND, SWDIO and SWCLK to your SWD programmer, like the ST-Link found on many STM devboards.
Right to the STM32, there is a debugging header with GND, 3V3, SWDIO and SWCLK. Connect GND, SWDIO and SWCLK to your SWD programmer, like the ST-Link found on many STM devboards.

Make sure you hold the powerbutton or connect a jumper to the power button pins while flashing the firmware, as the STM might release the power latch and switches itself off during flashing. Battery > 36V have to be connected while flashing.

Expand Down Expand Up @@ -80,6 +163,6 @@ Have a look at the config.h in the Inc directory. That's where you configure to
Currently supported: Wii Nunchuck, analog potentiometer and PPM-Sum signal from a RC remote.
If you need additional features like a boost button, have a look at the while(1) loop in the main.c

### Projects based on it
### Projects based on
* [bobbycar-optimized firmware](https://github.com/larsmm/hoverboard-firmware-hack-bbcar) based on this one with driving modes, acceleration ramps and some other features
* [wheel chair](https://github.com/Lahorde/steer_speed_ctrl) controlled with a joystick or using a CC2650 sensortag to control it over bluetooth with pitch/roll.
Loading