Compiling and flashing the firmware - EFeru/hoverboard-firmware-hack-FOC GitHub Wiki

Right to the STM32/GD32 chip, 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.

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

Do not power the mainboard from the 3.3V of your programmer! This has already killed multiple mainboards.

Make sure you hold the power button while flashing the firmware, as the STM will release the power latch and switch itself off during flashing. Battery > 36V have to be connected while flashing.

⚠If you are using a jumper instead of the power button, make sure you are not entering the Auto-Calibration by mistake, which would deactivate the inputs if you don't proceed with the calibration properly. If you face this issue, erase the chip in st-link utility before flashing the firmware, or do a proper auto-calibration⚠

To build and flash choose one of the following methods:

Method 0: Using GitHub Fork

  • Fork the project
  • Activate the workflows in the Actions tab
  • Remove the semicolon in front of the desired Variant in platformio.ini
  • 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 (see picture below)
  • Upload desired firmware.bin file using ST-Link Utility

Step by step video.

Download build

Method 1: Using Platformio IDE (recommended)

  • Install Vscode
  • Install Platformio
  • open the folder in Vscode
  • press the 'PlatformIO:Upload' button (bottom left in vscode) to build and upload the firmwware.

Method 2: Using Keil uVision

  • in Keil uVision, open the mainboard-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
  • or
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c flash "write_image erase build/hover.bin 0x8000000"

Method 4: MacOS CLI

  • prerequisites: first get brew https://brew.sh
  • then install stlink ST-Flash utility

Using Make

brew install stlink

You may also need to install arm-none-eabi-gcc:

brew install armmbed/formulae/arm-none-eabi-gcc
  • 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_####

If compiling fails because something is missing just install it with brew AND leave a comment to improve this howto or pull request ;-)

  • flash the firmware by typing:
make flash
  • if unlock is needed
make unlock

Using platformio CLI

brew install platformio
platformio run -e VARIANT_####
platformio run –target upload -e VARIANT_####

If you have set default_envs in platformio.ini you can ommit -e parameter

Troubleshooting

If you cannot flash the firmware:

  • If the LED on the ST-Link is blinking, the driver installation probably didn't go well
  • Make sure you properly soldered the headers/wires, good contact is mandatory to maintain proper connection during a few seconds for successfully flashing of the chip
  • Make sure your ST-Link dongle pins are real, by sliding the plastic cover and checking on the ST-Link board itself. An example can be seen here
  • Make sure you properly unlocked the chip
  • Make sure you don't have an already open connection to the chip in another software (st-link utility, ...)
  • Also keep in mind the debugging header pin-out can differ on some of the mainboards
  • If the led of the Stlink goes OFF and it gets disconnect, you have a short circuit somewhere on the mainboard