rtc.rs 643 B

1234567891011121314151617181920212223242526272829303132
  1. //! Outputs the current time in seconds to hstdout using the real time clock
  2. #![deny(unsafe_code)]
  3. #![deny(warnings)]
  4. #![no_std]
  5. #![no_main]
  6. extern crate panic_semihosting;
  7. use cortex_m_semihosting::hprintln;
  8. use stm32f1xx_hal::{
  9. prelude::*,
  10. pac,
  11. rtc::Rtc,
  12. };
  13. use cortex_m_rt::entry;
  14. #[entry]
  15. fn main() -> ! {
  16. let p = pac::Peripherals::take().unwrap();
  17. let mut pwr = p.PWR;
  18. let mut rcc = p.RCC.constrain();
  19. let mut backup_domain = rcc.bkp.constrain(p.BKP, &mut rcc.apb1, &mut pwr);
  20. let rtc = Rtc::rtc(p.RTC, &mut backup_domain);
  21. loop {
  22. hprintln!("time: {}", rtc.seconds()).unwrap();
  23. }
  24. }