refactor: use a proper delay instead of a useless for loop
It blinks every 500ms or so!
This commit is contained in:
parent
2d8bfaad02
commit
af4fed51ae
3 changed files with 11 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -123,6 +123,7 @@ checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
|||
name = "nucleo-l053r8-blink"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cortex-m",
|
||||
"cortex-m-rt",
|
||||
"panic-halt",
|
||||
"stm32l0xx-hal",
|
||||
|
|
|
@ -5,6 +5,7 @@ edition = "2024"
|
|||
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7.7"
|
||||
cortex-m-rt = "0.7.5"
|
||||
panic-halt = "1.0.0"
|
||||
stm32l0xx-hal = { version = "0.10.0", features = [
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -1,4 +1,3 @@
|
|||
#![deny(unsafe_code)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
|
@ -10,6 +9,7 @@ use stm32l0xx_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());
|
||||
|
@ -21,15 +21,14 @@ fn main() -> ! {
|
|||
// Configure PA1 as output.
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
|
||||
loop {
|
||||
// Set the LED high one million times in a row.
|
||||
for _ in 0..1_000_000 {
|
||||
led.set_high().unwrap();
|
||||
}
|
||||
// Get the delay provider.
|
||||
let mut delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
// Set the LED low one million times in a row.
|
||||
for _ in 0..1_000_000 {
|
||||
led.set_low().unwrap();
|
||||
}
|
||||
loop {
|
||||
led.set_high().unwrap();
|
||||
delay.delay_ms(500_u16);
|
||||
|
||||
led.set_low().unwrap();
|
||||
delay.delay_ms(500_u16);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue