Skip to content

Commit f5b97fd

Browse files
committed
Initial commit with a decent set of working code and examples
Signed-off-by: Daniel Egger <[email protected]>
0 parents  commit f5b97fd

13 files changed

+1910
-0
lines changed

.cargo/config

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.thumbv7em-none-eabihf]
2+
runner = 'arm-none-eabi-gdb'
3+
rustflags = [
4+
"-C", "link-arg=-Tlink.x",
5+
"-C", "linker=arm-none-eabi-ld",
6+
"-Z", "linker-flavor=ld",
7+
#"--emit=asm",
8+
]
9+
10+
[build]
11+
target = "thumbv7em-none-eabihf"

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
**/*.orig
3+
**/*.rs.bk
4+
Cargo.lock

Cargo.toml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[package]
2+
authors = ["Daniel Egger <[email protected]>"]
3+
categories = [
4+
"embedded",
5+
"hardware-support",
6+
"no-std",
7+
]
8+
description = "Peripheral access API for STM32F4 series microcontrollers"
9+
documentation = "https://docs.rs/stm32f4xx-hal"
10+
keywords = [
11+
"arm",
12+
"cortex-m",
13+
"stm32f4xx",
14+
"hal",
15+
]
16+
license = "0BSD"
17+
name = "stm32f4xx-hal"
18+
repository = "https://github.com/therealprof/stm32f4xx-hal"
19+
version = "0.1.0"
20+
21+
[dependencies]
22+
cortex-m = "0.5.7"
23+
cortex-m-rt = "0.6.3"
24+
nb = "0.1.1"
25+
26+
[dependencies.bare-metal]
27+
version = "0.2.3"
28+
features = ["const-fn"]
29+
30+
[dependencies.cast]
31+
default-features = false
32+
version = "0.2.2"
33+
34+
[dependencies.embedded-hal]
35+
features = ["unproven"]
36+
version = "0.2.1"
37+
38+
[dependencies.stm32f4]
39+
features = [
40+
"rt",
41+
]
42+
version = "0.2.3"
43+
44+
[features]
45+
default = ["rt", "stm32f407"]
46+
rt = []
47+
stm32f407 = ["stm32f4/stm32f407"]
48+
stm32f429 = ["stm32f4/stm32f429"]
49+
50+
[profile.dev]
51+
debug = true
52+
lto = true
53+
54+
[profile.release]
55+
debug = true
56+
lto = true
57+
opt-level = "s"

LICENSE-0BSD.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (C) 2018 [email protected]
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted.
5+
6+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
9+
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
12+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
stm32f4xx-hal
2+
=============
3+
4+
_stm32f4xx-hal_ contains a multi device hardware abstraction on top of the
5+
peripheral access API for the STMicro STM32F4 series microcontrollers. The
6+
selection of the MCU is done by feature gates, typically specified by board
7+
support crates. Currently supported configurations are:
8+
9+
* stm32f407
10+
* stm32f429
11+
12+
The idea behind this crate is to gloss over the slight differences in the
13+
various peripherals available on those MCUs so a HAL can be written for all
14+
chips in that same family without having to cut and paste crates for every
15+
single model.
16+
17+
Collaboration on this crate is highly welcome as are pull requests!
18+
19+
This crate relies on Adam Greigs fantastic [stm32f4][] crate to provide
20+
appropriate register definitions and implements a partial set of the
21+
[embedded-hal][] traits.
22+
23+
Some of the implementation was shamelessly adapted from the [stm32f103xx-hal][]
24+
crate by Jorge Aparicio.
25+
26+
[stm32f4]: https://crates.io/crates/stm32f4
27+
[stm32f103xx-hal]: https://github.com/japaric/stm32f103xx-hal
28+
[embedded-hal]: https://github.com/japaric/embedded-hal.git
29+
30+
License
31+
-------
32+
33+
[0-clause BSD license](LICENSE-0BSD.txt).

src/delay.rs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//! Delays
2+
3+
use cast::u32;
4+
use cortex_m::peripheral::syst::SystClkSource;
5+
use cortex_m::peripheral::SYST;
6+
7+
use hal::blocking::delay::{DelayMs, DelayUs};
8+
use rcc::Clocks;
9+
10+
/// System timer (SysTick) as a delay provider
11+
pub struct Delay {
12+
clocks: Clocks,
13+
syst: SYST,
14+
}
15+
16+
impl Delay {
17+
/// Configures the system timer (SysTick) as a delay provider
18+
pub fn new(mut syst: SYST, clocks: Clocks) -> Self {
19+
syst.set_clock_source(SystClkSource::External);
20+
21+
Delay { syst, clocks }
22+
}
23+
24+
/// Releases the system timer (SysTick) resource
25+
pub fn free(self) -> SYST {
26+
self.syst
27+
}
28+
}
29+
30+
impl DelayMs<u32> for Delay {
31+
fn delay_ms(&mut self, ms: u32) {
32+
self.delay_us(ms * 1_000);
33+
}
34+
}
35+
36+
impl DelayMs<u16> for Delay {
37+
fn delay_ms(&mut self, ms: u16) {
38+
self.delay_ms(u32(ms));
39+
}
40+
}
41+
42+
impl DelayMs<u8> for Delay {
43+
fn delay_ms(&mut self, ms: u8) {
44+
self.delay_ms(u32(ms));
45+
}
46+
}
47+
48+
impl DelayUs<u32> for Delay {
49+
fn delay_us(&mut self, us: u32) {
50+
let rvr = us * (self.clocks.hclk().0 / 8_000_000);
51+
52+
assert!(rvr < (1 << 24));
53+
54+
self.syst.set_reload(rvr);
55+
self.syst.clear_current();
56+
self.syst.enable_counter();
57+
58+
while !self.syst.has_wrapped() {}
59+
60+
self.syst.disable_counter();
61+
}
62+
}
63+
64+
impl DelayUs<u16> for Delay {
65+
fn delay_us(&mut self, us: u16) {
66+
self.delay_us(u32(us))
67+
}
68+
}
69+
70+
impl DelayUs<u8> for Delay {
71+
fn delay_us(&mut self, us: u8) {
72+
self.delay_us(u32(us))
73+
}
74+
}

0 commit comments

Comments
 (0)