From 6e1c5370bacf1d0f5fe244062fdd0d222e8788e0 Mon Sep 17 00:00:00 2001 From: jazzpi Date: Fri, 17 Oct 2025 07:33:36 +0200 Subject: [PATCH] HALified blinky --- Cargo.toml | 9 +++++---- src/main.rs | 35 ++++++++++++++++------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5921776..83f1823 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7" cortex-m-semihosting = "0.5" 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. # panic-itm = "0.4.1" @@ -21,9 +22,9 @@ panic-halt = "1.0.0" # Uncomment for the device example. # Update `memory.x`, set target to `thumbv7em-none-eabihf` in `.cargo/config`, # and then use `cargo build --example device` to build it. -[dependencies.stm32f3] -features = ["stm32f303", "rt"] -version = "^0.16.0" +# [dependencies.stm32f3] +# features = ["stm32f303", "rt"] +# version = "^0.16.0" # this lets you use `cargo fix`! [[bin]] diff --git a/src/main.rs b/src/main.rs index b00b42f..588522d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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_rt::entry; -use stm32f3::stm32f303; +use stm32f3xx_hal::{self as hal, pac, prelude::*}; #[entry] fn main() -> ! { @@ -19,33 +19,30 @@ fn main() -> ! { systick.set_clock_source(syst::SystClkSource::Core); systick.set_reload(8_000_000); // 1s 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) // 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()); + let mut gpioe = dp.GPIOE.split(&mut rcc.ahb); + let mut ld3 = gpioe + .pe9 + .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper); + let mut ld4 = gpioe + .pe8 + .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(); 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) - }); + ld3.toggle().unwrap(); + ld4.toggle().unwrap(); + ld5.toggle().unwrap(); } }