Skip to content

Commit

Permalink
examples: update blinky example to use GPIO driver (#26)
Browse files Browse the repository at this point in the history
Use the recently completed GPIO driver in the blinky example
  • Loading branch information
astapleton authored Nov 18, 2024
1 parent 4e2bed9 commit a230b98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size in flash
lto = true # better optimizations
opt-level = "s" # optimize for binary size

[[example]]
name = "blinky"
required-features = ["stm32h503"]
15 changes: 7 additions & 8 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#![no_main]
#![no_std]

Expand All @@ -6,7 +7,7 @@ mod utilities;
use cortex_m_rt::entry;
use embedded_hal::delay::DelayNs;
use fugit::SecsDurationU32;
use stm32h5xx_hal::{delay::Delay, pac, prelude::*, rcc::ResetEnable};
use stm32h5xx_hal::{delay::Delay, pac, prelude::*};

#[entry]
fn main() -> ! {
Expand All @@ -22,20 +23,18 @@ fn main() -> ! {
let rcc = dp.RCC.constrain();
let ccdr = rcc.sys_ck(250.MHz()).freeze(pwrcfg, &dp.SBS);

ccdr.peripheral.GPIOA.enable();

dp.GPIOA.moder().write(|w| w.mode5().output()); // output
dp.GPIOA.pupdr().write(|w| w.pupd5().pull_up()); // pull-up
let gpioa = dp.GPIOA.split(ccdr.peripheral.GPIOA);
let mut led = gpioa.pa5.into_push_pull_output();

let mut delay = Delay::new(cp.SYST, &ccdr.clocks);
let duration = SecsDurationU32::secs(1).to_millis();

loop {
dp.GPIOA.odr().write(|w| w.od5().low());
delay.delay_ms(duration);
led.set_low();
log::info!("Off");
dp.GPIOA.odr().write(|w| w.od5().high());
delay.delay_ms(duration);
led.set_high();
log::info!("On");
delay.delay_ms(duration);
}
}

0 comments on commit a230b98

Please sign in to comment.