From e032084a6c12933c4aac7f18b56fce328a94df3c Mon Sep 17 00:00:00 2001 From: Levi Pearson Date: Sat, 26 Feb 2022 23:21:54 -0700 Subject: [PATCH] Update to STM32F1xx HAL 0.8 and Rust 2021 --- Cargo.toml | 30 +++++++++++++----------------- src/main.rs | 17 ++++++----------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 35fcfc3..f88f913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,27 +4,23 @@ version = "0.1.0" authors = ["Levi Pearson "] description = "Base binary crate for STM32F103 Blue Pill boards" categories = ["embedded", "no-std"] -edition = "2018" +edition = "2021" [dependencies] -cortex-m = "0.6.2" -cortex-m-rt = "0.6.12" -#cortex-m-semihosting = "0.3.5" -# alternate panic impls, choose only one! -#panic-halt = "0.2.0" -#panic-semihosting = "0.5.3" # requires cortex-m-semihosting -#panic-itm = "0.4.1" -#panic-abort = "0.3.2" -#panic-ramdump = "0.1.1" -#panic-persist = "0.2.1" -panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] } +cortex-m = "0.7.4" +cortex-m-rt = "0.7.1" embedded-hal = "0.2.4" nb = "1.0.0" -rtt-target = { version = "0.2.0", features = ["cortex-m"] } - -[dependencies.stm32f1xx-hal] -version = "0.6.1" -features = ["rt", "stm32f103", "medium"] +stm32f1xx-hal = { version = "0.8.0", features = ["rt", "stm32f103", "medium"] } +rtt-target = { version = "0.3.1", features = ["cortex-m"] } +panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] } +# alternate panic impls, choose only one! +# panic-halt +# panic-semihosting # requires cortex-m-semihosting +# panic-itm +# panic-abort +# panic-ramdump +# panic-persist [[bin]] name = "blue_pill_base" diff --git a/src/main.rs b/src/main.rs index fd55b1a..6e53242 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,18 +9,13 @@ #![no_std] #![cfg_attr(not(doc), no_main)] -use rtt_target::{rprintln, rtt_init_print}; use panic_rtt_target as _; +use rtt_target::{rprintln, rtt_init_print}; use nb::block; -use stm32f1xx_hal::{ - prelude::*, - pac, - timer::Timer, -}; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; +use stm32f1xx_hal::{pac, prelude::*, timer::Timer}; #[entry] fn main() -> ! { @@ -34,14 +29,14 @@ fn main() -> ! { // 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(); + let 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); + let mut gpioc = dp.GPIOC.split(); // 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. @@ -54,9 +49,9 @@ fn main() -> ! { let mut i = 0; loop { block!(timer.wait()).unwrap(); - led.set_high().unwrap(); + led.set_high(); block!(timer.wait()).unwrap(); - led.set_low().unwrap(); + led.set_low(); i += 1; rprintln!("Hello again; I have blinked {} times.", i); if i == 10 {