led.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 stm32f1xx_hal::{
  16. prelude::*,
  17. pac,
  18. };
  19. use cortex_m_rt::entry;
  20. use embedded_hal::digital::v2::OutputPin;
  21. #[entry]
  22. fn main() -> ! {
  23. let p = pac::Peripherals::take().unwrap();
  24. let mut rcc = p.RCC.constrain();
  25. let mut gpioc = p.GPIOC.split(&mut rcc.apb2);
  26. #[cfg(feature = "stm32f100")]
  27. gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high().unwrap();
  28. #[cfg(feature = "stm32f101")]
  29. gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high().unwrap();
  30. #[cfg(feature = "stm32f103")]
  31. gpioc.pc13.into_push_pull_output(&mut gpioc.crh).set_low().unwrap();
  32. loop {}
  33. }