-
-
Save almindor/fc5b399a6c01a6c075638c202641a6ed to your computer and use it in GitHub Desktop.
Single LED blinking on Digital pin2 using cpu sleep
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
#![no_std] | |
#![no_main] | |
/* | |
* Basic blinking external LED using GPIO pin example. | |
* WARNING: requires a LED to be wired to physical PIN2 with at least | |
* a 320 Ohm resistor in series similar to | |
* https://create.arduino.cc/projecthub/rowan07/make-a-simple-led-circuit-ce8308 | |
*/ | |
extern crate panic_halt; | |
use riscv_rt::entry; | |
use hifive1::hal::prelude::*; | |
use hifive1::hal::delay::Sleep; | |
use hifive1::hal::DeviceResources; | |
use hifive1::pin; | |
#[entry] | |
fn main() -> ! { | |
let dr = DeviceResources::take().unwrap(); | |
let cp = dr.core_peripherals; | |
let p = dr.peripherals; | |
let gpio = dr.pins; | |
// Configure clocks | |
let clocks = hifive1::clock::configure(p.PRCI, p.AONCLK, 320.mhz().into()); | |
// GPIO PIN18 -> PIN2 physical on board (both hifive1 and hifive1-revB) | |
let mut eled = pin!(gpio, dig2).into_output(); | |
// get the sleep struct | |
let mut sleep = Sleep::new(cp.clint.mtimecmp, clocks); | |
const PERIOD: u32 = 1000; // 1s | |
loop { | |
eled.toggle().unwrap(); | |
// sleep for 1s | |
sleep.delay_ms(PERIOD); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment