Skip to content

Commit 1fc51b5

Browse files
committed
Adapt examples to RISC-V rework
1 parent e61f99f commit 1fc51b5

File tree

16 files changed

+72
-68
lines changed

16 files changed

+72
-68
lines changed

e310x-hal/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
- Update `e310x` dependency and adapt code
12+
1013
## [v0.12.0] - 2024-12-10
1114

1215
### Changed

e310x-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ embedded-io = "0.6.1"
1717
e310x = { path = "../e310x", version = "0.12.0", features = ["rt", "critical-section"] }
1818
nb = "1.0.0"
1919
portable-atomic = { version = "1.9", default-features = false}
20-
riscv = { version = "0.12.1", features = ["critical-section-single-hart"] }
20+
riscv = { version = "0.14.0", features = ["critical-section-single-hart"] }
2121

2222
[features]
2323
g002 = ["e310x/g002"]

e310x/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- The I2C0 code is now gated under the `g002` feature
1313
- Regenerate code with `svd2rust` 0.36.1
14-
- Use `riscv` v0.13.0 and `riscv-rt` v0.14.0
14+
- Use `riscv` v0.14.0, `riscv-peripheral` v0.3.0, and `riscv-rt` v0.15.0
1515
- In vectored mode, align `mtvec` to 64 bytes
1616

1717
## [v0.12.0] - 2024-12-10

e310x/Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ edition = "2021"
1212

1313
[dependencies]
1414
critical-section = { version = "1.2.0", optional = true }
15-
riscv = { git = "https://github.com/rust-embedded/riscv.git", branch = "riscv-peripheral-rework" }
16-
riscv-peripheral = { git = "https://github.com/rust-embedded/riscv.git", branch = "riscv-peripheral-rework" }
17-
riscv-rt = { git = "https://github.com/rust-embedded/riscv.git", branch = "riscv-peripheral-rework", features = ["no-interrupts"], optional = true }
18-
# riscv = "0.13.0"
19-
# riscv-peripheral = "0.2.0"
20-
# riscv-rt = { version = "0.14.0", features = ["no-interrupts"], optional = true }
15+
riscv = "0.14.0"
16+
riscv-peripheral = "0.3.0"
17+
riscv-rt = { version = "0.15.0", features = ["no-interrupts"], optional = true }
2118
vcell = "0.1.3"
2219

2320
[features]

hifive1-examples/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ rust-version = "1.72"
1515
[dependencies]
1616
critical-section = { version = "1.2.0" }
1717
hifive1 = { path = "../hifive1", version = "0.13.0", features = ["board-hifive1-revb"] } # Change to your board
18-
riscv = { version = "0.13.0" }
19-
riscv-rt = { version = "0.14.0", features = ["single-hart"] }
18+
riscv = { version = "0.14.0" }
19+
riscv-rt = { version = "0.15.0", features = ["single-hart"] }
2020
panic-halt = "1.0.0"
2121
semihosting = { version = "0.1", features = ["stdio", "panic-handler"] }
22-
# max3010x = "0.2.0" # TODO uncomment when the driver is published
23-
max3010x = { git = "https://github.com/eldruin/max3010x-rs.git" }
22+
max3010x = "0.2.0"
2423
mfrc522 = "0.8.0"
2524

2625
[features]

hifive1-examples/examples/button_poll.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Example of polling a button and turning on a LED when the button is pressed.
1+
//! Example of polling a button and turning on an LED when the button is pressed.
22
//!
33
//! # Hardware
44
//!
@@ -10,22 +10,23 @@
1010

1111
use hifive1::{
1212
clock,
13-
hal::{e310x::CLINT, prelude::*, DeviceResources},
14-
pin, sprintln, Led,
13+
hal::{prelude::*, DeviceResources},
14+
pin, sprintln, stdout, Led,
1515
};
1616
extern crate panic_halt;
1717

1818
#[riscv_rt::entry]
1919
fn main() -> ! {
2020
let dr = DeviceResources::take().unwrap();
21+
let cp = dr.core_peripherals;
2122
let p = dr.peripherals;
2223
let pins = dr.pins;
2324

2425
// Configure clocks
2526
let clocks = clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
2627

2728
// Configure UART for stdout
28-
hifive1::stdout::configure(
29+
stdout::configure(
2930
p.UART0,
3031
pin!(pins, uart0_tx),
3132
pin!(pins, uart0_rx),
@@ -40,8 +41,8 @@ fn main() -> ! {
4041
let pin = pin!(pins, led_blue);
4142
let mut led = pin.into_inverted_output();
4243

43-
// Get the sleep struct from CLINT
44-
let mut sleep = CLINT::delay();
44+
// Get the MTIMER peripheral from CLINT
45+
let mut mtimer = cp.clint.mtimer();
4546

4647
const STEP: u32 = 1000; // 1s
4748
loop {
@@ -53,6 +54,6 @@ fn main() -> ! {
5354
led.off();
5455
}
5556
sprintln!("LED is on: {}", led.is_on());
56-
sleep.delay_ms(STEP);
57+
mtimer.delay_ms(STEP);
5758
}
5859
}

hifive1-examples/examples/hello_world.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
//! Prints "hello world!" to the host console.
2-
//!
3-
//! If "semihosting" feature is enabled, the message is printed using semihosting.
4-
//! Otherwise, the message is printed using the UART0 peripheral.
1+
//! Prints "hello world!" to the host console using the UART0 peripheral.
52
63
#![no_std]
74
#![no_main]
85

96
extern crate panic_halt;
107
use hifive1::{
8+
clock,
119
hal::{prelude::*, DeviceResources},
12-
pin, sprintln as println,
10+
pin, sprintln, stdout,
1311
};
1412

1513
#[riscv_rt::entry]
@@ -19,18 +17,18 @@ fn main() -> ! {
1917
let pins = dr.pins;
2018

2119
// Configure clocks
22-
let clocks = hifive1::clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
20+
let clocks = clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
2321

2422
// Configure UART for stdout
25-
hifive1::stdout::configure(
23+
stdout::configure(
2624
p.UART0,
2725
pin!(pins, uart0_tx),
2826
pin!(pins, uart0_rx),
2927
115_200.bps(),
3028
clocks,
3129
);
3230

33-
println!("Hello, world!");
31+
sprintln!("Hello, world!");
3432
loop {
3533
riscv::asm::wfi();
3634
}

hifive1-examples/examples/i2c_max3010x.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use hifive1::{
88
clock,
99
hal::{
10-
e310x::CLINT,
1110
i2c::{I2c, Speed},
1211
prelude::*,
1312
DeviceResources,
@@ -20,6 +19,7 @@ extern crate panic_halt;
2019
#[riscv_rt::entry]
2120
fn main() -> ! {
2221
let dr = DeviceResources::take().unwrap();
22+
let cp = dr.core_peripherals;
2323
let p = dr.peripherals;
2424
let pins = dr.pins;
2525

@@ -50,12 +50,12 @@ fn main() -> ! {
5050

5151
let mut data = [0; 3];
5252

53-
// Get the sleep struct from CLINT
54-
let mut sleep = CLINT::delay();
53+
// Get the MTIMER peripheral from CLINT
54+
let mut mtimer = cp.clint.mtimer();
5555
const STEP: u32 = 1000; // 1s
5656
loop {
5757
let samples_read = sensor.read_fifo(&mut data).unwrap();
5858
sprintln!("Samples read: {}", samples_read);
59-
sleep.delay_ms(STEP);
59+
mtimer.delay_ms(STEP);
6060
}
6161
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
//! Basic blinking LEDs example using mtime/mtimecmp registers for "sleep" in a loop.
2-
//! Blinks each led once and goes to the next one.
1+
//! Basic blinking LED example using mtime/mtimecmp registers for "sleep" in a loop.
2+
//! Blinks the blue LED of RED-V board.
33
44
#![no_std]
55
#![no_main]
66

77
use hifive1::{
88
clock,
9-
hal::{e310x::CLINT, prelude::*, DeviceResources},
10-
pin, sprintln, Led,
9+
hal::{prelude::*, DeviceResources},
10+
pin, sprintln, stdout, Led,
1111
};
1212
extern crate panic_halt;
1313

1414
#[riscv_rt::entry]
1515
fn main() -> ! {
1616
let dr = DeviceResources::take().unwrap();
17+
let cp = dr.core_peripherals;
1718
let p = dr.peripherals;
1819
let pins = dr.pins;
1920

2021
// Configure clocks
2122
let clocks = clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
2223

2324
// Configure UART for stdout
24-
hifive1::stdout::configure(
25+
stdout::configure(
2526
p.UART0,
2627
pin!(pins, uart0_tx),
2728
pin!(pins, uart0_rx),
@@ -33,13 +34,13 @@ fn main() -> ! {
3334
let pin = pin!(pins, led_blue);
3435
let mut led = pin.into_inverted_output();
3536

36-
// Get the sleep struct from CLINT
37-
let mut sleep = CLINT::delay();
37+
// Get the MTIMER peripheral from CLINT
38+
let mut mtimer = cp.clint.mtimer();
3839

3940
const STEP: u32 = 1000; // 1s
4041
loop {
4142
Led::toggle(&mut led);
4243
sprintln!("LED toggled. New state: {}", led.is_on());
43-
sleep.delay_ms(STEP);
44+
mtimer.delay_ms(STEP);
4445
}
4546
}

hifive1-examples/examples/led_pwm.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99

1010
use hifive1::{
1111
clock,
12-
hal::{e310x::CLINT, prelude::*, DeviceResources},
13-
pin, sprintln,
12+
hal::{prelude::*, DeviceResources},
13+
pin, sprintln, stdout,
1414
};
1515
extern crate panic_halt;
1616

1717
#[riscv_rt::entry]
1818
fn main() -> ! {
1919
let dr = DeviceResources::take().unwrap();
20+
let cp = dr.core_peripherals;
2021
let p = dr.peripherals;
2122
let pins = dr.pins;
2223

2324
// Configure clocks
2425
let clocks = clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
2526

2627
// Configure UART for stdout
27-
hifive1::stdout::configure(
28+
stdout::configure(
2829
p.UART0,
2930
pin!(pins, uart0_tx),
3031
pin!(pins, uart0_rx),
@@ -40,8 +41,8 @@ fn main() -> ! {
4041

4142
let mut channel = pwm0.channel(pin);
4243

43-
// Get the sleep struct from CLINT
44-
let mut sleep = CLINT::delay();
44+
// Get the MTIMER peripheral from CLINT
45+
let mut mtimer = cp.clint.mtimer();
4546

4647
const STEP: u32 = 1000; // 1s
4748
const DUTY_DELTA: u8 = 32;
@@ -52,6 +53,6 @@ fn main() -> ! {
5253
channel.set_duty_cycle(duty as u16).unwrap();
5354
duty = duty.wrapping_add(DUTY_DELTA);
5455

55-
sleep.delay_ms(STEP);
56+
mtimer.delay_ms(STEP);
5657
}
5758
}

0 commit comments

Comments
 (0)