Skip to content

Commit

Permalink
Initial commit with a decent set of working code and examples
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
  • Loading branch information
therealprof committed Oct 1, 2018
0 parents commit f5b97fd
Show file tree
Hide file tree
Showing 13 changed files with 1,910 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .cargo/config
@@ -0,0 +1,11 @@
[target.thumbv7em-none-eabihf]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=arm-none-eabi-ld",
"-Z", "linker-flavor=ld",
#"--emit=asm",
]

[build]
target = "thumbv7em-none-eabihf"
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
/target/
**/*.orig
**/*.rs.bk
Cargo.lock
57 changes: 57 additions & 0 deletions Cargo.toml
@@ -0,0 +1,57 @@
[package]
authors = ["Daniel Egger <daniel@eggers-club.de>"]
categories = [
"embedded",
"hardware-support",
"no-std",
]
description = "Peripheral access API for STM32F4 series microcontrollers"
documentation = "https://docs.rs/stm32f4xx-hal"
keywords = [
"arm",
"cortex-m",
"stm32f4xx",
"hal",
]
license = "0BSD"
name = "stm32f4xx-hal"
repository = "https://github.com/therealprof/stm32f4xx-hal"
version = "0.1.0"

[dependencies]
cortex-m = "0.5.7"
cortex-m-rt = "0.6.3"
nb = "0.1.1"

[dependencies.bare-metal]
version = "0.2.3"
features = ["const-fn"]

[dependencies.cast]
default-features = false
version = "0.2.2"

[dependencies.embedded-hal]
features = ["unproven"]
version = "0.2.1"

[dependencies.stm32f4]
features = [
"rt",
]
version = "0.2.3"

[features]
default = ["rt", "stm32f407"]
rt = []
stm32f407 = ["stm32f4/stm32f407"]
stm32f429 = ["stm32f4/stm32f429"]

[profile.dev]
debug = true
lto = true

[profile.release]
debug = true
lto = true
opt-level = "s"
12 changes: 12 additions & 0 deletions LICENSE-0BSD.txt
@@ -0,0 +1,12 @@
Copyright (C) 2018 daniel@eggers-club.de

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
@@ -0,0 +1,33 @@
stm32f4xx-hal
=============

_stm32f4xx-hal_ contains a multi device hardware abstraction on top of the
peripheral access API for the STMicro STM32F4 series microcontrollers. The
selection of the MCU is done by feature gates, typically specified by board
support crates. Currently supported configurations are:

* stm32f407
* stm32f429

The idea behind this crate is to gloss over the slight differences in the
various peripherals available on those MCUs so a HAL can be written for all
chips in that same family without having to cut and paste crates for every
single model.

Collaboration on this crate is highly welcome as are pull requests!

This crate relies on Adam Greigs fantastic [stm32f4][] crate to provide
appropriate register definitions and implements a partial set of the
[embedded-hal][] traits.

Some of the implementation was shamelessly adapted from the [stm32f103xx-hal][]
crate by Jorge Aparicio.

[stm32f4]: https://crates.io/crates/stm32f4
[stm32f103xx-hal]: https://github.com/japaric/stm32f103xx-hal
[embedded-hal]: https://github.com/japaric/embedded-hal.git

License
-------

[0-clause BSD license](LICENSE-0BSD.txt).
74 changes: 74 additions & 0 deletions src/delay.rs
@@ -0,0 +1,74 @@
//! Delays

use cast::u32;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;

use hal::blocking::delay::{DelayMs, DelayUs};
use rcc::Clocks;

/// System timer (SysTick) as a delay provider
pub struct Delay {
clocks: Clocks,
syst: SYST,
}

impl Delay {
/// Configures the system timer (SysTick) as a delay provider
pub fn new(mut syst: SYST, clocks: Clocks) -> Self {
syst.set_clock_source(SystClkSource::External);

Delay { syst, clocks }
}

/// Releases the system timer (SysTick) resource
pub fn free(self) -> SYST {
self.syst
}
}

impl DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
self.delay_us(ms * 1_000);
}
}

impl DelayMs<u16> for Delay {
fn delay_ms(&mut self, ms: u16) {
self.delay_ms(u32(ms));
}
}

impl DelayMs<u8> for Delay {
fn delay_ms(&mut self, ms: u8) {
self.delay_ms(u32(ms));
}
}

impl DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
let rvr = us * (self.clocks.hclk().0 / 8_000_000);

assert!(rvr < (1 << 24));

self.syst.set_reload(rvr);
self.syst.clear_current();
self.syst.enable_counter();

while !self.syst.has_wrapped() {}

self.syst.disable_counter();
}
}

impl DelayUs<u16> for Delay {
fn delay_us(&mut self, us: u16) {
self.delay_us(u32(us))
}
}

impl DelayUs<u8> for Delay {
fn delay_us(&mut self, us: u8) {
self.delay_us(u32(us))
}
}

0 comments on commit f5b97fd

Please sign in to comment.