Skip to content

Commit

Permalink
Blinking LED
Browse files Browse the repository at this point in the history
This one actually blinks!

(example code from stm32l1xx-hal)
  • Loading branch information
englishm committed Aug 14, 2023
1 parent 051e24c commit 7966484
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cortex-m = "^0.6.3" # Access to the generic ARM peripherals
cortex-m-rt = "^0.6.12" # Startup code for the ARM Core
embedded-hal = "^0.2.4" # Access to generic embedded functions (`set_high`)
panic-halt = "^0.2.0" # Panic handler
panic-semihosting = "0.6.0"

# Access the SMT32L152TB6 HAL
[dependencies.stm32l1xx-hal]
Expand Down
25 changes: 11 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@

extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;
extern crate stm32l1xx_hal as hal;

use core::panic::PanicInfo;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::v2::ToggleableOutputPin;
use hal::prelude::*;
use hal::rcc::Config;
use hal::stm32;
use rt::entry;

#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();

let rcc = dp.RCC.freeze(Config::default());
let mut delay = cp.SYST.delay(rcc.clocks);

let gpiob = dp.GPIOB.split();
let mut led = gpiob.pb7.into_push_pull_output();
let mut led = gpiob.pb6.into_push_pull_output();

loop {
for _ in 0..1_000 {
led.set_high().unwrap();
}
for _ in 0..1_000 {
led.set_low().unwrap();
}
led.toggle().unwrap();
delay.delay(300.ms());
}
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}

0 comments on commit 7966484

Please sign in to comment.