refactor: make blinky an example
This commit is contained in:
parent
3c3066afe2
commit
1aac7bd456
4 changed files with 36 additions and 26 deletions
|
@ -3,6 +3,7 @@ target = "thumbv6m-none-eabi"
|
|||
|
||||
[target.thumbv6m-none-eabi]
|
||||
runner = 'probe-rs run --chip STM32L053R8'
|
||||
rustflags = ["-Clink-args=-Tlink.x"]
|
||||
|
||||
[alias]
|
||||
cflash = "flash --chip STM32L053R8"
|
||||
|
|
3
build.rs
3
build.rs
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
}
|
34
examples/blinky.rs
Executable file
34
examples/blinky.rs
Executable file
|
@ -0,0 +1,34 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use hal::{pac, prelude::*, rcc::Config};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
// Configure the clock.
|
||||
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
||||
|
||||
// Acquire the GPIOA peripheral. This also enables the clock for GPIOA in
|
||||
// the RCC register.
|
||||
let gpioa = dp.GPIOA.split(&mut rcc);
|
||||
|
||||
// Configure PA1 as output.
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
|
||||
// Get the delay provider.
|
||||
let mut delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
loop {
|
||||
led.set_high().unwrap();
|
||||
delay.delay_ms(500_u16);
|
||||
|
||||
led.set_low().unwrap();
|
||||
delay.delay_ms(500_u16);
|
||||
}
|
||||
}
|
24
src/main.rs
24
src/main.rs
|
@ -8,27 +8,5 @@ use hal::{pac, prelude::*, rcc::Config};
|
|||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
// Configure the clock.
|
||||
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
||||
|
||||
// Acquire the GPIOA peripheral. This also enables the clock for GPIOA in
|
||||
// the RCC register.
|
||||
let gpioa = dp.GPIOA.split(&mut rcc);
|
||||
|
||||
// Configure PA1 as output.
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
|
||||
// Get the delay provider.
|
||||
let mut delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
loop {
|
||||
led.set_high().unwrap();
|
||||
delay.delay_ms(500_u16);
|
||||
|
||||
led.set_low().unwrap();
|
||||
delay.delay_ms(500_u16);
|
||||
}
|
||||
compile_error!("Use blinky example")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue