init basic examples and setup
This commit is contained in:
14
examples/blinky-basic/Cargo.toml
Normal file
14
examples/blinky-basic/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "blinky-basic"
|
||||
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
|
||||
panic-probe.workspace = true
|
||||
stm32f1xx-hal = { workspace = true, features = ["medium", "stm32f103"] }
|
||||
9
examples/blinky-basic/build.rs
Normal file
9
examples/blinky-basic/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()
|
||||
);
|
||||
}
|
||||
37
examples/blinky-basic/src/main.rs
Normal file
37
examples/blinky-basic/src/main.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
#![deny(unsafe_code)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::info;
|
||||
use defmt_rtt as _;
|
||||
use panic_probe as _;
|
||||
use stm32f1xx_hal::{pac, prelude::*};
|
||||
|
||||
const ON_MS: u16 = 500;
|
||||
const OFF_MS: u16 = 500;
|
||||
|
||||
#[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);
|
||||
|
||||
// Splitting the GPIO block gives this function ownership of the LED pin.
|
||||
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||
let mut delay = cp.SYST.delay(&rcc.clocks);
|
||||
|
||||
info!("blinky-basic: PC13 LED is assumed active-low");
|
||||
|
||||
loop {
|
||||
led.set_low();
|
||||
info!("led on");
|
||||
delay.delay_ms(ON_MS);
|
||||
|
||||
led.set_high();
|
||||
info!("led off");
|
||||
delay.delay_ms(OFF_MS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user