Improve example to not hold on to the criticial section

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
This commit is contained in:
Daniel Egger 2019-08-04 12:16:30 +02:00
parent d5568bef8c
commit 3b124efe23
1 changed files with 13 additions and 13 deletions

View File

@ -13,25 +13,25 @@ use cortex_m_rt::entry;
#[entry]
fn main() -> ! {
if let Some(mut p) = stm32::Peripherals::take() {
cortex_m::interrupt::free(move |cs| {
let mut led = cortex_m::interrupt::free(|cs| {
let mut rcc = p.RCC.configure().sysclk(8.mhz()).freeze(&mut p.FLASH);
let gpioa = p.GPIOA.split(&mut rcc);
// (Re-)configure PA1 as output
let mut led = gpioa.pa1.into_push_pull_output(cs);
loop {
// Turn PA1 on a million times in a row
for _ in 0..1_000_000 {
led.set_high();
}
// Then turn PA1 off a million times in a row
for _ in 0..1_000_000 {
led.set_low();
}
}
gpioa.pa1.into_push_pull_output(cs)
});
loop {
// Turn PA1 on a million times in a row
for _ in 0..1_000_000 {
led.set_high();
}
// Then turn PA1 off a million times in a row
for _ in 0..1_000_000 {
led.set_low();
}
}
}
loop {