blinky.rs 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //! Blinks an LED
  2. #![deny(unsafe_code)]
  3. #![deny(warnings)]
  4. #![no_std]
  5. #![no_main]
  6. extern crate panic_halt;
  7. use nb::block;
  8. use stm32f1xx_hal::{
  9. prelude::*,
  10. pac,
  11. timer::Timer,
  12. };
  13. use cortex_m_rt::entry;
  14. #[entry]
  15. fn main() -> ! {
  16. let cp = cortex_m::Peripherals::take().unwrap();
  17. let dp = pac::Peripherals::take().unwrap();
  18. let mut flash = dp.FLASH.constrain();
  19. let mut rcc = dp.RCC.constrain();
  20. // Try a different clock configuration
  21. let clocks = rcc.cfgr.freeze(&mut flash.acr);
  22. // let clocks = rcc.cfgr
  23. // .sysclk(64.mhz())
  24. // .pclk1(32.mhz())
  25. // .freeze(&mut flash.acr);
  26. let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
  27. let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
  28. // Try a different timer (even SYST)
  29. let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
  30. loop {
  31. block!(timer.wait()).unwrap();
  32. led.set_high();
  33. block!(timer.wait()).unwrap();
  34. led.set_low();
  35. }
  36. }