Skip to content

Commit a230b98

Browse files
authored
examples: update blinky example to use GPIO driver (#26)
Use the recently completed GPIO driver in the blinky example
1 parent 4e2bed9 commit a230b98

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ codegen-units = 1 # better optimizations
6969
debug = true # symbols are nice and they don't increase the size in flash
7070
lto = true # better optimizations
7171
opt-level = "s" # optimize for binary size
72+
73+
[[example]]
74+
name = "blinky"
75+
required-features = ["stm32h503"]

examples/blinky.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#![no_main]
23
#![no_std]
34

@@ -6,7 +7,7 @@ mod utilities;
67
use cortex_m_rt::entry;
78
use embedded_hal::delay::DelayNs;
89
use fugit::SecsDurationU32;
9-
use stm32h5xx_hal::{delay::Delay, pac, prelude::*, rcc::ResetEnable};
10+
use stm32h5xx_hal::{delay::Delay, pac, prelude::*};
1011

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

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

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

3332
loop {
34-
dp.GPIOA.odr().write(|w| w.od5().low());
35-
delay.delay_ms(duration);
33+
led.set_low();
3634
log::info!("Off");
37-
dp.GPIOA.odr().write(|w| w.od5().high());
3835
delay.delay_ms(duration);
36+
led.set_high();
3937
log::info!("On");
38+
delay.delay_ms(duration);
4039
}
4140
}

0 commit comments

Comments
 (0)