Bart Massey 2024-07-29
This demo is a blinky for the Longan Nano RISC-V embedded board.
The instructions below are for a reasonably current Debian Linux host. You are on your own for others.
Unplug your Longan Nano from USB if plugged in.
Install 99-ftdi.rules
from this directory in
/etc/udev/rules.d/
and run
udevadm control --reload-rules
cargo install cargo-binutils
rustup component add llvm-tools-preview
- Get the Rust compiler for this chipset.
You are then ready to build a binary.
cargo objcopy --release -- -O binary nanoblinky.bin
Now grab and install the Sipeed dfu-util
from the link
below. Sadly stock Debian dfu-util
does not appear to work
with this board.
-
Hook your Longan Nano to your box via USB. The loader sometimes doesn't cope well with USB hubs, so if you have a problem try hooking directly to your host's USB.
-
Reset the Longan Nano by holding down the "BOOT" button (the taller one in the standard case, on the right when USB port is at the bottom), then pressing and releasing the "RESET" button (the other one).
-
Upload the demo.
sh dfuload.sh nanoblinky
You may need to power the Nano down and back up afterward.
The red LED should now be blinking once per second.
You'll need a JTAG unit to get started with this. I'm using the Sipeed USB-JTAG/TTL RISC-V Debugger, which is about $8. Connect as follows:
JTAG Nano
TDI JTDI
TMS JTMS
TDO JTDO
TCK JTCK
RXD R0
TXD T0
GND GND
You'll also need a version of OpenOCD that supports the
Nano's processor. Sadly, Debian's is not good enough: you'll
want to build and install
riscv-openocd
.
Finally, you'll need gdb-multiarch
or similar to actually
do the debugging.
Once you have everything set up, get the Nano ready for
upload as described at the beginning of this document
(+BOOT,+RESET,-RESET,-BOOT). Then run sh openocd.sh
. You
should see openocd
come up, give some mostly-meaningless
errors, then attach to your Nano. Go to a separate terminal
and run cargo run --release
. You should now see gdb
start up, upload nanoblinky.bin
, and start it running. Hit
^C
now to interrupt the running program. Gratz, you're
debugging away!
There's an older version of the Longan Nano that has less memory. I doubt anyone has one anymore. Anyway, all the stuff to handle these is here, but will require some rewiring to access.