-
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
f7e9e47
commit 4ae89f2
Showing
7 changed files
with
146 additions
and
8 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,34 @@ | ||
//! Prints "hello world!" to the host console using semihosting and the on-board UART. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use hifive1::{ | ||
hal::{prelude::*, DeviceResources}, | ||
pin, sprintln, | ||
}; | ||
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 = 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, | ||
); | ||
|
||
sprintln!("STDOUT: hello world!"); | ||
println!("Semihosting: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! 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, Led, | ||
}; | ||
use semihosting::println; | ||
|
||
#[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 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); | ||
|
||
println!("Starting blink loop"); | ||
|
||
const STEP: u32 = 1000; // 1s | ||
loop { | ||
Led::toggle(&mut led); | ||
println!("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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! 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; | ||
|
||
#[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); | ||
|
||
println!("Starting blink loop"); | ||
|
||
const STEP: u32 = 1000; // 1s | ||
loop { | ||
for (i, led) in ileds.iter_mut().enumerate() { | ||
led.toggle().unwrap(); | ||
println!("LED {i} 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