Skip to content

Commit

Permalink
adapt to riscv 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Oct 22, 2024
1 parent 05e9308 commit ddc85fd
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 40 deletions.
24 changes: 6 additions & 18 deletions hifive1-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,12 @@ 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 = { version = "0.11.0" }
riscv-rt = { version = "0.12.2", features = ["single-hart"] }
critical-section = { version = "1.2.0" }
hifive1 = { path = "../hifive1", version = "0.14.0", features = ["board-hifive1-revb"] } # Change to your board
riscv = { version = "0.12.1" }
riscv-rt = { version = "0.13.0", features = ["single-hart"] }
panic-halt = "0.2.0"
semihosting = { version = "0.1", features = ["stdio", "panic-handler"], optional = true }
semihosting = { version = "0.1", features = ["stdio", "panic-handler"] }

[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"]
v-trap = ["hifive1/v-trap"]
5 changes: 2 additions & 3 deletions hifive1-examples/examples/button_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use hifive1::{
clock,
hal::{delay::Sleep, prelude::*, DeviceResources},
hal::{e310x::CLINT, prelude::*, DeviceResources},
pin, sprintln, Led,
};
extern crate panic_halt;
Expand Down Expand Up @@ -41,8 +41,7 @@ fn main() -> ! {
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);
let mut sleep = CLINT::delay();

const STEP: u32 = 1000; // 1s
loop {
Expand Down
5 changes: 2 additions & 3 deletions hifive1-examples/examples/led_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use hifive1::{
clock,
hal::{delay::Sleep, prelude::*, DeviceResources},
hal::{e310x::CLINT, prelude::*, DeviceResources},
pin, sprintln, Led,
};
extern crate panic_halt;
Expand Down Expand Up @@ -34,8 +34,7 @@ fn main() -> ! {
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);
let mut sleep = CLINT::delay();

const STEP: u32 = 1000; // 1s
loop {
Expand Down
5 changes: 2 additions & 3 deletions hifive1-examples/examples/led_pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use hifive1::{
clock,
hal::{delay::Sleep, prelude::*, DeviceResources},
hal::{e310x::CLINT, prelude::*, DeviceResources},
pin, sprintln,
};
extern crate panic_halt;
Expand Down Expand Up @@ -41,8 +41,7 @@ fn main() -> ! {
let mut channel = pwm0.channel(pin);

// Get the sleep struct from CLINT
let clint = dr.core_peripherals.clint;
let mut sleep = Sleep::new(clint.mtimecmp, clocks);
let mut sleep = CLINT::delay();

const STEP: u32 = 1000; // 1s
const DUTY_DELTA: u8 = 32;
Expand Down
5 changes: 2 additions & 3 deletions hifive1-examples/examples/rgb_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use hifive1::{
clock,
hal::{delay::Sleep, prelude::*, DeviceResources},
hal::{e310x::CLINT, prelude::*, DeviceResources},
pin, pins, sprintln, Led,
};
extern crate panic_halt;
Expand Down Expand Up @@ -36,8 +36,7 @@ fn main() -> ! {
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);
let mut sleep = CLINT::delay();

const STEP: u32 = 1000; // 1s
loop {
Expand Down
1 change: 1 addition & 0 deletions hifive1-examples/examples/sh_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![no_std]
#![no_main]

extern crate hifive1;
use semihosting::{println, process::exit};

#[riscv_rt::entry]
Expand Down
5 changes: 2 additions & 3 deletions hifive1-examples/examples/sh_led_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use hifive1::{
clock,
hal::{delay::Sleep, prelude::*, DeviceResources},
hal::{e310x::CLINT, prelude::*, DeviceResources},
pin, Led,
};
use semihosting::{println, process::exit};
Expand All @@ -25,8 +25,7 @@ fn main() -> ! {
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);
let mut sleep = CLINT::delay();

const N_TOGGLE: usize = 4;
const STEP: u32 = 500; // 500 ms
Expand Down
5 changes: 2 additions & 3 deletions hifive1-examples/examples/sh_rgb_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use hifive1::{
clock,
hal::{delay::Sleep, prelude::*, DeviceResources},
hal::{e310x::CLINT, prelude::*, DeviceResources},
pins, Led,
};
use semihosting::{println, process::exit};
Expand All @@ -27,8 +27,7 @@ fn main() -> ! {
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);
let mut sleep = CLINT::delay();

const N_TOGGLES: usize = 4;
const STEP: u32 = 500; // 500ms
Expand Down
7 changes: 3 additions & 4 deletions hifive1-examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use hifive1::{
pin, sprintln,
};

#[cfg(not(feature = "semihosting"))]
extern crate panic_halt;
#[cfg(feature = "semihosting")]
extern crate semihosting;

#[riscv_rt::entry]
fn main() -> ! {
Expand All @@ -39,5 +36,7 @@ fn main() -> ! {

sprintln!("Hello, world!");

loop {}
loop {
riscv::asm::wfi();
}
}

0 comments on commit ddc85fd

Please sign in to comment.