TBD
Install a toolchain
The Gigadevices GD32F103 is a clone or a copy (not really clear at the moment of writing) of the well known STM32F103 chip. This chip is based on the ARM Cortex-M3 core and should be able to run on 108MHz.
To be able to use the the freshest toolchain we are not going to install the Ubuntu default one, but one provided from a ARM provided PPA.
Programmer
Programming the GD32F103 can be done with an ST-Link/V2 programmer. A cheap clone should work too.
(A generic clone)
Install the prerequisite libraries onto your system, we need libusb-1.0:
sudo apt-get install libusb-1.0-0-dev
Get the stlink tool from github:
git clone https://github.com/texane/stlink
cd stlink
./autogen.sh
If the last command complained about autoreconf or something else missing, then issue a:
sudo apt-get install autotools
That will install autoconf and companion tools.
If all went fine then do:
./configure
make
When that finishes without errors then install the tool:
sudo make install
Finally we need to permit access to out programmer. Copy the three .rules files to the directory named /etc/udev/rules.d. You need to do that as root.
sudo cp 49-stlinkv* /etc/udev/rules.d/
Then summon the udev gods to reload the rules:
sudo udevadm control --reload
Now your ST-Link/V2 should be ready to work with the GD32 chips.
Testing it out by erasing a device should go like this:
st-flash erase
2015-12-16T10:07:22 INFO src/stlink-common.c: Loading device parameters....
2015-12-16T10:07:22 INFO src/stlink-common.c: Device connected is: F1 Medium-density device, id 0x13030410
2015-12-16T10:07:22 INFO src/stlink-common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x8000 bytes (32 KiB) in pages of 1024 bytes
Mass erasing
Flashing a device
st-flash --reset write Project.bin 0x8000000
Should give you something like this:
2015-12-16T11:13:37 INFO src/stlink-usb.c: -- exit_dfu_mode
2015-12-16T11:13:37 INFO src/stlink-common.c: Loading device parameters....
2015-12-16T11:13:37 INFO src/stlink-common.c: Device connected is: F1 Medium-density device, id 0x13030410
2015-12-16T11:13:37 INFO src/stlink-common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x8000 bytes (32 KiB) in pages of 1024 bytes
2015-12-16T11:13:37 INFO src/stlink-common.c: Attempting to write 14068 (0x36f4) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08003400 erased
2015-12-16T11:13:38 INFO src/stlink-common.c: Finished erasing 14 pages of 1024 (0x400) bytes
2015-12-16T11:13:38 INFO src/stlink-common.c: Starting Flash write for VL/F0/F3 core id
2015-12-16T11:13:38 INFO src/stlink-common.c: Successfully loaded flash loader in sram
13/13 pages written
2015-12-16T11:13:39 INFO src/stlink-common.c: Starting verification of write complete
2015-12-16T11:13:39 INFO src/stlink-common.c: Flash written and verified! jolly good!
OpenOCD
Using OpenOCD it is also possible to flash the GD32F103. This is a link to a post on RCGroups on how to program the device using openocd instead of st-flash.