Coder Social home page Coder Social logo

eferu / hoverboard-sideboard-hack-gd Goto Github PK

View Code? Open in Web Editor NEW
105.0 13.0 81.0 109.54 MB

Hoverboard sideboard hack for GD32 boards

License: GNU General Public License v3.0

C 98.00% Assembly 1.60% Makefile 0.41%
sideboard hoverboard imu mpu-6050 gyroscope mems euler gd32 stm32 dmp

hoverboard-sideboard-hack-gd's Introduction

hoverboard-sideboard-hack-GD

Build status License: GPL v3 paypal

This repository implements the firmware for the hoveboard sideboards. The hoveboard comes with two identical sideboards that can be flashed with this firmware.

► If you have an STM32 sideboard check-out the repo hoverboard-sideboard-hack-STM


Table of Contents


Hardware

The original sideboard hardware supports one 4-pin cable that originally was connected to the hoveboard mainboard. It breaks out GND, 12/15V and USART. Additionally, two ports are used to connect to the LED boards. On the back of the board, two Photo Interrupter Optical Switches can be found, originally used to detect if a human is standing on the hoverboard. sideboard

The LED boards consist of colored LEDs (blue, red, green, orange) used for design and to inform the user about the current hoverboard state. Below the pinout of the LED boards is shown. ledboard

The sideboard brain is a GD32F130C6T6 with the pinout shown in the follwing figure: MCU_pinout

A very important component of the sideboard is the IMU MPU-6050 from Invensense. The MPU-6050 determines the board orientation by combining a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die, together with an onboard Digital Motion Processor™ (DMP™), which processes complex 6-axis MotionFusion algorithms. The DMP™ offers many features, such as:

  • Accelerometer and Gyroscope raw data output
  • Quaternion output
  • Temperature output
  • Pedometer
  • Interrupts on gesture events such as Tap on all axes or Orientation change
  • Low-power modes
  • Self-test and calibration

The MPU-6050 pinout and orientation of axes is shown in the follwing figure: MPU6050_pinout

For more details see the MPU-6050 datasheet and MPU-6050 registers.


Example Variants

This firmware offers currently these variants (selectable in platformio.ini or config.h):

  • VARIANT_DEBUG: In this variant the user can interact with sideboard by sending commands via a Serial Monitor to observe and check the capabilities of the sideboard
  • VARIANT_HOVERCAR: This variant can be used for Hovercar build. An RC receiver with iBUS protocol can be connected to the AUX serial Rx pin (see schematic)
  • VARIANT_HOVERBOARD: In this variant the sideboard is communicating with the mainboard of a hoverboard using the FOC firmware repository

Of course the firmware can be further customized for other needs or projects.


Flashing

On the sideboard, there is a debugging header with GND, 3V3, SWDIO and SWCLK. Connect GND, SWDIO and SWCLK to your ST-Link V2 programmer. The 3V3 can be either obtained by connecting the pin to the ST-Link programmer or powering the sideboard with 12/15V.

If you have never flashed your sideboard before, the MCU is probably locked. To unlock the flash, check-out the wiki page How to Unlock MCU flash.

To build and flash choose one of the following methods:

Method 0: Using GitHub Fork

  • Fork the project
  • Modify desired source files and commit
  • Go to Actions (in the repo top menu)
  • Click on latest build
  • Download the build zip file from the Artifacts section
  • Upload desired firmware.bin file using ST-Link Utility

Method 1: Using Platformio IDE (recommended)

  • open the project folder in the IDE of choice (vscode or Atom)
  • press the 'PlatformIO:Build' or the 'PlatformIO:Upload' button (bottom left in vscode).

Note the GD32F130C6T6 is now supported by PlatformIO, see https://github.com/CommunityGD32Cores/platform-gd32, alongside other GD32 chips.

Method 2: Using Keil uVision

  • in Keil uVision, open the sideboard-hack.uvproj
  • if you are asked to install missing packages, click Yes
  • click Build Target (or press F7) to build the firmware
  • click Load Code (or press F8) to flash the firmware.

Method 3: Using Linux CLI

  • prerequisites: install ST-Flash utility.
  • open a terminal in the repo check-out folder and if you have definded the variant in config.h type:
make

or you can set the variant like this

make -e VARIANT=VARIANT_####
  • flash the firmware by typing:
make flash

Wiring iBUS Receiver

An RC transmitter (Flysky FS-i6S or FS-i6X) can be connected to the sideboard using an FS-iA6B receiver as shown in the following schematic:

wiring_iBUS_pic


3D Visualization Demo

By converting Quaternions to Euler angles, we can make a 3D visualization example in Processing as shown below. For this Demo VARIANT_DEBUG was used.

sketch_pic


Contributions

Every contribution to this repository is highly appreciated! Feel free to create pull requests to improve this firmware as ultimately you are going to help everyone.

If you want to donate to keep this firmware updated, please use the link below:

paypal


hoverboard-sideboard-hack-gd's People

Contributors

eferu avatar maxgerhardt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hoverboard-sideboard-hack-gd's Issues

'FLASH' overflowed on VARIANT_DEBUG make

Hi, I'm obviously missing something since make fails with errors.

Help, please?

Ubuntu 16.04
stlink installed from stlink-1.6.1-1_amd64.deb
VARIANT_DEBUG selected
Makefile: added -std=gnu99 (else I get "'for' loop initial declarations are only allowed in C99 or C11 mode")

Result:
(...)
arm-none-eabi-gcc build/gd32f1x0_adc.o build/gd32f1x0_can.o build/gd32f1x0_cec.o build/gd32f1x0_cmp.o build/gd32f1x0_crc.o build/gd32f1x0_dac.o build/gd32f1x0_dbg.o build/gd32f1x0_dma.o build/gd32f1x0_exti.o build/gd32f1x0_fmc.o build/gd32f1x0_fwdgt.o build/gd32f1x0_gpio.o build/gd32f1x0_i2c.o build/gd32f1x0_ivref.o build/gd32f1x0_misc.o build/gd32f1x0_opa.o build/gd32f1x0_pmu.o build/gd32f1x0_rcu.o build/gd32f1x0_rtc.o build/gd32f1x0_slcd.o build/gd32f1x0_spi.o build/gd32f1x0_syscfg.o build/gd32f1x0_timer.o build/gd32f1x0_tsi.o build/gd32f1x0_usart.o build/gd32f1x0_wwdgt.o build/system_gd32f1x0.o build/main.o build/util.o build/systick.o build/mpu6050.o build/mpu6050_dmp.o build/setup.o build/i2c_it.o build/gd32f1x0_it.o build/startup_gd32f1x0.o -mcpu=cortex-m3 -mthumb -specs=nano.specs -TGD32F130C6T_FLASH.ld -lc -lm -lnosys -Wl,-Map=build/firmware.map,--cref -Wl,--gc-sections -o build/firmware.elf
(...)
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7-m/libc_nano.a(lib_a-errno.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/bin/ld: build/firmware.elf section .rodata' will not fit in region FLASH'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 684 bytes
collect2: error: ld returned 1 exit status

By the way, EmanuelFeru/hoverboard-firmware-hack-FOC (the mainboard) builds successfully.

Reset in 300-500ms

i've tested couple of such devices, and it seems that internal watchdog reset device in 300-500 ms
i've solved it by adding fwdgt_counter_reload(); inside delay_1ms while in systick.c , but not sure this is correct place for it

What does it do?

Hi, could you add an abstract to the readme, pointing out what this firmware does, e.g. does it reimplement the original behavior? Thanks.

Communicating with sideboard via USART

Hi!
I'd like to use sideboard as UART-driven sensor, i.e. the goal is to read gyro/accelerometer data via UART.
Had some problems flashing the GD chip using ST-link utility, but solved them with st-flash.
Connected sideboard to external power source with 15V and connected it via USB-TTL adapter to PC's USB port (this have worked earlier with main board)
Tried different variants and noticed the following:

  • 4-pin board LEDs (red/green) starts blinking in circle
  • in VARIANT_HOVERCAR and VARIANT_HOVERBOARD I can see RX blinks on the USB-TTL adapter, so seems like firmware flashed correctly (not sure though)
  • oscilloscope shows periodical bursts on TX pin of sideboard and they doesn't look like zeroes
  • when reading serial port to 16 byte buffer, 14 bytes is returned, like sizeof(SerialSideboard)

But values in the buffer are all zeroes.
Again, this setup worked normally when used with gyro's mainboard (sending commands, reading feedback).
I'm out of ideas. Maybe serial setup is different for sideboard?

HANDLE serialHandle = CreateFile("COM4", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

DCB serialParams = { 0 };
serialParams.DCBlength = sizeof(serialParams);
GetCommState(serialHandle, &serialParams);
serialParams.BaudRate = CBR_115200;
serialParams.ByteSize = 8;
serialParams.StopBits = ONESTOPBIT;
serialParams.Parity = NOPARITY;
SetCommState(serialHandle, &serialParams);

while (true)
{
	static char buf[16];
	memset(buf, 0xcc, sizeof(buf)); // just to make sure that zeroes comes from serial port
	DWORD bytesRead;
	ReadFile(serialHandle, buf, sizeof(buf), &bytesRead, NULL);

	std::string str;
	for (int i = 0; i < bytesRead; ++i)
	{
		str += format_string("%02x ", buf[i]);
	}

	log_msg("[%u] %s", bytesRead, str.c_str());
}

Theremin device.

Used hoverboard-firmware-hack-FOC. In complete delight. Thanks to the author.
I wanted to have fun with the side boards of the hoverboard. Create a theremin device.
When the board is tilted, it emits a sound of varying frequency.
Instead of LED1, I connected a speaker.
Using the STM32 ST-LINK Utility program, change Option Bytes Protection - Disabled, apply,
then check the box WDG_SW, apply.
The programmer gives errors, but changes the settings.
Download the program from ARM Keil v5.37
Create project, change compiler options c90 to gnu90 , No Warning
Debug Use options: ST-Link Debugger

file config.h
#define VARIANT_HOVERBOARD

file systick.c
// if (SysTick_Config(SystemCoreClock / 1000)){
if (SysTick_Config(SystemCoreClock / 200000)){

file mpu6050.c
// delay_ms(100);
delay_ms(20000);

file gd32f1x0_it.c
void SysTick_Handler(void)
{
tick_count_increment();
delay_decrement();
sound();
}

file util.c
extern MPU_Data mpu;
volatile int32_t x,x1;
void sound2(void) {
mpu_get_data(); x= mpu.euler.pitch >>2; if (x>1000) x=1000;
}
void sound(void) {
x1--; if (x1<1) {x1=x; toggle_led(LED1_GPIO_Port, LED1_Pin);}
}

file main.c
while(1) {
delay_1ms(100);
sound2();

// delay_1ms(DELAY_IN_MAIN_LOOP);

// handle_mpu6050();
// handle_sensors();
// handle_usart();
// handle_leds();
// main_loop_counter++;


Alternatively, you can compile with gcc-arm-none-eabi,
then rename the output file from proj.elf to proj.axf
and substitute in ARM Keil. And from it to load into the controller.

Can't flash firmware

I tried with keul uvision5 and st-link software. Keul gives error about missing packet (i installed GD32F130 package). St-link detect chip as some st version and start to flash it, but stops at beginning. I can disable read out protection.

Do i have to install some button to put chip in programmin mode like mainboard (must hold power button while flashing)?

Arduino control

Hello.
Would you share a code to control this board via UART?
Thank you.

Wrong Euler Angle.

I saw that Euler angles that calculate from DMP are so wrong.

When i checked with 3D Visualization Demo, the angle rotated more about 8 times than reality.

I saw your clip upload on Telegram, it's so cool and smooth.

Have you ever meet that behavior? Please help me teacher.

I have sent you a short clip on telegram, please accept my request (https://t.me/tonvanhieu)

MPU init and config intermittent failure

Hi,
sometimes the mu_init() and mpu_config() fail. When I power cycle the board it's good again for some time.

  • So I was wondering is there a software method to reset the mpu6050 ? Not sure if the I2C is failing or the MPU6050.
  • I don't find anymore a detailed schematic ? Somebody knows a location of the pdf ? The old link doen't work anymore.

Any help is appreciated,
Lieven

GD32F103C8T6 vs GD32F130C6T6

Hi Emanuel,

I have two sets of sideboards one of each shown below. One set has GD32F103C8T6 and the other set has GD32F130C6T6.

Programming the GD32F130C6T6 fails usually after writing somewhere between 4 and 12 pages and this is consistent for both sideboards in the pair. They unlock and erase / erase verify ok. I think there was another issue already open where people had experienced the same problem but no solution yet.

Programming the GD32F103C8T6 boards always succeeds, however the code does not appear to run properly, LED 4 or 5 turns on and nothing further happens, no communication with main board. Have you ever successfully run on this MCU? I suppose it is not working because of unsupported MPU 6052C?

Do you have any experience with either of these issues or any idea where to start to look to debug?

GD32F103C8T6
3386EF03-9248-498A-8F05-9B113BEACDD1

MPU appears to be 6052C.
5DFC246C-2A03-460C-BCCF-AE7E7133AD1F

GD32F130C6T6
8FBAD1E2-CC0D-4C6E-9AA1-EE4906DBE2F4

MPU is 6050.
81377D00-1E1C-4715-B1B8-E2A2A88F2D9F

Sensor Fusion

Dear Teacher,
_ Between DMP, Kalman Filter and Complementary filter which way you think that is the most stable and reliable.
_ How can we add bias in the DMP (i saw that there are dmp_set_bias_...() functions but can we set bias for each axis?)
_ There is gyro calib feature in DMP, but it only works after 8 secs of no motion, so can we save the bias for the next time?
Thank you very much my teacher.

Different SWD Programming Pins

On my hoverboard sideboards the SWD programming pins differ from the ones specified in sideboard pinout. From top -> bottom mine go:

  • VDD 3.3V
  • PA14 / SWCLK
  • PA13 / SWDIO
  • GND

It took a while to figure out since I thought there was something wrong with my STLINK/V2 programmer, so it might help others with the same board to add a notice in the readme for that.

No data received via Main Serial

Hello, I am having some problems in getting data from the IMU with an Arduino via Serial. First I have to say that im new to this kind of projects, so I apologize if can't explain properly.
I have a sideboard with a GD32F130 C6T6 and a MPU-6050A. I have unlocked the micro and then flashed it (with lot of difficulties because most of the time I get errors meanwhile writing the pages). Before flashing, I modified config.h to have the Hoverboard Variant because it includes the Serial Control via serial port (I have also tested with Serial Feedback deactivated).
Then, I modified this Arduino program to define the same Feedback struct that is sent via serial by the Sideboard.
And finally, I connected the 3.3V and GND pins from the SWD programming pins to power the board, and the GND and RX (pin number 2) pins from Arduino have been connected to GND and TX from the connector that connects the Mainboard with the Sideboard.
However, Arduino does not receive anything via serial. In fact, I have enabled DEBUG_RX in the Arduino program and I only receive 0s.
I have also tested to disable DMP as said in this comment, but again nothing happens.
I don't know what is wrong and I don't have more ideas. Any help would be appreciated.
Thanks

Support for GD32F130C8T6 based board

Is this firmware compatible with my GD32F130C8T6 board? It looks like this chip has double the flash and ram, but otherwise the same as the 6T6.

GD32F130C8T6

My sideboard chipset is GD32F130C8T6 different from yours (C6T6). I have flashed your firm ware to my chip success but it can't read MPU data. Do you know what i have to do to make project is suitable with C8T6 chip

Zero value and IMU failed

Hey @EmanuelFeru,
I followed all the steps to get sideboard data (GD32F130C6T6 with MPU-6050A).
I unlocked the board and got it flashed. However, when I monitored Euler value I got only zeros.

Command = e
Roll:0 Pitch:0 Yaw:0
Roll:0 Pitch:0 Yaw:0
Roll:0 Pitch:0 Yaw:0
Roll:0 Pitch:0 Yaw:0
Roll:0 Pitch:0 Yaw:0
Roll:0 Pitch:0 Yaw:0

When I run a self-test, I get this result

accel: 319802219 -323885 134236467
gyro: -1743067344 1087314292 -1256236507
Gyro failed
Accel failed
Compass failed

Any idea what's causing this ?
Thanks for your help
Cheers 😃

PS: After the flash, I have a steady green LED light.

Help with this board

So I've cracked an old hoverboard containing these identical 2 pcbs. It uses GD32F130C6T6 (reports 32k, I was able to upload the whole bin file, I had to hold the power button during flash)
And I was able to compile & flash the DEBUG example without the MPU_SENSOR definition
IMG_20220404_194632

Any help of the pinout of where is that UART that I can hook and observe/send commands?
One additional question - with that VARIANT_DEBUG can I send commands to move the motor? and what I should use if that's not the right variant (not interested in MPU sensor just sending command to move in specified direction and speed)

getting Cortex M3 legacy target in uVision

Here is a picture of the Windgoo sensorboard that was inside my Hoverboard. The SWD programming pins are directly below the connector for the mainboard. I have measured the pins and added them to the picture.
Windgoo_Hoverboard_GD_sensorboard-SWD-programming

Connecting the board through ST-Link utility and unlocking the flash went okay. No errors.

After that I tried to install uVision and open the .UVPROJ file but I get a lot of errors about missing files for the M3 Cortex boards. Probably the custom algorithm for the flashing utility. I have tried to install the legacy database but not sure what to do next.

The Hex file that is already in the build folder of the repository doesn't flash with ST-Link utility. Is it possible to get a pre-build bin file of the Hoverboard version?

Firmware.bin Will Not Flash

I tried forking the code and when I try and upload firmware.bin it will not download, ST-Link is saying "warning core is locked up." It will download firmware.elf (idk what that is) and when I power the board it beeps in sets of three. I am attempting to use US_ARtT variant. When I hook it to an Arduino it seems to have no effect.

New Sideboard layout found with same processor

I have a new variant of sideboard with 2 led headers and a slightly changed pinout. I will update with the pinout I find.
20231031_131136~2

So far, a lot of the pins line up for the sensors and battery meter pins. One notable difference is that this board is fed +36V instead of +15V, so the LEDs are most likely a different voltage config. There is also 3 colors in the front lights, so they are potentially RGB. will update!

Hoverboard not working

I tried forking the code and when I try and upload firmware.bin it will not download, ST-Link is saying "warning core is locked up." It will download firmware.elf (idk what that is) and when I power the board it beeps in sets of three. I am attempting to use US_ARtT variant. When I hook it to an Arduino it seems to have no effect.

debug variant not compiling

Hello, i'm trying to compile a debug variant, however i get the following error:

/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: build/firmware.elf section .rodata' will not fit in region FLASH'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 2696 bytes

so it seems it's bigger than flash region on the GD chip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.