-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ae89f2
commit 088dc69
Showing
16 changed files
with
300 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[target.'cfg(all(target_arch = "riscv32", target_os = "none"))'] | ||
runner = "qemu-system-riscv32 -machine sifive_e,revb=true -nographic -semihosting-config enable=on,target=native -kernel" # Uncomment for QEMU | ||
# runner = "riscv64-unknown-elf-gdb -q -x hifive1-examples/gdb_init" # Uncomment for hardware (no semihosting) | ||
# runner = "riscv64-unknown-elf-gdb -q -x hifive1-examples/gdb_init_sh" # Uncomment for hardware (semihosting) | ||
rustflags = [ | ||
"-C", "link-arg=-Thifive1-link.x", | ||
"--cfg", "portable_atomic_target_feature=\"zaamo\"", | ||
] | ||
|
||
[build] | ||
target = "riscv32imc-unknown-none-elf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "hifive1-examples" | ||
version = "0.1.0" | ||
repository = "https://github.com/riscv-rust/e310x" | ||
authors = ["David Craven <[email protected]>"] | ||
categories = ["embedded", "hardware-support", "no-std"] | ||
description = "Running examples for HiFive1 and LoFive boards" | ||
keywords = ["riscv", "register", "peripheral"] | ||
license = "ISC" | ||
edition = "2021" | ||
rust-version = "1.72" | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
critical-section = { version = "1.1.3" } | ||
hifive1 = { path = "../hifive1", version = "0.13.0", features = ["board-hifive1-revb"] } # Change to your board | ||
riscv-rt = { version = "0.12.2", features = ["single-hart"] } | ||
panic-halt = "0.2.0" | ||
semihosting = { version = "0.1", features = ["stdio", "panic-handler"], optional = true } | ||
|
||
[features] | ||
virq = ["hifive1/virq"] | ||
|
||
[[example]] | ||
name = "sh_hello_world" | ||
required-features = ["semihosting"] | ||
|
||
[[example]] | ||
name = "sh_led_blink" | ||
required-features = ["semihosting"] | ||
|
||
[[example]] | ||
name = "sh_rgb_blink" | ||
required-features = ["semihosting"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Basic blinking LEDs example using mtime/mtimecmp registers for "sleep" in a loop. | ||
//! Blinks each led once and goes to the next one. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use hifive1::{ | ||
clock, | ||
hal::{delay::Sleep, prelude::*, DeviceResources}, | ||
pin, sprintln, Led, | ||
}; | ||
extern crate panic_halt; | ||
|
||
#[riscv_rt::entry] | ||
fn main() -> ! { | ||
let dr = DeviceResources::take().unwrap(); | ||
let p = dr.peripherals; | ||
let pins = dr.pins; | ||
|
||
// Configure clocks | ||
let clocks = 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, | ||
); | ||
|
||
// get all 3 led pins in a tuple (each pin is it's own type here) | ||
let pin = pin!(pins, led_blue); | ||
let mut led = pin.into_inverted_output(); | ||
|
||
// Get the sleep struct from CLINT | ||
let clint = dr.core_peripherals.clint; | ||
let mut sleep = Sleep::new(clint.mtimecmp, clocks); | ||
|
||
const STEP: u32 = 1000; // 1s | ||
loop { | ||
Led::toggle(&mut led); | ||
sprintln!("LED toggled. New state: {}", led.is_on()); | ||
sleep.delay_ms(STEP); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! Prints "hello world!" to the host console using semihosting. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use semihosting::{println, process::exit}; | ||
|
||
#[riscv_rt::entry] | ||
fn main() -> ! { | ||
println!("Hello, world!"); | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Basic blinking LEDs example using mtime/mtimecmp registers for "sleep" in a loop. | ||
//! Blinks each led once and goes to the next one. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use hifive1::{ | ||
clock, | ||
hal::{delay::Sleep, prelude::*, DeviceResources}, | ||
pins, Led, | ||
}; | ||
use semihosting::{println, process::exit}; | ||
|
||
#[riscv_rt::entry] | ||
fn main() -> ! { | ||
let dr = DeviceResources::take().unwrap(); | ||
let p = dr.peripherals; | ||
let pins = dr.pins; | ||
|
||
// Configure clocks | ||
let clocks = clock::configure(p.PRCI, p.AONCLK, 320.mhz().into()); | ||
|
||
// get all 3 led pins in a tuple (each pin is it's own type here) | ||
let rgb_pins = pins!(pins, (led_red, led_green, led_blue)); | ||
let mut tleds = hifive1::rgb(rgb_pins.0, rgb_pins.1, rgb_pins.2); | ||
// get leds as the Led trait in an array so we can index them | ||
let mut ileds: [&mut dyn Led; 3] = [&mut tleds.0, &mut tleds.1, &mut tleds.2]; | ||
|
||
// Get the sleep struct from CLINT | ||
let clint = dr.core_peripherals.clint; | ||
let mut sleep = Sleep::new(clint.mtimecmp, clocks); | ||
|
||
const N_TOGGLES: usize = 4; | ||
const STEP: u32 = 500; // 500ms | ||
|
||
println!("Toggling LEDs {} times", N_TOGGLES); | ||
for _ in 0..N_TOGGLES { | ||
for (i, led) in ileds.iter_mut().enumerate() { | ||
led.toggle().unwrap(); | ||
println!("LED {i} toggled. New state: {}", led.is_on()); | ||
sleep.delay_ms(STEP); | ||
} | ||
} | ||
println!("Done toggling LEDs"); | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# GDB init file for HiFive1 boards | ||
|
||
# set history save on # uncomment to save history | ||
set confirm off | ||
set remotetimeout 240 | ||
set print asm-demangle on | ||
|
||
target extended-remote :3333 | ||
monitor reset halt | ||
load | ||
continue # uncomment to start running after loading | ||
# quit # uncomment to exit after loading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# GDB init file for HiFive1 boards (including semihosting) | ||
|
||
# set history save on # uncomment to save history | ||
set confirm off | ||
set remotetimeout 240 | ||
set print asm-demangle on | ||
|
||
target extended-remote :3333 | ||
monitor reset halt | ||
monitor arm semihosting enable | ||
load | ||
continue # uncomment to start running after loading | ||
# quit # uncomment to exit after loading |
Oops, something went wrong.