//! Blinks an LED using the real time clock to time the blinks #![deny(unsafe_code)] #![deny(warnings)] #![no_std] #![no_main] extern crate panic_halt; use stm32f1xx_hal::{ prelude::*, pac, rtc::Rtc, }; use nb::block; use cortex_m_rt::entry; #[entry] fn main() -> ! { let dp = pac::Peripherals::take().unwrap(); let mut pwr = dp.PWR; let mut rcc = dp.RCC.constrain(); // Set up the GPIO pin let mut gpioc = dp.GPIOC.split(&mut rcc.apb2); let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); // Set up the RTC // Enable writes to the backup domain let mut backup_domain = rcc.bkp.constrain(dp.BKP, &mut rcc.apb1, &mut pwr); // Start the RTC let mut rtc = Rtc::rtc(dp.RTC, &mut backup_domain); let mut led_on = false; loop { // Set the current time to 0 rtc.set_seconds(0); // Trigger the alarm in 5 seconds rtc.set_alarm(5); block!(rtc.wait_alarm()).unwrap(); if led_on { led.set_low(); led_on = false; } else { led.set_high(); led_on = true; } } }