I’m using the Rust RISC-V quickstart template from github, specifically the hello-world.rs. I modified the program to read the MISA register and print the contents instead of “hello, world.” I use
in one terminal, then in another I cargo build then cargo run the program. Using another terminal to run
sudo screen /dev/ttyACM0 115200
to display the sprintln! from the program. This works perfectly, but I found that if I connect the HiFive1 RevB board to my laptop and run the screen command with out JLink or cargo run I never see the sprintln!. How come I only see it print if I use GDB server and cargo run? Shouldn’t the program already be loaded to the microcontroller and run by itself? below is the program
#![no_std]
#![no_main]
extern crate panic_halt;
use riscv_rt::entry;
use hifive1::hal::prelude::*;
use hifive1::hal::DeviceResources;
use hifive1::{sprintln, pin};
#[entry]
fn main() -> ! {
let dr = DeviceResources::take().unwrap();
let p = dr.peripherals;
let pins = dr.pins;
// Configure clocks
let clocks = hifive1::clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
// Configure UART for stdout
hifive1::stdout::configure(p.UART0, pin!(pins, uart0_tx), pin!(pins, uart0_rx), 115_200.bps(), clocks);
//Read the misa CSR to see all implemented extensions
let ext = riscv::register::misa::read();
sprintln!("MISA register Contents: {}", ext.map_or(0, |v| v.bits()));
loop {}
}
You could accidentally erase the bootloader. To check this, connect to the serial port and reset the board. You should see a few messages from the bootloader. If there aren’t any, try restoring the bootloader: https://github.com/riscv-rust/hifive1-recover/tree/master/hifive1-revb
Sometimes there are problems with the very first sprintln, you can add another dummy sprintln before your “main” one.
Also, connecting the board and then connecting to the serial port will not show you the data you want because the serial port receiver on the board needs to know the correct baud rate to receive the data, so everything between poweron and serial connection will be lost.
It must be the bootloader was overwritten, I uploaded the leds_blink.rs then reset the ucontroller and it never blinked except after cargo run… I have another hifive1 that is at factory default and it always blinks green a time or two on reset. I will restore the bootloader tonight and try again.
How would I have overwritten the bootloader? I never did anything other than the basic instructions from github. Below are the details from flashing
Cargo run
IIRC there was a bug in LLVM (and therefore in Rust) a while ago, that, together with the hacky linker script in riscv-rt, produced an ELF file that was loaded to the beginning of the flash, effectively destroying the bootloader. I was about to add a big red warning to the quickstart repo, but then the bug was apparently fixed, so I ended up with the hifive1-recover repo I mentioned above.
Hmm, actually, according to the logs you posted, you have this problem right now, so I recommend you switching to the beta or nightly Rust compiler for now.
I don’t understand how to reload the bootloader from your link. I downloaded the .bin file into my JLink folder, along with the recover.jlink file. I cd into the JLink directory then tried to run
Okay I got it work this time I made “recover” a shell script and executed it and all went well. The board is working correctly now. Appreciate the link, now can I upload my program without wiping it out again
Neither one will compile any of the quick start examples, it says
error[E0463]: can't find crate for `core`
|
= note: the `riscv32imac-unknown-none-elf` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: could not compile `bit_field`.
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
If I switch back to stable rust, it compiles without fail.