led.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 manaual for an explanation.
  10. //! This is not an issue on the blue pill.
  11. #![deny(unsafe_code)]
  12. #![deny(warnings)]
  13. #![no_main]
  14. #![no_std]
  15. extern crate panic_halt;
  16. extern crate cortex_m_rt as rt;
  17. use stm32f1xx_hal::{
  18. prelude::*,
  19. pac,
  20. };
  21. use cortex_m_rt::entry;
  22. #[entry]
  23. fn main() -> ! {
  24. let p = pac::Peripherals::take().unwrap();
  25. let mut rcc = p.RCC.constrain();
  26. let mut gpioc = p.GPIOC.split(&mut rcc.apb2);
  27. #[cfg(feature = "stm32f100")]
  28. gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high();
  29. #[cfg(feature = "stm32f103")]
  30. gpioc.pc13.into_push_pull_output(&mut gpioc.crh).set_low();
  31. loop {}
  32. }