delay.rs 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //! "Blinky" using delays instead of a timer
  2. #![deny(unsafe_code)]
  3. #![deny(warnings)]
  4. #![no_main]
  5. #![no_std]
  6. extern crate panic_halt;
  7. use stm32f1xx_hal::{
  8. prelude::*,
  9. pac,
  10. delay::Delay,
  11. };
  12. use cortex_m_rt::entry;
  13. #[entry]
  14. fn main() -> ! {
  15. let dp = pac::Peripherals::take().unwrap();
  16. let cp = cortex_m::Peripherals::take().unwrap();
  17. let mut flash = dp.FLASH.constrain();
  18. let mut rcc = dp.RCC.constrain();
  19. let clocks = rcc.cfgr.freeze(&mut flash.acr);
  20. let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
  21. #[cfg(feature = "stm32f100")]
  22. let mut led = gpioc.pc9.into_push_pull_output(&mut gpioc.crh);
  23. #[cfg(feature = "stm32f103")]
  24. let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
  25. let mut delay = Delay::new(cp.SYST, clocks);
  26. loop {
  27. led.set_high();
  28. delay.delay_ms(1_000_u16);
  29. led.set_low();
  30. delay.delay_ms(1_000_u16);
  31. }
  32. }