delay.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //! "Blinky" using delays instead of a timer
  2. #![deny(unsafe_code)]
  3. #![no_main]
  4. #![no_std]
  5. use panic_halt as _;
  6. use stm32f1xx_hal::{
  7. prelude::*,
  8. pac,
  9. delay::Delay,
  10. };
  11. use cortex_m_rt::entry;
  12. use embedded_hal::digital::v2::OutputPin;
  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 = "stm32f101")]
  24. let mut led = gpioc.pc9.into_push_pull_output(&mut gpioc.crh);
  25. #[cfg(feature = "stm32f103")]
  26. let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
  27. let mut delay = Delay::new(cp.SYST, clocks);
  28. loop {
  29. led.set_high().unwrap();
  30. delay.delay_ms(1_000_u16);
  31. led.set_low().unwrap();
  32. delay.delay_ms(1_000_u16);
  33. }
  34. }