123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //! Blinks an LED
- //!
- //! This assumes that a LED is connected to pc13 as is the case on the blue pill board.
- //!
- //! Note: Without additional hardware, PC13 should not be used to drive an LED, see page 5.1.2 of
- //! the reference manaual for an explanation. This is not an issue on the blue pill.
- //! This example assumes that a LED is connected to PC13 which is where an LED is connected on the
- //! [blue_pill] board. If you have different hardware, you need to change which gpio pin is used.
- //!
- //! Note: PC13 can not source much current and should not be used to drive an LED directly.
- //!
- //! [blue_pill]: http://wiki.stm32duino.com/index.php?title=Blue_Pill
- #![deny(unsafe_code)]
- #![deny(warnings)]
- #![no_std]
- #![no_main]
- extern crate panic_halt;
- use nb::block;
- use stm32f1xx_hal::{
- prelude::*,
- pac,
- timer::Timer,
- };
- use cortex_m_rt::entry;
- #[entry]
- fn main() -> ! {
- // Get access to the core peripherals from the cortex-m crate
- let cp = cortex_m::Peripherals::take().unwrap();
- // Get access to the device specific peripherals from the peripheral access crate
- let dp = pac::Peripherals::take().unwrap();
- // Take ownership over the raw flash and rcc devices and convert them into the corresponding
- // HAL structs
- let mut flash = dp.FLASH.constrain();
- let mut rcc = dp.RCC.constrain();
- // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
- // `clocks`
- let clocks = rcc.cfgr.freeze(&mut flash.acr);
- // Acquire the GPIOC peripheral
- let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
- // Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
- // in order to configure the port. For pins 0-7, crl should be passed instead.
- let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
- // Configure the syst timer to trigger an update every second
- let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
- // Wait for the timer to trigger an update and change the state of the LED
- loop {
- block!(timer.wait()).unwrap();
- led.set_high();
- block!(timer.wait()).unwrap();
- led.set_low();
- }
- }
|