Update to STM32F1xx HAL 0.8 and Rust 2021

master
Levi Pearson 2022-02-26 23:21:54 -07:00
parent cd0858873c
commit e032084a6c
2 changed files with 19 additions and 28 deletions

View File

@ -4,27 +4,23 @@ version = "0.1.0"
authors = ["Levi Pearson <levipearson@gmail.com>"] authors = ["Levi Pearson <levipearson@gmail.com>"]
description = "Base binary crate for STM32F103 Blue Pill boards" description = "Base binary crate for STM32F103 Blue Pill boards"
categories = ["embedded", "no-std"] categories = ["embedded", "no-std"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
cortex-m = "0.6.2" cortex-m = "0.7.4"
cortex-m-rt = "0.6.12" cortex-m-rt = "0.7.1"
#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"] }
embedded-hal = "0.2.4" embedded-hal = "0.2.4"
nb = "1.0.0" nb = "1.0.0"
rtt-target = { version = "0.2.0", features = ["cortex-m"] } stm32f1xx-hal = { version = "0.8.0", features = ["rt", "stm32f103", "medium"] }
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
[dependencies.stm32f1xx-hal] panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] }
version = "0.6.1" # alternate panic impls, choose only one!
features = ["rt", "stm32f103", "medium"] # panic-halt
# panic-semihosting # requires cortex-m-semihosting
# panic-itm
# panic-abort
# panic-ramdump
# panic-persist
[[bin]] [[bin]]
name = "blue_pill_base" name = "blue_pill_base"

View File

@ -9,18 +9,13 @@
#![no_std] #![no_std]
#![cfg_attr(not(doc), no_main)] #![cfg_attr(not(doc), no_main)]
use rtt_target::{rprintln, rtt_init_print};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use nb::block; use nb::block;
use stm32f1xx_hal::{
prelude::*,
pac,
timer::Timer,
};
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@ -34,14 +29,14 @@ fn main() -> ! {
// Take ownership over the raw flash and rcc devices and convert them into the corresponding // Take ownership over the raw flash and rcc devices and convert them into the corresponding
// HAL structs // HAL structs
let mut flash = dp.FLASH.constrain(); 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 // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
// `clocks` // `clocks`
let clocks = rcc.cfgr.freeze(&mut flash.acr); let clocks = rcc.cfgr.freeze(&mut flash.acr);
// Acquire the GPIOC peripheral // 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 // 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. // 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; let mut i = 0;
loop { loop {
block!(timer.wait()).unwrap(); block!(timer.wait()).unwrap();
led.set_high().unwrap(); led.set_high();
block!(timer.wait()).unwrap(); block!(timer.wait()).unwrap();
led.set_low().unwrap(); led.set_low();
i += 1; i += 1;
rprintln!("Hello again; I have blinked {} times.", i); rprintln!("Hello again; I have blinked {} times.", i);
if i == 10 { if i == 10 {