Skip to content

alvinhochun/gd32vf103-pinecil-demo-rs

Repository files navigation

Pinecil GD32VF103 RISC-V Rust Demos

Pinecil running OLED demo animation

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.

How to use

Prerequisite

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.

Optional goodies

  • An official Pinecil breakout board is strongly recommended since it allows you to connect the UART and/or a JTAG debugger.
  • A device to connect to the 3.3V UART is needed to make use of the UART, such as a USB to UART adapter, a single board computer like Raspberry Pi, or even an Arduino. Beware that if using a 5V UART device, you should not connect the TX pin of your device to the RX pin of the Pinecil directly, as the RX pin on the Pinecil is not 5V-tolerant. You can use a resistor voltage divider to convert the voltage level.
  • It may be nice to have a debugging setup using a JTAG debugger. If you use a JTAG, you probably also want OpenOCD and GDB. (Also check out my notes on connecting JTAG.)
  • An LED and a current-limiting resistor can be used to provide a binary output, as a simple indicator, or just to get started with a simple blinking LED demo.
  • Jumper wires with DuPont connectors to connect the pins, and a breadboard to go with it.
  • A multimeter is almost necessary for any electronics work.
  • A digital oscilloscope or a logic analyzer can also come in handy.

Running the demos

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.

Further reading

Licence

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.

About

Trying embedded Rust on the Pinecil GD32VF103 RISC-V device.

Topics

Resources

License

Stars

Watchers

Forks