HALified blinky

This commit is contained in:
2025-10-17 07:33:36 +02:00
parent 34b11fb262
commit 6e1c5370ba
2 changed files with 21 additions and 23 deletions

View File

@@ -10,7 +10,8 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7" cortex-m-rt = "0.7"
cortex-m-semihosting = "0.5" cortex-m-semihosting = "0.5"
panic-halt = "1.0.0" panic-halt = "1.0.0"
# stm32f3 = "0.7.1" stm32f3 = { version = "0.16.0", features = ["stm32f303"] }
stm32f3xx-hal = { version = "0.10.0", features = ["stm32f303xc"] }
# Uncomment for the panic example. # Uncomment for the panic example.
# panic-itm = "0.4.1" # panic-itm = "0.4.1"
@@ -21,9 +22,9 @@ panic-halt = "1.0.0"
# Uncomment for the device example. # Uncomment for the device example.
# Update `memory.x`, set target to `thumbv7em-none-eabihf` in `.cargo/config`, # Update `memory.x`, set target to `thumbv7em-none-eabihf` in `.cargo/config`,
# and then use `cargo build --example device` to build it. # and then use `cargo build --example device` to build it.
[dependencies.stm32f3] # [dependencies.stm32f3]
features = ["stm32f303", "rt"] # features = ["stm32f303", "rt"]
version = "^0.16.0" # version = "^0.16.0"
# this lets you use `cargo fix`! # this lets you use `cargo fix`!
[[bin]] [[bin]]

View File

@@ -10,7 +10,7 @@ use panic_halt as _; // you can put a breakpoint on `rust_begin_unwind` to catch
use cortex_m::peripheral::{syst, Peripherals}; use cortex_m::peripheral::{syst, Peripherals};
use cortex_m_rt::entry; use cortex_m_rt::entry;
use stm32f3::stm32f303; use stm32f3xx_hal::{self as hal, pac, prelude::*};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@@ -19,33 +19,30 @@ fn main() -> ! {
systick.set_clock_source(syst::SystClkSource::Core); systick.set_clock_source(syst::SystClkSource::Core);
systick.set_reload(8_000_000); // 1s systick.set_reload(8_000_000); // 1s
systick.clear_current(); systick.clear_current();
let dp = pac::Peripherals::take().unwrap();
let mut rcc = dp.RCC.constrain();
let device_peripherals = stm32f303::Peripherals::take().unwrap();
let rcc = device_peripherals.RCC;
rcc.ahbenr().write(|w| w.iopeen().set_bit());
// PE9: LD3 (red) // PE9: LD3 (red)
// PE8: LD4 (blue) // PE8: LD4 (blue)
// PE10: LD5 (orange) // PE10: LD5 (orange)
let gpioe = device_peripherals.GPIOE; let mut gpioe = dp.GPIOE.split(&mut rcc.ahb);
gpioe let mut ld3 = gpioe
.moder() .pe9
.write(|w| w.moder9().output().moder8().output().moder10().output()); .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
gpioe.bsrr().write(|w| w.bs9().set_bit()); let mut ld4 = gpioe
gpioe.bsrr().write(|w| w.bs8().set_bit()); .pe8
gpioe.bsrr().write(|w| w.bs10().set_bit()); .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
let mut ld5 = gpioe
.pe10
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
systick.enable_counter(); systick.enable_counter();
let mut enabled = true; let mut enabled = true;
loop { loop {
while !systick.has_wrapped() {} while !systick.has_wrapped() {}
enabled = !enabled; enabled = !enabled;
gpioe.odr().write(|w| { ld3.toggle().unwrap();
w.odr8() ld4.toggle().unwrap();
.bit(enabled) ld5.toggle().unwrap();
.odr9()
.bit(enabled)
.odr10()
.bit(enabled)
});
} }
} }