led.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //! Turns the user LED on
  2. //!
  3. //! If compiled for the stm32f103, this assumes that an active low LED is connected to pc13 as
  4. //! is the case on the blue pill board.
  5. //!
  6. //! If compiled for the stm32f100, this assumes that an active high LED is connected to pc9
  7. //!
  8. //! Note: Without additional hardware, PC13 should not be used to drive a LED, see
  9. //! section 5.1.2 of the reference manual for an explanation.
  10. //! This is not an issue on the blue pill.
  11. #![deny(unsafe_code)]
  12. #![no_main]
  13. #![no_std]
  14. use panic_halt as _;
  15. use cortex_m_rt::entry;
  16. use embedded_hal::digital::v2::OutputPin;
  17. use stm32f1xx_hal::{pac, prelude::*};
  18. #[entry]
  19. fn main() -> ! {
  20. let p = pac::Peripherals::take().unwrap();
  21. let mut rcc = p.RCC.constrain();
  22. let mut gpioc = p.GPIOC.split(&mut rcc.apb2);
  23. #[cfg(feature = "stm32f100")]
  24. gpioc
  25. .pc9
  26. .into_push_pull_output(&mut gpioc.crh)
  27. .set_high()
  28. .unwrap();
  29. #[cfg(feature = "stm32f101")]
  30. gpioc
  31. .pc9
  32. .into_push_pull_output(&mut gpioc.crh)
  33. .set_high()
  34. .unwrap();
  35. #[cfg(any(feature = "stm32f103", feature = "stm32f105", feature = "stm32f107"))]
  36. gpioc
  37. .pc13
  38. .into_push_pull_output(&mut gpioc.crh)
  39. .set_low()
  40. .unwrap();
  41. loop {}
  42. }