rust-stm32-blinky/src/main.rs

51 lines
1.4 KiB
Rust
Raw Normal View History

2019-08-22 17:10:35 +02:00
#![deny(unsafe_code)]
2019-05-11 15:32:38 +02:00
#![no_std]
#![no_main]
2020-04-19 18:02:31 +02:00
extern crate panic_semihosting;
2019-08-22 17:10:35 +02:00
use stm32f1xx_hal::{
prelude::*,
pac,
2020-04-19 18:02:31 +02:00
delay::Delay,
2019-08-22 17:10:35 +02:00
};
2019-05-11 15:32:38 +02:00
use cortex_m_rt::entry;
2019-08-22 17:10:35 +02:00
use embedded_hal::digital::v2::OutputPin;
2019-05-11 15:32:38 +02:00
#[entry]
fn main() -> ! {
2019-08-22 17:10:35 +02:00
// 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);
2020-04-19 18:02:31 +02:00
let mut delay = Delay::new(cp.SYST, clocks);
2019-08-22 17:10:35 +02:00
// Wait for the timer to trigger an update and change the state of the LED
loop {
led.set_high().unwrap();
2020-04-19 18:02:31 +02:00
delay.delay_ms(1000u16);
2019-08-22 17:10:35 +02:00
led.set_low().unwrap();
2020-04-19 18:02:31 +02:00
delay.delay_ms(1000u16);
2019-05-11 15:32:38 +02:00
}
}