Files
embedded-rs/src/main.rs
2025-10-16 22:57:16 +02:00

52 lines
1.6 KiB
Rust

#![no_std]
#![no_main]
// 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 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 {
while !systick.has_wrapped() {}
enabled = !enabled;
gpioe.odr().write(|w| {
w.odr8()
.bit(enabled)
.odr9()
.bit(enabled)
.odr10()
.bit(enabled)
});
}
}