Trying embedded Rust on the Pinecil GD32VF103 RISC-V device.
My personal collection of Rust demos running on the PINE64 Pinecil portable soldering iron, featuring a GD32VF103TBU6 Risc-V microcontroller.
I do not guarantee the correctness of any code in this repository.
Obviously you'll need a Pinecil and a computer, and the USB Type-C cable to connect the two.
A not-too-outdated Rust compiler is expected. I am using rustc 1.50.0.
You need to add the relevant Rust compiler target:
$ rustup target add riscv32imac-unknown-none-elf
You will also need a GNU binutils objcopy
capable of producing a raw binary
file from an ELF file for flashing. Generally any objcopy
tools should work,
but I've mostly been using riscv-nuclei-elf-objcopy
from the Nuclei RISC-V
toolchain.
At last, you will need a tool to flash the resulting binary onto the device. If you have ever updated the firmware of your Pinecil, you should already have such a tool.
Building a demo is simple. This:
$ cargo build -p demo-00-blinky-raw-pointer --release
... will build the demo "00-blinky-raw-pointer" and produce the ELF file
target/riscv32imac-unknown-none-elf/release/demo-00-blinky-raw-pointer
.
To produce a flashable firmware binary, use objcopy
:
$ riscv-nuclei-elf-objcopy -O binary target/riscv32imac-unknown-none-elf/release/demo-00-blinky-raw-pointer firmware.bin
The resulting firmware.bin
can be flashed with dfu-util
or the
"GD32 Dfu Tool". The official firmware updater is also capable of
flashing the file, since it uses dfu-util
under the hood.
In the folder of each demo there is a readme file which provides some background information and special instructions.
riscv-rt
: https://docs.rs/riscv-rt/0.8.0/riscv_rt/
gd32vf103-pac
: https://docs.rs/gd32vf103-pac/0.4.0/gd32vf103_pac/
gd32vf103xx-hal
: https://docs.rs/gd32vf103xx-hal/0.4.0/gd32vf103xx_hal/
embedded-hal
: https://docs.rs/embedded-hal/0.2.4/embedded_hal/
ssd1306
: https://docs.rs/ssd1306/0.5.1/ssd1306/
cargo doc --open
.All code and resources in this repository are released under the MIT License, unless otherwise specified.
Rust and the Rust logo are trademarks owned by the Rust Foundation.
Ferris the crab is created by Karen Rustad Tölva and has been released into the Public Domain.
Copyright (c) 2021 Alvin Wong
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.