Board support crate for the Longan Nano board
-
Rust 1.36 or a newer toolchain. e.g.
rustup default stable
-
rust-std
components (pre-compiledcore
crate) for the RISC-V target. Run:
rustup target add riscv32imac-unknown-none-elf
-
RISC-V toolchain (e.g. from SiFive)
Start openocd:
/path/to/openocd -f sipeed-jtag.cfg -f openocd.cfg
Run one of the examples:
cargo run --example blinky
or
cargo run --release --example ferris --features lcd
RV-LINK is a Chinese firmware, similar to Black Magic Probe (BMP). It supports the Longan Nano, allowing to use one Longan Nano board as a debug probe for another one. It can be built & flashed via PlatformIO. Check out the latest version to ensure that the code compiles:
> git clone https://gitee.com/zoomdy/RV-LINK
> cd RV-LINK
> git tag
v0.0.1
v0.1
v0.2 # <- seems to be the latest tag, so let's check this out
> git checkout tags/v0.2
PlatformIO allows building & flashing of firmware with a single command. To do so, the board needs to be in bootloader mode (DFU mode). The board boots to bootloader mode if the bootloader button is pressed while powering it up (e.g. by plugging it in). However, it is also possible to enter bootloader mode without un- and replugging the board: press the boot button, press the reset button, release the reset button and finally release the boot button while the board is plugged in.
> pio run -t upload # put the board in bootloader mode before
Once RV-LINK is flashed to your probe, connect the eight debug pins on the probe with the debug pins on the debug target. Ensure that you connect the pins according to this table:
Probe Pin | Target Pin |
---|---|
JTDO | JTDO |
JTDI | JTDI |
JTCK | JTCK |
JTMS | JTMS |
3V3 | 3V3 |
GND | GND |
After you connected the debug probe to your host, a new serial port shows up.
You can connect GDB to this serial port as an extended-remote
. For
predictable behavior when multiple serial devices are present (and hence
/dev/ttyACM0
is not necessarily the RV-LINK device),
udev offers id symlinks.
However you may also use /dev/ttyACM0
or even COMx
if you run Windows.
> gdb
(gdb) target extended-remote /dev/serial/by-id/usb-RV-LINK_Longan_Nano_GD32XXX-3.0.0-7z8x9yer-if00
To flash the firmware, execute load
in GDB:
> gdb target/remote/debug/demo
(gdb) target extended-remote /dev/ttyACM0
(gdb) monitor reset halt
(gdb) load
(gdb) monitor reset
To improve your workflow, you can put the aforementioned GDB commands in
a debug.gdb
file and add these lines to .cargo/config
:
[target.riscv32imac-unknown-none-elf]
runner = 'gdb -command=debug.gdb'
This way cargo run --target riscv32imac-unknown-none-elf
will automatically
launch GDB, flash your firmware on the target and provide you with a full debug
environment.
Copyright 2019-2020 RISC-V team
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Contribution to this crate is organized under the terms of the Rust Code of Conduct, the maintainer of this crate, the RISC-V team, promises to intervene to uphold that code of conduct.