Skip to content

Commit ddc85fd

Browse files
committed
adapt to riscv 0.12
1 parent 05e9308 commit ddc85fd

File tree

9 files changed

+22
-40
lines changed

9 files changed

+22
-40
lines changed

hifive1-examples/Cargo.toml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,12 @@ rust-version = "1.72"
1313
[workspace]
1414

1515
[dependencies]
16-
critical-section = { version = "1.1.3" }
17-
hifive1 = { path = "../hifive1", version = "0.13.0", features = ["board-hifive1-revb"] } # Change to your board
18-
riscv = { version = "0.11.0" }
19-
riscv-rt = { version = "0.12.2", features = ["single-hart"] }
16+
critical-section = { version = "1.2.0" }
17+
hifive1 = { path = "../hifive1", version = "0.14.0", features = ["board-hifive1-revb"] } # Change to your board
18+
riscv = { version = "0.12.1" }
19+
riscv-rt = { version = "0.13.0", features = ["single-hart"] }
2020
panic-halt = "0.2.0"
21-
semihosting = { version = "0.1", features = ["stdio", "panic-handler"], optional = true }
21+
semihosting = { version = "0.1", features = ["stdio", "panic-handler"] }
2222

2323
[features]
24-
virq = ["hifive1/virq"]
25-
26-
[[example]]
27-
name = "sh_hello_world"
28-
required-features = ["semihosting"]
29-
30-
[[example]]
31-
name = "sh_led_blink"
32-
required-features = ["semihosting"]
33-
34-
[[example]]
35-
name = "sh_rgb_blink"
36-
required-features = ["semihosting"]
24+
v-trap = ["hifive1/v-trap"]

hifive1-examples/examples/button_poll.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use hifive1::{
1212
clock,
13-
hal::{delay::Sleep, prelude::*, DeviceResources},
13+
hal::{e310x::CLINT, prelude::*, DeviceResources},
1414
pin, sprintln, Led,
1515
};
1616
extern crate panic_halt;
@@ -41,8 +41,7 @@ fn main() -> ! {
4141
let mut led = pin.into_inverted_output();
4242

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

4746
const STEP: u32 = 1000; // 1s
4847
loop {

hifive1-examples/examples/led_blink.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use hifive1::{
88
clock,
9-
hal::{delay::Sleep, prelude::*, DeviceResources},
9+
hal::{e310x::CLINT, prelude::*, DeviceResources},
1010
pin, sprintln, Led,
1111
};
1212
extern crate panic_halt;
@@ -34,8 +34,7 @@ fn main() -> ! {
3434
let mut led = pin.into_inverted_output();
3535

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

4039
const STEP: u32 = 1000; // 1s
4140
loop {

hifive1-examples/examples/led_pwm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use hifive1::{
1111
clock,
12-
hal::{delay::Sleep, prelude::*, DeviceResources},
12+
hal::{e310x::CLINT, prelude::*, DeviceResources},
1313
pin, sprintln,
1414
};
1515
extern crate panic_halt;
@@ -41,8 +41,7 @@ fn main() -> ! {
4141
let mut channel = pwm0.channel(pin);
4242

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

4746
const STEP: u32 = 1000; // 1s
4847
const DUTY_DELTA: u8 = 32;

hifive1-examples/examples/rgb_blink.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use hifive1::{
88
clock,
9-
hal::{delay::Sleep, prelude::*, DeviceResources},
9+
hal::{e310x::CLINT, prelude::*, DeviceResources},
1010
pin, pins, sprintln, Led,
1111
};
1212
extern crate panic_halt;
@@ -36,8 +36,7 @@ fn main() -> ! {
3636
let mut ileds: [&mut dyn Led; 3] = [&mut tleds.0, &mut tleds.1, &mut tleds.2];
3737

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

4241
const STEP: u32 = 1000; // 1s
4342
loop {

hifive1-examples/examples/sh_hello_world.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![no_std]
44
#![no_main]
55

6+
extern crate hifive1;
67
use semihosting::{println, process::exit};
78

89
#[riscv_rt::entry]

hifive1-examples/examples/sh_led_blink.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use hifive1::{
88
clock,
9-
hal::{delay::Sleep, prelude::*, DeviceResources},
9+
hal::{e310x::CLINT, prelude::*, DeviceResources},
1010
pin, Led,
1111
};
1212
use semihosting::{println, process::exit};
@@ -25,8 +25,7 @@ fn main() -> ! {
2525
let mut led = pin.into_inverted_output();
2626

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

3130
const N_TOGGLE: usize = 4;
3231
const STEP: u32 = 500; // 500 ms

hifive1-examples/examples/sh_rgb_blink.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use hifive1::{
88
clock,
9-
hal::{delay::Sleep, prelude::*, DeviceResources},
9+
hal::{e310x::CLINT, prelude::*, DeviceResources},
1010
pins, Led,
1111
};
1212
use semihosting::{println, process::exit};
@@ -27,8 +27,7 @@ fn main() -> ! {
2727
let mut ileds: [&mut dyn Led; 3] = [&mut tleds.0, &mut tleds.1, &mut tleds.2];
2828

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

3332
const N_TOGGLES: usize = 4;
3433
const STEP: u32 = 500; // 500ms

hifive1-examples/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use hifive1::{
1414
pin, sprintln,
1515
};
1616

17-
#[cfg(not(feature = "semihosting"))]
1817
extern crate panic_halt;
19-
#[cfg(feature = "semihosting")]
20-
extern crate semihosting;
2118

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

4037
sprintln!("Hello, world!");
4138

42-
loop {}
39+
loop {
40+
riscv::asm::wfi();
41+
}
4342
}

0 commit comments

Comments
 (0)