1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //! 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.
- #![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() -> ! {
- let cp = cortex_m::Peripherals::take().unwrap();
- let dp = pac::Peripherals::take().unwrap();
- let mut flash = dp.FLASH.constrain();
- let mut rcc = dp.RCC.constrain();
- // Try a different clock configuration
- let clocks = rcc.cfgr.freeze(&mut flash.acr);
- // let clocks = rcc.cfgr
- // .sysclk(64.mhz())
- // .pclk1(32.mhz())
- // .freeze(&mut flash.acr);
- let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
- let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
- // Try a different timer (even SYST)
- let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
- loop {
- block!(timer.wait()).unwrap();
- led.set_high();
- block!(timer.wait()).unwrap();
- led.set_low();
- }
- }
|