Blinky STM32F3-DISCOVERY
This commit is contained in:
42
src/main.rs
42
src/main.rs
@@ -3,15 +3,49 @@
|
||||
|
||||
// pick a panicking behavior
|
||||
use panic_halt as _; // you can put a breakpoint on `rust_begin_unwind` to catch panics
|
||||
// use panic_abort as _; // requires nightly
|
||||
// use panic_itm as _; // logs messages over ITM; requires ITM support
|
||||
// use panic_semihosting as _; // logs messages to the host stderr; requires a debugger
|
||||
// use panic_abort as _; // requires nightly
|
||||
// use panic_itm as _; // logs messages over ITM; requires ITM support
|
||||
// use panic_semihosting as _; // logs messages to the host stderr; requires a debugger
|
||||
|
||||
use cortex_m::peripheral::{syst, Peripherals};
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
use stm32f3::stm32f303;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let cortex_peripherals = Peripherals::take().unwrap();
|
||||
let mut systick = cortex_peripherals.SYST;
|
||||
systick.set_clock_source(syst::SystClkSource::Core);
|
||||
systick.set_reload(8_000_000); // 1s
|
||||
systick.clear_current();
|
||||
|
||||
let device_peripherals = stm32f303::Peripherals::take().unwrap();
|
||||
let rcc = device_peripherals.RCC;
|
||||
rcc.ahbenr().write(|w| w.iopeen().set_bit());
|
||||
// PE9: LD3 (red)
|
||||
// PE8: LD4 (blue)
|
||||
// PE10: LD5 (orange)
|
||||
let gpioe = device_peripherals.GPIOE;
|
||||
gpioe
|
||||
.moder()
|
||||
.write(|w| w.moder9().output().moder8().output().moder10().output());
|
||||
gpioe.bsrr().write(|w| w.bs9().set_bit());
|
||||
gpioe.bsrr().write(|w| w.bs8().set_bit());
|
||||
gpioe.bsrr().write(|w| w.bs10().set_bit());
|
||||
|
||||
systick.enable_counter();
|
||||
let mut enabled = true;
|
||||
loop {
|
||||
// your code goes here
|
||||
while !systick.has_wrapped() {}
|
||||
enabled = !enabled;
|
||||
gpioe.odr().write(|w| {
|
||||
w.odr8()
|
||||
.bit(enabled)
|
||||
.odr9()
|
||||
.bit(enabled)
|
||||
.odr10()
|
||||
.bit(enabled)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user