49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
|
#![deny(unsafe_code)]
|
||
|
#![no_std]
|
||
|
#![no_main]
|
||
|
|
||
|
extern crate panic_semihosting;
|
||
|
|
||
|
use cortex_m_rt::entry;
|
||
|
use embedded_hal::digital::v2::OutputPin;
|
||
|
use rtt_target::{rprintln, rtt_init_print};
|
||
|
use stm32f1xx_hal::{delay::Delay, pac, prelude::*};
|
||
|
|
||
|
#[entry]
|
||
|
fn main() -> ! {
|
||
|
rtt_init_print!();
|
||
|
|
||
|
// 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);
|
||
|
|
||
|
let mut delay = Delay::new(cp.SYST, clocks);
|
||
|
|
||
|
// Blink using the delay function
|
||
|
loop {
|
||
|
rprintln!("blink");
|
||
|
led.set_high().unwrap();
|
||
|
delay.delay_ms(1000u16);
|
||
|
rprintln!("blonk");
|
||
|
led.set_low().unwrap();
|
||
|
delay.delay_ms(1000u16);
|
||
|
}
|
||
|
}
|