Updated to newest embedded hal version

This commit is contained in:
Sebastian 2020-04-19 18:02:31 +02:00
parent 9f55b6dc08
commit b2f80a8da2
6 changed files with 33 additions and 70 deletions

View File

@ -1,33 +1,9 @@
[target.thumbv7m-none-eabi] [target.thumbv7m-none-eabi]
# uncomment this to make `cargo run` execute programs on QEMU runner = "arm-none-eabi-gdb -q -x openocd.gdb"
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# uncomment ONE of these three option to make `cargo run` start a GDB session
# which option to pick depends on your system
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
# runner = "gdb-multiarch -q -x openocd.gdb"
# runner = "gdb -q -x openocd.gdb"
rustflags = [ rustflags = [
# LLD (shipped with the Rust toolchain) is used as the default linker "-C", "linker=rust-lld",
"-C", "link-arg=-Tlink.x", "-C", "link-arg=-Tlink.x",
# if you run into problems with LLD switch to the GNU linker by commenting out
# this line
# "-C", "linker=arm-none-eabi-ld",
# if you need to link to pre-compiled C libraries provided by a C toolchain
# use GCC as the linker by commenting out both lines above and then
# uncommenting the three lines below
# "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles",
] ]
[build] [build]
# Pick ONE of these compilation targets target = "thumbv7m-none-eabi"
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

View File

@ -2,32 +2,20 @@
authors = ["sebastian"] authors = ["sebastian"]
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"
name = "STM32F1Test" name = "stm32_f1_blinky"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
cortex-m = "0.6.0" cortex-m = "0.6"
cortex-m-rt = "0.6.8" cortex-m-rt = "0.6"
cortex-m-semihosting = "0.3.2" stm32f1xx-hal = { version = "0.5.3", features = ["stm32f103", "stm32-usbd", "rt"] }
panic-halt = "0.2.0" panic-semihosting = "0.5"
nb = "0.1.2" embedded-hal = "0.2.3"
[dependencies.stm32f1]
version = "0.8.0"
features = ["stm32f103"]
[dependencies.stm32f1xx-hal]
version = "0.4.0"
features = ["stm32f103", "rt"]
[dependencies.embedded-hal]
version = "0.2.3"
features = ["unproven"]
# this lets you use `cargo fix`! # this lets you use `cargo fix`!
[[bin]] [[bin]]
name = "STM32F1Test" name = "stm32_f1_blinky"
test = false test = false
bench = false bench = false

View File

@ -1,18 +1,15 @@
use std::env; use std::env;
use std::fs::File; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
fn main() { fn main() {
// Put the linker script somewhere the linker can find it // Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
File::create(out.join("memory.x")) fs::File::create(out_dir.join("memory.x"))
.unwrap() .unwrap()
.write_all(include_bytes!("memory.x")) .write_all(include_bytes!("memory.x"))
.unwrap(); .unwrap();
println!("cargo:rustc-link-search={}", out.display()); println!("cargo:rustc-link-search={}", out_dir.display());
// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=memory.x"); println!("cargo:rerun-if-changed=memory.x");
} }

11
openocd.gdb Normal file
View File

@ -0,0 +1,11 @@
set history save on
set confirm off
target extended-remote :3333
set print asm-demangle on
monitor arm semihosting enable
monitor reset halt
load
# monitor verify
# monitor reset
# quit
continue

3
run.sh
View File

@ -1,3 +0,0 @@
#!/bin/bash
cargo build || exit -1
arm-none-eabi-gdb target/thumbv7m-none-eabi/debug/STM32F1Test

View File

@ -1,22 +1,15 @@
//! Blinks an LED
//!
//! This assumes that a LED is connected to pc13 as is the case on the blue pill board.
//!
//! Note: Without additional hardware, PC13 should not be used to drive an LED, see page 5.1.2 of
//! the reference manaual for an explanation. This is not an issue on the blue pill.
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![no_std] #![no_std]
#![no_main] #![no_main]
use panic_halt as _;
use nb::block; extern crate panic_semihosting;
use stm32f1xx_hal::{ use stm32f1xx_hal::{
prelude::*, prelude::*,
pac, pac,
timer::Timer, delay::Delay,
}; };
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
@ -43,14 +36,15 @@ fn main() -> ! {
// 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.
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
let mut delay = Delay::new(cp.SYST, clocks);
// Wait for the timer to trigger an update and change the state of the LED // Wait for the timer to trigger an update and change the state of the LED
loop { loop {
block!(timer.wait()).unwrap();
led.set_high().unwrap(); led.set_high().unwrap();
block!(timer.wait()).unwrap(); delay.delay_ms(1000u16);
led.set_low().unwrap(); led.set_low().unwrap();
delay.delay_ms(1000u16);
} }
} }