blinky.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //! Blinks an LED
  2. //!
  3. //! This assumes that a LED is connected to pc13 as is the case on the blue pill board.
  4. //!
  5. //! Note: Without additional hardware, PC13 should not be used to drive an LED, see page 5.1.2 of
  6. //! the reference manaual for an explanation. This is not an issue on the blue pill.
  7. #![deny(unsafe_code)]
  8. #![deny(warnings)]
  9. #![no_std]
  10. #![no_main]
  11. extern crate panic_halt;
  12. use nb::block;
  13. use stm32f1xx_hal::{
  14. prelude::*,
  15. pac,
  16. timer::Timer,
  17. };
  18. use cortex_m_rt::entry;
  19. #[entry]
  20. fn main() -> ! {
  21. let cp = cortex_m::Peripherals::take().unwrap();
  22. let dp = pac::Peripherals::take().unwrap();
  23. let mut flash = dp.FLASH.constrain();
  24. let mut rcc = dp.RCC.constrain();
  25. // Try a different clock configuration
  26. let clocks = rcc.cfgr.freeze(&mut flash.acr);
  27. // let clocks = rcc.cfgr
  28. // .sysclk(64.mhz())
  29. // .pclk1(32.mhz())
  30. // .freeze(&mut flash.acr);
  31. let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
  32. let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
  33. // Try a different timer (even SYST)
  34. let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
  35. loop {
  36. block!(timer.wait()).unwrap();
  37. led.set_high();
  38. block!(timer.wait()).unwrap();
  39. led.set_low();
  40. }
  41. }