init basic examples and setup
This commit is contained in:
15
examples/blinky-timer/Cargo.toml
Normal file
15
examples/blinky-timer/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "blinky-timer"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
cortex-m.workspace = true
|
||||
cortex-m-rt.workspace = true
|
||||
defmt.workspace = true
|
||||
defmt-rtt.workspace = true
|
||||
nb.workspace = true
|
||||
panic-probe.workspace = true
|
||||
stm32f1xx-hal = { workspace = true, features = ["medium", "stm32f103"] }
|
||||
9
examples/blinky-timer/build.rs
Normal file
9
examples/blinky-timer/build.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=../../memory.x");
|
||||
println!(
|
||||
"cargo:rustc-link-search={}",
|
||||
std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||
.join("../..")
|
||||
.display()
|
||||
);
|
||||
}
|
||||
35
examples/blinky-timer/src/main.rs
Normal file
35
examples/blinky-timer/src/main.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
#![deny(unsafe_code)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::info;
|
||||
use defmt_rtt as _;
|
||||
use nb::block;
|
||||
use panic_probe as _;
|
||||
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
|
||||
|
||||
const BLINK_HZ: u32 = 2;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
let mut rcc = dp.RCC.constrain();
|
||||
let mut gpioc = dp.GPIOC.split(&mut rcc);
|
||||
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||
|
||||
// A timer gives stable periodic work without burning cycles in a delay loop.
|
||||
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
|
||||
timer.start(BLINK_HZ.Hz()).unwrap();
|
||||
|
||||
led.set_high();
|
||||
info!("blinky-timer: {} Hz toggle loop", BLINK_HZ);
|
||||
|
||||
loop {
|
||||
block!(timer.wait()).unwrap();
|
||||
led.toggle();
|
||||
info!("tick");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user